Difference between revisions of "YUV"

From VideoLAN Wiki
Jump to navigation Jump to search
m (Format, grammar)
 
(32 intermediate revisions by 5 users not shown)
Line 1: Line 1:
YUV is a class of pixel formats used in Video application and in {{VLC}}.
+
{{See also|Huffyuv|Creative YUV}}
 +
{{Wikipedia|YUV}}
 +
YUV is a class of pixel formats used in video applications, including {{VLC}}.
  
YUV is also colorspace and the way to represent pixels colors is based on Luminance and Chrominance.
+
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.
  
= Planar =
+
YUV can also be referred to as YCbCr, although the terms mean slightly different things,<span id="note1_backlink"></span><sup><small>[[#note1|&#x5B;note 1&#x5D;]]</small></sup> they tend to be confused and used interchangeably (including in VLC-related venues).
== YUV 4:2:0 (I420/YV12)==
 
  
=== I420 ===
+
This page explains the most useful YUV pixel formats in the context of VLC media player. Unless otherwise stated, values for each component are stored in one octet (8 bits).
In I420, you have one luma "luminance" plane '''''Y''''' and 2 chroma planes '''''U''''', '''''V'''''.
 
  
In I420, chroma planes (blue and red projections) are subsampled in both the horizontal and vertical dimensions by a factor of 2.
+
== Planar formats ==
  
For a 2x2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.
+
Planar (or sometimes "triplanar") formats use separate matrices for each of the 3 color components. In other words, there is one table of luminance pixel values, and two separate tables for the chrominance components. This segregated representation in memory of pixels is more convenient for video coding.
  
=== YV12 ===
+
=== <span id="4:2:0"></span> YUV 4:2:0 (I420/J420/YV12) ===
  
YV12 is exactly like I420, but with '''U''' and '''V''' order reversed.
+
==== I420 ====
 +
It has the luma "luminance" plane '''''Y''''' first, then the '''''U''''' chroma plane and last the '''''V''''' chroma plane.
  
== NV12/NV21 ==
+
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 2×2 square of pixels, there are 4 Y samples but only 1 U sample and 1 V sample.
  
=== NV12 ===
+
This format requires 4×8+8+8=48 bits per 4 pixels, so its depth is 12 bits per pixel.
Related to I420, in NV12, you have one luma "luminance" planes '''''Y''''' and one plane with '''''U''''' and '''''V''''' data interleaved. NV12 is considered as ''semiplanar''.
 
  
In NV12, chroma planes (blue and red) are subsampled in both the horizontal and vertical dimensions by a factor of 2.
+
'''I420 is by far the most common format in VLC.''' Most video decoders output raw pictures in I420 format.
 +
 
 +
A graphical illustration:
 +
Each letter represents one bit.
 +
* For a single I420 pixel: {{font colour|blue|YYYYYYYY}} {{font colour|green|UU}} {{font colour|red|VV}}
 +
* For a 50-pixel I420 frame: YYYYYYYY×50 UU×50 VV×50 (or Y×8×50 U×2×50 V×2×50 for short)
 +
* For an <var>n</var>-pixel I420 frame: Y×8×<var>n</var> U×2×<var>n</var> V×2×<var>n</var>
 +
 
 +
==== 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.
 +
 
 +
=== <span id="4:2:2"></span> 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 2×2 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.
  
For a 2x2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.
+
Some video codecs support I422 (optionally) for higher quality video encoding.
  
=== NV21 ===
+
==== 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.
  
NV21 is like NV12, but with '''U''' and '''V''' order reversed: it starts with '''V'''.
+
=== <span id="4:4:4"></span> YUV 4:4:4 ===
 +
==== 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).
  
== YUV 4:2:2 ==
+
A few video codecs support I444 optionally.
=== I422 ===
 
In I422, like in [[I420]], you have one luma  plane '''''Y''''' and 2 chroma planes '''U''', '''V'''.
 
  
However, in I422, chroma planes (blue and red projections) are subsampled just in the horizontal dimension by a factor of 2.
+
== Packed formats ==
There is the same amount of lines than in the luma.
+
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.
  
For a 2x2 group of pixels, you have 4 Y samples and 2 U and 2 V sample.
+
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.
  
= Packed =
+
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).
In packed formats, you only have one plane, with all the luma and chroma interleaved.
 
  
== UYVY ==
+
=== UYVY ===
Know as ''UYVY'', ''Y422'', ''UYNV''
+
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''' again and then another luma.
+
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 ===
Know as ''YUY2'', ''YUYV'', ''V422'', ''YUNV''
+
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.
  
== YVYU ==
+
Conversion between YUY2 and UYVY is achieved by swapping bytes pairwise.
 +
 
 +
=== 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 2×2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.
 +
 +
It can be helpful to think of NV12 as I420 with the U and V planes interleaved.
 +
 +
Here is a graphical representation of NV12. Each letter represents one bit:
 +
* For 1 NV12 pixel: {{font colour|blue|YYYYYYYY}} {{font colour|green|UVUV}}
 +
* For a 2-pixel NV12 frame: {{font colour|blue|YYYYYYYYYYYYYYYY}} {{font colour|green|UVUVUVUV}}
 +
* For a 50-pixel NV12 frame: Y×8×50 (UV)×2×50
 +
* For a <var>n</var>-pixel NV12 frame: Y×8×<var>n</var> (UV)×2×<var>n</var>
 +
 +
==== 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).
 +
 +
== Notes ==
 +
<div class="plainlist">
 +
* <span id="note1"></span><sup>[[#note1_backlink|^&nbsp;note 1]]</sup> Technical details are generally understood from context. Everything described on this page is Y&prime;CbCr, not Y&prime;UV.<br /><!--
 +
-->Y&prime;CbCr [[wikipedia:chroma subsampling|chroma subsampling]] formats (e.g. 4:2:0) are used only for digital signals; VLC deals with digital signals.<br /><!--
 +
-->In many cases: Y&prime;UV is for analog signals, Y&prime;PbPr for analog signals in video component cables; Y&prime;CbCr for digital signals (including [[MPEG-2]]). [[wikipedia:Gamma correction|Gamma correction]] is indicated by a prime&nbsp;<code>&prime;</code>, thus gamma-corrected YCbCr is written <code>Y&prime;CbCr</code>. For an extended discussion see [https://poynton.ca/PDFs/YUV_and_luminance_harmful.pdf YUV and luminance considered harmful] or [https://poynton.ca/notes/colour_and_gamma/ColorFAQ.html#RTFToC26 Color FAQ &sect; What are colour differences?] by Charles Poynton
 +
</div>
  
 +
== Further reading ==
 +
* https://fourcc.org/yuv.php
  
 
{{documentation}}
 
{{documentation}}

Latest revision as of 07:07, 6 May 2019

See also: Huffyuv and Creative YUV

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,[note 1] 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 are stored in one octet (8 bits).

Planar formats

Planar (or sometimes "triplanar") formats use separate matrices for each of the 3 color components. In other words, there is one table of luminance pixel values, and two separate tables for the chrominance components. This 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 2×2 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 per 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.

A graphical illustration: Each letter represents one bit.

  • For a single I420 pixel: YYYYYYYY UU VV
  • For a 50-pixel I420 frame: YYYYYYYY×50 UU×50 VV×50 (or Y×8×50 U×2×50 V×2×50 for short)
  • For an n-pixel I420 frame: Y×8×n U×2×n V×2×n

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 2×2 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.

YUV 4:4:4

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 2×2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.

It can be helpful to think of NV12 as I420 with the U and V planes interleaved.

Here is a graphical representation of NV12. Each letter represents one bit:

  • For 1 NV12 pixel: YYYYYYYY UVUV
  • For a 2-pixel NV12 frame: YYYYYYYYYYYYYYYY UVUVUVUV
  • For a 50-pixel NV12 frame: Y×8×50 (UV)×2×50
  • For a n-pixel NV12 frame: Y×8×n (UV)×2×n

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).

Notes

Further reading

This page is part of official VLC media player Documentation (User GuideStreaming HowToHacker GuideModules)
Please read the Documentation Editing Guidelines before you edit the documentation
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.