如何调整 AVFrame 的大小?

Dav*_*vid 2 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);
Run Code Online (Sandbox Code Playgroud)

但毕竟这resizedFrames->widthheight仍然0时,AVFrame样子垃圾的内容,我得到一个警告,数据不对齐,当我打电话sws_scale。注意:我不想更改像素格式,也不想对其进行硬编码。

Ron*_*tje 5

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

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

  • 谢谢!如果我使用 `av_image_get_buffer_size` 和 `av_image_fill_arrays` 我应该通过什么对齐方式? (2认同)