While I’m at it: AAC to MP3 conversion script

June 4th, 2008 by Strawp

Based on Converting FLAC to MP3 in Linux (I tweaked the LAME settings a bit though):


# Converts all AAC (m4a) files in a folder into mp3s, plus the id3 tag
# Requires faad, lame, id3v2

for a in *
  # Check the file is a flac file
  if [[ "$a" =~ (m4a)$ ]]
    # Name of outfile
    OUTF=`echo "$a" | sed s/\.m4a/.mp3/g`
    echo "$a => $OUTF"

    # Capture all the FLAC metadata
    ARTIST=`faad -i "$a" 2>&1 | grep "^artist" | sed "s/.*: //g"`
    TITLE=`faad -i "$a" 2>&1 | grep "^title" | sed "s/.*: //g"`
    ALBUM=`faad -i "$a" 2>&1 | grep "^album" | sed "s/.*: //g"`
    GENRE=`faad -i "$a" 2>&1 | grep "^genre" | sed "s/.*: //g"`
    TRACKNUMBER=`faad -i "$a" 2>&1 | grep "^track" | sed "s/.*: //g"`
    YEAR=`faad -i "$a" 2>&1 | grep "^date" | sed "s/.*: //g"`


    # Convert the audio data from AAC to MP3
    faad -w "$a" | lame -V 2 -m j -b 192 -B 224 -s 44.1 - "$OUTF"

    # Tag the resulting MP3 with the captured metadata
    id3v2 -t "$TITLE" -T "$TRACKNUMBER" -a "$ARTIST" -A "$ALBUM" -g "$GENRE" -y "$YEAR" "$OUTF"

Comments are closed.