YUV colour space question

Do any of you know the actual bit representation of the different YUV formats?

i.e.

4:4:4
4:2:2
4:1:1
4:2:0

?

I know that RGB is represented by 24 bits, each colour getting 8 bits.

If you could point me to a site that has this information i would be very much appreciative :slight_smile:

The byte order varies a bit depending on the software/device that generates it. Those numbers only refer to how the original data is sampled.

The wikipedia is your friend: http://en2.wikipedia.org/wiki/YUV

However, typically 4:2:2 is ordered u1y1v1y2u3y3v3y4u5y5v5y6 …
Note that the wikipedia has this wrong. The way the wikipedia describes it here, it would appear as if the U & V samples align with different luma samples. That is generally NOT the case.

4:2:0 is usually represented in memory in a planar format, one buffer of Y, one of U, one of V, with the U & V buffers being 1/4 the size of the Y buffer.

These formats also don’t specify the number of bits per sample. Typically the sampling is 8-bit for each component, but there may be times when more bits are used to avoid banding, or loss during processing.

4:4:4 would be the YUV equivalent of RGB, One byte for each component per pixel.

4:2:2 has one sample of Y per pixel, and U & V are sampled at half the horizontal bandwidth, so there are half the samples.

4:1:1 is like 4:2:2, but the U & V are sampled at one quarter of the horizontal bandwidth.

4:2:0 has the same amount of samples as 4:1:1, but the U & V are samples at half the bandwidth in both the horizontal and vertical directions, resulting in the same total of 1/4 the numebr of samples as the luma.

There was a really nice diagram on the net that showed all of this, I thought it was in the wikipedia, but I can’t find it now.

Thanks for replying. I understand what each of the formats are and how to implement them, however my progblem what exactly is the stream format.

e.g. as said in wikipedia it could be u1y1v1y2u3y3v3y4u5y5v5y6 or it may be y1y2y3y4u1u2v1v2

or any other combination… i wish to know what the standard is… if there is one.

How can programs understand the different YUV streams unless they are told how to interpret them?

There is no standard :frowning: Or rather there is more than one “standard” for the exact same sampling, so it’s just as good as having no standard.

The way programs know what to do is that they have implemented proprietary file formats or written codecs that read someone else’s proprietary format.

With AVI files for instance you would look to the FOURCC code and it is enough to know the exact byte order.

Google for FOURCC codes and you can get a table of known codes and what the data format is … e.g. there are FourCC codes like YUYV, UYVY, YUY2… the description of the code will tell you the byte order.

ah, well that is annoying :frowning:

thanks for the fourcc suggestion. www.fourcc.org as exactly what i was after.

hmm. i guess i will stick with YUV2 as it seems to be the most common…

I assume you meant YUY2… I didn’t see any YUV2 listed at fourcc.org

It is one of the more popular formats. I think I’ve encountered it and UYVY which fourcc.org claims may be the most popular
"UYVY (and Y422 and UYNV)

UYVY is probably the most popular of the various YUV 4:2:2 formats. It is output as the format of choice by the Radius Cinepak codec and is often the second choice of software MPEG codecs after YV12."