Created
October 29, 2017 00:20
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
What does it do? It justs seeks to the end for me.
Gif