Maintaining aspect ratio with FFmpeg

前端 未结 8 1429
悲&欢浪女
悲&欢浪女 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
    2021-01-29 22:54

    -vf "scale=640:-1"
    

    works great until you will encounter error

    [libx264 @ 0x2f08120] height not divisible by 2 (640x853)
    

    So most generic approach is use filter expressions:

    scale=640:trunc(ow/a/2)*2
    

    It takes output width (ow), divides it by aspect ratio (a), divides by 2, truncates digits after decimal point and multiplies by 2. It guarantees that resulting height is divisible by 2.

    Credits to ffmpeg trac

    UPDATE

    As comments pointed out simpler way would be to use -vf "scale=640:-2". Credits to @BradWerth for elegant solution

提交回复
热议问题