How to Use the FFmpeg testsrc2 Filter

This article provides a quick guide on how to use the testsrc2 video source filter in FFmpeg to generate synthetic test videos. You will learn the basic command syntax, how to customize parameters such as resolution, frame rate, and duration, and see practical examples for creating test files.

What is the testsrc2 Filter?

The testsrc2 filter is a built-in virtual input device in FFmpeg (part of the lavfi / libavfilter library). Unlike the older testsrc filter, testsrc2 generates a modern, visually detailed test pattern. It includes:

This filter is highly useful for benchmarking encoders, testing streaming setups, and verifying playback configurations without needing actual video files.

Basic Syntax

To use testsrc2, you must declare the input format as lavfi (Libavfilter) using the -f flag.

The simplest command to generate and view the test pattern (using ffplay) is:

ffplay -f lavfi -i testsrc2

To render the default pattern to an MP4 video file, use:

ffmpeg -f lavfi -i testsrc2 -t 10 output.mp4

(Note: The -t 10 option limits the output duration to 10 seconds, as the virtual source will otherwise generate video indefinitely.)

Customizing testsrc2 Parameters

You can customize the output of the testsrc2 filter by passing arguments separated by colons (:). The most common parameters include:

Examples of Custom Commands

1. Generate a 1080p Video at 60 FPS

To create a Full HD (1920x1080) video at 60 frames per second for 5 seconds:

ffmpeg -f lavfi -i testsrc2=size=1920x1080:rate=60:duration=5 output_1080p.mp4

2. Generate a 4K Video at 30 FPS

To create an Ultra HD (3840x2160) video at 30 frames per second for 10 seconds:

ffmpeg -f lavfi -i testsrc2=s=3840x2160:r=30:d=10 output_4k.mp4

3. Stream a Test Pattern via UDP

If you are testing network stream configurations, you can stream the testsrc2 pattern directly to a local UDP port:

ffmpeg -f lavfi -i testsrc2=s=1280x720:r=30 -vcodec libx264 -preset ultrafast -f mpegts udp://127.0.0.1:1234