Generate SMPTE Color Bars Test Pattern in FFmpeg

This article provides a straightforward guide on how to generate a SMPTE color bars test pattern using FFmpeg. You will learn the exact command-line syntax required to customize the video's resolution, frame rate, and duration, allowing you to quickly create standard-compliant testing assets.

To generate a SMPTE color bars test pattern, you use FFmpeg's built-in virtual input device, lavfi (Libavfilter), along with the smptebars or smptehdbars source filters.

The Basic Command

Use the following command template to generate a standard 10-second SMPTE color bar video at a resolution of 1920x1080 and a frame rate of 30 frames per second (fps):

ffmpeg -f lavfi -i smptebars=size=1920x1080:rate=30 -t 10 output.mp4

Command Breakdown

  • -f lavfi: Tells FFmpeg to use the Libavfilter virtual input format.
  • -i smptebars=size=1920x1080:rate=30: Specifies the input source filter.
    • smptebars generates the standard definition SMPTE pattern.
    • size=1920x1080 (or s=1920x1080) sets the custom resolution.
    • rate=30 (or r=30) sets the frame rate to 30 fps.
  • -t 10: Sets the duration of the output video to 10 seconds. If this is omitted, FFmpeg will generate the pattern indefinitely.
  • output.mp4: The output file name.

Generating HD SMPTE Color Bars

For high-definition projects, standard SMPTE bars may look slightly out of spec. FFmpeg provides a specific filter for HD-compliant color bars called smptehdbars.

To generate a 1080p HD version at 23.976 fps:

ffmpeg -f lavfi -i smptehdbars=size=1920x1080:rate=24000/1001 -t 5 output_hd.mp4

Ensuring Playback Compatibility

By default, FFmpeg might encode the output using a pixel format that is not widely supported by standard media players (like QuickTime or default Windows players). To ensure maximum compatibility, force the H.264 encoder and the YUV 4:2:0 chroma subsampling format using the following command:

ffmpeg -f lavfi -i smptehdbars=size=1280x720:rate=60 -c:v libx264 -pix_fmt yuv420p -t 10 output_compatible.mp4
  • -c:v libx264: Encodes the video stream using the H.264 codec.
  • -pix_fmt yuv420p: Sets the pixel format to YUV 4:2:0, which is required for playback on most hardware and web browsers.