How to Use the testsrc Filter in FFmpeg
This guide explains how to use the testsrc video source
filter in FFmpeg to generate test patterns and placeholder videos. You
will learn the basic command syntax, how to customize video properties
like resolution, frame rate, and duration, and how to output these
synthetic streams for testing your media workflows.
Understanding the testsrc Filter
The testsrc filter is part of FFmpeg’s
lavfi (Libavfilter) virtual input device. It generates a
synthetic video stream showing a color test pattern with a scrolling
color bar, a timestamp, and a ticking clock. This is highly useful for
benchmarking, testing streaming configurations, or creating placeholder
videos without needing a physical input file.
Basic Syntax
To use testsrc, you must specify the lavfi
format using the -f flag and pass the filter name as the
input (-i).
The most basic command to generate a test video is:
ffmpeg -f lavfi -i testsrc -t 10 output.mp4In this command: * -f lavfi tells FFmpeg to use the
Libreavfilter virtual input device. * -i testsrc specifies
the testsrc filter as the input source. *
-t 10 limits the output duration to 10 seconds (without
this, FFmpeg will generate the video indefinitely). *
output.mp4 is the destination file.
By default, this command generates a video with a resolution of 320x240 pixels at 25 frames per second (fps).
Customizing Resolution and Frame Rate
You can configure the properties of the generated video by passing
parameters directly to the testsrc filter. Parameters are
separated from the filter name by an equals sign (=) and
from each other by colons (:).
Changing Resolution
To change the resolution, use the size (or
s) parameter:
ffmpeg -f lavfi -i testsrc=size=1920x1080 -t 5 output_1080p.mp4You can also use common abbreviations like hd720 or
hd1080:
ffmpeg -f lavfi -i testsrc=size=hd720 -t 5 output_720p.mp4Changing Frame Rate
To change the frame rate, use the rate (or
r) parameter:
ffmpeg -f lavfi -i testsrc=rate=60 -t 5 output_60fps.mp4Combining Parameters
To customize both resolution and frame rate simultaneously, combine them with a colon:
ffmpeg -f lavfi -i testsrc=size=1280x720:rate=30 -t 10 output_720p_30fps.mp4Adding Audio to the Test Video
The testsrc filter only generates a video stream. If you
need an audio track for your test, you can combine testsrc
with the sine audio filter:
ffmpeg -f lavfi -i testsrc=size=1280x720:rate=30 -f lavfi -i sine=frequency=1000 -t 5 -c:v libx264 -c:a aac output_with_audio.mp4This command generates a 720p, 30fps video accompanied by a continuous 1000Hz audio beep for 5 seconds.