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 apt-get 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 apt-get 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”.

53 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

  29. Posted August 5, 2008 at 2:57 am | Permalink

    Worked great, thanks for the article!

  30. Julian67
    Posted September 25, 2008 at 9:23 am | Permalink

    Here’s a way to have the cue+flac split and resulting files named and tagged correctly. You need a tool called lltag, it’s in Debian so I assume it’s in Ubuntu too.

    For cue + flac:

    cuebreakpoints *.cue | shnsplit -o flac *.flac && cuetag *.cue `ls split-track*.flac` && lltag –yes –no-tagging –rename ‘%n – %a – %t’ `ls split-track*.flac`

    That’s all one line btw, not sure how it’s going to be formatted on posting it here.

    Similalry for cue+ape:

    cuebreakpoints *.cue | shnsplit -o flac *.ape && cuetag *.cue `ls split-track*.flac` && lltag –yes –no-tagging –rename ‘%n – %a – %t’ `ls split-track*.flac`

    The lltag options explained:

    –yes

    Don’t stop for confirmation. lltag is an interactive script but we’re not using it interactively here.

    –no-tagging

    tells lltag to ignore tagging operations and only deal with the renaming

    –rename

    obvious? possible components to make up the final name string:

    %a to match the author.

    %A to match the album.

    %g to match the genre.

    %n to match the track number.

    %t to match the title.

    %d to match the date.

    %c to match the comment.

    %i to match anything and ignore it.

    %% to match %.
    Additionaly, while renaming, the following codes are available:

    %F is replaced by the original basename of the file.

    %E is replaced by the original extension of the file.

    %P is replaced by the original path of the file.

    You can see what an easy and flexible tool lltag is compared to shntool split/shnsplit for renaming. I assume there is a *reliable* way to do this with shntool but I didn’t find it, and the only real tutorial for shntool has been unavailable for a long time. The shntool man page has some frustrating gaps, assumes too much knowledge imo and generally makes me want to break something (wind/heads/windows/sweat).

    Using this method you get some warning messages from cuetag. Ignore them, it’s no problem.

    I’ve found the nicest way to use these commands is to have them as scripts i.e. cue+flac2flac.sh and cue+ape2flac.sh, put them in /usr/local/bin, make them executable and then I can have them run by way of a Thunar custom action which opens a terminal and runs them. You can see how easy it is to have a similar script for any cue+lossless format you might encounter.

  31. Anonymous
    Posted December 6, 2008 at 3:48 am | Permalink

    mac-port is dead, but one could use jmac to decode and then use the .wav file with shnsplit.

  32. Non-nerd
    Posted January 5, 2009 at 8:23 pm | Permalink

    Doesn’t work. Error message:

    shnsplit: warning: failed to read data from input file using format: [ape]
    shnsplit: + you may not have permission to read file: [Contours.ape]
    shnsplit: + arguments may be incorrect for decoder: [mac]
    shnsplit: + verify that the decoder is installed and in your PATH
    shnsplit: + this file may be unsupported, truncated or corrupt
    shnsplit: error: cannot continue due to error(s) shown above

    What does this mean decoder must be in your path? I have to move it every time to the same directory with the music or what? This command line shit is really bullshit, not for non-nerds at all. Besides, I want to convert to mp3 to get this shit to work in an mp3-player. ISn’t there a GUI solution?

  33. Altair IV
    Posted January 6, 2009 at 4:08 pm | Permalink

    Thank you for this post. It helped me a lot. And after a careful reading of the manpage, in return I’d like to point out that you no longer need to use cuebreakpoints, because shntool can now handle cue files directly (I’m using v.3.0.7). It can also rename files based on the cuesheet information.

    shnsplit -f *.cue -o flac -t “%p-%a-%n-%t” -m \ _ *.ape

    The above will take the index numbers directly from the cuesheet file and encode the resulting tracks to flac, naming them (with -t) as performer-album-tracknum-title.flac. It also (with -m) replaces all spaces with underscores.

    Unfortunately, it still doesn’t do tagging, so it looks like we’ll have to continue to use cuetag for that.

  34. Cesar
    Posted January 8, 2009 at 10:40 am | Permalink

    just installed the script and follow guidelines.

    in Ubuntu Intrepid, no script modifications were needed and worked nicely!

    thanks a zillion!

  35. vt220
    Posted February 10, 2009 at 8:41 am | Permalink

    Still great,

    The workaround for a cue file containing spaces is quite simple. First you have to change the script
    1 change all the $cue_file strings to “$cue_file”
    2 change in the main function the $@ to “$@”
    (basicaly the variables have to be quoted)

    You call cueprint with all the files quoted (eg cueprint “my cue file with spaces.cue” “my file with spaces.flac” … Then it should work (Only tested with a cue file containing spaces, not with mp3/flac files containing spaces

    Hope this helps

    BTW who is the maintainer of this script?

  36. Goldon
    Posted February 11, 2009 at 1:23 am | Permalink

    the easiest way that i know and using http://farbeat.com/clips/440-split-a-flac-or-wav-file-when-a-cue-file-available.html

  37. Posted February 12, 2009 at 11:52 am | Permalink

    holy crap dude…this is EXACTLY what I was looking for. granted I run freebsd, I already had some of this stuff installed from the last time I converted a bunch of music. everything works like a charm, just took a lot of stress of my back.

    thanks!

  38. Posted February 17, 2009 at 4:44 am | Permalink

    I’m was put metaflac and sh file to edit flac tag file, but not working “metaflac: command not found” any one can help me, i’m not good about linux . Thank you very much

  39. Pipps
    Posted March 3, 2009 at 7:17 am | Permalink

    A beautifully simply article. Worked perfectly. Thank you!

  40. xavix
    Posted March 16, 2009 at 6:21 am | Permalink

    Very clear and useful article. And the comments are also constructive.

    Thanks!

  41. Jevi
    Posted March 22, 2009 at 7:14 am | Permalink

    What I do, in brief, is

    shnsplit -o flac -f file.cue -t “%n – %p %t” -m \ _ file.flac

    to split in track files, and then

    cuetag file.cue $j.flac (in a loop) to tag the files correctly.

    But I can’t find the way to tag the year of the tracks.

    Does anybody knows how to write the tag YEAR from a cue sheet??

    Very nice article, by the way.

  42. Dev
    Posted April 5, 2009 at 8:10 am | Permalink

    Wonderful, just wonderful! Split an .ape CD image to individual flac files — your instructions worked like a charm!

    Thanks!

  43. Louis Antoine
    Posted April 11, 2009 at 10:22 am | Permalink

    Thank you for your very useful blog

  44. Benjamin
    Posted April 13, 2009 at 9:13 pm | Permalink

    Thanks a lot for this wonderful tutorial :) it helped me a lot.

  45. gokuchess
    Posted April 25, 2009 at 9:38 am | Permalink

    Hi.
    works like a charm with k3b:
    - Open k3b and select New Audio CD Project
    - Select the .cue file with the file.flac in the same directory
    - Press the blue arrow and convert it to whatever you want
    regards,
    goku

  46. gokuchess
    Posted April 25, 2009 at 9:45 am | Permalink

    more infos: it splits and tags, and so far it worked for me with bigfile.flac to splitedfile.flac and bigfile.ape to splitedfile.flac.
    I found the tip here: http://bbs.archlinux.org/viewtopic.php?id=39955
    regards

  47. gdm
    Posted June 16, 2009 at 3:56 am | Permalink

    Thank you very much!

    @gokuchess k3b=kde
    we are (probably) on gnome or xfce…

  48. atti
    Posted June 30, 2009 at 10:54 pm | Permalink

    many thanks :)

  49. John the molten ox
    Posted July 2, 2009 at 5:14 pm | Permalink

    Very useful, thanks!

  50. brk3
    Posted August 10, 2009 at 7:19 am | Permalink

    This is so great :) Thanks!

  51. Posted August 12, 2009 at 10:53 am | Permalink

    hi there
    for these lazy boys willing to do it quickly with one step and a GUI, use xcfa, well ported under ubuntu linux too, using the tools mentionned in this post.

    XCFA home page (in french, sorry :(

  52. peter
    Posted November 1, 2009 at 12:13 am | Permalink

    Thx from germany, works perfect on Kubuntu 9.04. :D

  53. Posted November 19, 2009 at 8:45 pm | Permalink

    Hi, tanks for this article, it works like a charm! So I’ve been able to take a big APE with CUE ando to convert to a collection of FLAC plus the CUE with the same info as CD-TEXT… with no audio loss! Great!
    The MAC package only installs on i386, so in order to compile it on Ubuntu 9.10 amd64 I had to fix 4 lines of code in file:
    src/MACLib/APELink.cpp
    lines 66-69:
    const char * pHeader = strstr(pData, APE_LINK_HEADER);
    const char * pImageFile = strstr(pData, APE_LINK_IMAGE_FILE_TAG);
    const char * pStartBlock = strstr(pData, APE_LINK_START_BLOCK_TAG);
    const char * pFinishBlock = strstr(pData, APE_LINK_FINISH_BLOCK_TAG);

    and the same on line 84:
    const char * pImageCharacter = &pImageFile[strlen(APE_LINK_IMAGE_FILE_TAG)];

    The change consisted on adding the “const ” keyword in front of each line, in order to avoid this:
    error: invalid conversion from ‘const char*’ to ‘char*’

    Hope this helps…


9 Trackbacks/Pingbacks

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

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

  3. [...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu (tags: tutorial audio lossless flac cue wav editing) [...]

  4. [...] ниже взят с http://aidanjm.wordpress.com/2007/02/15/split-lossless-audio-ape-flac-wv-wav-by-cue-file/ и представляет способ решения данной проблемы — [...]

  5. [...] full howto can be found here [...]

  6. [...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu « aidanjm’s stuff (tags: audio ubuntu flac cue) [...]

  7. [...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu « aidanjm’s stuff (tags: linux multimedia mp3 conversion audio howto music convert code tools tutorial reference documentation ubuntu article debian bash split ogg file english tool ape cue lossless wav wv amarok en) [...]

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

  9. [...] I came across a really good page describing what to do which is basically using shntool (homepage). It’s really good, easy to [...]

Post a Comment

Your email is never published nor shared.