First understand why video encoding uses YUV420 instead of rgb. Then you need to understand the principles of the two, look at the picture and talk

Therefore, from the memory point of view, the yuv unit pixel uses lower memory, but the effect of the two representations is the same. It can also be considered that rgb is overdrawn, and the area that the human eye cannot distinguish is also drawn.
Let’s take a look at the temporary memory usage comparison between the two. Here we use the ·rgb24 comparison
RGB24 uses 24 bits to represent a pixel, and RGB components are represented by 8 bits, with a value range of 0-255. In a 2*2 pixel area, the number of bytes temporarily used by RRG is 2*2*3=12 bytes. Then expressed by yuv, the number of bytes occupied is 4(Y)+1(u)+1(v)=6 bytes, where Y occupies 4 bytes, U and V each occupy 1 byte, the ratio is 4 :1:1
So on a device with a width and height of w*h,Use rgb to indicate that the number of bytes occupied by the encoding is w*h*3, and use yuv to indicate that the temporarily used memory is w*h*+w*h/4+w*h/4 = w*h*3/2.
The first thing to understand is that yuv has many encoding formats, of which yuv420 is one type, and nv21 is another type of yuv420. And nv21 is a video encoding for android devices.
nv21 encoding format: For example, a 1920*1280 picture, after nv21 encoding, will become 1920*1280 bytes in front of it are all Y, starting from 1920*1280 bytes in length, U and V will be arranged alternately, their words The section length is 1920*1280/4 respectively. Please see the picture below

As shown in the color box, 4 Ys will correspond to one UV.
I420 is also a kind of YUV420 encoding format. Due to the reasons of android mobile phone manufacturers, the data collected by the camera is always NV21 encoded data, but for this kind of data cannot be displayed on the Apple or Windows platform, then this encoding format is required The data needs to be re-encoded, and all manufacturers are adapted to the I420 encoding format.
I420 encoding format: For example, a 1920*1280 picture, after I420 encoding, will become 1920*1280 bytes in front of it are all Y, starting from 1920*1280 bytes, U will be arranged first, and the total byte length is 1920*1280/4, arrange V starting from 1920*1280+1920*1280/4, and the byte length is 1920*1280/4, so the total byte length is the same as NV21, but the encoding order of UV is different. Please see the picture below:

RGB_2_NV21 YUYV_2_NV21 UYVY_2_NV21...
I420 corresponds YUV420P storage plane format, 4: 2: 0 sampling, U first, followed by V. YV12 corresponds YUV420P storage plane format, 4: 2: 0 sampling, V first, U after. NV12 corresponds yuv420sp, s...
The three components of YUV420P, Y, U, and V are all in flat format, which are divided into I420 and YV12. The difference between the I420 format and the YV12 format lies in the location of the U plan...
Android implements YUV i420 data to NV21 data. Reference articleThis blog I420 data turn NV21 has a problem....
One,Introduction to YUV420 I420 A color coding method. In the YUV color space, Y represents the luminance signal, and U and V represent the chrominance signal; The YUV arrangement is as follows, 4 Y c...
nv21Tojpg jpg2nv21...
The above is NV21 to rgb, then how to write NV12 to rgb? Very simple, you can exchange the u and v code....
...
The camera data is NV21, converted to RGB. The performance was found to be poor during testing: ...