How do you resize an AVFrame
? I
Here's what I'm currently doing:
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 this resizedFrames->width
and height
are still 0, the contents of the AVFrame look like garbage, and I get an warning that data is unaligned when I call sws_scale
. Note: I don't want to change the pixel format, and I don't want to hard code what it is.