Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu

Lossless audio files can be split by cue file using “shnsplit” (part of the “shntool” package). You will also need the “cuebreakpoints” tool (part of the “cuetools” package). To install cuetools and shntool in Ubuntu/ Kubuntu, open a terminal window and enter the following:

sudo aptitude install cuetools shntool

You will also need software for your prefered lossless audio format. For Monkey’s Audio you need to install “mac” - see here for details. For FLAC and WavPack formats you need to install “flac” and “wavpack” respectively:

sudo aptitude install flac wavpack

Shnsplit requires a list of break-points with which to split an audio file. Conveniently, cuebreakpoints prints the break-points from a cue or toc file in a format that can be used by shnsplit. You can pipe the output of cuebreakpoints to shnsplit as follows:

cuebreakpoints sample.cue | shnsplit -o flac sample.flac

In this example, a flac file called “sample.flac” is split according to the break-points contained in “sample.cue” and the results are output in the flac format.

The output file format is specified via the “-o” option. If you don’t specify an output format your split files will be in shntool’s default format (i.e., wave files, “wav”).

To split a monkey’s audio file by cue file and output the results in the flac format:

cuebreakpoints sample.cue | shnsplit -o flac sample.ape

Note that a default prefix “split-track” is used to name the output files. (The default output format is split-track01, split-track02, split-track03, …). You can specify your own prefix via the “-a” option.

To see all the options for shntool split type “shntool split -h” or “shnsplit -h”.

Transferring tags

The audio files output by shnsplit do not contain tag data. However you can use the “cuetag” script (installed as part of the cuetools package) to transfer tag data directly from a cue file to your split audio files. You specify the individual audio files corresponding to the tracks contained in your cue file as follows:

cuetag sample.cue split-track01.flac split-track02.flac split-track03.flac split-track04.flac

This will transfer the tag data contained in “sample.cue” to the flac audio tracks “split-track01.flac” “split-track02.flac” “split-track03.flac” and “split-track04.flac”.

The above command could be streamlined as:

cuetag sample.cue split-track*.flac

Cuetag works with flac, ogg and mp3 files. The cuetag script is not currently able to handle file names containing spaces.

Note: If you are running flac version 1.1.4 or higher then you may need to make some small changes to the cuetag script before it will work correctly with flac files. Open the cuetag script (for Ubuntu installations it will be located at /usr/bin/cuetag) in a text editor and make these two changes: 1) search for the text “remove-vc-all” and replace it with “remove-all-tags”. 2) search for the “import-vc-from” and replace with “import-tags-from”.

28 Comments

  1. Anonymous
    Posted February 19, 2007 at 4:03 am | Permalink

    This was kind of what I was looking for.

    To bad it’s still rather useless, since all id tags are lost.

  2. Foxy
    Posted March 19, 2007 at 11:46 pm | Permalink

    I am trying to split flac files into individual songs and convert them into oggs. I do
    cuebreakpoints sample.cue | shntool split -o flac sample.flac and then use soundconverter to convert into oggs. All works fine and the only problem is that I cannot get songs names from the cuesheet written anywhere. They are neither in tags nor in file names.

  3. John
    Posted April 19, 2007 at 3:45 am | Permalink

    Thank you, this worked flawlessly.

    Foxy: The best way I’ve found to re-tag music is Musicbrainz Picard. The newest version is nearly automated.

  4. Tim
    Posted May 2, 2007 at 7:51 pm | Permalink

    This splits a flac file with cue sheet, into multiple flacs, but leaves out the tags.

    I’ve a cue sheet which contains the track meta tags. There must be a way to the add the tags in the cue sheet to each new flac file.

    Picard is great for retagging. But I like to do things the elegant way. If I can do it all on one line I’ll be happy.

  5. Posted May 3, 2007 at 1:17 am | Permalink

    unfortunately shnsplit does not put tag data from the cue file into the new files that it outputs.
    however mp3split (which is able to split mp3 and ogg files by cue file) will insert tag details into the individual mp3 or ogg files.
    Foxy, if you are wanting to produce ogg files from a flac+cue file, a better method might be to convert the flac file to ogg first (using soundkonverter or other preferred method) and then split the ogg file by cue file using mp3splt:
    mp3splt -c sample.cue sample.ogg
    (where sample.cue is a cue file and sample.ogg is the music file you want to split)

  6. bartek
    Posted May 30, 2007 at 5:02 pm | Permalink

    I was trying to use oggsplt, but when I try to play processed files in Amarok, it almost crashes my system due to some memory problem. It goes to about 80 percent of memory on my system and settles to about 25 (that is something around 200 MB). When I play the original ogg file it is fine and memory that is used by amarok goes up to 6 percent… :/ very strange… ogg123 plays those files OK so I suspect this is xine engine problem… or is it oggsplt?

  7. bartek
    Posted May 30, 2007 at 7:23 pm | Permalink

    Hey, there is a way to do it without oggsplt and keeping the cue file information!

    cuetag is the tool :)

    cuetag file.cue track1.ogg track2.ogg …

    and I got rid of the bug :D

  8. Posted May 30, 2007 at 9:56 pm | Permalink

    Thanks for that tip on cuetag, Bartek. It seems that the cuetag script gets installed when you install cuetools. I didn’t know about it until reading your comment. I’ve now tried it with flac files and it works as expected (successfully transfers tag data from within a cue file to individual flac files).

  9. Forgnog Zambrucken
    Posted September 9, 2007 at 1:24 pm | Permalink

    thanks muchly for this guide, its helped me hugely.

  10. mugurelu
    Posted October 6, 2007 at 10:06 pm | Permalink

    For me cuetag didn’t worked out of the box for flac files (in Debian Sid). It was something about non existing parameters for metaflac, and nothing was written to the file.

    So I manually edited cuetag (/usr/X11R6/bin/cuetag), and changed the line:

    METAFLAC=”metaflac –remove-vc-all –import-vc-from=-”

    with this one:

    METAFLAC=”metaflac –import-tags-from=-”

    Now it works as expected. Maybe someone googleing around has the same problem as I did, and will find this usefull.

  11. Posted October 7, 2007 at 12:09 pm | Permalink

    thanks for the tip, mugurelu

  12. Posted October 9, 2007 at 8:28 am | Permalink

    Thanks alot mate!

  13. Posted November 16, 2007 at 12:15 am | Permalink

    Use k3b dude and Plugin for ape + cue

  14. Dmitry
    Posted December 11, 2007 at 10:43 pm | Permalink

    Thanks a lot!

    First, I had a same problem as mentioned above: cuetag doesn’t work because of the problems with metaflac usage. In Ubuntu 7.10 the way to fix it is to edit /usr/bin/cuetag like this:

    # METAFLAC=”metaflac –remove-vc-all –import-vc-from=-”
    METAFLAC=”metaflac –remove-all-tags –import-tags-from=-”

    Second, you mention “-n” option of shnsplit to specify default file prefix, but whis is wrong and the correct option in “-a”. Also, the files are numbered by default with only one leading zero, not two.

    Maybe you update your post? It is really very helpful and comes out first when you google for “ubuntu ape cue”, so I guess it’s important to keep it up to date :)

  15. Posted December 12, 2007 at 8:19 pm | Permalink

    Thanks for you comments, Dmitry, I’ve incorporated your corrections into the text.

  16. Hervé
    Posted December 31, 2007 at 1:41 am | Permalink

    Thank you for this post, and the corrections in the comments. I was just looking for this.

    Just a hint: a more compact syntax for selecting a interval may be:

    cuetag sample.cue split-track0[1-4].flac

    Which also works with “a-z”, “A-Z”, and probably more.

    @EKrava
    Well, explain your method. I first tried to write a CD Audio image from the cue file using k3b. But it refused to just write an image.

    Directly spliting and tagging the flac file is far more efficient!

  17. mike
    Posted January 10, 2008 at 8:09 am | Permalink

    Adding a few “’s in the cuetag.sh script seems to fix the issue of files with spaces in their names.

    66c65
    value=`$CUEPRINT -n “$1″ -t “$conv\n” $cue_file`
    141a141
    >
    144c144
    ntrack=`cueprint -d ‘%N’ “$cue_file”`

  18. Posted January 10, 2008 at 9:56 am | Permalink

    Hello, thanks for the great post. I’ve made an extremely simple script which uses this, you can check it out here: http://jottit.com/2qyze/

  19. nix
    Posted January 25, 2008 at 7:21 pm | Permalink

    Everything works fine except I can’t get cuetag to work. It says “command not found” even though I have cuetools installed. Hmmm…..

  20. Anonymous
    Posted January 25, 2008 at 7:53 pm | Permalink

    that’s odd. what distribution are you running? is the cuetag script present in /usr/bin (i.e., /usr/bin/cuetag)?

  21. nix
    Posted January 26, 2008 at 8:24 am | Permalink

    Mandriva 2008. It seems there is no “cuetag” anywhere on my computer. Perhaps it wasn’t included in this version of cuetools (cuetools-1.3.1-3). So I had to update the tags manually after consulting with the cue file via kwrite.

  22. Posted January 26, 2008 at 8:49 am | Permalink

    if you want to use cuetag and it isn’t being installed along with cuetools on your distribution, you could get a copy from the cuetools home page:
    http://developer.berlios.de/project/showfiles.php?group_id=2130
    (Download “cuetools-1.3.1.tar.gz” and open it up - the cuetag script is contained inside the extras folder.)
    I put a copy of cuetag here as an alternative place to grab it:
    http://members.iinet.net.au/~aidanjm/cuetag

  23. nix
    Posted January 26, 2008 at 1:33 pm | Permalink

    Alright, thanks, the script from that second link works. Now I’m off to install YellowDog on my PS3. Cheers.

  24. tris
    Posted January 31, 2008 at 1:57 am | Permalink

    Don’t know if shntools has been upgraded recently, but I found that

    shnsplit -o flac -f sample.cue -t “%n - %t” sample.flac

    worked pretty well: you get
    “01 - First.flac”, “02 - Second.flac” style names then.
    (you can also use %a for album and %p for performer).

  25. Angus77
    Posted February 20, 2008 at 3:34 am | Permalink

    I found I had to do:

    cuebreakpoints sample.cue | shnsplit -o flac -f sample.cue -t “%n - %t” sample.flac

    in order to make it work.

  26. pker
    Posted April 7, 2008 at 12:18 am | Permalink

    Wow, thanks a lot, it works like a charm! You just made my day :)

  27. Posted April 12, 2008 at 11:14 am | Permalink

    Thanks for the tip!
    I made a french translation here:
    http://fluoblog.wordpress.com/2008/04/12/decouper-un-fichier-audio-a-laide-dun-fichier-cue/

  28. Posted May 17, 2008 at 1:29 am | Permalink

    Thanks dude. This is similar to what’s here: http://linuxbraindump.org/2007/09/03/howto-split-a-flac-file-using-the-cue-sheet/

    Except this helped me with my codec and tagging issues. Thanks

2 Trackbacks/Pingbacks

  1. [...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu « aidanjm?s stuff [...]

  2. [...] Source: Adanjm’s Stuff [...]

Post a Comment

Your email is never published nor shared.