Maintaining aspect ratio with FFmpeg

前端 未结 8 1340
悲&欢浪女
悲&欢浪女 2021-01-29 22:39

I need to convert a bunch of video files using FFmpeg. I run a Bash file that converts all the files nicely, however there is a problem if a file converted is not in 16:9 format

8条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 22:54

    Although most of these answers are great, I was looking for a command that could resize to a target dimension (width or height) while maintaining aspect ratio. I was able to accomplish this using ffmpeg's Expression Evaluation.

    Here's the relevant video filter, with a target dimension of 512:

    -vf "thumbnail,scale='if(gt(iw,ih),512,trunc(oh*a/2)*2)':'if(gt(iw,ih),trunc(ow/a/2)*2,512)'"


    For the output width:

    'if(gt(iw,ih),512,trunc(oh*a/2)*2)'

    If width is greater than height, return the target, otherwise, return the proportional width.


    For the output height:

    'if(gt(iw,ih),trunc(ow/a/2)*2,512)'

    If width is greater than height, return the proportional height, otherwise, return the target.

提交回复
热议问题