首先想要了解YUV为何物,请猛戳:https://msdn.microsoft.com/en-us/library/aa904813(VS.80).aspx
上面的链接中,微软已经写的很详细了,国内大部分文章都是翻译这篇文章的,如果还有疑问的同学可以参考下面这些大神的博客:
- 最简单的基于FFmpeg的libswscale的示例(YUV转RGB) http://blog.youkuaiyun.com/leixiaohua1020/article/details/42134965
- 图文详解YUV420数据格式:http://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.htm
- ANDROID 高性能图形处理: http://tangzm.com/blog/?p=1
看完上面的文章应该都会有所了解和认识了,因为在Android API <= 20(Android5.0之前的版本)中Google支持的Camera Preview Callback的YUV常用格式有两种:一个是NV21,一个是YV12,在此针对这两种格式做分析。
NV21:
先贴一段微软的叙述:
4:2:0 Formats, 12 Bits per Pixel
Four 4:2:0 12-bpp formats are recommended, with the following FOURCC codes:
- IMC2
- IMC4
- YV12
- NV12
In all of these formats, the chroma channels are subsampled by a factor of two in both the horizontal and vertical dimensions.
YV12
All of the Y samples appear first in memory as an array of unsigned char values. This array is followed immediately by all of the V (Cr) samples. The stride of the V plane is half the stride of the Y plane, and the V plane contains half as many lines as the Y plane. The V plane is followed immediately by all of the U (Cb) samples, with the same stride and number of lines as the V plane (Figure 12).
Figure 12. YV12 memory layout
NV12
All of the Y samples are found first in memory as an a