9
我想将YUV420P
图像(从H.264
流接收)转换为RGB
,同时还调整它的大小,使用sws_scale
。
原始图像的大小是480 × 800
。只需转换相同的尺寸就可以。
但是,当我试图改变尺寸,我得到一个扭曲的图像,具有以下模式:sws_scale YUV - > RGB失真图像
- 改为
481 × 800
将产生扭曲乙&用黑白它看起来像它在中间 - 被切
482 × 800
将多个来甚至歪曲 483 × 800
失真但在彩色484 × 800
是确定(正确缩放)。
现在,这种模式如下 - 缩放只会正常工作,如果由4
分歧之间的区别这里是我解码和转换图像的方式示例代码。所有方法都显示“成功”。
int srcX = 480;
int srcY = 800;
int dstX = 481; // or 482, 483 etc
int dstY = 800;
AVFrame* avFrameYUV = avcodec_alloc_frame();
avpicture_fill((AVPicture *)avFrameYUV, decoded_yuv_frame, PIX_FMT_YUV420P, srcX , srcY);
AVFrame *avFrameRGB = avcodec_alloc_frame();
AVPacket avPacket;
av_init_packet(&avPacket);
avPacket.size = read; // size of raw data
avPacket.data = raw_data; // raw data before decoding to YUV
int frame_decoded = 0;
int decoded_length = avcodec_decode_video2(g_avCodecContext, avFrameYUV, &frame_decoded, &avPacket);
int size = dstX * dstY * 3;
struct SwsContext *img_convert_ctx = sws_getContext(srcX, srcY, SOURCE_FORMAT, dstX, dstY, PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
avpicture_fill((AVPicture *)avFrameRGB, rgb_frame, PIX_FMT_RGB24, dstX, dstY);
sws_scale(img_convert_ctx, avFrameYUV->data, avFrameYUV->linesize, 0, srcY, avFrameRGB->data, avFrameRGB->linesize);
// draws the resulting frame with windows BitBlt
DrawBitmap(hdc, dstX, dstY, rgb_frame, size);
sws_freeContext(img_convert_ctx);
在sws_getContext()函数,你是路过的参数格式标识符PIX_FMT_BGR24而不是PIX_FMT_RGB24你做avpicture_fill – 2012-12-04 16:11:40
随时https://ffmpeg.org/trac/ffmpeg/newticket – 2011-12-29 16:17:55