Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large collection of WAVs. They are:

  • RIFF, little-endian
  • WAVE audio
  • GSM 6.10
  • Mono 8000Hz
  • effective bitrate of 13.6

I need to convert these to MP3. Current I am forced to send the file first through sox:

sox input.wav -s input-pcm.wav

Then through lame:

lame input-pcm.wav output.mp3

There are a couple of problems with this a 1MB file takes 5s and the MP3 sounds like crap. It's mostly intelligible, not really staticy, but just poor quality.

Has anyone successfully converted between this specific WAV and MP3 in a way that is fast and doesn't yield horrible sound quality? Thanks in advance.

share|improve this question
Could you provide a sample WAV file? – Tometzky May 24 '12 at 18:09
Would you say the quality on the original .wav is better? Some phone audio does sound bad from the start. – Koos van den Hout Jun 2 '12 at 15:07
Yes, the original .wav actually sounds quite decent. – kmarks2 Jun 4 '12 at 14:15

You can try with ffmpeg:

ffmpeg -i file.wav file.mp3
share|improve this answer
Thanks. I'll try this out. – kmarks2 May 23 '12 at 18:18
try also with ffmpeg -i file.wav -b 64k file.mp3 (or any other bitrate) – mulaz May 23 '12 at 18:19
Thanks @mulaz. Is there some a way tweak the input parameters so the operation completes faster. With both of these commands it still takes about ~4 seconds per 1MB. Also if my wave is 1MB ffmpeg is output a 5MB MP3. How can I bring this down to less than 1MB with ffmpeg? – kmarks2 May 23 '12 at 19:13

If you have access to the files with a Linux box with a GUI, SoundConverter works very well for batch transcodes. Then you won't have to do any script-fu either.

share|improve this answer
Does SoundConverter expose a command line interface? Also is it fast? Thanks. – kmarks2 May 23 '12 at 19:14
I didn't realize it did, but I just looked and yes, it does have a CLI. I haven't had to use it in quite a while, but from what I remember it was plenty fast. – reverendj1 May 23 '12 at 19:18
@reverdj Thanks again, I'll have a look. That's my main thing right now is that everything is taking around 5s per megabyte, which is just killing me. – kmarks2 May 23 '12 at 19:23

You could parallelize execution on multicore processor:

  • create `/tmp/`:
    T=`mktemp /dev/shm/wav2mp3.XXXXXX.wav`
    #/dev/shm is a tmpfs - a filesystem in memory
    sox "$1" -s "$T"
    lame --silent "$T" "$2"
    rm -f "$T"
  • convert all wavs in current directory and subdirectories:
    find -name \*.wav -print0 | xargs -0 -i -P 4 sh /tmp/ {} {}.mp3
share|improve this answer
I have a script that does this same exact thing. What exactly makes this parallelized? That is executes from /dev/shm? Either way, thanks. I will try this. – kmarks2 May 24 '12 at 14:33
xargs option -P 4 makes it run in 4 parallel processes. – Tometzky May 24 '12 at 18:04
using a temporary file in tmpfs mounted in /dev/shm/ is an optimization - it will not write this temporary file to disk which can speed up its execution somewhat. – Tometzky May 24 '12 at 18:08
Yeah, I got the shared memory optimization, my eyeballs just did not see the -P 4. Thanks for pointing this out. – kmarks2 May 24 '12 at 18:45
Another quick question. This will decrease the user time when running the conversion once. However, if I run this over a large set, won't the scheduler just throw successive calls the script to different cores anyway, therefore resulting in the same overall system time? – kmarks2 May 24 '12 at 18:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.