c++ - 如何调整 AVFrame 的大小?

标签 c++ c ffmpeg

如何调整 AVFrame 的大小?我

这是我目前正在做的事情:

AVFrame* frame = /*...*/;

int width = 600, height = 400;
AVFrame* resizedFrame = av_frame_alloc();

auto format = AVPixelFormat(frame->format);

auto buffer = av_malloc(avpicture_get_size(format, width, height) * sizeof(uint8_t));

avpicture_fill((AVPicture *)resizedFrame, (uint8_t*)buffer, format, width, height);

struct SwsContext* swsContext = sws_getContext(frame->width, frame->height, format,
                                               width,         height,         format,
                                               SWS_BILINEAR,  nullptr,        nullptr,        nullptr);

sws_scale(swsContext, frame->data, frame->linesize, 0, frame->height, resizedFrame->data, resizedFrame->linesize);

但是在这个resizedFrames->widthheight仍然是0之后,AVFrame的内容看起来像垃圾,当我调用 sws_scale 。注意:我不想更改像素格式,也不想对其进行硬编码。

最佳答案

所以,有一些事情正在发生。

我认为,如果您遵循这两个建议,您会发现重新缩放按预期工作,不会发出警告并且具有正确的输出。质量可能不是很好,因为您正在尝试执行 bilinear缩放。大多数人使用bicubic缩放(SWS_BICUBIC)。

关于c++ - 如何调整 AVFrame 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31253485/

相关文章:

c - 输出是什么? C语言编程

python - OpenCV VideoCapture 无法从流中读取

.net - 使用...进行实时视频编码?

c++ - C++编程实践与异常处理的混淆

C++ - 将类转换为其他类型

变量 '' 周围的 C++ 堆栈已损坏。 (D3D9)

nginx - 使用 ffmpeg 在文件夹中流式传输视频

c++ - 确定 Qt 库链接

c - read() 和 write() 使用 spi 设备驱动程序

c++ - 将 FORTRAN 转换为 C/C++