Batch .MP4 to mp3 conversion on FreeBSD

So I’ve got all these videos in MP4 format that I want to listen to only. So I wrote a quick script that utilizes ffmpeg from the ports collection and converts all the files it finds in sub directories into mp3 files.
I had to build ffmpeg from the ports tree as it didn’t have libmp3lame enabled by default. A simple “make config-recursive” and then “make reinstall” is all that is needed.
Here is the shell script:
[code language=”c”]
#/bin/sh
IFS=$’\n’
for file in */*.mp4; do
ffmpeg -i $file -vn -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 $file”.mp3″;
done
[/code]
The IFS line makes shell interpret commands by newline and stops errors due to spaces in filenames and directories.
Hope it helps you!

Leave a comment

Your email address will not be published. Required fields are marked *