Generate Gradient Test Pattern Using FFmpeg testsrc2
This article explains how to use the FFmpeg testsrc2
source filter to generate a high-quality video test pattern that
features a color gradient. You will learn the basic command structure,
how to customize the video’s resolution, frame rate, and duration, and
how to export the final file in your desired format.
The Basic Command
The testsrc2 filter is part of FFmpeg’s
lavfi (Libavfilter) virtual input device. It generates a
modern test pattern containing a color wheel, gradient bands, binary
counters, and scrolling text.
To generate a default 10-second test pattern at 30 frames per second, use the following command:
ffmpeg -f lavfi -i testsrc2 -t 10 output.mp4Customizing Resolution, Frame Rate, and Duration
You can pass specific parameters directly to the
testsrc2 filter to customize the output to fit your project
requirements. The parameters are appended to the filter name, separated
by colons.
Use this command to define custom dimensions, frame rate, and duration:
ffmpeg -f lavfi -i testsrc2=size=1920x1080:rate=60 -t 5 output.mp4Here is a breakdown of the key parameters used in the filter:
size(ors): Sets the resolution of the video (e.g.,1920x1080,1280x720, or3840x2160).rate(orr): Sets the frame rate of the video (e.g.,30,60, or24).-t: Specifies the duration of the output file in seconds (e.g.,-t 5for 5 seconds). Alternatively, you can use thedurationparameter inside the filter itself, liketestsrc2=duration=5.
Exporting to Different Codecs
If you need the test pattern for professional editing or
broadcasting, you can export it using high-quality or lossless codecs
instead of the default H.264 (.mp4).
To export as Apple ProRes 422:
ffmpeg -f lavfi -i testsrc2=size=1920x1080:rate=29.97 -t 10 -c:v prores_ks -profile:v 3 output.movTo export as a lossless H.264 file:
ffmpeg -f lavfi -i testsrc2=size=1920x1080:rate=30 -t 10 -c:v libx264 -crf 0 output.mp4