How to Use the FFmpeg mptestsrc Filter

This article explains how to use the mptestsrc video source filter in FFmpeg to generate test video patterns. You will learn the purpose of the filter, its basic command syntax, key configuration parameters, and practical command-line examples for testing video encoders, decoders, and playback systems.

What is the mptestsrc Filter?

The mptestsrc filter is a built-in virtual input device in FFmpeg (part of the lavfi / libavfilter library). It generates a specialized test video pattern designed for testing various MPEG encoding and decoding features. Unlike the standard testsrc filter which displays a color palette and a timer, mptestsrc generates a sequence of various test patterns including moving blocks, gradients, and noise. This makes it highly useful for analyzing macroblock boundaries, motion estimation, and compression artifacts.

Basic Syntax and Usage

To use mptestsrc, you must specify the format of the input as lavfi (Libavfilter virtual input) using the -f lavfi flag.

The basic command to generate a test video file is:

ffmpeg -f lavfi -i mptestsrc output.mp4

To preview the test pattern in real-time without saving it to a file, you can use ffplay:

ffplay -f lavfi -i mptestsrc

Key Configuration Parameters

You can customize the output of the mptestsrc filter by passing key-value arguments. The syntax for applying arguments is mptestsrc=key1=value1:key2=value2.

Practical Examples

1. Generating a 10-Second Test Video at 30 FPS

To create a 10-second MP4 video file with a frame rate of 30 fps, run the following command:

ffmpeg -f lavfi -i mptestsrc=r=30:d=10 output.mp4

2. Testing Encoder Performance with mptestsrc

Because mptestsrc contains fast-moving patterns and complex textures, it is ideal for testing how different encoders handle motion and compression. The following command pipes the source directly into the x264 encoder with a specific constant rate factor (CRF):

ffmpeg -f lavfi -i mptestsrc=r=60:d=5 -c:v libx264 -crf 23 test_output.mp4

3. Setting Custom Block Alignment

To adjust the block alignment parameter to test specific decoder tolerances, use the max_block_align option:

ffmpeg -f lavfi -i mptestsrc=max_block_align=12:d=5 output.mkv