IceGuye Blog

Batch ffmpeg conversion in bash

Ffmpeg is good software to convert formats for video and audio. This article is going to show you how to do batch conversion.

Example 1:

for f in *.ape; do ffmpeg -i "$f" "$( sed -e 's/\.ape/.flac/g' <<< $f )"; done

The Example 1 is to convert all ape files into flac files in a folder. This example is very simple, because there is nothing to do with either ape or flac. They are both lossless.

Example 2:

for f in *.mpeg; do ffmpeg -i "$f" -c:v libvpx -b:v 1800K -c:a libvorbis -b:a 192K "$( sed -e 's/\.mpeg/.webm/g' <<< $f )"; done

Example 2 is more complicated. They are lossy format, so in order to control their quality and size, we added some parameters -c:v libvpx -b:v 1800K -c:a libvorbis -b:a 192K for them. If we need even more parameters, we can just add them between for f in *.mpeg; do ffmpeg -i "$f" and "$( sed -e 's/.mpeg/.webm/g' <<< $f )"; done

Have fun; be free.




Back to Blog's index