Convert ape to wav/mp3/ogg

There are several solutions to choose:

Using ffmpeg to Convert ape to wav
.ape is the file extension for Monkey’s Audio Files. Monkey’s Audio is a pseudo-free lossless audio codec, like flac.

If you have ffmpeg installed, it is enough to do:

ffmpeg -i file.ape output.wav

If for some reason you cannot get a version of ffmpeg with Monkey’s Audio support, you’ll need to use the JMAC decoder.

Alternative: Using JMAC to Convert ape to wav

JMAC is a Java implementation of the Monkey’s Audio decoder/encoder/JavaSound SPI.

First, make sure you have a java runtime environment installed, then download the package from JMAC’s website. Once you have decompressed the package, cd into the “distributables” directory and type this command:

java -jar jmac.jar d FILE1.ape FILE2.wav

Split ape with cue

To be able to split up a single ape file with cue file to single tracks, you will first have to decompress it to wav like described above. Then you can use the tool bchunk to split it. no need to change the cue file that came together with the ape:

bchunk -w image.wav image.cue result

Where :

image.wav is your large wav file
image.cue is the cue file
result is the prefix for your wav songs (which gives you
result01.wav, result02.wav...)

Big thx to nico for that hint!

Note: If you intend to convert to mp3 or ogg anyway, the best is to convert the complete decompressed .wav to mp3 using lame, and then using mp3splt to split it. mp3splt writes the tags!

An alternative to bchunk is shnutils that can split the wav in single tracks, or even feed the resulting splitted streams to an external encoder like oggenc. The individual ogg files are named according to the “track” field (%t) in the cue file:

 shnsplit -o 'cust ext=ogg oggenc - -o "%f"' -f image.cue -t "%t" image.wav

cueape.sh

Thanks to Rafael Ponieman there is a script that encodes ape+cue or flac+cue to single mp3/ogg files using mac, mp3splt, lame and/or oggenc. Very handy!

Usage: cueape [input ape file] [input cue file] [parameters] Parameters can be: -m for mp3 encoding or -o for ogg encoding.

Download: cueape.sh

Batch conversion

Note: Following script has been greately enhanced by Nuisance-Value from gentoo Forum and can

be found at http://lossless2lossy.sourceforge.net/

Pithlit from the gentoo forum wrote a nice script for converting multiple files:

#!/bin/bash
#My first ever attempt at scripting something. The result is perfect for me.
#I'm NOT the one to blame if this wipes out your hdd or breaks your CPU. You've
#been warned. Other than that... I realise it's not a good script. It needs
#tweaking or even better: a complete rewrite. But as stated before - it works
#for me. It spews out some trivial errors.
#
#Pithy

[ ! -d "$1" ] && echo "usage: ape2mp3 " && exit
#Set the OUTDIR to where you want your intermediate wav files to end up
OUTDIR="/home/media/Music/$(basename "$1")"
[ ! -d "$OUTDIR" ] && mkdir -p "$OUTDIR"
#Set the OUTDIR2 to where you want your final mp3 files to end up
OUTDIR2="/home/media/Music/128/$(basename "$1")"
[ ! -d "$OUTDIR2" ] && mkdir -p "$OUTDIR2"
cd "$1" || exit

echo OUTDIR: $OUTDIR

find -depth -print0 | while read -d $'\0' filename;
do
    filename="${filename##*/}"
    mac "${filename}" "$OUTDIR/${filename}" -d
done

cd "$OUTDIR"
for e in *.ape
do
    mv "$e" "`echo $e | sed 's/\(.*\.\)ape/\1wav/'`"
done

echo OUTDIR2: $OUTDIR2

find -depth -print0 | while read -d $'\0' filename;
do
    filename="${filename##*/}"
#Set the lame options to your liking. The optins here will result in
#a decent 128kbps mp3. Good enough for your regular mp3 player.
    lame -h "${filename}" "$OUTDIR2/${filename}"
done

cd "$OUTDIR2"
for i in *.wav
do
    mv "$i" "`echo $i | sed 's/\(.*\.\)wav/\1mp3/'`"
done

#Uncomment the following line if you want to remove the folder with your wav
#files. I like to keep it. You know... better safe than sorry. And I just might
#decide to burn me an audio CD.
#The script will probably complain about missing folders. Ignore it.

#rm -r "$OUTDIR"

echo "conversion finished"
cd "$OLDPWD"

THX Pithlit! If someone finds error, has better solution whatever, just drop a mail 😉

I like this wiki. Here is my ape to wav convert script. this script will take a “.ape” and a “.cue” file in the current directory and convert the tracks to single mp3 format audio files. each file will be id3-tagged by “cuetag” and named with the pattern “<trackno>-<title>”.

#!/bin/bash
#
# Convert ".APT" (Monkey Audio Codec) to MP3
#
# TOOLS: shnsplit(shntool), lame, ffmpeg
#
# Licence: GPL
# by jens (dot) harms (at) informatik.uni-oldenburg.de
#
# shnsplit variables
#  	       %p     Performer
#              %a     Album
#              %t     Track title
#              %n     Track number
#
set -x
WAV=/tmp/output.wav
APE=$(echo *.ape)
CUE=$(echo *.cue)
#
create_mp3()
{
# convert APE to WAVE - Format Audio File
ffmpeg -i "$APE" "$WAV"
if [ $? != 0 ]
then
    echo 1>&2 "ffmpeg reported an error"
    exit 1
fi
#
# split single .wav with the help of cue-file into separate mp3 format audio files
shnsplit -q -o 'cust ext=mp3 lame --quiet --preset standard - "%f"' -f "$CUE" -t "%n. %t" "$WAV"
if [ $? != 0 ]
then
    echo 1>&2 "shnsplit reported an error"
    exit 1
fi
#
# clean up double quotes in filenames
for a in *.mp3
do
    out=$(echo "$a" | sed s/\\\"//g)
    mv "$a" "$out"
done
}
#
list_files()
{
    a=($@)
    echo "Number of files: " ${#a[@]}
}
#
main()
{
    create_mp3
    rm $WAV
#
    # create a list of all .mp3 files sorted by track number
    for((i=1;i<200;i++))
    do
	n=$(printf "%0.2d." $i)
	f=$(echo $n*.mp3)
	if ! [ -f "$f" ]
	then
	    break
	fi
	p=$(($i-1))
	flist[$p]="$f"
    done
    cuetag "$CUE" "${flist[@]}"
}
#
main $@

admin

About admin