解碼高分別率
如果圖片分辨率太高,影響解碼速率,可以采用降采樣后再解碼
參考opencv的pyrDown降采樣接口
cv::pyrDown(yuv, yuvDown, cv::Size(yuv.cols / 2, yuv.rows / 2));
YUV轉(zhuǎn)RGB,不同實現(xiàn)方式效率比較
轉(zhuǎn)換效率分析
測試序列:1920*1080
測試環(huán)境: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轉(zhuǎn)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;
}