[英]ffmpeg: sws_scale returning wrong values in plane V during RGB to YUV420 conversion
I am trying to use sws_scale to transform an image from RGB to YUV420P. 我正在尝试使用sws_scale将图像从RGB转换为YUV420P。 The code I use in C++ is the following: 我在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);
The Y and U planes are encoded properly but the V plane is completely written with the value 0x80
I wonder if I am doing anything wrong. Y和U平面编码正确,但V平面完全用值0x80
写入,我想知道我做错了什么。
I still have no idea of why it works, but this solved the problem: 我仍然不知道它为什么起作用,但这解决了问题:
BYTE *dest[3] = {yuv,
yuv + current_width * current_height,
yuv + (current_width * current_height)
+ ((current_width >> 1) * (current_height >> 1))};
Semantically they are the same, so I will leave this question open in case someone come up with an explanation. 从语义上讲,它们是相同的,因此,如果有人提出解释,我将保留此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.