我正在尝试使用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
我想知道我做错了什么。
答案 0 :(得分:0)
我仍然不知道它为什么会起作用,但这解决了这个问题:
BYTE *dest[3] = {yuv,
yuv + current_width * current_height,
yuv + (current_width * current_height)
+ ((current_width >> 1) * (current_height >> 1))};
在语义上它们是相同的,所以我会保留这个问题,以防有人提出解释。