Skip to content

mpv step forward is fast but step back is slow #4019

Closed

Description

@sant527

in mpv keyboard shortcuts:

.      Step forward. Pressing once will pause, every consecutive press will play one frame and then go into pause mode again.
,        Step backward. Pressing once will pause, every consecutive press will play one frame in reverse and then go into pause mode again.

Step forward is faster but step backward is slow. Because i am using some lua scripts to trim video.

how to make both work easily.

If i re encode the video to mjpeg format then it its vert smooth

Activity

  1. ghost closed this as completedon Jan 11, 2017
  2. stibinator commented on Sep 20, 2017

    @stibinator

    Playing back prores (all I-frame) shows the same behaviour.

  3. stibinator commented on Sep 20, 2017

    @stibinator

    Djvview has the option of caching decoded frames in memory, is this possible with mpv? Maybe with a user specifiable RAM cache, like djvview? I use mpv for previewing renders and so on, the ability to smoothly play backwards would be really useful.

    http://djv.sourceforge.net/

  4. TheSneakySniper commented on Dec 18, 2020

    @TheSneakySniper

    --demuxer-seekable-cache=yes --cache=yes --demuxer-max-back-bytes=10000M --hr-seek=yes --demuxer-cache-wait=yes

  5. kanehekili commented on Dec 30, 2021

    @kanehekili

    In addition to the tip above I could seek precisely in mts streams using the --hr-seek-deumuxer-offset=1.5 option solved it.

  6. metavolution commented on Feb 26, 2022

    @metavolution

    wow u dev guys r0ck ~ what u write here and in man page !!

    with play-dir hack, and tuning the demuxer options,
    got it to work with 4K HEVC x265 smooth backwards playback,
    video synced with reverse audio, using cpu or gpu decode : -)

    best video player feature ever ; -)

    cache=yes
    demuxer-readahead-secs=60
    demuxer-seekable-cache=yes
    demuxer-max-bytes=1000MiB
    video-reversal-buffer=500MiB
    audio-reversal-buffer=200MiB
    demuxer-max-back-bytes=700MiB
    hwdec-extra-frames=256
    demuxer-cache-wait=yes
    #hr-seek=yes
    #demuxer-backward-playback-step=

    what might be nonsensical in the above config?

    thx 4 all the code

  7. ntevenhere commented on Nov 5, 2022

    @ntevenhere

    --demuxer-seekable-cache=yes --cache=yes --demuxer-max-back-bytes=10000M --hr-seek=yes --demuxer-cache-wait=yes

    I don't know why this has so many positive reactions, doesn't look like it did anything. Doesn't mpv use a cache already? Increasing the cache size doesn't do anything. Depending on the video, stepping back , continues to take on second or more, yet stepping forwards is instant. seek -0.05 exact is just as slow too. These configurations don't change that mpv still does what @/Mia-0 said at the start of the thread, mpv has to decode forwards since the last keyframe to find the frame just one frame ago.

    I would prefer if mpv could have a small cache of previous frames.

  8. metavolution commented on Nov 5, 2022

    @metavolution

    with the options i mentioned, it works for me on most video files to go any direction one frame. there is even a hotkey for playing backwards. and that works instantly u can go back and forth in video in any playback speed. if its 4k and x265 one needs a GPU that supports that decoding. in my simple setup mpv can play most video files any speed and any direction. even with reverse sound and pretty instant no delay. hook up a usb playstation controller to controll it, and it is the coolest media player ever. have to experiment with tuning these options to your system though ;)

  9. ntevenhere commented on Nov 6, 2022

    @ntevenhere

    with the options i mentioned, it works for me on most video files to go any direction one frame. there is even a hotkey for playing backwards. and that works instantly u can go back and forth in video in any playback speed.

    Those sets of options don't do anything for me. This might depend on the video codec and mpv configuration. I will test with a sample video and report back. Meanwhile I came up with a funny hack:

    , cycle-values play-dir - +
    . frame-step               
    
  10. 2 remaining items

  11. metavolution commented on Nov 8, 2022

    @metavolution

    ah yes with ur file Buck Bunny single step back is about half the framerate of single frame forward.
    but what works for me as a hack is, switching to reverse playback mode, and then single step forward :)

  12. lucas-deangelis commented on Dec 9, 2022

    @lucas-deangelis

    Meanwhile I came up with a funny hack:

    , cycle-values play-dir - +
    . frame-step  
    

    That's a great hack, it works like a charm, thanks! However, I think the . frame-step might be unnecessary? I've tried with and without it and there's no difference, I'm not sure I understand why it's used here.

  13. ntevenhere commented on Mar 14, 2023

    @ntevenhere

    Meanwhile I came up with a funny hack:

    , cycle-values play-dir - +
    . frame-step  
    

    That's a great hack, it works like a charm, thanks! However, I think the . frame-step might be unnecessary? I've tried with and without it and there's no difference, I'm not sure I understand why it's used here.

    Yeah . frame-step is the default already, I just included it as a reminder.

  14. added a commit that references this issue on Aug 18, 2023
  15. All3xJ commented on Nov 6, 2023

    @All3xJ

    I fixed by uncommenting the RIGHT seek 5 and LEFT seek -5 lines in input.conf
    and also by adding hr-seek=yes in mpv.conf

  16. prez commented on Jul 4, 2024

    @prez

    Those sets of options don't do anything for me. This might depend on the video codec and mpv configuration. I will test with a sample video and report back. Meanwhile I came up with a funny hack:

    , cycle-values play-dir - +
    . frame-step               
    

    This is cute, but is it possible to create a faster keybind to only step back one frame by switching the direction, doing a frame-step, then switching direction again?
    I tried , set play-dir -; frame-step; set play-dir +, but it does not work as expected.

  17. richardpl commented on Jul 4, 2024

    @richardpl
    Contributor

    play-dir - need to cache frames in memory, and changing direction of play probably kills previous state.

  18. nucspl commented on Nov 12, 2024

    @nucspl

    sorry to necro this but i got really annoyed by the slow , backstepping that i made a script to "fix" it

    backstep.lua
    -- backstep.lua
    --
    -- Faster frame-back-step for mpv
    
    local mp = require('mp')
    
    function change_direction(direction)
    	if mp.get_property('play-direction') ~= direction then
    		mp.command('cycle play-direction')
    		osd_message = string.format('P: %s', direction:gsub('^%l', string.upper))
    		mp.osd_message(osd_message)
    	end
    end
    
    function frame_step(event, direction)
    	change_direction(direction)
    	if event.event == 'down' or event.event == 'repeat' then
    		mp.command('frame-step')
    	elseif event.event == 'up' then -- counters imprecision of 'repeat'
    		mp.set_property('pause', 'yes')
    	end
    end
    
    mp.add_key_binding(nil, 'frame-forestep', function(event)
    	frame_step(event, 'forward')
    end, {complex = true})
    
    mp.add_key_binding(nil, 'frame-backstep', function(event)
    	frame_step(event, 'backward')
    end, {complex = true})
    
    mp.add_key_binding(nil, 'fore-play', function(event)
    	change_direction('forward')
    	mp.command('cycle pause')
    end)
    
    input.conf changes
    # backstep.lua - frame stepping
    , script_binding frame-backstep
    . script_binding frame-forestep
    
    # backstep.lua - pause cycling
    MBTN_RIGHT script_binding fore-play
    p script_binding fore-play
    SPACE script_binding fore-play
    PLAY script_binding fore-play
    PAUSE script_binding fore-play
    PLAYPAUSE script_binding fore-play
    

    there's just a few issues:

    • prolonged or too much playback on play-direction backward can sometimes cause reversal frame queue overflow
      • i've read that increasing video-reversal-buffer or demuxer-max-back-bytes helps but it can still occur every now and then
    • it's prone to audio-video desync
    • it takes two inputs to properly begin stepping frames after changing play-direction (i never understood why) but it's better than waiting 20 seconds just to go back 5 frames
      • in case you want to observe this, add a line to your osd-status-msg to display video frame count like so:
    nvenc_h264_1080p_Q25.mp4

    despite the small problems, it's more than enough for my use case, i hope this helps(:

  19. geextahslex commented on Nov 14, 2024

    @geextahslex

    @nucspl Awesome script, thank you :)

  20. netExtra commented on Nov 14, 2024

    @netExtra

    @nucspl Hi, the solution for me is to not use the scripts forward seeking and just leave it at default, and only keybind the backward seeking to the script. This way you don't have to press the key twice. Awesome script, thank you :)

    mpv seek

    . frame-step
    #, frame-back-step
    

    script seek

    , script_binding frame-backstep
    #. script_binding frame-forestep
    

    sorry to necro this but i got really annoyed by the slow , backstepping that i made a script to "fix" it

    backstep.lua
    input.conf changes
    there's just a few issues:

    • prolonged or too much playback on play-direction backward can sometimes cause reversal frame queue overflow

      • i've read that increasing video-reversal-buffer or demuxer-max-back-bytes helps but it can still occur every now and then
    • it's prone to audio-video desync

    • it takes two inputs to properly begin stepping frames after changing play-direction (i never understood why) but it's better than waiting 20 seconds just to go back 5 frames

      • in case you want to observe this, add a line to your osd-status-msg to display video frame count like so:

    nvenc_h264_1080p_Q25.mp4
    despite the small problems, it's more than enough for my use case, i hope this helps(:

    I used to use a script then reverted to using the mpv input file and playdir which worked much better. I will try your script and see what how well it works in comparison. Well worth the necro if it works. Even if it doesn't, it's definitely something that I hope one day can be improved :)

  21. geextahslex commented on Nov 14, 2024

    @geextahslex

    @netExtra what do you mean by playdir?

  22. netExtra commented on Nov 14, 2024

    @netExtra

    @netExtra what do you mean by playdir?

    From the mpv manual

    --play-direction=<forward|+|backward|->
    Control the playback direction (default: forward). Setting backward will attempt to play the file in reverse direction, with decreasing playback time. If this is set on playback starts, playback will start from the end of the file. If this is changed at during playback, a hr-seek will be issued to change the direction.

    It then goes on to explain why backward playback will usually be slow and always be problematic.

  23. netExtra commented on Nov 14, 2024

    @netExtra

    @nucspl Hi, the solution for me is to not use the scripts forward seeking and just leave it at default, and only keybind the backward seeking to the script. This way you don't have to press the key twice. Awesome script, thank you :)
    mpv seek

    . frame-step
    #, frame-back-step
    

    script seek

    , script_binding frame-backstep
    #. script_binding frame-forestep
    

    sorry to necro this but i got really annoyed by the slow , backstepping that i made a script to "fix" it
    backstep.lua
    input.conf changes
    there's just a few issues:

    • prolonged or too much playback on play-direction backward can sometimes cause reversal frame queue overflow

      • i've read that increasing video-reversal-buffer or demuxer-max-back-bytes helps but it can still occur every now and then
    • it's prone to audio-video desync

    • it takes two inputs to properly begin stepping frames after changing play-direction (i never understood why) but it's better than waiting 20 seconds just to go back 5 frames

      • in case you want to observe this, add a line to your osd-status-msg to display video frame count like so:

    nvenc_h264_1080p_Q25.mp4
    despite the small problems, it's more than enough for my use case, i hope this helps(:

    I used to use a script then reverted to using the mpv input file and playdir which worked much better. I will try your script and see what how well it works in comparison. Well worth the necro if it works. Even if it doesn't, it's definitely something that I hope one day can be improved :)

    I've just tried it and it's very smooth. But I still prefer playdir because I don't want to have to hold down the key all the time. So I'm modifying to play continuously in reverse to compare and since it's basically using the same mechanism, the results are the same. I'm also running through the SVP frame interpolation software. Without that, playdirection works perfectly well. With SVP both playdir and you script which uses playdir perform the same. But when holding down the key, that seems to get around the issue.

  24. geextahslex commented on Nov 14, 2024

    @geextahslex

    How do you keybind it?

  25. LonelyFarts commented on Jun 7, 2025

    @LonelyFarts

    I find this to be nice. Then you can still step back 1 frame if you need to.
    / cycle-values play-dir - +
    . frame-step

    One thing I wouldn't mind would be if MPV would use as many resources as it needs. My computer is barely jogging while MPV is lagging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions