Wensveen's Blog

March 12, 2013

Batch converting a directory of FLAC files to MP3

Filed under: Uncategorized — Tags: , , , , , — wensveen @ 12:35 am

Just a quick one, because it took me a while to get the command right. Hope it helps someone out there with a similar problem. I’m using Debian unstable with (unofficial) deb-multimedia repositories enabled.

The magic command I use is:


find . -name "*.flac" -print0 | xargs -0 -n 1 basename -s ".flac" | xargs -n 1 -I % ffmpeg -i %.flac -ab 196k %.mp3

The 1st command of course finds the input files. The 2nd turns filename.flac into filename. The last command runs ffmpeg on all flac files to convert it to mp3 files (at 196kbps).

If you’re running a version of ffmpeg that can’t encode mp3 files (because of format / patent restrictions), you’ll have to pipe the output from ffmpeg into lame or some other mp3 encoder.

Enjoy!

Create a free website or blog at WordPress.com.