ffmpeg resize down larger video to fit desired size and add padding

后端 未结 3 1458
一整个雨季
一整个雨季 2020-12-25 13:43

I\'m trying to resize a larger video to fit an area that I have. In order to achieve this I calculate first the dimensions of the resized video so That it fits my area, and

3条回答
  •  醉梦人生
    2020-12-25 13:49

    try -vf "scale=iw*min(405/iw\,320/ih):ih*min(405/iw\,320/ih),pad=405:320:(405-iw)/2:(320-ih)/2"

    Edit to clarify what's going on in that line: you are asking how to scale one box to fit inside another box. The boxes might have different aspect ratios. If they do, you want to fill one dimension, and center along the other dimension.

    # you defined the max width and max height in your original question
    max_width     = 405
    max_height    = 320
    
    # first, scale the image to fit along one dimension
    scale         = min(max_width/input_width, max_height/input_height)
    scaled_width  = input_width  * scale
    scaled_height = input_height * scale
    
    # then, position the image on the padded background
    padding_ofs_x = (max_width  - input_width) / 2
    padding_ofs_y = (max_height - input_height) / 2
    

提交回复
热议问题