你如何调整 AVFrame 的大小?

How do you resize an AVFrame?

如何调整 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 scaling. Most people use bicubic scaling (SWS_BICUBIC)。