FFmpeg YUV Foundation (2)

The origin of

In life, RGB primary colors and the colors derived from them constitute our colorful world. We can see the same colors because of the way our eyes are constructed. The color vision of human eyes has the characteristics: there are three kinds of cone cells in the retina, respectively containing three kinds of light-sensitive pigments by RGB. When the light of a certain wavelength acts on the retina, the three kinds of cone cells produce different degrees of excitement and transmit to the nerve center of the brain to produce vision in a certain proportion. In RGB color space, all three are juxtaposed in importance.

RGB storage takes up a lot of space. In audio and video, it requires a large storage medium and is not fast to transmit. So we need to compress it. Excellent predecessors are more sensitive to brightness than chroma according to the degree of sensitivity of the human eye. And so YUV was born.

Introduction to the

YUV is a type of compiler true-color color space. The proper terms Y ‘uv, YUV, YCbCr, YPbPr, etc., can all be called YUV and overlap each other. “Y” denotes Luminance (Luma), while “U” and “V” denote Chrominance (Chroma). Y prime is luma; And U and V store chroma (color signal; chrominance; Color); Let’s call luminance Y.

Let’s simply say that Y is brightness; UV means chroma.

format

  • Y, U and V values are stored in an array of Macro Pixels, which are mixed together. Such as: UYVY, YUYV, etc
  • Each Y component, U component, and V component are organized in a separate plane, that is, all U components must follow Y components, and V components must follow all U components. This format is applicable to subsamples. Such as: I420, YV12, etc. Remember a particular: semi-planar, meaning the y-component is arranged normally, with UV phases, as in the common NV21.

Commonly used type

Planar format

I420

YUV components are stored separately; Y is width by height, and then you arrange U, which is 1/4 by width by height, and then you arrange V, which is also 1/4 by width by height.

YV12

YUV components are stored separately; Y is width by height, and then you arrange V, which is 1/4 by width by height, and then you arrange U, which is also 1/4 by width by height. It’s exactly the opposite of UV for I420.

NV12

NV12 is also Planar, unlike before, UV is arranged in phases, which is called semi-planar.

Y is width * height, and the total length of UV is 1/2 * width * height.

NV21

NV12 is also Planar, unlike before, UV is arranged in phases, which is called semi-planar.

Y is width * height, and the total length of UV is 1/2 * width * height.

I422

Y is width * height, U is 1/2 * width * height,Y is 1/2 * width * height.

YV16

Swap the UV arrays of I422.

NV16

Belongs to a kind of YUV422sp, SP, according to the previous said, should be UV interphase arrangement, this YUY422sp U head and V component interphase arrangement. At this point, I believe you can think of NV61.

I444

Yuvs are arranged on a scale of 1:1:1. The Y, U and V components are stored separately. Y\U\V, length 3 * width * height.

Compact format

YUVY

YUV spacing, you can see that the two Y’s share the same SET of UVs. Belong to YUV422.

VYUY

YUV is just not in the same order as YUV. Two Y’s share one set of UVs. Belong to YUV422.

The rules

  • Those beginning with I are planar and are stored separately in terms of Y, U and V components.
  • Sp stands for semi-planar, UV is arranged in phases.
  • P stands for planar, not packed.

reference

zh.wikipedia.org/wiki/YUV

Blog.csdn.net/xjhhjx/arti…

www.jianshu.com/p/538ee63f4…

libYUV

Libyuv is an open source project that includes YUV scaling and conversion capabilities.

Download: github.com/lemenkov/li…

Compile the official documentation, here provide a compiled, link: pan.baidu.com/s/1tcToG4kY… Extract code: Dydy

API look at the documentation. Just pay attention to understanding the concept of step size.