How do you resize an AVFrame?

前端 未结 1 908
别跟我提以往
别跟我提以往 2021-01-01 07:09

How do you resize an AVFrame? I

Here\'s what I\'m currently doing:

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

int width = 600, height = 400;
AVFrame* r         


        
相关标签:
1条回答
  • 2021-01-01 08:02

    So, there's a few things going on.

    • avpicture_fill() does not set frame->width/height/format. You have to set these values yourself.
    • avpicture_get_size() and avpicture_fill() do not guarantee alignment. The underlying functions called in these wrappers (e.g. av_image_get_buffer_size() or av_image_fill_arrays()) are called with align=1, so there's no buffer alignment between lines. If you want alignment (you do), you either have to call the underlying functions directly with a different align setting, or call avcodec_align_dimensions2() on the width/height and provide aligned width/height to the avpicture_*() functions. If you do that, you can also consider using avpicture_alloc() instead of avpicture_get_size() + av_malloc() + avpicture_fill().

    I think if you follow these two suggestions, you'll find that the rescaling works as expected, gives no warnings and has correct output. The quality may not be great because you're trying to do bilinear scaling. Most people use bicubic scaling (SWS_BICUBIC).

    0 讨论(0)
提交回复
热议问题