Understanding Video Color Spaces, Gamut, Transfer Functions, and YUV Conversion for Editing
To edit video correctly you must read its color metadata with ffprobe, understand the YUV model, limited versus full range, BT.601/BT.709 gamuts and transfer functions, apply the appropriate YUV‑to‑RGB matrices, convert gamuts to BT.709, and re‑encode with matching color parameters.
To inspect the color information of a video file, the ffprobe -i video_file_path -show_streams command can be used, which prints details such as the color model, sampling format, range, conversion matrix, transfer function, and primaries.
The output indicates that the video uses the YUV color model with 4:2:0 sampling, a limited (TV) range, the BT.601 (smpte170m) conversion matrix, BT.601 transfer function, and BT.601 (bt470bg) primaries.
In editing scenarios, multiple video files may have different color parameters. Correctly handling these parameters ensures accurate on‑screen display and prevents color shifts in exported videos. Key concepts to master include color gamut, transfer function, conversion matrix, and the YUV/YCbCr model.
Color Gamut (color_primaries) is defined by the three primary colors and the white point. Mapping the RGB primaries to the CIE 1931 XY space forms a triangle that represents the gamut. For example, BT.709 (sRGB) primaries are R(0.640,0.330), G(0.300,0.600), B(0.150,0.060); BT.2020 primaries are R(0.708,0.292), G(0.170,0.797), B(0.131,0.046). A larger triangle covers a larger portion of perceivable colors (BT.709 ≈ 35.9 % of the CIE space, BT.2020 ≈ 75.8 %). The white point for BT.601/BT.709/BT.2020 is D65 (x=0.3127, y=0.3290).
Transfer Function (color_transfer) , also known as gamma correction, converts linear light signals to non‑linear electrical signals (OETF) and back (EOTF). Video files often label this as BT.601, BT.709, etc. BT.601 uses a gamma of 2.4, BT.709 uses 2.2. Gamma correction is needed because:
Human visual perception of brightness is non‑linear, making linear encoding look unnatural.
Display devices (CRT, LCD, projectors) exhibit non‑linear voltage‑to‑luminance relationships.
Non‑linear encoding preserves more detail in dark regions and improves coding efficiency.
YUV Color Range comes in two forms: TV (limited) range and PC (full) range. In FFmpeg they are represented by AVCOL_RANGE_MPEG (limited) and AVCOL_RANGE_JPEG (full). Limited range was historically required for analog TV compatibility and to reserve headroom/footroom for sync signals.
Conversion between YUV and RGB involves several matrix steps. For example, converting BT.2020 to BT.709 requires:
Apply the BT.2020‑to‑XYZ matrix.
Apply the XYZ‑to‑BT.709 matrix.
Multiply the two matrices to obtain a direct BT.2020‑to‑BT.709 matrix.
The YUV‑to‑RGB matrix for a given standard (e.g., BT.709) is defined in the video’s color_space field. The matrix is a 3×3 set of coefficients that maps Y, U, V to R, G, B.
Editing Workflow (Target: BT.709)
Derive the YUV‑to‑RGB matrix from color_space and color_range (e.g., YUV2RGB_BT470BG_TV_MAT).
Decode the non‑linear RGB using the transfer function (e.g., rgb = BT470BG_EOTF_gammaMethod(rgb) ).
Convert the source gamut to the target gamut by first mapping to XYZ and then to BT.709 (e.g., rgb = BT601_TO_BT709_MAT * rgb ).
Pass the linear RGB to the rendering engine for effects such as Gaussian blur.
Encode the final RGB back to a non‑linear form for display (e.g., rgb = BT709_OETF_gammaMethod(rgb) ).
Export the video: multiply the non‑linear RGB by the inverse of the BT.709 matrix and set the stream’s color range to TV, color space to 709, and transfer function to BT.709.
Conclusion
Accurate color processing is essential for professional video editing. Understanding color gamut, transfer functions, YUV ranges, and conversion matrices enables reliable color correction, supports HDR workflows, and ensures consistent visual quality across different playback environments.
Bilibili Tech
Provides introductions and tutorials on Bilibili-related technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.