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.mp4

In 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:

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.mp4

Evaluating Video Encoding Performance

The dynamic elements within the mptestsrc pattern make it an excellent tool for comparative encoding evaluations:

  1. 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.
  2. Deblocking Filter Performance: The sharp edges of the moving blocks will highlight the effectiveness of an encoder’s deblocking filter.
  3. Motion Estimation: Because the patterns move at predictable intervals, you can compare how different encoders (or preset speeds like fast vs. verytop) handle motion vector calculations without the unpredictable noise of real-world camera footage.