格式转换至yuv422转 yuv420
//pYUV为422,yuv为420
/*ok!
* brief:pyuv is yuv422sp srcIn, and yuv is yuv420p desOut
*/
int YUV422To420(unsigned char *pYUV, unsigned char*yuv, int lWidth, int lHeight)
int YUV422To420(unsigned char *pYUV, unsigned char*yuv, int lWidth, int lHeight)
{
int i,j;
unsigned char*pY = yuv;
unsigned char *pU = yuv + lWidth*lHeight;
unsigned char *pV = pU + (lWidth*lHeight)/4;
unsigned char *pYUVTemp = pYUV;
unsigned char *pYUVTempNext = pYUV+lWidth*2;
for(i=0; i<lheight; i+=2) <="" div="">
{
for(j=0; j<lwidth; j+=2) <="" div="">
{
pY[j] = *pYUVTemp++;
pY[j+lWidth] = *pYUVTempNext++;
pU[j/2] =(*(pYUVTemp) + *(pYUVTempNext))/2;
pYUVTemp++;
pYUVTempNext++;
pY[j+1] = *pYUVTemp++;
pY[j+1+lWidth] = *pYUVTempNext++;
pV[j/2] =(*(pYUVTemp) + *(pYUVTempNext))/2;
pYUVTemp++;
pYUVTempNext++;
}
pYUVTemp+=lWidth*2;
pYUVTempNext+=lWidth*2;
pY+=lWidth*2;
pU+=lWidth/2;
pV+=lWidth/2;
}
return 1;
}
大意了,每四行计算时,牵引错误,试试下面的代码吧,不过这种代码很有优化的余地
书籍可以参考“视频技术手册”,上面有YUV422到YUV420采样转换的讲解
http://bbs.csdn.net/topics/370045077
http://blog.csdn.net/searchsun/article/details/2443867 yuv pannle packet
http://blog.chinaunix.net/uid-29181887-id-3992543.html
http://www.videolan.org/developers/x264.html x264编码器
http://www.cnblogs.com/zhengbin/p/5023640.html js 黑客帝国特效
root