FFmpeg VP9 Color Primaries Space and TRC Guide
This article provides a direct guide on how to configure the
-color_primaries, -color_trc, and
-colorspace settings when encoding VP9 video using FFmpeg.
Correctly setting these metadata flags ensures that web browsers,
operating systems, and media players render colors accurately, whether
you are encoding Standard Definition (SD), High Definition (HD), or High
Dynamic Range (HDR) content.
Understanding the Color Parameters
When encoding VP9 video with the libvpx-vp9 encoder,
defining color metadata prevents video players from guessing the color
space, which often results in washed-out or distorted colors.
-color_primaries: Defines the chromaticity coordinates of the source color primaries (the color gamut).-color_trc: Defines the transfer characteristics (the gamma curve).-colorspace: Defines the matrix coefficients used for converting between RGB and YUV.
Standard Configurations
1. Standard HD Video (BT.709 / SDR)
For standard 1080p or 4K SDR video, you should explicitly set the color space to BT.709. Use the following FFmpeg command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -color_primaries bt709 -color_trc bt709 -colorspace bt709 output.webm2. HDR10 Video (BT.2020 with PQ)
For High Dynamic Range (HDR10) content, you must use the BT.2020
color gamut and the SMPTE 2084 (PQ) transfer function. You must also
specify a 10-bit pixel format (yuv420p10le):
ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc output.webm3. HLG HDR Video (Hybrid Log-Gamma)
For broadcast-friendly HDR using HLG, configure the transfer
characteristics to arib-std-b67:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -color_primaries bt2020 -color_trc arib-std-b67 -colorspace bt2020nc output.webmSupported FFmpeg Values Reference
| Parameter | Common Values | Description |
|---|---|---|
-color_primaries |
bt709bt2020smpte170m |
Rec. 709 (HD) Rec. 2020 (UHD/HDR) NTSC/PAL (SD) |
-color_trc |
bt709smpte2084arib-std-b67iec61966-2-1 |
Rec. 709 (SDR) SMPTE ST 2084 (HDR10) HLG (Hybrid Log-Gamma) sRGB |
-colorspace |
bt709bt2020ncsmpte170m |
Rec. 709 (HD) Rec. 2020 Non-Constant Luminance NTSC/PAL (SD) |