Tuesday, 28 April 2009

How-To: Convert APE to Ogg Vorbis or MP3 in Debian and Ubuntu

APE is an open-source, free lossless audio format, just like FLAC or WAV. APE is also known as Monkey's Audio. To convert it to either Ogg Vorbis or MP3, you will first need to install several packages:

apt-get install monkeys-audio vorbis-tools

The first package includes the mac tool, which is a command-line frontend to the APE decoder. vorbis-tools is the package required to encode to the free Ogg Vorbis audio format. I recommend this one over MP3, since it's completely free and usually all the players on Linux support it by default.

Next, we will use the mac tool to convert the APE file(s) to WAV. For a single file, use the following command:

mac audio_file.ape audio_file.wav -d

For several files, use:

for i in *.ape; do mac "$i" "$i.wav" -d; done

Now all the APE files will be converted into WAV, which can be easily converted to Ogg Vorbis or MP3 using the commands below.

Ogg Vorbis
Convert WAV to Vorbis using the following command:

oggenc -b 256 audio_file.wav

Which will convert audio_file.wav to Ogg Vorbis at a nominal bitrate of 256 kbps. To convert more than one file at a time, use wildcards, e.g.:

oggenc -b 256 *.wav

MP3
Still, for MP3 the lame utility is required, which is included in the debian-multimedia.org repositories for Debian and Medibuntu for Ubuntu. After adding those repositories to your /etc/apt/sources.list file and updated the package lists (apt-get update), install the lame package:

apt-get install lame

Now, to convert WAV to MP3, use:

lame -b 256 audio_file.wav

If you want to convert several WAV files at a time, use:

for i in *.wav; do lame -b 192 "$i"; done

Which will convert all the files with the .wav extension using a nominal bitrate of 192 kbps.

If you're having trouble splitting a larger APE file with a CUE file, read this tutorial I wrote in the past.

6 comments:

Ari Torhamo said...

According to Wikipedia, Monkey's Audio isn't considered free software:

"While the license text claims to permit using the official Monkey's Audio codec in GPL projects, several Linux distribution maintainers have found the license to be contradictory. It does not permit redistribution or modification, and thus is not considered open source or free software."

Anonymous said...

the command "ape" doesn't work, so this line:

ape audio_file.ape audio_file.wav -d

should really be:

mac audio_file.ape audio_file.wav -d

Otherwise, thanks for sharing, it helped me :)

Craciun Dan said...

You are right, that was a mistake. The correct command is mac, not ape. Thanks for reporting this ;)

Sam said...

Do you know anything about mac not decoding correctly?

mac CDImage.ape CDtest.wav -d

creates an 88 byte file, which causes

lame -V 0 --vbr-new CDtest.wav CD01.mp3

dies on an "Unsupported number of channels:"

K3b can burn the CD from the .cue file, but mac can't seem to decode it correctly.

Thoughts? (Other tools?)

Thanks

Sam

Barry said...

Only problem with this is that the monkeys-audio is NOT available in any repository that I can find

Unknown said...

if your ogg file is not too large you can try using this free converter
http://www.oggconvert.com

it's all online, nothing to download