Generate Moving Pattern Videos with FFmpeg testsrc
This article explains how to use the FFmpeg testsrc
filter to generate synthetic test videos featuring moving patterns. You
will learn the basic command structure, how to customize the video’s
resolution, frame rate, and duration, and how to output the final video
file for testing or troubleshooting purposes.
What is the FFmpeg testsrc Filter?
The testsrc filter is a virtual input device in FFmpeg
(part of the lavfi / Libavfilter library) that generates a
test video pattern. The default pattern includes a color grid, a
scrolling timecode, and a moving graphical indicator, making it ideal
for testing video encoders, streaming configurations, or display devices
without needing an actual video file.
Basic Command Syntax
To generate a basic moving pattern video, use the following FFmpeg command:
ffmpeg -f lavfi -i testsrc -t 10 output.mp4Here is a breakdown of the parameters used in this command: *
-f lavfi: Specifies that the input comes
from the Libavfilter virtual input format. *
-i testsrc: Defines testsrc
as the input source. * -t 10: Sets the
duration of the output video to 10 seconds. *
output.mp4: The output filename and
container format.
Customizing Resolution, Frame Rate, and Duration
You can pass specific parameters directly to the testsrc
filter to customize the output. Parameter key-value pairs are appended
to the filter name, separated by colons.
ffmpeg -f lavfi -i testsrc=size=1920x1080:rate=60:duration=5 output.mp4size(ors): Sets the resolution (e.g.,1920x1080or1280x720).rate(orr): Sets the frame rate (e.g.,30or60).duration(ord): Sets the duration in seconds. Defining this inside the filter arguments allows you to omit the-toption.
Alternative Moving Patterns
If you require different types of moving visual patterns, FFmpeg provides other built-in source filters that function similarly:
testsrc2
This filter generates a modern test pattern containing a moving rainbow bar, a color spectrum, and an updated timer.
ffmpeg -f lavfi -i testsrc2=size=1280x720:rate=30:duration=10 output.mp4mandelbrot
This filter generates an animated, continuously zooming Mandelbrot fractal pattern.
ffmpeg -f lavfi -i mandelbrot=size=1280x720:duration=10 output.mp4