Previously on Optimizing Video: 2021 Honda Odyssey RES I had a beautiful ffmpeg
1-liner to convert videos to “space-saving-letterbox-loving-USB-sized” videos to be played on my Vehicles Entertainment System. Unfortunately, some of the videos continued to fail to play to the point where the system would reset and would need me to cycle the vehicles power to cold reboot the entertainment system.
Suffice to write it’s led to much trial-and-error, with much more excitement on success.
Fast forward to today I’ve learned two things about my previous one-liner:
– The Honda Entertainment System cannot support 6-channel audio
– The Honda Entertainment System cannot support specific pixel formats
So, with all that said my one-liner has GROWN significantly to bear the following:
ffmpeg -i "%F" -c:v libx264 -crf 28 -c:a aac -b:a 128k -ac 2 -sn -dn -map_metadata:c -1 -vf format=yuv420p,scale=1024:576:force_original_aspect_ratio=decrease,pad=1024:576:-1:-1:color=black "%F.honda.mp4"
Breaking it out one parameter at a time:
-i "%F"
: Input filename. Quotes for spaces and to avoid escaping fancy things.-c:v libx264
: Setting the video to use H.264/AVC format-crf 28
: A level of compression I’m happy with when it comes to this encoder-c:a aac
: Sets the audio to use AAC encoding-b:a 128k
: Sets the audio to use constant 128k bitrate for all audio channels-ac 2
: Tells us we want 2 channels. This upsizes mono to L/R and downsizes 6-channel to stereo-sn
: If there are subtitles we don’t want that additional data-dn
: If there is a separate data track (chapters, other subtitles) discard of that, too-map_metadata:c -1
: A fancy way to drop any metadata by mapping it out of bounds-vf ...
: This starts our Video Filter block, a comma-separate set of parametersformat=yuv420p
- We want this specific pixel format, not cooler ones like yuv420p10le
scale=1024:576:force_original_aspect_ratio=decrease
- This sets our output resolution, making sure we enforce it
pad=1024:576:-1:-1:color=black
- If input/output has blankness we pad with black
"%F.honda.mp4"
: Our output filename.
This “final” iteration had me add the -ac 2
and format=
parameters. Now videos that crashed the system play perfectly now, and that is just awesome, especially for those long trips to keep the kids entertained.
I can even batch run this easily on windows by creating a blank list of files (via dir /b > filelist.txt
) and pumping in a for loop such as:
FOR /F "tokens=*" %F IN ('type filelist.txt') DO ffmpeg [all the fun]
It’s much simpler in bash with find . -name '*.mp4' -exec ffmpeg "{}" [all the fun] \;