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.mp4

Customizing 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.mp4

Here is a breakdown of the key parameters used in the filter:

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.mov

To 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