HOWTO splitt lossless audio files (ape, flac, wv, wav) using .cue files

From LinuxReviews
Jump to navigationJump to search

Lossless audio such as music albums sometimes come as one huge file and a small .cue file with the actual track information. This is not ideal if you just want to copy one or two tracks onto a portable device. Graphical CD recording software such as K3b can use this huge file and the .cue to create an exact CD copy of the music album. You can also easily make separate audio files for each track using command-line tools.

Splitting using command-line tools[edit]

Music CDs are out. Most people like to keep their music collection on a harddrive or portable player. Huge files are not suitable for music software like mpd and audacious. This is why you probably want to split your huge complete-album .flac into separate files for each track. You need two small tools to accomplish this: cuebreakpoints from the cuetools package and shntool.

  • Debian/Ubuntu: sudo apt install cuetools shntool
  • Fedora: dnf -y install cuetools shntool
  • Gentoo: emerge -v app-cdr/cuetools media-sound/shntool

You also need some software for the lossless audio format you will be using. If you want to use .flac and .wav files then you'll need flac and wavpack,

  • Debian/Ubuntu: sudo apt install flac wavpack
  • Gentoo: emerge media-libs/flac media-sound/wavpack

The trick that is used so powerfully by the power l33t hax0rs is to use cuebreakpoints to print all the break-points from a .cue or .toc file. These breakpoints are then piped to shnsplit like this:

Shell command(s):
cuebreakpoints example.cue | shnsplit -o flac example.flac

This splits example.flac according to the breakpoints listed in example.cue. You will have separate files named split-track01.flac, split-track02.flac, etc after running this command. The prefix for the output files can be changed wth the -a option if you want something different from split-track. You likely want to rename your newly created files regardless.

The output format must be specified with the -o option. shntool's default is to make .wav wave files, and you don't want that.

You can split one format and output another, to split flac audio and output APE you could do:

Shell command(s):
cuebreakpoints example.cue | shnsplit -o ape example.ape

shntool split -h or shnsplit -h will give you a list of all available options. shntool -f prints a list of the formats it supports.

Creating tag metadata[edit]

shnsplit does not add any metadata when it creates new split audio files. There is a script called cuetag.sh you can use to transfer tag data from .cue files directly into the split files.

Debian/Ubuntu and Fedora will install this script for you. Gentoo will place it in the doc folder (like /usr/share/doc/cuetools-1.3.1/extras/cuetag.sh, adjust path for version). cp it to your /usr/local/bin and chmod a+x it.

You can now use the cuetag.sh script like this:

Shell command(s):
cuetag example.cue split-track01.flac split-track02.flac split-track03.flac split-track04.flac

Or simpler:

Shell command(s):
cuetag example.cue split-track*.flac

Cuetag can work with with flac, ogg and mp3 files. Cuetag will freak out if you try to use it on files with spaces in their names.