解码高分别率
如果图片分辨率太高,影响解码速率,可以采用降采样后再解码
参考opencv的pyrDown降采样接口
cv::pyrDown(yuv, yuvDown, cv::Size(yuv.cols / 2, yuv.rows / 2));
YUV转RGB,不同实现方式效率比较
转换效率分析
测试序列:1920*1080
测试环境:OpenCV2.4.8, FFmpeg2.0, YUV2RGB v0.03
https://blog.csdn.net/lg1259156776/article/details/53071961
Method | Time(ms) |
---|---|
YV12ToBGR24_Native | 83.7263 |
YV12ToBGR24_Table | 54.2376 |
YV12ToBGR24_OpenCV | 26.0529 |
YV12ToBGR24_FFmpeg | 3.41499 |
YV12ToBGR24_Pinknoise | 14.1215 |
附录:
YV12转RGB32
此算法解析低分辨率效率还行,但是高于2K的效率就不行了,解析3392*2008分辨率的视频 125ms一帧。会导致视频不流畅
bool YV12_to_RGB32(unsigned char* pYV12, unsigned char* pRGB32, int iWidth, int iHeight)
{
if (!pYV12 || !pRGB32)
return false;
const long nYLen = long(iHeight * iWidth);
const int nHfWidth = (iWidth >> 1);
if (nYLen < 1 || nHfWidth < 1)
return false;
unsigned char* yData = pYV12;
unsigned char* vData = pYV12 + iWidth*iHeight + (iHeight / 2)*(iWidth / 2);//&vData[nYLen >> 2];
unsigned char* uData = pYV12 + iWidth*iHeight;// &yData[nYLen];
if (!uData || !vData)
return false;
int rgb[4];
int jCol, iRow;
for (iRow = 0; iRow < iHeight; iRow++)
{
for (jCol = 0; jCol < iWidth; jCol++)
{
rgb[3] = 1;
int Y = yData[iRow*iWidth + jCol];
int U = uData[(iRow / 2)*(iWidth / 2) + (jCol / 2)];
int V = vData[(iRow / 2)*(iWidth / 2) + (jCol / 2)];
int R = Y + (U - 128) + (((U - 128) * 103) >> 8);
int G = Y - (((V - 128) * 88) >> 8) - (((U - 128) * 183) >> 8);
int B = Y + (V - 128) + (((V - 128) * 198) >> 8);
// r分量值
R = R<0 ? 0 : R;
rgb[2] = R > 255 ? 255 : R;
// g分量值
G = G<0 ? 0 : G;
rgb[1] = G>255 ? 255 : G;
// b分量值
B = B<0 ? 0 : B;
rgb[0] = B>255 ? 255 : B;
pRGB32[4 * (iRow*iWidth + jCol) + 0] = rgb[0];
pRGB32[4 * (iRow*iWidth + jCol) + 1] = rgb[1];
pRGB32[4 * (iRow*iWidth + jCol) + 2] = rgb[2];
pRGB32[4 * (iRow*iWidth + jCol) + 3] = rgb[3];
}
}
return true;
}
网友评论