First of all: YUV pixel formats and Recommended 8-Bit YUV Formats for Video Rendering. Chromium's source code contains good documentation about those formats too: chromium/src/media/base/video_types.h and chromium/src/media/base/video_frame.cc (search for RequiresEvenSizeAllocation()
, NumPlanes()
and those kinds of functions).
You can think of an image as a superposition of several planes (or layers in a more natural language). YUV formats have three planes: Y
, U
, and V
.
Y
is the luma plane, and can be seen as the image as grayscale. U
and V
are reffered to as the chroma planes, which are basically the colours. All the YUV formats have these three planes, and differ by the different orderings of them.
Sometimes the term YCrCb
is used. It's essentially the same thing: Y
, Cr
, Cb
respectively refer to Y
, U
, V
although Cr
and Cb
are sometimes used when speaking of the components of U
and V
(that is U
= Cr1Cr2…Crn and V
= Cb1Cb2…Cbn).
The chroma planes (U
and V
) are subsampled. This means there is less information in the chroma planes than in the luma plane. This is because the human eye is less sensitive to colours than luminance; so we can just gain space by keeping less information about colours (chroma planes) than luminance (luma plane, Y
).
The subsampling is expressed as a three part ratio: J:a:b
(e.g. 4:2:0
). This ratio makes possible to get the size of the planes relative to each others. Refer to the Wikipedia article "Chroma subsampling" for more information.
Basically the chroma planes are often shorter than the luma plane. Most commonly, the ratio is length(Y) / n = length(U) = length(V)
where n
is 1, 2, 4, …
YUV formats are either:
- Packed (or interleaved)
- Planar (the names of those formats often end with "p")
- Semi-planar (the names of those formats often end with "sp")
Those terms define how the planes are ordered in the format. In the memory:
- Packed means the components of
Y
,U
, andV
are interleaved. For instance: Y1U1Y2V1Y3U2Y4V2…Yn-1Un/2YnVn/2. - Planar means the components of
Y
,U
, andV
are respectively grouped together. For instance: Y1Y2…YnU1U2…Un/2V1V2…Vn/2. - Semi-planar means the components of
Y
are grouped together, and the components ofU
andV
are interleaved. For instance: Y1Y2…YnU1V1U2V2…Un/2Vn/2
Semi-planar formats are sometimes put in the Planar familly.
The following formats are described in the picture:
- YV12
- I420 = IYUV = YUV420p (sometimes YUV420p can refer to YV12)
- NV21
- NV12 = YUV420sp (sometimes YUV420sp can refer to NV21)
Thank you !