Pitch-Correct Play Speed with MPlayer

This commmand will boost playback speed by 1.5x, without changing pitch (quite useful for lectures):

mplayer -speed 1.5 -af ladspa=tap_pitch:tap_pitch:0:-33:-90:0 foo.avi

This version will slow playback by half, again without affecting pitch. I find this helpful when learning guitar licks from video:

mplayer -speed 0.5 -af ladspa=tap_pitch:tap_pitch:0:100:-90:0 foo.avi

This requires the pitch shifter from Tom’s LADSPA Plugins (apt-get install tap-plugins).

16 Responses to “Pitch-Correct Play Speed with MPlayer”


  1. 1 chkno

    Thanks. This works much better than -ao pcm | sox pitch.

    The mplayer speed and the pitch shift can be set together with:

    pitchshift=`awk “BEGIN { print (-12*log($speed)/log(2)); exit }”`

    mplayer -speed $speed -af “ladspa=tap_pitch:tap_pitch:$pitchshift:0:-90:0″ …

    How do you go past 2.0x though? Specifing two -af’s doesn’t seem to chain them.

  2. 2 Mark

    I think tap_pitch limits us to [2.0x ... 0.5x] play speed. It also doesn’t sound quite as good as the pitch shifter in Windows Media Player.

    I’m hunting for a better way.

  3. 3 chkno

    Ah, -af chains with commas. So, you can get 2.5x playback with -speed 2.5 -af ladspa=tap_pitch:tap_pitch:-12.0:0:-90:0,ladspa=tap_pitch:tap_pitch:-3.863137:0:-90:0

    Here’s a script for this: http://chkno.net/fastplay

  4. 4 Mark

    Nice. Thanks, chkno.

  5. 5 jfly

    Hi, I’ve been searching for a system like that for a long time now. Without the script, I can see a video at speed 1.5x with a pretty good sound quality. But I would want to read faster. I tried your script chkno and I get an error that says that it cannot allocate memory. Do you have any idea what should I do?

    It seems to me that the script asks for too much memory. I have this message:
    ensure_space: failed to validate 8589869056 bytes at 0×1000000000
    8.5Go it’s a bit exagerated I think :)
    Thank you in advance

  6. 6 chkno

    ( I should note that I am continuing to revise http://chkno.net/fastplay . The version that was current in the above post is now available at http://chkno.net/fastplay-ladspa . )

  7. 7 chkno

    I finally have a version with sound quality I’m happy with. The key is to undo the fake rate shift of mplayer’s -speed before running it through any other filters.

    Here’s a giant, tangled mess of perl thas uses sox -r to undo the -speed and then soundstretch from libsamplerate to change the tempo: http://chkno.net/fastplay-soundstretch1

  8. 8 Jonathan Wright

    soundstretch[1] has a -tempo option, so much of http://chkno.net/fastplay-soundstretch1 is unneeded.

    The following should make a faster.wav which plays at 1.5x the original speed with the correct pitch:

    mplayer foo.avi -ao pcm:file=tmp.wav
    soundstretch tmp.wav faster.wav -tempo=50

    Or as a script change-speed.sh:

    #!/bin/bash
    # ./change-speed 1.5 path/to/foo.mp3
    # Will create a foo-1.5x.mp3 in the current directory

    FIFOTMPS=`mktemp -d`

    SPEED=$1

    mkfifo $FIFOTMPS/in.wav $FIFOTMPS/out.wav
    mplayer “$2″ -ao pcm:file=$FIFOTMPS/in.wav &
    soundstretch $FIFOTMPS/in.wav $FIFOTMPS/out.wav -naa -tempo=`awk “BEGIN { print 100 * ($SPEED - 1); exit }”` &
    #lame $FIFOTMPS/out.wav `basename “$2″ .mp3`-${SPEED}x.mp3
    dd if=$FIFOTMPS/out.wav of=`basename “$2″ .mp3`-${SPEED}x.wav

    rm $FIFOTMPS/in.wav $FIFOTMPS/out.wav
    rmdir $FIFOTMPS

    [1] http://www.surina.net/soundtouch/

  9. 9 WK

    Thanks for trying, chkno, but your fastplay scripts cause mplayer to crash:

    MPlayer interrupted by signal 13 in module: play_audio
    - MPlayer crashed. This shouldn’t happen.
    It can be a bug in the MPlayer code _or_ in your drivers _or_ in your
    gcc version. If you think it’s MPlayer’s fault, please read
    DOCS/HTML/en/bugreports.html and follow the instructions there. We can’t and
    won’t help unless you provide this information when reporting a possible bug.

  10. 10 WK

    Mark, here is the error message after trying your hack. Yes, I have ladspa installed (via apt-get):

    Couldn’t find audio filter ‘ladspa’
    [libaf] Couldn’t create or open audio filter ‘ladspa’
    Error at audio filter chain pre-init!

    Exiting… (Fatal error)

  11. 11 WK

    I figured it out, Mark. Your instructions are incomplete (and in the wrong order).

    1) Install LADSPA (on debian-based systems: apt-get install tap-plugins)
    2) reconfigure, recompile, and re-install mplayer
    3) mplayer -speed 1.5 -af ladspa=tap_pitch:tap_pitch:0:-33:-90:0 foo.avi

    You can, of course skip steps 1 and 2 if you already have ladspa enabled into mplayer. If you have never read this blog before, but found it while searching for a way to watch any modern Sci-Fi show without falling asleep, and have never heard of ladspa, then you probably do not have it enabled.

    How’s that?

  12. 12 chkno

    The ladspa=tap_pitch techniques have poor audio quality.

    Piping mplayer output through soundstretch has better audio quality, but poor audio-video sync.

    For something with good audio quality and good a-v sync, see Robert Juliano’s af_scale patch: http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2007-June/052368.html

  13. 13 lizzin

    I received the same error as WK and would like to follow the instructions he/she presented to solve the problem, but I do not know what commands I should execute to accomplish step 2: ‘reconfigure, recompile, and re-install mplayer’. If anyone could post suggestions on how I can do this or email them to me at powertothepenguins AT gmail DOT com, I would appreciate it very much. I am a Linux noob running Ubuntu 7.10 Gutsy Gibbon, so I don’t know how to do things like compile from source — so far, I’ve gotten by just using the Synaptic package manager. Sorry for the lack of experience here, but any help would be appreciated. Thanks!

  14. 14 chkno

    Robert Juliano’s af_scale patch is now part of mplayer. Since release 1.0rc2, mplayer has pitch-correct playback at any speed built right in. Just add “-af scaletempo” to the command line and use the normal speed controls — -speed or [ and ] during playback.

  15. 15 iron

    “mplayer 0003.mpg -speed 0.5 -af ladspa=tap_pitch:tap_pitch:0:100:-90:0


    Starting playback…”

    But I don’t see a film. Only 100% cpu load

    opensuse 10.3

  16. 16 Finite

    WK, recompiling mplayer is not needed.

    After apt-get install tap-plugins, “mplayer -speed 1.5 -af ladspa=/usr/lib/ladspa/tap_pitch.so:tap_pitch:0:-33:-90:0 file.mpg” works for me (on Debian etch).

Leave a Reply




Creative Commons Attribution-NonCommercial 3.0 United States
Creative Commons Attribution-NonCommercial 3.0 United States