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”.
52 Comments
This was kind of what I was looking for.
To bad it’s still rather useless, since all id tags are lost.
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.
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.
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.
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)
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?
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
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).
thanks muchly for this guide, its helped me hugely.
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.
thanks for the tip, mugurelu
Thanks alot mate!
Use k3b dude and Plugin for ape + cue
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
Thanks for you comments, Dmitry, I’ve incorporated your corrections into the text.
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!
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”`
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/
Everything works fine except I can’t get cuetag to work. It says “command not found” even though I have cuetools installed. Hmmm…..
that’s odd. what distribution are you running? is the cuetag script present in /usr/bin (i.e., /usr/bin/cuetag)?
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.
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
Alright, thanks, the script from that second link works. Now I’m off to install YellowDog on my PS3. Cheers.
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).
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.
Wow, thanks a lot, it works like a charm! You just made my day
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/
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
Worked great, thanks for the article!
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.
mac-port is dead, but one could use jmac to decode and then use the .wav file with shnsplit.
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?
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.
just installed the script and follow guidelines.
in Ubuntu Intrepid, no script modifications were needed and worked nicely!
thanks a zillion!
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?
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
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!
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
A beautifully simply article. Worked perfectly. Thank you!
Very clear and useful article. And the comments are also constructive.
Thanks!
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.
Wonderful, just wonderful! Split an .ape CD image to individual flac files — your instructions worked like a charm!
Thanks!
Thank you for your very useful blog
Thanks a lot for this wonderful tutorial
it helped me a lot.
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
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
Thank you very much!
@gokuchess k3b=kde
we are (probably) on gnome or xfce…
many thanks
Very useful, thanks!
This is so great
Thanks!
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
Thx from germany, works perfect on Kubuntu 9.04.
8 Trackbacks/Pingbacks
[...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu « aidanjm?s stuff [...]
[...] Source: Adanjm’s Stuff [...]
[...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu (tags: tutorial audio lossless flac cue wav editing) [...]
[...] ниже взят с http://aidanjm.wordpress.com/2007/02/15/split-lossless-audio-ape-flac-wv-wav-by-cue-file/ и представляет способ решения данной проблемы — [...]
[...] full howto can be found here [...]
[...] Split lossless audio (ape, flac, wv, wav) by cue file in Ubuntu « aidanjm’s stuff (tags: audio ubuntu flac cue) [...]
[...] 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) [...]
[...] There are other arguments besides those which I used in my commands above. You can read quite a lot about similar methods here. [...]