Image FFMPEG:sws_scale不会在目标帧中生成任何数据

Image FFMPEG:sws_scale不会在目标帧中生成任何数据,image,ffmpeg,Image,Ffmpeg,我使用FFMPEG对H264流进行解码。在解码YUV420帧后,我想将它们转换为RGB24 struct SwsContext * ctx = NULL; // frame is AVFrame in YUV420 obtained from decoder. It has all three strides and seem to be valid. if (ctx == NULL) { ctx = sws_getCo

我使用FFMPEG对H264流进行解码。在解码YUV420帧后,我想将它们转换为RGB24

struct SwsContext * ctx = NULL;

// frame is AVFrame in YUV420 obtained from decoder. It has all three strides and seem to be valid.

if (ctx == NULL)
                {
                    ctx = sws_getContext(frame->width, frame->height, frame->format, frame->width, frame->height,
                        AV_PIX_FMT_RGB24, SWS_BICUBIC, 0, 0, 0);
                }

            AVFrame* frame2 = av_frame_alloc();

            int num_bytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, frame->width, frame->height, 32);

            uint8_t* frame2_buffer = (uint8_t *)av_malloc(num_bytes * sizeof(uint8_t));

            int size = av_image_fill_arrays(frame2->data, frame2->linesize, frame2_buffer, AV_PIX_FMT_RGB24, frame->width, frame->height, 32);

            int height_of_output = sws_scale(ctx, frame->data, frame->linesize, 0, frame->height, frame2->data, frame2->linesize);

            callbackFullRGB(state, frameIndex, 0, frame2->data[0], num_bytes, (__int32)frame2->format, (__int32)frame2->width, (__int32)frame2->height);

            av_frame_free(&frame2);
但frame2没有分辨率集,像素格式为-1,数据缓冲区为空。我有1280x720输入,输出帧的步长设置为3840,这是正确的。sws_scale也返回720作为结果-没有错误,没有异常


可能有什么问题?

尽量不要自己分配帧缓冲区。而是先分配框架,然后设置其宽度、高度和格式。然后在其上调用
av_frame\u get_buffer
AvFrame*frame2=av_frame\u alloc();frame2->format=AV_PIX_FMT_RGB24;帧2->宽度=帧->宽度;框架2->高度=框架->高度;av_帧_获取_缓冲区(帧2,0)@Crigges,谢谢你的回复。我试过了,但结果是一样的。在我看来,sws_scale内部无法解码,但不知何故不会产生异常。我还将我的libs更新为最新的稳定版本-4.1.3 x64,没有任何更改。如果您有可用的OpenCV,请运行此代码段:它将直接从AvFrame数据成员创建一个Mat,并将其作为.png写入磁盘。如果此操作没有失败且.png有效,则可以确保AvFrame有效。也请链接你的更新代码。代码看起来是正确的。尝试使用调试器,确认输入值是否有意义。代码是否在命令行上运行?通常,ffmepg会输出有用的调试消息。@Crigges-ah。。这修复了我的内存泄漏。上帝保佑你:)