

How to convert between colorspaces using FFmpeg?Ĭonversion between RGB/YUV is typically done using swscale. The RGB/XYZ matrix, in AVFrame-> color_primaries.transformation characteristics), in AVFrame-> color_trc The YUV/RGB transformation matrix, in AVFrame-> colorspace.

The signal range, in AVFrame-> color_range.The format (type and bit-depth), in AVFrame-> format.The conversion matrix between the linearized RGB and the device-independent XYZ colorspace.įFmpeg stores all these properties in the AVFrame struct:.The linearization function from RGB to a linear RGB signal.The transformation matrix between YUV and RGB.(YUV only, unlikely a problem for other type of signals.) (Note: "Full range" refers to the YUV component values being in the range 0–255, whereas "restricted range" has values between 16–235) Whether the signals are full range or restricted range.Whether the pixel buffer contains RGB, YUV or some other type of signals, and the bit-depth.In practical terms, the things you care are:

In FFmpeg, colorspaces are represented in the form of pixel format. These standards describe not just things like how to convert a YUV signal to RGB, but also how a RGB signal should be represented in terms of photon emission, in a device-independent way.

A more accurate term for how color is stored in digital video would be YCbCr. Note: The term "YUV" is ambiguous and often used wrongly, including the definition of pixel formats in FFmpeg.
