YUV encoding format

Source: Internet
Author: User
ArticleDirectory
    • YUV encoding format
YUV encoding format

YUV is a color encoding method (PAL) used by European television systems. It is the color space used by the PAL and SECAM analog color TV systems. In Modern Color TV systems, three-channel color cameras or color CCD cameras are usually used to retrieve images, and then the acquired color image signals are divided by color, respectively amplified and corrected to obtain RGB, after the matrix conversion circuitBrightness SignalYAnd two chromatic aberration SignalsR-Y(That isU),B-Y(That isV)At last, the sender encodes the brightness and chromatic aberration signals and sends them through the same channel. ThisColorIs the so-calledYUVColor Space Representation.The importance of using YUV color space is that its brightness signal y is separated from the color signal u and v.

Benefits

YUV is mainly used to optimize the transmission of color video signals, so that it is backward compatible with vintage black and white TVs. Compared with RGB video signal transmission, RGB requires three independent video signals to be transmitted at the same time ). "Y" indicates the brightness (luminance or Luma), that is, the gray scale value. "U" and "V" indicate the color (chrominance or chroma), which is used to describe the image.ColorAnd saturationUsed to specify the color of a pixel. The "brightness" is established through the RGB input signal by overlapping specific parts of the RGB signal. "Color" defines two aspects of color-tone and saturation, expressed by Cr and CB respectively.

Cr reflects the difference between the red part of the RGB input signal and the brightness value of the RGB signal. CB reflects the difference between the blue part of the RGB input signal and the brightness value of the RGB signal.

The importance of using YUV color space is that its brightness signal y is separated from the color signal u and v. If only the Y Signal component is used, but not the U or V component, the black and white gray images are displayed.Color TVUseYUVThe purpose of space is to use the Brightness Signal.YSolve the compatibility problem between the color TV and the black and white TV, so that the black and white TV can also receive the color TV Signal.

For Digital videos, the conversion from RGB to two major YUV is defined. Both conversions are based on specifications known as ITU-R recommendation bt.709. The first conversion is the earlier YUV format defined in bt.709 for 50-Hz. It is the same as the relationship specified in the ITU-R recommendation bt.601, And the ITU-R recommendation bt.601 is also known as its old name CCIR 601. This format should be considered as the preferred YUV format for standard definition of TV resolution (720x576) and lower resolution videos. Its features are defined by the values of the following two constants Kr and KB:

KR = 0.299kb = 0.114 the second conversion is the newer YUV format for 60-Hz defined in bt.709 and should be considered as the preferred format for video resolution higher than sdtv. Its features are defined by two different constant values:

KR = 0.2126kb = 0.0722 the conversion from RGB to YUV defines the following columns:

L = Kr * r + kb * B + (1-Kr-KB) * G, then obtain the YUV value in the following way:

Y = floor (2 ^ (M-8) * (219 * (L-Z)/S + 16) + 0.5)

U = clip3 (0, 2 ^ M-1, floor (2 ^ (M-8) * (112 * (B-L)/(1-kb) * s) + 128) + 0.5 ))

V = clip3 (0, 2 ^ M-1, floor (2 ^ (M-8) * (112 * (R-L)/(1-kr) * s) + 128) + 0.5 ))

Where

M is the number of digits (M> = 8) of each YUV sample ).

Z is a black variable. For computer RGB, z is equal to 0. For the Studio video RGB, z is equal to 16*2, where N is the number of digits (n> = 8) of each RGB sample ).

S is the scaling variable. For computer RGB, S equals 255. For Studio video RGB, S is equal to 219*2.

The function floor (x) returns the largest integer greater than or equal to X. The clip3 (x, y, z) function is defined as follows:

Clip3 (x, y, z) = (z <X )? X: (z> Y )? Y: z) The y sample indicates the brightness, and the u and v samples indicate the color deviations in favor of blue and red respectively. The nominal range of Y is 16*2 to 235*2. Black indicates 16*2, White indicates 235*2. The nominal range of U and V is 16*2 to 240*2. The value 128*2 indicates neutral color. However, the actual value may not be within these ranges.

For input data in the studio video RGB format, the edit operation is required to keep u and v values within the range of 0 to 2 ^ M-1. If the input is computer RGB, you do not need to edit because the conversion formula does not generate a value out of this range.

These are precise formulas with no approximate values.

In DirectShow, common RGB formats include rgb1, rgb4, rgb8, rgb565, rgb555, rgb24, rgb32, and argb32; common YUV formats include yuy2, yuyv, yvyu, uyvy, ayuv, y41p, y411, y211, if09, iyuv, yv12, yvu9, yuv411, and yuv420.

YUV sampling format

The main sampling formats are YCbCr, and YCbCr. YCbCr is commonly used. It means that each vertex stores an 8-bit brightness value (that is, the Y value ).2x2Points save a Cr and CB value, the image in the naked eye does not feel too much change. Therefore, the original RGB (R, G, and B are all 8bit unsigned) models, where 8x3 = 24 bits (such as the first graph) is required for a single vertex (after full sampling, YUV still accounts for 8 bits ). After sampling at, the current average only needs 8 + (8/4) + (8/4) = 12 bits (4 points, 8*4 (y) + 8 (u) + 8 (v) = 48 bits), with an average of 12 bits for each vertex (such as the second figure ). In this way, the image data is halved.

The above only provides a theoretical example, which may be different in actual data storage. Below are several specific storage formats:

(1) YUV 4: 4

The sampling rate of the three channels of YUV is the same. Therefore, in the generated image, the information of the three components of each pixel is complete (each component is usually 8 bits). After 8 bits quantization, each uncompressed pixel occupies 3 bytes.

The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

The stored code stream is y0 U0 V0 Y1 U1 V1 Y2 U2 V2 Y3 U3 v3

(2) YUV

The sampling rate of each chromatic aberration channel is half of the brightness channel, so the color sampling rate in the horizontal direction is only half. For non-compressed 8-bit quantization images, each macro pixel consisting of two adjacent horizontal pixels occupies 4 bytes of memory.

The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

The stored code stream is y0 U0 Y1 V1 Y2 U2 Y3 v3

The mapped pixel is: [y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]

(3) YUV

The color sampling at is a sample of the color in the horizontal direction. This is acceptable for low-end users and consumer products. For non-compressed 8-bit quantization videos, each macro pixel consisting of four adjacent horizontal pixels occupies 6 bytes of memory.

The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

The stored code stream is y0 U0 Y1 Y2 V2 Y3.

The mapped pixel is: [y0 U0 V2] [Y1 U0 V2] [Y2 U0 V2] [Y3 U0 V2]

(4) yuv4: 2: 0

Doesn't mean only y, CB, and no Cr component. It means that for each scanned line, only one color component is stored at a sampling rate of 2 to 1. The adjacent scan lines store different color components. That is to say, if the line is, the next line is, And the next line is... and so on. For each color component, the sampling rate in both the horizontal and vertical directions is, so the color sampling rate is. For non-compressed 8-bit quantization videos, each macro pixel consisting of 2x2, 2 rows, and 2 columns of adjacent pixels occupies 6 bytes of memory.

The following eight pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]

[Y5 U5 V5] [y6 U6 V6] [y7u7 V7] [Y8 u8 V8]

The stored code stream is y0 U0 Y1 Y2 U2 Y3.

Y5 V5 y6 y7 V7 Y8

The mapped pixel is: [y0 U0 V5] [Y1 U0 V5] [Y2 U2 V7] [Y3 U2 V7]

[Y5 U0 V5] [y6 U0 V5] [y7u2 V7] [Y8 U2 V7]

YUV format

The YUV format generally has two categories: packed format and planar format. The former stores the YUV component in the same array, usually several adjacent pixels constitute a macro pixel (macro-pixel), while the latter uses three arrays to separate the three components of YUV, it is like a three-dimensional plane. In table 2.3, yuy2 to y211 are both in the packaging format, while if09 to yvu9 are in the flat format. (Note: When introducing various formats, each YUV component carries a subscript. For example, y0, U0, and V0 indicate the yuv component of the first pixel, y1, u1, and V1 indicate the YUV component of the second pixel, and so on .)

The yuy2 (and yuyv) format retains the Y component for each pixel, while the UV component samples every two pixels horizontally. A macro pixel is 4 bytes, which actually represents 2 pixels. (Means that a macro pixel contains four Y components, two U components, and two v components .) The YUV component order in the image data is as follows:

Y0 U0 Y1 V0 Y2 U2 Y3 V2...

The yvyu format is similar to yuy2, except that the order of YUV components in the image data is different:

Y0 V0 Y1 U0 Y2 V2 Y3 U2...

The format of uyvy is similar to that of yuy2, but the order of YUV components in image data is different:

U0 y0 V0 Y1 U2 Y2 V2 Y3...

The ayuv format has an alpha channel and extracts YUV components for each pixel. The image data format is as follows:

A0 y0 U0 V0 A1 Y1 U1 V1...

The y41p (and y411) format retains the Y component for each pixel, while the UV component samples every 4 pixels horizontally. A macro pixel is 12 bytes, which actually represents 8 pixels. The YUV component order in the image data is as follows:

U0 y0 V0 Y1 U4 Y2 V4 Y3 Y4 Y5 y6 Y8...

In the y211 format, the Y component is sampled every two pixels in the horizontal direction, while the UV component is sampled every four pixels. A macro pixel is 4 bytes, which actually represents 4 pixels. The YUV component order in the image data is as follows:

Y0 U0 Y2 V0 Y4 U4 y6 V4...

The yvu9 format extracts the Y component for each pixel. When the UV component is extracted, the image is first divided into several 4x4 macro blocks, then, each Macro Block extracts one u component and one V component. When storing image data, the first is the array of Y components of the entire image, followed by the U Component Array and the V Component Array. The if09 format is similar to yvu9.

The iyuv format extracts the Y component for each pixel. When the UV component is extracted, the image is first divided into several 2x2 macro blocks, then, each Macro Block extracts one u component and one V component. The yv12 format is similar to that of iyuv.

The yuv411 and yuv420 formats are mostly used in DV data. The former is used in NTSC and the latter is used in palth. Yuv411 extracts the Y component for each pixel, while the UV component samples every four pixels horizontally. Yuv420 does not mean that the V component sampling is 0. Compared with yuv411, it increases the color difference sampling frequency by one time in the horizontal direction, and reduces the color difference sampling by half at the U/V interval in the vertical direction, as shown in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.