Split a FLAC and Tag the Children using Cue Information

(Though this article will still be useful to some, most users will prefer my updated article here.)

It may come to pass that you download a concert or album only to discover that the encoder has helped you out by encoding the entire thing as a single FLAC file accompanied by a .cue file for determining the track changes.  Rhythmbox, for instance, will play these large FLAC’s just fine and it will even display the correct track information as you progress through the file.  However, I find it much more palatable to have single tracks be single files.

It’s actually pretty easy to break that large FLAC file into its component tracks and to add the appropriate tag information into those individual FLAC files.  It only requires a couple of lines of code, in fact.  The code may look complicated, but once you understand how to parse the different pieces you should have no difficulty in manipulating the code to process your files.

Before you begin with that you will want to add two utility packages which contain the tools you will need to make these splits and do the tagging of the individual files.  Open a terminal (Applications —> Accessories —> Terminal) and run these two commands:

sudo apt-get install shntool
sudo apt-get install cuetools

It doesn’t matter in which order you run them but you will need both packages.

First I offer a couple of examples of how the code might look.  Suppose you have a folder which contains a Van Morrison album as a single flac (and the cue file is in there as well).  In your terminal (Applications —> Accessories —> Terminal) navigate into that folder (using the cd command).  Your commands might look like such:

## Two commands as an example

shnsplit -o flac -f "Van Morrison - Astral Weeks.cue" -t "%n – %t" "Van Morrison - Astral Weeks.flac"

cuetag "Van Morrison - Astral Weeks.cue" 0*.flac


As I said, the code looks a little complex but let’s look at another example.  Suppose you have volume one from the Hôtel Costes series by Stéphane Pompougnac.  Your code might look like this:

## Two commands in a different example

shnsplit -o flac -f VA-Hotel_Costes_1.cue -t "%n – %t" VA-Hotel_Costes_1.flac

cuetag VA-Hotel_Costes_1.cue *.flac


As you can see, certain elements do not change.  What changes is your particular file names.  In the Van Morrison example the files contain spaces and said spaces must be preceded by a slash in order to be taken as a space within the file name (or you must quote the entire file name).  In the end what you are really seeing is this (the square brackets are only there to remind you what needs replacing):

## More examples for better understanding

shnsplit -o flac -f [cuefile].cue -t "%n – %t" [albumflac].flac
# OR
shnsplit -o flac -f "cue file.cue" -t "%n – %t" "album flac.flac"
# OR
shnsplit -o flac -f cue\ file.cue -t "%n – %t" album\ flac.flac

cuetag [cuefile].cue *.flac

# &c


I like to change both my FLAC  and cue files to the name a.  Also, you may or may not want to add the name of the performer in your file names. (I only include the performer names on various artist albums. So you know, %a is for Album and %p is for performer.) Then I can simply run (no slashes; no quotes around the file names):

## Choose one of these first two
## Then run the last

shnsplit -o flac -f a.cue -t "%n – %t" a.flac
# OR
shnsplit -o flac -f a.cue -t "%n – %p – %t" a.flac

cuetag a.cue *.flac


(Be sure to either send the album FLAC to the trash or change its file extension after running the first command but before running the second, or you will get an error about having the wrong number of FLAC files.)

Let me explain that zero (0) in the Van Morrison example.  That album happens to have fewer than 10 tracks.  So all of the tracks begin with a zero (01, 02, &c).  That is not the case on the Hôtel Costes album; it has tracks 11, 12, 13, &c.  You must add something like .remove to the album FLAC (so VA-Hotel_Costes_1.flac.remove) or move to different location (like the trash) after you have run the first command and before you run the second command (since the album FLAC file also ends in .flac and would be within the scope of *.flac).  If you leave the original FLAC within range, cuetag will inform you that the number of tracks does not match the number of cue breaks and it will not tag the files.  Not a big deal, but it could be a point of confusion if you were not prepared properly for it.

There are other arguments besides those which I used in my commands above.  You can read quite a lot about similar methods here.

Happy hunting, music lovers.


4 thoughts on “Split a FLAC and Tag the Children using Cue Information

  1. I am seeking methods for dealing with high-definition audio (files at rates like 24 x 96 rather than CD quality audio at 16 x 44.1). There have been a couple of suggestions posted to this Ubuntu forum thread.

    Also, I have written to the folks who maintain shntool (among others) and asked about plans to address this matter. I will report back when I have more information from them.

  2. The number one problem I have in splitting is some misformat of a cue file. If you get odd output (once my files ended …” .flac instead of just .flac) or if shnsplit complains about your cue file and won’t split anything, consider performing surgery on it.

    If for some reason you have to perform surgery on your CUE file, there two basic elements which make up a cue file: the album information and the track information (blocks).

    The album information should be at the top of the file and resemble this:

    REM GENRE Avantgarde
    REM DATE 2011
    REM DISCID 0C127A11
    REM COMMENT “ExactAudioCopy v0.99pb5”
    PERFORMER “Shan”
    TITLE “Kamelz Kik Nads == Musical WORKS 2010 2011”
    FILE “Shan – Kamelz Kik Nads == Musical WORKS 2010 2011.flac” WAVE

    The track blocks should be after the album chunk at the top and each should be separated by an extra line break and resemble this:

    PERFORMER “Son Volt”
    TITLE “Wide Swing Tremolo”
    FILE “01 – Straightface.flac” WAVE
    __TRACK 01 AUDIO
    ____TITLE “Straightface”
    ____PERFORMER “Son Volt”
    ____PREGAP 00:00:32
    ____INDEX 01 00:00:00


    ___TITLE “Muy Elegante Shagging Walruses”
    ___PERFORMER “Shan”
    ___FLAGS DCP
    ___INDEX 01 00:00:00

    (Replace the underscores (_) with spaces ( ). The spacing can cause problems as can the ordering of various elements.)

    (The file name seems to be optional and seems as though it is not required to be accurate. I’ve included just as a reference for where it belongs.)

Leave a Reply

Your email address will not be published. Required fields are marked *