How to Use the FFmpeg yuvtestsrc Filter

This article explains how to use the yuvtestsrc video source filter in FFmpeg to generate test patterns. You will learn the basic syntax of this filter, how to customize parameters like resolution, frame rate, and duration, and see practical command-line examples for your video testing workflows.

The yuvtestsrc filter is a library source in FFmpeg (part of libavfilter) that generates a synthetic video pattern specifically designed for testing YUV color spaces. It displays a color pattern that helps visualize how different YUV pixel formats handle color and chroma subsampling.

Basic Syntax

To use yuvtestsrc, you must invoke the Libreavfilter virtual input device using the -f lavfi option.

The simplest command to generate a test video is:

ffmpeg -f lavfi -i yuvtestsrc -t 5 output.mp4

In this command, -t 5 limits the output duration to 5 seconds, as the filter will generate an infinite stream by default.

Customizing Filter Parameters

You can customize the output of the yuvtestsrc filter by passing specific options inside the filter argument, separated by colons (:).

The most common parameters include:

Practical Examples

1. Generate a Full HD 1080p Test Video

To generate a 10-second test video at a resolution of 1920x1080 and a frame rate of 30 fps, use the following command:

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

2. Using Short-hand Notation

You can achieve the same results using the abbreviated parameter names (s for size, r for rate, and d for duration):

ffmpeg -f lavfi -i yuvtestsrc=s=1280x720:r=60:d=5 -c:v libx264 output.mp4

This command generates a 720p video at 60 fps lasting 5 seconds.

3. Outputting to Raw YUV

If you need to test raw YUV video processing, you can output the filter directly to a raw .yuv file:

ffmpeg -f lavfi -i yuvtestsrc=s=720x480:r=29.97:d=5 -pix_fmt yuv420p output.yuv