Generate Zone Plate Patterns with FFmpeg yuvtestsrc

This guide explains how to generate synthetic test patterns in FFmpeg using the yuvtestsrc video filter source and how to produce mathematical zone plate patterns for video testing. You will learn the exact command syntax for configuring yuvtestsrc parameters, understand the structural capabilities of this filter, and see how to create standard optical zone plates using FFmpeg's built-in filtering tools.

Understanding the yuvtestsrc Filter

The yuvtestsrc filter is an FFmpeg source filter that generates a synthetic video pattern designed specifically to test YUV color spaces, chroma subsampling behaviors, and luma range transitions. It generates standardized color and luma gradients to verify that decoders and pixel-format converters process color matrices correctly.

To generate a basic video stream using yuvtestsrc, use the following command:

ffmpeg -f lavfi -i yuvtestsrc=size=1920x1080:rate=30:duration=10 -c:v libx264 -pix_fmt yuv420p yuv_test.mp4

In this command:

  • size (or s): Sets the resolution of the generated frame (e.g., 1920x1080).
  • rate (or r): Sets the frame rate (e.g., 30 or 60).
  • duration (or d): Sets the length of the generated clip in seconds.
  • pix_fmt: Ensures the output conforms to standard YUV color formatting.

Generating a Zone Plate Pattern

In video engineering, a classic zone plate is a pattern of concentric circular fringes where spatial frequency increases quadratically with distance from the center. It is primarily used to analyze resolution, frequency response, aliasing, and scaling artifacts.

The native yuvtestsrc filter generates static YUV color-ramp blocks and frequency bars rather than a sinusoidal, concentric Fresnel zone plate. To generate a true, mathematically accurate zone plate pattern within FFmpeg, combine a blank source canvas (nullsrc) with the generic equation filter (geq):

ffmpeg -f lavfi -i nullsrc=size=1920x1080:rate=30:duration=10 -vf "geq=lum='127.5+127.5*cos((PI/2000)*((X-W/2)*(X-W/2)+(Y-H/2)*(Y-H/2)))':cb=128:cr=128" -c:v libx264 -pix_fmt yuv420p zoneplate.mp4

Key components of the zone plate expression:

  • X and Y: Represent the current pixel coordinates.
  • W/2 and H/2: Center the origin of the concentric rings in the middle of the frame.
  • PI/2000: Governs the spatial frequency scale; decreasing this value expands the rings, while increasing it tightens the fringe density.
  • cb=128:cr=128: Sets neutral chroma channels to output a pure luma zone plate in the YUV colorspace.

Alternative: Using mptestsrc for Circular Ring Patterns

If you require a preset circular frequency pattern without defining manual mathematical expressions, FFmpeg provides circular test rings through the mptestsrc filter:

ffmpeg -f lavfi -i mptestsrc=t=ring2:rate=30:duration=10 -c:v libx264 -pix_fmt yuv420p ring_test.mp4

Setting t=ring1 or t=ring2 generates concentric test rings that test high-frequency circular detail and optical resolution across decoders.