VP9 HDR Encoding Flags for libvpx
This article provides a direct guide to the command-line flags
required to enable High Dynamic Range (HDR) encoding using the
libvpx library (specifically for VP9 video). You will learn
the exact parameters needed for color space, pixel format, and transfer
characteristics to produce HDR10 or HLG compliant video files using
FFmpeg with libvpx-vp9.
To successfully encode HDR video using libvpx, you must
use the VP9 codec, as VP8 does not support HDR. Encoding HDR requires
shifting to a 10-bit color depth profile and explicitly signaling the
HDR metadata so playback devices can recognize and display the wider
color gamut and dynamic range.
Essential Command-Line Flags
The following flags must be passed to your encoder (typically via FFmpeg) to enable HDR:
1. Enable 10-bit Profile
- Flag:
-profile:v 2 - Description: VP9 Profile 2 is required for 10-bit color depth. Profile 0 only supports 8-bit, which will cause color banding in HDR content.
2. Set 10-bit Pixel Format
- Flag:
-pix_fmt yuv420p10le - Description: Configures the output pixel format to YUV 4:2:0 with 10-bit little-endian color depth.
3. Define the Color Primaries
- Flag:
-color_primaries bt2020 - Description: Signals that the video uses the Rec. 2020 wide color gamut.
4. Set the Transfer Characteristics (HDR Type)
You must choose the transfer function based on whether you are
encoding HDR10 (PQ) or HLG: * For HDR10 (PQ):
-color_trc smpte2084 * For HLG:
-color_trc arib-std-b67
5. Set the Color Space Matrix
- Flag:
-colorspace bt2020nc - Description: Specifies the Rec. 2020 non-constant luminance color matrix coefficients.
6. Set the Color Range
- Flag:
-color_range tv - Description: Limits the color range to standard broadcast “TV” levels (16-235 for 8-bit equivalent, scaled to 10-bit), which is standard for HDR distribution.
Static Metadata Flags (For HDR10)
If you are encoding HDR10, you should also include mastering display metadata and Content Light Level (CLL) metadata so compatible TVs can map the brightness levels correctly.
- Mastering Display Metadata:
-mastering_display_metadata "G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)" - Content Light Level:
-max_cll "max_content,max_average"
Complete Command-Line Example
Here is a complete FFmpeg command-line example utilizing
libvpx-vp9 to encode an HDR10 video:
ffmpeg -i input.mp4 \
-c:v libvpx-vp9 \
-profile:v 2 \
-pix_fmt yuv420p10le \
-color_primaries bt2020 \
-color_trc smpte2084 \
-colorspace bt2020nc \
-color_range tv \
-b:v 15M \
-crf 15 \
output.webm