H.264编码器输入要YUV420,而解码器解码之后显示一般又要YUV422,并且视频采集芯片输出往往也是YUV422,下面以我一个实际使用为例说一下YUV422格式:
/* YUV4:2:2格式(这是初始化背景为纯色,所以用了同一个Y) */
/* Black color in UYVY format */
#define UYVY_BLACK/*Y Cr Y Cb*/ 0x10801080/*black*/ /*blue:0x286e28ef red:0x51ef515b green:0x90239036/*/
/* DM6446中的测试代码,整个宏像素赋值 */
for (bufIdx=; bufIdx < NUM_DISPLAY_BUFS; bufIdx++) {
/* Clear the video buffer */
buf = (unsigned int *) virtDisplays[bufIdx];
for (i=; i < displaySize / sizeof(unsigned int); i++) {
buf[i] = UYVY_BLACK;
}
/* Translate the virtual address to physical as resizer needs this */
physDisplays[bufIdx] = Memory_getPhysicalAddress(virtDisplays[bufIdx]);
DBG("virtDisplays[%d] LA:%#lx PA:%#lx\n",
bufIdx, (unsigned long) virtDisplays[bufIdx], physDisplays[bufIdx]);
}
可以看到YUV422存储顺序为Y Cr Y Cb Y Cr Y Cb Y Cr Y Cb……,Y是全部保留,而Cr,Cb则是在一行中交替采样,而不像YUV420,一行采样 Cb,下一行采用Cr。注意区别。

再说一下上面YCbCr的由来,是通过RGB转化的,具体代码如下:
RGB -> YCbCr代码
void rgb2ycbcr(unsigned char r,unsigned char g,unsigned char b)
{
unsigned char ycbcr_res[];
ycbcr_res[]= (unsigned char)(r * + g * + b * )+ ;
ycbcr_res[]= (unsigned char)(r *- + g * - + b * )+ ;
ycbcr_res[]= (unsigned char)(r * + g * - + b *-)+ ;
}
代码测试