Generate FFmpeg Test Screens with mptestsrc
This article provides a practical guide on how to use the
mptestsrc filter in FFmpeg to generate synthetic test video
streams. You will learn the basic syntax, explore the available
configuration options like frame rate and duration, and see real-world
command examples for rendering test screens directly to a file or a
media player.
The mptestsrc filter is an input source in FFmpeg’s
libavfilter library. It generates a test video pattern that is
particularly useful for testing encoders, analyzing compression
artifacts, and debugging video filters.
Basic Syntax
To use the mptestsrc source, you must specify the
Libavfilter virtual input device (-f lavfi). The simplest
command to generate a test video is:
ffmpeg -f lavfi -i mptestsrc output.mp4This command outputs a default test screen with a resolution of 512x512 pixels at 25 frames per second.
Configuring mptestsrc Parameters
You can customize the output of the mptestsrc filter by
passing parameters separated by colons.
1. Duration (duration or
d)
Specifies the length of the generated video. By default, it runs
indefinitely until stopped. * Example: duration=10 or
d=10 for a 10-second video.
2. Frame Rate (rate or
r)
Sets the frame rate of the generated video. The default is 25 fps. *
Example: rate=30 or r=30 for 30 frames per
second.
3. Test Pattern (test or
t)
Changes the specific test pattern used in the video. Available values
include: * dc_assim (default) * mpeg1 *
it * unaligned * reorder
Practical Command Examples
Example 1: Create a 5-Second Test Video at 30 FPS
To generate a standard 5-second test MP4 file at 30 frames per second, use:
ffmpeg -f lavfi -i mptestsrc=duration=5:rate=30 output.mp4Example 2: Use a Specific Test Pattern
To change the default pattern to the mpeg1 test pattern,
pass the t parameter:
ffmpeg -f lavfi -i mptestsrc=t=mpeg1:d=10 output.mp4Example 3: Previewing the Test Screen Instantly
If you want to view the test pattern in real-time without saving it
to a file, you can use ffplay:
ffplay -f lavfi -i mptestsrc