-
-
Save vukanac/a3d82d815d0135edae9036acf366c3e2 to your computer and use it in GitHub Desktop.
cd $HOME/my_funny_video | |
for i in *.mp4; | |
do name=`echo "$i" | cut -d'.' -f1` | |
echo "$name" | |
ffmpeg -hide_banner \ | |
-i "$i" \ | |
-r 25 \ | |
-vf scale=w=720:h=404:force_original_aspect_ratio=decrease:force_divisible_by=2 ease \ | |
-c:v libx264 \ | |
-preset medium \ | |
-tune animation \ | |
-profile:v baseline \ | |
-crf 23 \ | |
-maxrate 1750k -bufsize 1750k \ | |
-c:a aac -b:a 192k \ | |
"$HOME/audi_mmi/${name}_480.mp4" | |
done | |
# https://www.audiworld.com/forums/audio-video-security-discussion-15/converting-video-working-formats-2014-a4-mmi-3g-cdn-2855965/ | |
# https://en.wikipedia.org/wiki/Multi_Media_Interface |
Please confirm if (old and/or new command) works for you, others to know. For me, my original command didn't work. I had to use Handbrake, which gave playable videos, but it's manual processing file by file so I stop after a few. Still don't get what settings Handbrake uses that I cannot set in FFmpeg.
You've a small typo in your '-vf scale...' line.
Change force_original_aspect_ratio=decr:force_divisible_by=2 ease
to force_original_aspect_ratio=decrease:force_divisible_by=2
Original code without force_divisible_by=2
works most of the time, just ffmpeg's calculation to decrease resolution to force original aspect ratio can sometimes arrive at resolutions that aren't divisible by 2, which the libx264 encoder won't accept:
[libx264 @ 0x560245e8b500] width not divisible by 2 (719x404)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
It's a relatively new option that will probably require latest stable FFmpeg-4.4 ->
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190703153337.25116-1-lkiesow@uos.de/
Older versions may need to use the way more complex iw/ih command-line calcuations outlined here -> https://trac.ffmpeg.org/wiki/Scaling
Thanks :)
PS> The resulting video output is working in as far back as Audi MMI 2012
Thanks for the update!
Big thanks for getting this sorted.
One minor improvement is to add 'force_divisible_by=2' to the '-vf scale...' chain so libx264 encoder doesn't abort on dimensions that aren't divisible by 2.