AnimeMusicVideos.org > Guide Index
When storing video digitally there are two ways in which you can store it: RGB and YUV. Each has a variation or two that change how accurate they are, but that's it (i.e. RGB16,RGB24,RGB32 and then YUV, YUY2, YV12, I420 etc).
RGB stores video rather intuitively. It stores a color
value for each of the 3 color levels, Red Green and Blue, on a per
pixel basis. The most common RGB on computers these days is RGB24 which
gives 8 bits to each color level (that's what gives us the 0-255 range
as 2 to the 8th power is 256), thus white is 255,255,255 and black is
RGB uses the fact that three color components can be added
together to create any color. In contrast, YUV stores the
color the same way human brain
Luma can be relatively
easily calculated from RGB channels by averaging the color values and
giving more weight to some colors over others to find out the luma
Scientists came up with weights that match human
perception where green has high contribution, red half of that, blue -
third of red. Why this is the case is simply a matter of the way the
brain works and this perceptive model is important in how YUV was
Cr, when positive, means that the object is red.
Cr negative means that the object is green.
these two colors as opposites - If you think about it, no object can
ever be red-greenish.
There are a couple of reasons for storing in YUV
- a historical reason: when color TV was invented, it needed to be both backwards and forwards compatible with black-and-white TV. The old B&W channel became luminance, while two color channels were added on top of that. Old TVs simply ignore the two extra channels while color TVs just understand that chroma is zero in B&W signal.
So, when dealing with YUV you can imagine Y as being the black
and white image then U
and V as the "coloring" of the image. Here's a visual example:
Although you can have one Y, U and V sample per pixel like you
do with R,G and B, it is common for the chroma samples (the U and V) to
be sampled less often because the accuracy of the chroma is less
noticable. There are a many ways to do this but we are going
to demonstrate the two that you will deal with most - YUY2 and YV12.
YUY2 is a type of YUV that samples the luma once every
but only samples the chroma once every horizontal pair of pixels - the
point being that the human eye doesn't really notice that the chroma of
the two pixels is the same when the luma values are different. It's
just like the way you can be less accurate when coloring in a black and
white picture than if you were making the picture from scratch with
only colored pencils.
So basically YUY2 stores color data at a lower accuracy than
RGB without us really noticing that much. Effectively what happens is
that the chroma information is half the regular vertical resolution.
Due to this nature of YUY2, when you convert between YUY2 and
RGB you either lose some data (as the chroma is averaged), or
assumptions have to be made and data must be guessed at or interpolated
(because the chroma is averaged already we can't find out what the real
value was before).
Even less chroma sampling: YV12
The top image is an original and below it is an image sampled with YUV 4:2:0 (YV12) sampling , notice how the colors of the hairline at the top left become puzzled because of the chroma averaging between pixels.
The sharp among you may think "um ok but what if the image is
interlaced - you'd be sampling color from two different fields!" and
you'd be right... which is why YV12 interlaced footage has to be
sampled a field at a time instead of a frame at a time.
- Video can be stored in different colorspaces, most notably RGB and YV12
- DVD and MPEG1/2/4 all use YV12 colorspace.
- Video editing software typically uses the RGB colorspace (but can still usually read files that use the YV12 colorspace)
- Doing lots of colorspace conversions can result in quality loss, so you want to do as few conversions as possible.