I have videos with different resolution. I want that all of them will be in resolution of 480x320. I tried the command:
ffmpeg -i %s_ann.mp4 -vf scale=480x320,setsar=1:1 %s_annShrink.mp4' %(dstfile,dstfile)
but the output of the videos are files with the size of 0 kb.
What I'm doing wrong?
I guess that really there are two questions here...
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.)
This is a little trickier. As you have your command, the aspect ratio is potentially going to get messed up. Options here...
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"