Change video resolution ffmpeg

I guess that really there are two questions here...

  1. How do I batch convert files?
  2. How do I auto scale a video?

How do I batch convert files?

These scripts ought to do the trick...

Windows

for %%i in (*.mp4) do (
    ffmpeg -y -i "%%i" << TODO >> "%%~ni_shrink.mp4"
)

Linux (UNTESTED!)

for i in *.mp4; 
do
    ffmpeg -y -i "$i" << TODO >> "${i%.mp4}_shrink.mp4";
done

(I'm not too sure about the output file expansion in the Linux script, worth validating that.)


How do I auto scale a video?

This is a little trickier. As you have your command, the aspect ratio is potentially going to get messed up. Options here...

  1. Scale the video, ignore aspect ratio. Result = distorted video
  2. Scale the video, keep aspect ratio so that the scaled height (or width) is adjusted to fit. Result = optimal
  3. Scale the video, keep aspect ratio and pad with black bars so that the video size is exactly 480x320. Result = wasted/increased file size
  4. Crop the input before scaling so that it "fills" the 480x320 resolution. Result = incomplete video

Option 2 would be the preferred solution, otherwise you are (probably unnecessarily) increasing the output file size. Option 3, I'll give a partially tested solution. Option 4 I'm not even going to touch.

Option 2: Scale the video, keep aspect ratio so that height is adjusted to fit

ffmpeg -y -i "%%i" -vf scale=480:-2,setsar=1:1 -c:v libx264 -c:a copy "%%~ni_shrink.mp4"

Option 3: Scale the video, keep aspect ratio and pad with black bars so that the video size is exactly 480x320

ffmpeg -y -i "%%i" -vf "[in]scale=iw*min(480/iw\,320/ih):ih*min(480/iw\,320/ih)[scaled]; [scaled]pad=480:320:(480-iw*min(480/iw\,320/ih))/2:(320-ih*min(480/iw\,320/ih))/2[padded]; [padded]setsar=1:1[out]" -c:v libx264 -c:a copy "%%~ni_shrink.mp4"

You can use ffmpeg tool for it and enter command

ffmpeg -i input.mp4 -vf scale=480:320 output_320.mp4

or if you want to changing the video aspect ratio please use setdar

ffmpeg -i input.mp4 -vf scale=480:320,setdar=4:3 output_320.mp4