1

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.

kmarks2
  • 192
  • 1
  • 2
  • 12

3 Answers3

2

You can try with ffmpeg:

ffmpeg -i file.wav file.mp3
mulaz
  • 10,472
  • 1
  • 30
  • 37
  • 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
1

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.

reverendj1
  • 354
  • 1
  • 6
  • 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
1

You could parallelize execution on multicore processor:

  • create `/tmp/wav2mp3.sh`:
    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/wav2mp3.sh {} {}.mp3
Tometzky
  • 2,649
  • 4
  • 26
  • 32
  • 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
  • No - it does not work like this. The time to run the conversion on one file will not change. `xargs` will start to convert 4 different files at once and then manage starting following conversions so it will always be 4 different conversions running at any given time until job is done. – Tometzky May 24 '12 at 22:42