FLAC -> MP3

with 5 Comments

So… I finally got my hard drives installed on my home server and now I just need to get my music collection into shape so I can actually play stuff. When I originally made copies of my CDs I converted them to FLAC. Why FLAC? Because I was being anal and didn’t want to “downgrade” my music to a measily 192kbps MP3 format. I know this is probably trivial, but if I retain the FLAC versions, it’s as if I have the original CD. Yes, I can’t tell the difference between 192kbps MP3 and the lossless FLAC, but the point is, if I ever want to convert all my music into AAC or (heaven’s forbid!) WMA format, I can do it fairly easily if I’m starting from a lossless format. If I start from the 192kbps MP3 I’ll start getting really degraded sounding stuff pretty quickly. So that’s my excuse.

How to accomplish this? In the past I’d used mpg321 to do the conversion but this time I used ffmpeg. I have all my CD collection in a directory on my system.

find "/var/mirror/Data/Audio/My CD Archive/" -name *.flac -exec /var/scripts/convert.sh {} \;

And /var/scripts/convert.sh contains:

ffmpeg -y -i "$1" -ab 192 "`echo "$1" | sed -e 's/.flac/.mp3/g'`"

This seems too much mess, but it appears to be working. The drawback? ffmpeg doesn’t seem to parse the “tag” information for each file so I’m ending up with “naked” MP3s (no ID3 tag). Not the end of the world. I’ll clean them up when I’m done.

The process is still chugging away — it’s completed about half of my collection.

Edit: I went ahead and figured out what I need to do to get the tags across. I installed the flac and id3 ebuilds and can now run the following script (using the same find command) to get the tags to match up from the flac files to the mp3 files.

OUTF=`echo "$1" | sed s/\.flac/.mp3/g`
ARTIST=`metaflac "$1" --show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac "$1" --show-tag=TITLE | sed s/.*=//g`
ALBUM=`metaflac "$1" --show-tag=ALBUM | sed s/.*=//g`
GENRE=`metaflac "$1" --show-tag=GENRE | sed s/.*=//g`
TRACKNUMBER=`metaflac "$1" --show-tag=TRACKNUMBER | sed s/.*=//g`
id3 -t "$TITLE" -T "$TRACKNUMBER" -a "$ARTIST" -A "$ALBUM" -g "$GENRE" "$OUTF"

Thanks to this page for the info.

5 Responses

  1. Diane Feucht
    |

    Wow andrew… that was very exciting. I wish I knew what it all meant. 🙂

  2. Dave Feucht
    |

    I’d recommend using LAME to encode them (you can find OSX binaries or you can compile it yourself), and do them 192 or 256k variable bitrate, you end up keeping the quality but getting smaller filesizes because it will use lower bitrates for parts of the music that have less information. A lot of online sellers are starting to do this (eMusic, Amazon, etc…). I’m not entirely sure if LAME will automatically grab the ID tags from the FLAC files, but it at least has commandline options to set them at encoding time, so you could do something similar to that last script to pull out the ID tags and stick them in the commandline to LAME 🙂

  3. Andrew Flanagan
    |

    Dave — I had *thought* that the ffmpeg package was actually used LAME (which I’ve heard is the best). I was going to take a look and compare speeds on these… However, the interesting thing is that since I ran this script, the updated version of ffmpeg (at least the ebuild for Gentoo) no longer supports mp3 natively. So… the new solution (that would definitely be using LAME) would be something like:

    flac -d -c FLACFILE.flac | lame -V2 – output.mp3

    Thanks! 🙂

  4. Dave Feucht
    |

    Some useful options for lame:

    -h (high quality)
    -v (tells it to do variable bitrate)
    -b 192 (sets the average bitrate in this case, or the bitrate if you’re doing constant)
    –tt
    –ta
    –tl
    –ty
    –tn
    –tg

    🙂

  5. Dave Feucht
    |

    oh, oops, some of that got lost in the posting…

    everything below -b should have double hyphens, and I had stuff in brackets after them, which I realized disappeared. those are the options to set the ID tag info, they are (in order), title, artist, album, year, track number and genre 🙂

Leave a Reply