Recursive FLAC to MP3 converter

I like my music to be in MP3 v0, meaning the data has a variable bitrate of between 200-300 kbit/s. It makes for tiny MP3s that are in my opinion almost indistinguishable from ‘pure’ CD quality, sound-wise.

However, to get music in that format is not always possible, so my music directory has become littered with FLACs. Converting them all to v0 the simple way means the poor old NAS will have a hard time keeping up with other tasks. Enter flac2mp3.sh:

https://gist.github.com/rkok/d1d624fb9a2a458e44b928e9c1f2dbcf

It recursively searches a given directory for FLACs that don’t have an MP3 with the same name yet, converts them to MP3 v0 and while doing that, limits the amount of CPU muscle it needs, so the NAS can continue doing its NAS-y business.

Note that it will also keep the old FLACs in place, just in case something went wrong converting them. From time to time, I check and delete them using this Python script.

Usage

As usual, this was tested on the Netgear ReadyNAS 102 and should run on any UNIX system providing it has the necessary packages.

  1. Install the packages: lame, flac and cpulimit.
  2. In the script, set CPU_LIMIT to your favourite CPU percentage.
  3. Run the script by doing:
./flac2mp3.sh /path/to/the/flacs/

Tip: make a cron job out of it that runs every hour:

crontab -e
<editor opens, add line:>
0 1 * * * /home/a-schwarzenegger/flac2mp3.sh /data/mymusic/ >> /var/log/flac2mp3.log 2>&1

Tags: , | July 13th, 2014 | Posted in Uncategorized

Comments are closed.