Batch Audio Conversion using Command-Line


By Michael L Farrell

With today’s long list of audio formats, multiple music providers, and countless brands of mp3 players, a Linux user can quickly become frustrated trying to manage their music collection. Whether you’re using an iPod, generic mp3 player, or still burning CDs this article will help you make the necessary conversions to get your music where you want it.

Getting Started

The first thing you need to do is create a temporary working directory for your audio files. This will hold the temporary converted songs that will eventually be burned to a CD or copied to your mobile audio device.

kain@slickbox:~> cd /tmp
kain@slickbox:~> mkdir audio-tmp
kain@slickbox:~> cd audio-tmp


From here, it all depends on the formats you have and what you want to do.

iTunes plus files (unencrypted m4a files)

In this scenario, lets say you have purchased iTunes plus files that you want to be able to play on your generic mp3 player. This section shows you how to do this conversion easily. It also assumes that you have the utility “faad” installed (available from, and the lame utility (

First things first, lets symlink our album of choice into our temporary directory.
kain@slickbox:/tmp/audio-tmp> ln -s ~/Music/Band\ -\ Album/*.m4a .

Next, lets use a bash for-loop to decompress the m4a files to wave format and re-encode them as mp3.

kain@slickbox:/tmp/audio-tmp> for name in *.m4a; do faad "$name" -o -|lame - "$name.mp3"; done


When the process completes, you should have a fresh set of mp3’s that you can copy to your media player. Note that this re-encoding is a lossy process, meaning some quality will be lost during the transition. Some audio enthusiasts may want to add options to the lame command to increase the mp3 encoding quality to minimize this loss.

If you wanted wave files only (ie for burning a cd), merely omit the lame step as follows:

kain@slickbox:/tmp/audio-tmp> for name in *.m4a; do faad "$name”; done


Ogg Vorbis (ogg) Files

If you’re an iPod owner like me, you may find that it will not play your ogg audio files. This section shows you how to convert ogg files to m4a files for iPod usage.

Again, symlink the ogg files of choice into your temporary directory

kain@slickbox:/tmp/audio-tmp> ln -s ~/Music/Band\ -\ Album/*.ogg



Next, as before we’ll use use a bash for-loop to decompress the ogg files to wave format and re-encode them as m4a. You’ll need the oggdec program available from ( to do this.

kain@slickbox:/tmp/audio-tmp> for name in *.ogg; do oggdec "$name" -o -|faac -o "$name.m4a" -; done


To convert from ogg to mp3, we do this instead:

kain@slickbox:/tmp/audio-tmp> for name in *.ogg; do oggdec "$name" -o -|lame - "$name.mp3"; done


Once again, this is a lossy process, so the original files should remain in your music library as they hold the best quality.

Mplayer-supported Audio & Video Files (avi, wma, flv, etc)

If you have mplayer installed, you can use it to extract audio from your video files and convert them to the any format!

To do this, first link to your audio or video file of choice

kain@slickbox:/tmp/audio-tmp> ln -s ~/Videos/riff.avi


Next, we extract the uncompressed audio using mplayer

kain@slickbox:/tmp/audio-tmp> mplayer riff.avi -vc null -vo null -ao pcm:fast


This creates a file called audiodump.wav

We can now use faac, lame, or oggenc to encode the audio to our desired format.

For example, to encode as mp3:

kain@slickbox:/tmp/audio-tmp> lame audiodump.wav


Being that this is once again, a lossy process, it may be useful for advanced users to use the “-dumpaudio” feature of mplayer to dump the raw uncompressed audio stream to verify whether or not it is in a usable state (some videos come with MP3’s embedded and require no re-encoding).

(Visited 1 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet