Convert Ape to Flac or MP3

You need to have ffmpeg (or avconv), shntool and cuetools installed.

To convert all your .ape to .flac in place:

find . -name "*.ape" -exec sh -c 'exec ffmpeg -i "$1" "${1%.ape}.flac"' _ {} \;

If you install the patched MAC encoder and decoder for APE files from http://www.etree.org/shnutils/shntool/, this first step is unnecessary. But you would need to compile it with g++ and yasm yourself. Same goes for .tta files, which are also often used instead of .ape.

Split and name .flac files:

find . -name "*.cue" -exec sh -c 'exec shnsplit -f "$1" -o flac -t "%n_%p-%t" "${1%.cue}.flac"' _ {} \;

If shnsplit is also used for the conversion, replace the .flac in "${1%.cue}.flac" with the extension of the format you are converting from.

    • %n – track number
    • %p – performer
    • %t – track name

is taken from the .cue file for the .flac file names. To tag the resulting, split .flac files:

find . -name "*.cue" -execdir sh -c 'exec cuetag "$1" *.flac' _ {} \;

Remove the remaining CDImage.ape.cue, CDImage.flac, and CDImage.ape files at your leisure. The names are unique, so a simple find . -name "CDImage*" -delete is sufficient, except if Mozart made a composition starting with CDImage which I am not aware of.

For shnsplit to work, all necessary encoders/decoders need to be installed so it can read and write files. Modules for APE (and for the TTA format) would need to be compiled from source, the others by installing the package (i. e. FLAC).

This works for all standard cases where .cue and .tta/.flac/.ape files have the same name, except for the extension.

Side remark for others: If you deal with this conversion, your source files might be of Japanese origin, where APE and TTA were more popular than elsewhere. If the .cue files were initially SHIFT-JIS coded and now opened as UTF-8, the shnsplit step will break. You need to rename the .cue files with

find . -name "*.cue" -exec rename 's/\.cue$/.cux/' -- {} +

and convert the intermediate files to UTF-8 with

find . -name "*.cux" -exec sh -c 'exec iconv -f SHIFT-JIS -t UTF-8 -o "${1%.cux}.cue" -- "$1"' _ {} \;

before you attempt to do the steps above. Don't forget to get rid of the .cux files when you are done with:

find . -name "*.cux" -delete

To convert a file from flac to ogg of MP3 simply use soundconverter

sudo apt install soundconverter