How to bulk convert FLAC to MP3 at the command line

How to bulk convert FLAC to MP3 at the command line

Sometimes you just gotta break out the console if you want to do big jobs with a minimum of time involved. Here's a little trick to convert an entire directory of FLAC files into MP3 files from your Linux machine.

So you just ripped all your CD collection to FLAC files because everyone says they're the greatest thing since sliced bread and sound the best. Sure they're huge (relatively speaking) but storage is cheap these days. Suddenly you realize one of your players can't handle FLAC files, or you want to put them on your phone and you don't have enough storage.

First, install the required packages:

sudo apt-get install lame flac

Then simply run the following command:

for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.*}".mp3; done

That loops through every file, creating a MP3 version at a fixed 320kbps bitrate. You can change that option from "-b 320" to simply "-v" without a number to get a decent variable bitrate MP3 file. Some devices, particularly older cars, may still have trouble today playing VBR files though so I tend to stick with 320 fixed.

This process may take a while if you have a lot of files or a slower PC. My own PC requires around 8 seconds per song to convert them.

Posted by Tony on May 19, 2015 | Linux Tricks