Can libvpx-vp9 Encode HLG HDR Video?
Yes, the libvpx-vp9 encoder can effectively encode Hybrid Log-Gamma (HLG) video content. Because HLG is a High Dynamic Range (HDR) standard designed for broadcast and streaming, encoding it requires a 10-bit color depth and precise metadata tagging. This article explains how libvpx-vp9 handles HLG content, provides the exact FFmpeg parameters needed for successful encoding, and outlines the practical benefits and limitations of using this codec for HLG video.
To encode HLG video, the encoder must support 10-bit color depth. Standard VP9 (Profile 0) only supports 8-bit color, which is insufficient for HDR and causes severe color banding. Fortunately, libvpx-vp9 supports VP9 Profile 2, which enables 10-bit color spaces. By forcing the encoder to use a 10-bit pixel format, you activate Profile 2, allowing the codec to accurately represent the wide color gamut (Rec. 2020) and high dynamic range inherent to HLG.
The key to effectively encoding HLG with libvpx-vp9 lies in passing the correct color metadata to the container and video stream. Without this metadata, playback devices will not recognize the video as HDR and will render the colors washed out. When using FFmpeg, you must explicitly define the color space, transfer characteristics, and color primaries using the following flags:
- -pix_fmt yuv420p10le: Forces 10-bit encoding to trigger VP9 Profile 2.
- -color_primaries bt2020: Sets the color primaries to Rec. 2020.
- -color_trc arib-std-b67: Sets the transfer characteristics to HLG (ARIB STD-B67).
- -colorspace bt2020nc: Sets the matrix coefficients to Rec. 2020 non-constant luminance.
A standard FFmpeg command line structure for encoding an HLG input to VP9 looks like this:
ffmpeg -i input_hlg.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -color_primaries bt2020 -color_trc arib-std-b67 -colorspace bt2020nc -b:v 5M -c:a libopus output_hlg.webm
In terms of distribution, VP9 is highly effective and widely supported. Platforms like YouTube utilize VP9 for distributing HDR content, including HLG. HLG is uniquely advantageous because it is backward-compatible with Standard Dynamic Range (SDR) displays. When encoded properly with libvpx-vp9, the resulting WebM or MKV file will display vibrant HDR on compatible screens while degrading gracefully to SDR on older monitors without requiring separate video streams.
While highly effective for playback compatibility, encoding 10-bit VP9 with libvpx-vp9 is incredibly CPU-intensive and slow compared to hardware-accelerated HEVC encoders. Additionally, to preserve the visual quality of HLG’s highlight details, you must allocate sufficient bitrate, as low-bitrate 10-bit encodes can still suffer from compression artifacts in high-contrast scenes.