How to resize AVFrame?

How to resize AVFrame? I

Here is what I am doing now:

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);

But after that resizedFrames->widthand heightstill 0, the contents of the AVFrame look like garbage, and I get a warning that the data does not align when called sws_scale. Note. I don’t want to change the pixel format, and I don’t want to hard code what it is.

0
source share
1 answer

So, a few things happen.

, , , , , . , bilinear . bicubic (SWS_BICUBIC).

+3

Source: https://habr.com/ru/post/1621593/


All Articles