Brief description of YUV color format

Source: Internet
Author: User
    • Brief description of YUV color format
    • 1 cause
    • 2 root causes
    • 3 Comparison
    • 4. Reference
Introduction YUV Color format -- Starting from the problem of color skewness in Xvid Decoding

(Chen YiChuan ybc2084@163.com UESTC, Cd)

1Cause The reason was that two weeks ago, when I decoded a MPEG-4 code stream with Xvid, I found that the decoded video sequence was blue. The color field space specified at that time was yv12. I remember that yv12 is in the yuv4: 2: 0 color format. But the output is obviously incorrect.

2Root Cause I studied several YUV color formats last night and found out the problem.

The YUV format is divided into two types: compress YUV format (packed) and flat YUV format (planar ).

In the tightening YUV format, the brightness component y (luminance), two color components U and V (chrominance) it is stored in a separate matrix. This is similar to the RGB storage method. RGB is stored in a tight format. Figure 1 is a 4x4 compressed YUV format.

Figure 1 tightening YUV format

For the yuv4: 4: 4 format, it is appropriate to adopt the tightening format, but because the other formats of YUV are obtained through subsample, the brightness component and the color component have different resolutions. In this case, it is inconvenient to store data in a compressed format.

In the flat YUV format, the three components of YUV are stored in different matrices. Each matrix is regarded as a plane, and the final image is obtained by combining the three planes.

In Xvid, three colors in yuv4: 2: 2 format are defined, which are all stored in the compressed format. The names of the three yuv4: 2: 2 color formats are yuy2, uyvy, and yvyu. Their fourcc codes are as follows: 0x32595559, 0x59565955, and 0x55595659. For more information about the fourcc code, see [1].

Xvid defines two colors in yuv4: 2: 0 format, which are stored in a flat format. The names of the two yuv4: 2: 0 color formats are i420 and yv12 respectively. Their fourcc codes are 0x30323449 and 0x32315659 respectively.

Taking an image of 4x4 size as an example, this section describes how to store the color data in i420 format, as shown in figure 2.

Figure 2 i420 plane YUV format

For images of the same size, the yv12 format is stored in method 3.

Figure 3 yv12 flat YUV format

The yv12 format differs from the i420 format in that the position of the V plane and the U plane is different. In the i420 format, the U plane follows the Y plane, followed by the V plane. However, in the yv12 format, the Y plane is followed by the V plane, followed by the U plane.

In the presence of partial colorsProgramIn, I decode the Xvid and output it to the file in the order of the Y plane, the U plane, and the last v plane, that is, it is the same as the color plane order of i420, this is also the order of planes required by YUV viewer. The mistake I made was to confuse yv12 and i420. The output format I specified for Xvid is yv12. XviD faithfully executes my command and outputs the decoded image in the first Y plane, then v plane, and finally U plane, however, when I save the data to a file, it is saved in the i420 order. Obviously, this is not an error.

3Comparison The following compares the partial color image with the image obtained after normal decoding (obtained through YUV viewer ). Figure 4 shows the image in the yv12 output format, and the color is obviously incorrect. Figure 5 shows the normal image obtained after the i420 output format is specified, which is right and wrong when compared with figure 4.

Figure 4 partial Color Image

Figure 5 normal image

4Reference [1] http://www.fourcc.org /.

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.