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).

About these ads

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

  1. 1 chkno October 27, 2006 at 9:49 am

    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 October 27, 2006 at 10:33 am

    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 October 28, 2006 at 11:57 am

    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 October 28, 2006 at 7:38 pm

    Nice. Thanks, chkno.

  5. 5 jfly February 5, 2007 at 2:56 am

    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 March 26, 2007 at 7:18 pm

    ( 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 April 22, 2007 at 10:14 am

    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 August 11, 2007 at 7:16 am

    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:

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

    FIFOTMPS=`mktemp -d`


    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 August 22, 2007 at 10:46 pm

    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 August 22, 2007 at 10:50 pm

    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 August 22, 2007 at 11:06 pm

    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 September 12, 2007 at 12:09 am

    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 October 29, 2007 at 2:53 am

    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 January 10, 2008 at 11:36 pm

    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 January 30, 2008 at 9:24 am

    “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 July 29, 2008 at 1:33 am

    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).

  17. 17 Ross September 21, 2008 at 12:35 pm

    If you find yourself having to use a whole path for tap_pitch.so instead of just “tap_pitch”, the problem is that the LADSPA_PATH variable isn’t set. Try adding the line “LADSPA_PATH=/usr/lib/ladspa” to your .bashrc

  18. 18 Pat Gunn March 6, 2009 at 7:40 pm

    With more current versions of mplayer, the “scaletempo” filter automatically corrects for speed without needing any parameters (meaning you can use the brackets to alter tempo while music is playing and it figures it out immediately).

  19. 19 Baylink May 27, 2009 at 6:55 pm

    But, it screws the a/v sync — which I *think* is because some part of the machinery tells the video to play X times faster *when it should not*, since the audio is being scaled back to normal.

    I’ve just dropped a note to Mr Juliano, who originally wrote the patch; I don’t know if it’s still in his domain, of whether he’d know a good spot to patch against it.

  20. 20 Baylink May 30, 2009 at 7:48 pm

    And here is the wackiest report of all:

    If I use the Ascii-art video driver? It tracks the audio perfectly, no matter what I do to the … no, false alarm.

    That test didn’t have -af scaletempo set; when I set it (=speed=pitch), it also falls out of sync.


  1. 1 mplayer: changing speed without changing pitch (avoiding the chipmunk effect) « The Lumber Room Trackback on May 29, 2009 at 6:54 pm
Comments are currently closed.


Get every new post delivered to your Inbox.

%d bloggers like this: