Tuesday, November 15, 2011

ffmpeg -- maintain aspect ratio with fixed height/width.

I found this in the ffmpeg man pages; 99% users thing this's not possible, but it is possible without   calculating aspect ratio in mind.

Use the scale filter before specifying the input file -

-vf scale=www:www/a

Where 'www' is the desired width of the video you want. To maintain the height - 

-vf scale=hhh*a:hhh

Where hhh is the desired height you want.

1 comment:

  1. i came to this blog from

    peace said:"The spec's for the iPod Classic (160G) are below."

    were you say "That's cause it doesn't have a powerful processor to rescale and play the video" "If you want, I can make the ffmpeg presets."

    just thought id mention that you don't need custom presets to play 640x480

    this line works fine

    ffmpeg -threads 4 -i "infile.whatever" -f mp4 -vcodec libx264 -crf 18 -minrate 600k -maxrate 1500k -bufsize 1500k -refs 3 -preset slow -vprofile Baseline -level 3.0 -flags2 -bpyramid -wpredp 0 -strict experimental -acodec aac -ac 2 -ab 128k -vf hqdn3d,unsharp=5:5:0.5,scale=640:480 "outfile.MP4"

    if your input video is 16:9 ratio this should also play fine but not tested for this

    just add ,setdar=16:9 after the scale part to make it display widescreen/16:9 ratio files properly