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:

#/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

The IFS line makes shell interpret commands by newline and stops errors due to spaces in filenames and directories.

Hope it helps you!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s