FLAC files are a audio files that retain 100% of their original data. They are great for storing archive copies of CD’s.
If you have FLAC files and want to play them on an MP3 player that doesn’t support the FLAC file format then you’ll need to convert them down to MP3 files.
Every once in a while I need to convert an entire directory of FLAC files to MP3. The FLAC decoder does a great job of handling lots of files in a directory, but the LAME encoder can’t seem to wrap it’s mind around the concept of “do this to all my files”. With a little batch file we can make LAME handle an entire directory.
Here is a quick way to convert an entire directory of files from FLAC to MP3.
- This guide is for Windows.
- You need to have both flac.exe and lame.exe available on your computer.
- I keep my binaries like these in c:\bin and I take that directory with me whenever I reinstall Windows.
- This guide assumes that the files you want to encode are located in c:\temp.
Convert FLAC Files to WAV
We’re going to first convert the entire directory to WAV. We’ll do this using the FLAC decoder.
- Open up a command prompt.
- Navigate to the directory that has flac.exe in it (for me, it’s c:\bin, so I type cd \bin)
- Run this command: (Don’t forget the star near the end, inside the quotes.)
flac -d "c:\path\to\music\*"
That should run the FLAC decoder on all files in c:\path\to\music. When it’s done all of your original files will be there, and there will copies of them with a WAV extension. They’ll also be 2-4x larger than their equivalent FLAC files. Now that we have WAV files we can convert them to MP3 files with LAME.
Convert WAV Files to FLAC
This is where it gets a little more challenging. The LAME mp3 encoder does not support * wildcards to encode all files in a directory. It acts like it does, but it only encodes the first file it finds then it exits.
To work around this limitation well use a simple batch file. We’ll create it with notepad like this:
- Open up a command prompt.
- Navigate to the directory that has the WAV files in it (for me, it’s c:\temp, so I type cd \temp)
- Create a batch file called “go.bat” with notepad like this:
- Put the following line in go.bat: (Notice this refers to c:\bin which is where I have lame.exe located.)
for %%i in (*.wav) do "c:\bin\lame.exe" --preset medium "%%i" "%%~ni.mp3"
- Save the batch file and exit notepad
- Run the batch file by typing go and pressing the enter key.
This should run the LAME encoder on each WAV file that is located in the same directory as the batch file, and encode it with the medium preset, which is good enough for most people. If you want higher audio quality you can change the medium preset to either “standard”, “extreme”, or “insane”.
Now that we are done with the WAV files you can delete them.