What I am trying to do is set up one script that will check the ratio of height over width and then determine WHICH dimension to scale to fit HD(1920x1080). Is this possible using standard FFMPEG commands?

I also need to crop either height or width if the resulting dimension is larger than 1080 or 1920 respectively.

I've already read this Resize videos with different widths to a fixed height preserving aspect ratio with ffmpeg

so i know how to scale if you know in advance WHICH dimension of your source video is larger.

  • 1
    superuser.com/questions/547296/… does this cover your question? – Jasper Jan 26 '15 at 22:23
  • If you had a square input video, say 500x500, would you want the output to be 1080x1080, or 1920x1080 with pillarboxes? – David Yaw Jan 26 '15 at 22:44

I would use ffprobe to read the width & height of the existing video, and do the math in bash to figure out which is the limiting factor.

(You mentioned that you wanted to set up one "script", so I'm hoping that means bash is acceptable.)


W=$( ffprobe input.mp4 -show_streams |& grep width )

H=$( ffprobe input.mp4 -show_streams |& grep height )

# Target a 1920x1080 output video. 

# I'm not familiar with the resizing parameters to ffmpeg, 
# so I'm writing the below code based on the question you linked to. 

if [ $(( $W * $TARGETH )) -gt $(( $H * $TARGETW" )) ]; then
    # The width is larger, use that
    # The height is larger, use that

ffmpeg -i input.mp4 -vf $SCALEPARAM output.mp4

Not the answer you're looking for? Browse other questions tagged or ask your own question.