Difference between revisions of "YUV"
(→J422: Let's get the numbers correct, too...) |
|||
Line 1: | Line 1: | ||
− | YUV is a class of pixel formats used in | + | [YUV http://en.wikipedia.org/wiki/YUV] is a class of pixel formats used in video applications, including {{VLC}}. |
− | YUV is | + | YUV is actually the name of the color space that is common to all "YUV" pixel formats. Contrary to RGB formats (Red-Green-Blue), YUV colors are represented with one "luminance" component called Y (equivalent to grey scale) and two "chrominance" components, |
+ | called U (blue projection) and V (red projection) respectively, hence the name. | ||
− | This | + | YUV can also be referred to as YCbCr, although the terms mean slightly different things, they tend to be confused and used interchangeably (including in VLC-related venues). |
+ | |||
+ | This page explains the most useful YUV pixel formats in the context of {{VLC}}. Unless otherwise stated, values for each component is stored in one octet (8 bits). | ||
= Planar formats = | = Planar formats = | ||
+ | |||
+ | Planar (or sometimes "triplanar") formats use separate matrices for each of the 3 color component. In other words, there is one table of luminance pixel values, and two separate tables for the chrominance components. This is segregated representation in memory of pixels is more convenient for video coding. | ||
+ | |||
== YUV 4:2:0 (I420/J420/YV12)== | == YUV 4:2:0 (I420/J420/YV12)== | ||
=== I420 === | === I420 === | ||
− | + | It has the luma "luminance" plane '''''Y''''' first, then the '''''U''''' chroma plane and last the '''''V''''' chroma plane. | |
− | + | The two chroma planes (blue and red projections) are sub-sampled in both the horizontal and vertical dimensions by a factor of 2. That is to say, for a 2x2 square of pixels, there are 4 Y samples but only 1 U sample and 1 V sample. | |
− | + | This format requires 4*8+8+8=48 bits for 4 pixels, so its depth is 12 bits per pixel. | |
+ | |||
+ | '''I420 is by far the most common format in VLC.''' Most video decoders output raw pictures in I420 format. | ||
=== J420 === | === J420 === | ||
− | J420 is exactly like | + | J420 is exactly like I420, but with a full range ("digital", 0-255) luma ('''''Y''''') component instead of limited range ("analog", 16-240). The chroma planes are exactly the same as in I420. |
=== YV12 === | === YV12 === | ||
+ | YV12 is exactly like I420, but the order of the '''U''' and '''V''' planes is reversed. In the name, "YV" refers to the plane order: Y, then V (then U). "12" refers to the pixel depth: 12-bits per pixel as for I420. | ||
− | + | == YUV 4:2:2 (I422/J422) == | |
+ | === I422 === | ||
+ | Like I420, I422 has one luma plane '''''Y''''' and 2 chroma planes '''U''', '''V'''. | ||
− | + | However, in I422, chroma planes (blue and red projections) are sub-sampled only in the horizontal dimension, still by a factor of 2. Thus, there is the same amount of lines in chroma planes as in the luma plane. | |
− | + | For a 2x2 group of pixels, there are 4 Y samples and 2 U and 2 V samples each. The depth is 4*8+2*8+2*8 = 64 bits per 4 pixels, so 16 bits per pixel. | |
− | |||
− | + | Some video codecs support I422 (optionally) for higher quality video encoding. | |
− | + | === J422 === | |
+ | J422 is exactly like I422, but with a full range ("digital", 0-255) luma ('''''Y''''') component instead of limited range ("analog", 16-240). The chroma planes are exactly the same as in I422. | ||
− | === | + | === I444 === |
+ | As I420 and I422, I444 has one luma plane '''''Y''''' and 2 chroma planes '''U''' and '''V'''. Chroma planes are not sub-sampled: there are 3 octet values for each pixels. The depth is thus 24 bits per pixel (as with RGB24 or RGB32). | ||
− | + | A few video codecs support I444 optionally. | |
− | = | + | = Packed formats = |
− | + | In packed formats, you usually have only one plane, with all the luma and chroma data interleaved. This is similar to RGB pixel formats, only using a different color space. | |
− | In | ||
− | |||
− | |||
− | |||
− | + | Packed formats are very popular inside ''webcams''. In hardware, using separate planes is inefficient: several memory accesses are needed for each pixel. Packed formats are easier and thus cheaper to use. | |
− | + | On the other hand, packet formats cannot normally deal with vertical sub-sampling. Otherwise scan lines would have different sizes. So generally, packed formats are horizontally subsampled, especially by a factor of 2 (i.e. YUV 4:2:2). | |
− | |||
− | |||
− | |||
− | |||
== UYVY == | == UYVY == | ||
− | + | Known as ''UYVY'', ''Y422'' or ''UYNV''. | |
In UYVY, the chroma samples are sub-sampled by a factor of 2. | In UYVY, the chroma samples are sub-sampled by a factor of 2. | ||
− | In UYVY, the succession for 2 pixels, starts by '''U''' then one luma, then '''V''' | + | In UYVY, the succession for 2 pixels, starts by '''U''' then one luma if the first pixel, then '''V''' and then another luma for the second pixel. |
== YUY2 == | == YUY2 == | ||
− | + | Known as ''YUY2'', ''YUYV'', ''V422'' or ''YUNV''. | |
In YUY2, the chroma samples are sub-sampled by a factor of 2. | In YUY2, the chroma samples are sub-sampled by a factor of 2. | ||
− | In YUY2, the succession for 2 pixels, starts by one luma, then '''U''', then another luma and then '''V''' again. | + | In YUY2, the succession for 2 pixels, starts by one luma for the first pixel, then '''U''', then another luma for the second pixel and then '''V''' again. |
+ | |||
+ | Conversion between YUY2 and UYVY is achieved by swapping bytes pairwise. | ||
== YVYU == | == YVYU == | ||
YVYU is just like [[YUY2]], but with '''U''' and '''V''' order reversed. | YVYU is just like [[YUY2]], but with '''U''' and '''V''' order reversed. | ||
+ | == VYUV == | ||
+ | TBD. | ||
+ | |||
+ | = Semi-planar = | ||
+ | |||
+ | Semi planar formats have two planes instead of three, one plane for luminance, and one plane for both chrominance components. They are also sometimes referred to as biplanar formats also. | ||
+ | |||
+ | == NV12/NV21 == | ||
+ | |||
+ | === NV12 === | ||
+ | Related to I420, NV12 has one luma "luminance" plane '''''Y''''' and one plane with '''''U''''' and '''''V''''' values interleaved. | ||
+ | |||
+ | In NV12, chroma planes (blue and red) are subsampled in both the horizontal and vertical dimensions by a factor of 2. | ||
+ | |||
+ | For a 2x2 group of pixels, you have 4 Y samples and 1 U and 1 V sample. | ||
+ | |||
+ | === NV21 === | ||
+ | |||
+ | NV21 is like [[NV12]], but with '''U''' and '''V''' order reversed: it starts with '''V'''. | ||
+ | |||
+ | === Other NV formats === | ||
+ | Following the same pattern as NV12/NV21, there are NV16/NV61 (4:2:2 sub-sampling) and NV24/NV42 (4:4:4 sampling) formats. They are mostly used in some funky cheap camera circuitry and not supported in VLC (as of VLC version 2.0). | ||
{{documentation}} | {{documentation}} |
Revision as of 19:01, 27 January 2012
[YUV http://en.wikipedia.org/wiki/YUV] is a class of pixel formats used in video applications, including VLC media player.
YUV is actually the name of the color space that is common to all "YUV" pixel formats. Contrary to RGB formats (Red-Green-Blue), YUV colors are represented with one "luminance" component called Y (equivalent to grey scale) and two "chrominance" components, called U (blue projection) and V (red projection) respectively, hence the name.
YUV can also be referred to as YCbCr, although the terms mean slightly different things, they tend to be confused and used interchangeably (including in VLC-related venues).
This page explains the most useful YUV pixel formats in the context of VLC media player. Unless otherwise stated, values for each component is stored in one octet (8 bits).
Contents
Planar formats
Planar (or sometimes "triplanar") formats use separate matrices for each of the 3 color component. In other words, there is one table of luminance pixel values, and two separate tables for the chrominance components. This is segregated representation in memory of pixels is more convenient for video coding.
YUV 4:2:0 (I420/J420/YV12)
I420
It has the luma "luminance" plane Y first, then the U chroma plane and last the V chroma plane.
The two chroma planes (blue and red projections) are sub-sampled in both the horizontal and vertical dimensions by a factor of 2. That is to say, for a 2x2 square of pixels, there are 4 Y samples but only 1 U sample and 1 V sample.
This format requires 4*8+8+8=48 bits for 4 pixels, so its depth is 12 bits per pixel.
I420 is by far the most common format in VLC. Most video decoders output raw pictures in I420 format.
J420
J420 is exactly like I420, but with a full range ("digital", 0-255) luma (Y) component instead of limited range ("analog", 16-240). The chroma planes are exactly the same as in I420.
YV12
YV12 is exactly like I420, but the order of the U and V planes is reversed. In the name, "YV" refers to the plane order: Y, then V (then U). "12" refers to the pixel depth: 12-bits per pixel as for I420.
YUV 4:2:2 (I422/J422)
I422
Like I420, I422 has one luma plane Y and 2 chroma planes U, V.
However, in I422, chroma planes (blue and red projections) are sub-sampled only in the horizontal dimension, still by a factor of 2. Thus, there is the same amount of lines in chroma planes as in the luma plane.
For a 2x2 group of pixels, there are 4 Y samples and 2 U and 2 V samples each. The depth is 4*8+2*8+2*8 = 64 bits per 4 pixels, so 16 bits per pixel.
Some video codecs support I422 (optionally) for higher quality video encoding.
J422
J422 is exactly like I422, but with a full range ("digital", 0-255) luma (Y) component instead of limited range ("analog", 16-240). The chroma planes are exactly the same as in I422.
I444
As I420 and I422, I444 has one luma plane Y and 2 chroma planes U and V. Chroma planes are not sub-sampled: there are 3 octet values for each pixels. The depth is thus 24 bits per pixel (as with RGB24 or RGB32).
A few video codecs support I444 optionally.
Packed formats
In packed formats, you usually have only one plane, with all the luma and chroma data interleaved. This is similar to RGB pixel formats, only using a different color space.
Packed formats are very popular inside webcams. In hardware, using separate planes is inefficient: several memory accesses are needed for each pixel. Packed formats are easier and thus cheaper to use.
On the other hand, packet formats cannot normally deal with vertical sub-sampling. Otherwise scan lines would have different sizes. So generally, packed formats are horizontally subsampled, especially by a factor of 2 (i.e. YUV 4:2:2).
UYVY
Known as UYVY, Y422 or UYNV.
In UYVY, the chroma samples are sub-sampled by a factor of 2.
In UYVY, the succession for 2 pixels, starts by U then one luma if the first pixel, then V and then another luma for the second pixel.
YUY2
Known as YUY2, YUYV, V422 or YUNV.
In YUY2, the chroma samples are sub-sampled by a factor of 2.
In YUY2, the succession for 2 pixels, starts by one luma for the first pixel, then U, then another luma for the second pixel and then V again.
Conversion between YUY2 and UYVY is achieved by swapping bytes pairwise.
YVYU
YVYU is just like YUY2, but with U and V order reversed.
VYUV
TBD.
Semi-planar
Semi planar formats have two planes instead of three, one plane for luminance, and one plane for both chrominance components. They are also sometimes referred to as biplanar formats also.
NV12/NV21
NV12
Related to I420, NV12 has one luma "luminance" plane Y and one plane with U and V values interleaved.
In NV12, chroma planes (blue and red) are subsampled in both the horizontal and vertical dimensions by a factor of 2.
For a 2x2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.
NV21
NV21 is like NV12, but with U and V order reversed: it starts with V.
Other NV formats
Following the same pattern as NV12/NV21, there are NV16/NV61 (4:2:2 sub-sampling) and NV24/NV42 (4:4:4 sampling) formats. They are mostly used in some funky cheap camera circuitry and not supported in VLC (as of VLC version 2.0).
Please read the Documentation Editing Guidelines before you edit the documentation