Friday, July 16, 2010

Increasing podcast tempo (playback speed) with Mplayer and Lame

The following commands will re-encode an mp3 file at a faster speed without increasing the pitch and making it sound like a chipmunk. How this actually works is pretty neat.

mplayer -vo null -vc null \
        -speed 1.33 \
        -af scaletempo,volume=0,resample=44100:0:1 \
        -ao pcm:fast:waveheader:file=temp.wav \
        source.mp3
lame -b 64 --resample 22.05 temp.wav faster.mp3

It will also set the bitrate to 64kbit which was for compatibility with my old player and to reduce the filesize for some podcasts which are unnecessarily big.

There should be a way to use mkfifo instead of temp.wav, and run the mplayer process and lame at the same time, I'll update this when I figure it out.

Update: The above method broke after upgrading to Ubuntu 11.10 (one or both of mplayer or lame changed something I suspect...), so I swapped it out for the simpler and better SoX:

sox --show-progress --norm source.mp3 dest.mp3 \
    tempo -s 1.33 channels 1 rate 22050

This version is easier to understand, faster, doesn't leave need a temp file and also, as a bonus, normalizes the audio to prevent clipping and not hurt my ears.

No comments: