How to Use FFmpeg mptestsrc for Video Evaluation

The mptestsrc filter in FFmpeg generates synthetic test video sequences originally derived from the MPlayer project, specifically designed to stress video codecs and expose compression artifacts. This guide explains how the mptestsrc filter works, details its core parameters and test patterns, and provides practical command-line examples for evaluating codec performance, edge preservation, color reproduction, and high-frequency retention.

Understanding the mptestsrc Filter

The mptestsrc filter is a built-in libavfilter source that outputs specialized synthetic test frames at a fixed native resolution of 512x512 pixels. Unlike standard test patterns such as color bars, mptestsrc generates sharp geometric shapes, high-frequency spatial patterns, chroma gradients, and circular bands. These structures present challenging scenarios for discrete cosine transform (DCT) and discrete wavelet transform (DWT) algorithms, making flaws such as ringing artifacts, mosquito noise, color banding, and macroblocking immediately visible.

Filter Syntax and Parameters

The basic filter accepts three primary parameters:

  • rate or r: Specifies the output frame rate (default is 25 fps).
  • duration or d: Sets the duration of the generated sequence in seconds.
  • test or t: Determines the specific pattern or cycle of patterns to render.

Available test modes include:

  • all: Cycles through all available test patterns sequentially.
  • dc_luma: Displays solid blocks to verify DC prediction and flat-surface quantizer behavior.
  • ring_1 and ring_2: Produces concentric rings of varying widths to expose ringing artifacts around sharp, curved edges.
  • cbands: Draws color bands to evaluate chroma subsampling quality and color banding.
  • freq: Generates spatial frequency bursts to measure fine detail resolution and cutoff frequencies.
  • zones: Produces zone plates to detect moiré patterns and scaling anomalies.

Basic Usage

To generate a raw or compressed test sequence cycling through all patterns, run the filter via the lavfi virtual device:

ffmpeg -f lavfi -i mptestsrc=rate=30:duration=10 output.mp4

To output a single continuous pattern—such as the concentric rings test—specify the t parameter:

ffmpeg -f lavfi -i mptestsrc=t=ring_1:rate=60:duration=5 -c:v libx264 -crf 18 rings_test.mp4

Practical Encoding Evaluation Workflows

1. Stress Testing Rate Control and Compression Artifacts

To observe how a specific codec handles edge transitions at varying bitrates, encode the test pattern across different Constant Rate Factor (CRF) levels:

ffmpeg -f lavfi -i mptestsrc=t=all:d=15 -c:v libx264 -crf 28 x264_crf28.mp4
ffmpeg -f lavfi -i mptestsrc=t=all:d=15 -c:v libx264 -crf 18 x264_crf18.mp4

Inspect the ring_1 and freq segments in the resulting videos. Higher compression levels will exhibit visible distortion and edge smearing along high-contrast boundaries.

2. Testing at Modern Display Resolutions

Because mptestsrc generates frames at 512x512, evaluating modern encoder presets at 1080p or 4K requires chaining the scale filter:

ffmpeg -f lavfi -i mptestsrc=t=all:r=60:d=20 -vf "scale=1920:1080:flags=neighbor" -c:v libx265 -crf 22 -preset medium x265_1080p.mp4

Using flags=neighbor (nearest-neighbor scaling) preserves sharp pixel transitions without introducing pre-compression bilinear or bicubic filtering blur, ensuring the encoder receives maximum edge sharpness.

3. Comparing Chroma Subsampling Degradation

The cbands pattern highlights color degradation caused by subsampling (such as YUV 4:2:0 versus YUV 4:4:4). You can evaluate this by forcing pixel formats during encoding:

# Encode with standard 4:2:0 chroma subsampling
ffmpeg -f lavfi -i mptestsrc=t=cbands:d=5 -pix_fmt yuv420p -c:v libx264 -crf 16 cbands_420.mp4

# Encode with full 4:4:4 chroma preservation
ffmpeg -f lavfi -i mptestsrc=t=cbands:d=5 -pix_fmt yuv444p -c:v libx264 -crf 16 cbands_444.mp4

Comparing the two outputs side by side reveals color fringing and bleeding along narrow vertical chromatic borders in the 4:2:0 render.