ffmpeg:sws_scale在RGB到YUV420转换期间在平面V中返回错误的值

时间:2012-02-29 10:18:48

标签: c++ image-processing ffmpeg

我正在尝试使用sws_scale将图像从RGB转换为YUV420P。我在C ++中使用的代码如下:

SwsContext *swscontext = sws_getContext(current_width,
                                        current_height,
                                        PIX_FMT_RGB24,
                                        current_width,
                                        current_height,
                                        PIX_FMT_YUV420P,
                                        SWS_FAST_BILINEAR,
                                        NULL,
                                        NULL,
                                        NULL);
const int srcstride[3] = {current_width * 3, 0, 0};
BYTE *data_pos[3] = {data, NULL, NULL};
BYTE *dest[3] = {yuv,
                yuv + current_width * current_height,
                yuv + (current_width * current_height) 
                    + ((current_width * current_height) / 2)};
const int dststride[3] = {current_width, current_width / 2, current_width / 2};
sws_scale(swscontext, data_pos, srcstride, 0, current_height,
          dest, dststride);

Y和U平面编码正确,但V平面完全写入值0x80我想知道我做错了什么。

1 个答案:

答案 0 :(得分:0)

我仍然不知道它为什么会起作用,但这解决了这个问题:

BYTE *dest[3] = {yuv,
                 yuv + current_width * current_height,
                 yuv + (current_width * current_height) 
                     + ((current_width >> 1) * (current_height >> 1))};

在语义上它们是相同的,所以我会保留这个问题,以防有人提出解释。