Sep 042011
 

So you have a bunch of FLAC files for whatever reason, but if you’re like me, it’s because you are an audiophile and prefer a lossless codec for files you play on your high-end stereo equipment. However, FLAC files are huge, which can make them impractical for small personal music players with limited storage. This is especially true if you’re just going to plug the player into a cheap-ass stereo (like the one in my base model Toyota RAV4, for example.) That’s a bit like hunting squirrels with hand-grenades: overkill. Your best bet is to convert your FLAC files to something smaller and more manageable (and sounds better than MP3!): OGG/Vorbis.

Let’s get started. We’ll assume your FLAC files are tagged with the artist name, song title, etc. (Maybe you previously ripped them with Rubyripper?) The little script below will do the following:

  • Find all the FLAC files in the current directory
  • Extract relevant id3 tag data (ignoring Comments, if there are any)
  • Convert 01. Some Song.flac to 01. Some Song.ogg at 320kbps and apply the id3 tag data from the FLAC file.

Save this as a file such as flac2ogg and give it chmod 755. Put it in a directory that contains FLAC files you want to convert and execute it. This results in the following (example) output:

And the resulting properties page for the new OGG files look like this:

If you want to run the script from any directory on your machine without the need to copy it every time, just put it somewhere on your path. For example, on my Arch Linux box:

Of course, there are other ways to get this on your $PATH; read your distribution’s help for specifics.

Another thing to note is that the script sets the quality to -q9, which yields 320kbps. If this is still overkill for your needs, try -q6; that will give you 192kbps. This yields a smaller file size and most folks can’t hear the difference in the quality.

A slight variation

With just a minor tweak or two, the script can also recursively scan for FLAC files starting with the current directory, and then put the resulting OGG files in a tidy directory structure:

This will spit out the OGG files to a structure like this:

If you don’t care about free file formats

Well, you should. But maybe you’re a subservient little lamb and you paid The New Evil Empire for an iDevice to play your music. If that’s the case, you probably want MP3 files. Ba-a-a-a, little lamb. Ba-a-a-a.

Use the lame encoder in place of oggenc. Modify the script to do something like this:

Then, read up on why you should consider moving away from MP3: http://www.fsf.org/campaigns/playogg/en/.

Cheers!

Share

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">