为sws_scale()分配AVFrame

问题描述 投票:0回答:1

尝试编写使用libav从任意视频中提取原始像素数据(〜BMP)的程序。除了sws_scale()无法将AVFrame转换为RGB24之外,其他所有操作都进行顺利。

[我给出了一个最小的例子,其中AVFrame的创建和初始化是通过Internet上找到的4种不同方法进行的:https://github.com/SlavMFM/libav_bmp_example-所有这些都以不同的方式失败。我该如何解决它,以便sws_scale()进行转换?

ffmpeg libav libavcodec
1个回答
0
投票

首先,请勿使用avcodec_decode_video2。使用avcodec_send_packetavcodec_receive_frame

第二,不要在源上调用av_frame_get_buffer,只需将其分配给av_frame_allocavcodec_receive_frame就会建立其余的]

然后分配目标帧,例如:

AVFrame* frame = av_frame_alloc();
frame->format = whatever;
frame->width = w;
frame->height = h;
av_frame_get_buffer(frame, 32);
© www.soinside.com 2019 - 2024. All rights reserved.