Generate Test Patterns with FFmpeg mptestsrc
This article explains how to use FFmpeg’s mptestsrc
filter to generate standardized video test patterns. You will learn the
basic command syntax, key parameters for customizing the video output,
and how to use these generated patterns to evaluate and benchmark video
encoders.
Understanding mptestsrc
The mptestsrc source filter generates a video pattern
designed specifically for testing motion picture encoders. Unlike static
test cards, mptestsrc produces a dynamic pattern containing
various shapes, moving blocks, and color gradients. This complexity is
ideal for stressing video encoders, allowing you to analyze how
algorithms handle motion estimation, macroblock allocation, color
preservation, and compression artifacts.
Basic Command Syntax
To generate a default test video using mptestsrc, use
the Libavfilter virtual input device (-f lavfi). The
following command generates a 10-second video encoded with H.264:
ffmpeg -f lavfi -i mptestsrc=duration=10 -c:v libx264 -pix_fmt yuv420p output.mp4In this command: * -f lavfi specifies the Libavfilter
input virtual device. * -i mptestsrc=duration=10 calls the
filter and sets the output duration to 10 seconds. *
-c:v libx264 encodes the output using the x264 library. *
-pix_fmt yuv420p ensures maximum compatibility with
standard media players.
Customizing the Test Pattern
You can customize the output of the mptestsrc filter by
passing specific parameters. The most common parameters include:
- rate, r: Sets the frame rate (default is 25 fps).
- duration, d: Sets the duration of the generated video.
- max_scnt: Sets the maximum number of screen counts, which changes the frequency of the test pattern variations.
To generate a 60 fps video lasting 5 seconds, use:
ffmpeg -f lavfi -i mptestsrc=r=60:d=5 -c:v libx265 -pix_fmt yuv420p x265_test.mp4Evaluating Video Encoding Performance
The dynamic elements within the mptestsrc pattern make
it an excellent tool for comparative encoding evaluations:
- Bitrate Control and Quality: Encode the pattern at different constant rate factors (CRF) or target bitrates. Analyze how the fine details and gradients in the pattern degrade under low-bitrate constraints.
- Deblocking Filter Performance: The sharp edges of the moving blocks will highlight the effectiveness of an encoder’s deblocking filter.
- Motion Estimation: Because the patterns move at
predictable intervals, you can compare how different encoders (or preset
speeds like
fastvs.verytop) handle motion vector calculations without the unpredictable noise of real-world camera footage.