【发布时间】:2019-03-31 12:46:21
【问题描述】:
我正在使用 FFMpeg 解码视频,并想使用 OpenGL 编辑解码的帧,但为了做到这一点,我需要将 AVFrame 中的数据从 YUV 转换为 RGB。
为此,我创建了一个新的 AVFrame:
AVFrame *inputFrame = av_frame_alloc();
AVFrame *outputFrame = av_frame_alloc();
av_image_alloc(outputFrame->data, outputFrame->linesize, width, height, AV_PIX_FMT_RGB24, 1);
av_image_fill_arrays(outputFrame->data, outputFrame->linesize, NULL, AV_PIX_FMT_RGB24, width, height, 1);
创建转换上下文:
struct SwsContext *img_convert_ctx = sws_getContext(width, height, AV_PIX_FMT_YUV420P,
width, height, AV_PIX_FMT_RGB24,
0, NULL, NULL, NULL);
然后尝试转成RGB:
sws_scale(img_convert_ctx, (const uint8_t *const *)&inputFrame->data, inputFrame->linesize, 0, inputFrame->height, outputFrame->data, outputFrame->linesize);
但这会在运行时导致“[swscaler @ 0x123f15000] bad dst image pointers”错误。翻了一下FFMpeg的源码,发现原因是outputFrame的数据没有初始化,但是不明白应该怎么做。
我发现的所有现有答案或教程 (see example) 似乎都使用了已弃用的 API,并且不清楚如何使用新的 API。如有任何帮助,我将不胜感激。
【问题讨论】: