.flac to .mp3 parallel conversion script

I’ve been using FLAC to backup my CDs for some time, but due to the ubiquity of MP3, I frequently found myself transcoding a large number of these files for various devices.

I found a good number of scripts[1] for doing the conversion, and it seems to be  a bike shed everyone wants to chime in on.  What I found didn’t really handle modern multi-core processors, so I made some quick tweaks and thought I’d post my results.  There are two scripts:

mp3xcode:

#!/bin/bash

mkdir mp3
parallel mp3xcode_sub — *.flac

mp3xcode_sub:

#!/bin/bash

[ -r “$1″ ] || { echo can not read file \”$1\” >&1 ; exit 1 ; } ;

FLAC=$1
MP3=”mp3/${FLAC%.flac}.mp3″

eval `metaflac –export-tags-to=- “$FLAC” | sed ‘s/=\(.*\)/=”\1″/’`

flac -dc “$FLAC” | lame –replaygain-accurate -v -V 2 –tt “$TITLE” \
–tn “$TRACKNUMBER” \
–tg “$GENRE” \
–ty “$DATE” \
–ta “$ARTIST” \
–tl “$ALBUM” \
–add-id3v2 \
– “$MP3”

This script seems to be a good way to do it. I’ve only tested this on linux.

On FreeBSD, there may be some tweaks required to not depend on bash.  Also, you’ll need to install the GNU parallel program (sysutils/parallel).