Wednesday, June 23, 2010

My digital audio guide - format conversion


This second part of my complete guide to digital audio covers transcoding your audio CDs.  This means converting them to MP3s, AACs (for iPod) or whatever format and quality you want.  Fortunately, all of the hard work has already been done and this is an easily automated task.

Once you have your music stored on your computer, you will probably want to enjoy them on other devices such as your phone or portable music player.  Your car CD player might support MP3 discs (a CDR containing folders of MP3s or WMAs).  You might also want to create a music "mix" CD, combining your favorite tracks

Unfortunately, the cue/flac format really isn't all that convenient (directly) for these applications.  Don't worry because it is really easy to transcode your files into just about any format you wish.  This is a simple task and it can all be handled by your computer with a few clicks.  Converting things is what computers do best.

Finally, because we started with cue sheets and lossless flac files, we will end up with the best possible (highest quality) results.

All the Transcoding we need can be accomplished with free software, but it does require a little bit of setup.  You will also need a helper script that I wrote to put everything together.  The script is written in Perl and should be easy to customize if you want it to perform a different task or change it's behavior.

Before we setup the script, let me tell you what it can do.  On the surface, the purpose of the script is pretty simple:  Split a cue/flac album into individual tracks and re-encode them.  However, there is quite a bit more to it.

Features:
  • Supports CDs stored as Cue Sheets with either FLAC or Monkey's Audio
  • Transcode single albums, lists of albums, or recursive folders of albums
  • Uses multiple cpus (if available) to convert albums faster 
  • Supports (currently) 7 formats: AAC (iPhone), MP3 (portable use), MP3 (home use), Ogg Vorbis (portable use), WMA Pro (portable/car use), FLAC, and FLAC w/o HDCD decoding.
  • Resulting audio tracks will be tagged appropriately
  • Tracks may include embedded album art (depending upon format choice)
  • Automatically detects pre-emphasis and applies de-emphassis at 24-bit resolution
  • Automatically detects HDCD and decodes the audio stream to 20-bit resolution
  • Supports writing to a temporary directory, or one you specify
  • Allows selecting a simpler (flatter) target folder hierarchy
  • Saves format & hierarchy when run multiple times to the same target folder
  • Uses drag-n-drop to select folders
  • Takes an argument so you can create a shortcut with a target folder
  • Errors (if any) are tracked and a report is printed at the end
Now, be forewarned:  this is just a simple script with no GUI or fancy interface.  It also isn't multi-threaded.  However, if you have multiple cores and a fast computer you can run two or three jobs at once to speed up large conversion jobs.

UPDATE:  The script now has a bit better UI, an improved drag and drop interface, and takes advantage of multiple cpus.  If you have a dual or quad core cpu, the conversion time should be significantly reduced!

UPDATE 6/16/20202: The script had a problem dealing with file names that contain special characters (umlaut, enya, etc.).  This should be fixed now.  I also increased the quality level / bit rate for portable use (mp3s only).  If you don't want this, simply edit the script to tailor the conversion to suit your needs.

The main way that I use this script is that I launch it, drop the folders containing the albums and let the computer do it's thing.   If the device that I want to copy the files to is directly attached to my computer, I can simply have the script write the converted audio files directly to the device.  Otherwise, I put the converted files in a folder and copy them over later.

You can even use the script to convert your entire library all at once (though this may take some time!).  If you run the script multiple times, it should ignore files already converted.  This could be useful to keep an up-to-date MP3 conversion of your CDs.  However, I don't do this and this script isn't optimized for this purpose.

Note that you can even "convert" your CDs to FLAC.   What I mean by this is that it will split your CDs into separate FLAC tracks (with or without HDCD processing).   Of course, "converting" from FLAC (cue sheet) to single FLAC tracks involves no loss at all audio quality.  I actually use this to create mix albums (where cue sheets no longer make sense).

If this sounds like a useful tool, let me show you how to get it set up.

Step #1: Installation

In order to support all of these different formats, we need to install a few codecs and tools.  Of course, if you only care about one or two formats, feel free to skip the codecs you don't care about (the script will still work).  For example, if you don't want WMA, you don't need the Windows Media Encoder package or have to hassle with the patch.

Install the following software packages:
  • FLAC decoder (should already be installed, or see here)
  • ActiveState Perl (same as above)
  • Monkey's Audio (to support cue/mac files, like cue/flac)
  • Windows media encoder 9 (Note - see comments below regarding this now obsolete package)
Now we need to apply a patch (or two) to get the windows media encoder to work correctly.

You can get the first patch here.  Extract the file "WMcmd.vbs" and replace the existing file by the same name in the folder "c:\program files\windows media encoder\encoder".

Note the comment in this page regarding Vista users needing a hotpatch.  I ran into the same issue on Windows 7 and the patch worked for me.

Next, create a directory/folder called "Audiotools".  In this directory, save the following downloaded files.  For those files that are archives (e.g. zip files), extract them in this same directory so that they create sub-folders.  These downloads are: 
  • A super utility called CueProc which will do all the cue file splitting for us
  • SoX, a sound file processing tool (make sure it installs into the Audiotools directory
  • The latest version of Lame, the MP3 encoder
  • An Ogg vorbis encoder.  A old, but really fast version of is here, or newer one is here.
  • Nero's AAC encoder
  • HDCD software decoder
When all of this software is extracted into the Audiotools directory, you should have folders that look like this:
  • \cueproc-1.10_win32\win32bin
  • \lame3.98.4
  • \oggenc283_sse3mt_lancer20061110
  • \NeroAACCodec-1.5.1\win32
  • \sox-14-3-1
  • \hdcd.exe          (not a directory)
    If you have downloaded newer versions than I have, your folders may be slightly different.  All you need to do is edit a script to correct the paths.

    Note:  Cueproc expects an older AAC executable called "neroaacenc_sse2".  Newever versions of Nero's encoder are named "neroaacenc".  Simply copy or rename the binary (in the win32 folder) to "neroaacenc_sse2".

    Finally, download a wrapper script that I wrote that manages all of the conversion for us:
    Place this script into the Audiotools directory.  However, you may also find it convenient to place a shortcut to it elsewhere (like on your desktop).

    UPDATE:  I've changed the script to use Tk (a GUI toolkit library).  Before running the script you must also install Tk and Sys::CPU.  After installing ActiveState Perl, simply type "ppm install Tk" followed by "ppm install Sys::CPU" in a command window.  Both Perl modules should install automatically.

    Note: Unfortunately, for the latest version of perl 5.14.2, you need a workaround to get Tk. After installing Activestate Perl, type ppm in a command window. Edit preferences, then click on the Repositories tab. Finally add a named repository with the location of "http://www.bribes.org/perl/ppm". Afterwards, you should be able to install Tk normally.

    Step #2: Using the script

    To launch the script, simply double click on it.  A window will pop-up.  Drag and drop folders containing Cue files into this window.



    The script will count the number of Cue files it finds as you go (and will look in sub-folders).  When you are done dropping folders, click on the "Finish" button.



    After you have entered all of the folders, the script will open a directory chooser and ask you where you want the converted files placed.

    If you cancel the directory chooser, the script will create a temporary directory for you to use.

    Next, the script will ask which format you want.  There are 7 choices provided.



    Finally, the script will ask what folder hierarchy you want created on the target.



    Once you select a hierarchy, the conversion will begin.



    At the end, if there were any errors with the album conversions, they will be reported and you must press enter to exit.

    If you specified a temporary directory, the script will report the directory name to you at the end (so that you can copy the files elsewhere, burn them to a CD, etc.).  The script will wait for you to press enter and then will automatically remove the directory.



    Notes:

    • If there is HDCD or Preemphasis detected in any album, the audio will be processed prior to conversion.
    • If you select FLAC conversion w/o HDCD processing, obviously no HDCD decoding will take place.  This is useful if you intend the files to be played by a device that supports HDCD natively (e.g. a high-end DAC) or when playing them with SqueezeCenter.
    • Your choices for format and hierarchy are saved in the target directory so that if you specify the same target twice, the script won't ask you those questions again.
    Usage Tip: create a shortcut to the script (with optional arguments).

    • If you specify one argument to the script, it will open an explorer window using that folder (e.g. where you store your Cue / Flac files).
    • If you specify a second argument to the script, it will use that folder as the destination (and won't ask).
    In Windows, you add arguments to shortcuts by editing the shortcut's property (just add your arguments to the end of the "Target field" - separated by a space of course).

    For example:  I create a shortcut to the script on my desktop called "phone-convert".  The first argument to the script is where I store my cue/flac files (e.g. d:\CueFiles).  The second argument is the folder in which my phone shows up at when I plug it in (e.g. f:\Music).

    To convert files, I click on my shortcut and drag and drop the albums I want converted.  Since the script remembers my preferences from a previous run (conversion type, hierarchy style), conversion starts immediately after I finish selecting the albums.  The converted files are written directly to my phone.  When the script is done, I just disconnect my phone.  Simple, easy and (now) fast!


    2 comments:

    1. The link to Windows media encoder 9 is broken. Microsoft has replace it with Expression
      Encoder 4, will that work?

      ReplyDelete
    2. @anonymous: Thanks for pointing out the broken link. I checked out Expression Encoder 4 and it looks like they might have removed the command line encoder (WMcmd.vbs) that we need:

      http://blogs.msdn.com/b/expressionencoder/archive/2009/07/10/9828866.aspx

      The article references Expression Encoder 3, so it could be that they have added it back in the latest version.

      In case they haven't, I'd look for an archived copy of the now obsolete Windows Media Encoder 9. I'd imagine someone has it posted somewhere.

      ReplyDelete

    Copyright (c) 2010 CuttingTheBills.com. All Rights Reserved.