Set Transfer Characteristics in FFmpeg Colorspace
The FFmpeg colorspace filter enables high-precision
conversion of video color properties between different standards and
formats. This guide explains how to specify input and output transfer
characteristics—the transfer functions or gamma curves—using the
itrc and trc options to ensure accurate
brightness and color reproduction when converting video streams.
The Transfer Characteristics Parameters
In the colorspace filter, transfer characteristics are
controlled by two specific arguments:
itrc(oritransfer): Sets the input transfer characteristics. This tells FFmpeg how the source video's luminance levels are encoded.trc(ortransfer): Sets the output transfer characteristics. This defines the target curve FFmpeg will apply to the encoded output.
If itrc is omitted, FFmpeg attempts to read the transfer
characteristics from the input file's metadata. If metadata is missing
or incorrect, explicitly defining itrc is required.
Basic Syntax
To apply the filter in an FFmpeg command, use the -vf
(video filter) flag:
ffmpeg -i input.mp4 -vf "colorspace=itrc=bt709:trc=smpte2084" output.mp4Supported Transfer Characteristic Values
Commonly supported values for both itrc and
trc include:
bt709: Standard Rec.709 curve used for standard HD video.smpte170m: Standard definition curve for NTSC/PAL.bt2020-10: Rec. 2020 10-bit system curve.bt2020-12: Rec. 2020 12-bit system curve.smpte2084: Perceptual Quantizer (PQ) curve used for HDR10 and Dolby Vision.arib-std-b67: Hybrid Log-Gamma (HLG) curve for broadcast HDR.iec61966-2-1: Standard sRGB curve commonly used for computer monitors and web graphics.linear: Linear transfer curve without gamma correction.
Complete Conversion Example
When converting transfer characteristics, you typically need to specify the color primaries and matrix coefficients alongside the transfer curves to perform a mathematically correct conversion (such as HDR to SDR tone mapping or standard color conversion).
Here is a full command converting an HDR PQ video (Rec.2020) to standard SDR (Rec.709):
ffmpeg -i hdr_input.mp4 -vf "colorspace=iprimaries=bt2020:ispace=bt2020nc:itrc=smpte2084:primaries=bt709:space=bt709:trc=bt709" -c:v libx264 -crf 18 -c:a copy sdr_output.mp4In this command:
itrc=smpte2084instructs the filter to interpret the input signal using the PQ curve.trc=bt709transforms the output signal to the standard Rec.709 gamma curve.