Set Bit Depth in FFmpeg libvpx-vp9 Encoder

Configuring the target bit depth when encoding video with the VP9 codec (libvpx-vp9) in FFmpeg is crucial for achieving high-quality output, especially for HDR content. This article provides a straightforward guide on how to set 8-bit, 10-bit, or 12-bit depth using specific FFmpeg parameters and pixel formats.

How VP9 Handles Bit Depth

In FFmpeg, the bit depth of the libvpx-vp9 encoder is determined by the pixel format (-pix_fmt) you select. The VP9 codec supports different “profiles” based on the bit depth and chroma subsampling you choose:

FFmpeg automatically selects the correct VP9 profile based on your chosen pixel format, but you can also define it explicitly using the -profile:v flag.


Command Examples for Different Bit Depths

1. Encoding 8-bit VP9 Video

To encode standard 8-bit video with 4:2:0 chroma subsampling, use the yuv420p pixel format.

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

To encode 10-bit video, which is standard for High Dynamic Range (HDR) content and reduces color banding, use the yuv420p10le pixel format.

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

3. Encoding 12-bit VP9 Video

For maximum color precision, you can encode in 12-bit depth using the yuv420p12le pixel format.

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

Summary of Pixel Formats

Target Bit Depth Chroma Subsampling Pixel Format (-pix_fmt) VP9 Profile
8-bit 4:2:0 yuv420p Profile 0
8-bit 4:4:4 yuv444p Profile 1
10-bit 4:2:0 yuv420p10le Profile 2
10-bit 4:4:4 yuv444p10le Profile 3
12-bit 4:2:0 yuv420p12le Profile 2
12-bit 4:4:4 yuv444p12le Profile 3