How to Set VP9 Pixel Format in FFmpeg

Specifying the correct output pixel format when encoding video with the libvpx-vp9 encoder in FFmpeg is crucial for achieving the desired compatibility, color depth, and video quality. This article provides a straightforward guide on how to use the -pix_fmt flag to define your pixel format, details the supported formats for VP9 (including 8-bit, 10-bit, and 12-bit options), and provides practical command-line examples for your encoding workflow.

Using the -pix_fmt Flag

To specify the output pixel format in FFmpeg when using the libvpx-vp9 encoder, you must use the -pix_fmt option after defining the video encoder. The basic syntax is:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt [pixel_format] output.webm

Replace [pixel_format] with the specific format required for your project.

Supported VP9 Pixel Formats

The libvpx-vp9 encoder supports several pixel formats representing different chroma subsampling methods and color depths:

Standard 8-Bit Formats

High-Bit Depth Formats (10-bit and 12-bit)

VP9 supports profile 2 (10-bit) and profile 3 (12-bit) encoding, which are essential for High Dynamic Range (HDR) content: * yuv420p10le: 10-bit color depth with 4:2:0 subsampling (highly recommended for HDR web video). * yuv422p10le: 10-bit color depth with 4:2:2 subsampling. * yuv444p10le: 10-bit color depth with 4:4:4 subsampling. * yuv420p12le / yuv422p12le / yuv444p12le: 12-bit equivalents for maximum color precision.


Practical Examples

Example 1: Standard 8-Bit VP9 for Web Playback

To encode a video for maximum compatibility with standard web browsers and devices, use the yuv420p pixel format:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p output.webm

Example 2: 10-Bit VP9 (HDR)

For HDR workflows or to avoid color banding in gradients, use the yuv420p10le pixel format. Note that you may also need to specify the -profile:v 2 flag to force 10-bit profile compatibility:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -profile:v 2 output.webm

Verifying Supported Pixel Formats

You can verify all pixel formats supported by your local installation of the libvpx-vp9 encoder by running the following command in your terminal:

ffmpeg -h encoder=libvpx-vp9

Look for the “Supported pixel formats” section in the output to see the exact list of formats your FFmpeg build can encode.