Skip to content

Instantly share code, notes, and snippets.

@blinry
Created October 29, 2017 00:20
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save blinry/865723228e00d682ede851797e8c677e to your computer and use it in GitHub Desktop.
Put this into ~/.mpv/scripts/, then press M while playing a movie to turn on "Memento mode"
is_on = false
step = 5*60 -- seconds
overlap = 10 -- seconds
function recalc()
local pos = mp.get_property_number("time-pos")
local duration = mp.get_property_number("duration")
next_seek = math.ceil((pos+1)/step)*step+overlap
if next_seek > duration then
next_seek = duration-1
end
seek_to = (math.floor((pos+1)/step)-1)*step
end
function start()
local duration = mp.get_property_number("duration")
mp.commandv("seek", math.floor(duration/step)*step, "absolute+exact")
recalc()
end
function toggle()
is_on = not is_on
if is_on then
mp.osd_message("Memento mode: on")
start()
timer = mp.add_periodic_timer(1, function()
local pos = mp.get_property_number("time-pos")
if pos >= next_seek then
if seek_to < 0 then
mp.command("stop")
end
mp.commandv("seek", seek_to, "absolute+exact")
recalc()
end
end)
mp.register_event("seek", function()
local pos = mp.get_property_number("time-pos")
recalc()
end)
else
mp.osd_message("Memento mode: off")
timer:kill()
end
end
mp.add_key_binding("M", "toggle-memento", toggle)
@phanirithvij
Copy link

phanirithvij commented Mar 24, 2020

What does it do? It justs seeks to the end for me.
Gif

@blinry
Copy link
Author

blinry commented Jun 17, 2020

Hey @phanirithvij, thanks for commenting! If you let it run to the end, it will jump 10 minutes ahead, and then again after 5 minutes, allowing you to watch the movie backwards, in 5 minute-blocks. I wrote about it here: https://morr.cc/watching-movies-backwards/

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