Skip to content

Instantly share code, notes, and snippets.

@TheAMM
Created November 14, 2017 23:03
Show Gist options
  • Save TheAMM/6260c8e46aed81fda12462cb3a089e79 to your computer and use it in GitHub Desktop.
Save TheAMM/6260c8e46aed81fda12462cb3a089e79 to your computer and use it in GitHub Desktop.
Simple mpv script to fix subtitle delay (ie. signs starting too soon, too late)
--[[
Simple script to fix sub-delay on offset subs
First, framestep to where the desired subtitle (sign) SHOULD start, press ALT+Z
Next, framestep to where the desired subtitle (sign) DOES start, press ALT+Z
Done.
You may press ALT+Z twice in succession to zero out sub-delay.
]]--
local start_time = nil
function on_script_action()
local playback_time = mp.get_property_native("playback-time")
if start_time == playback_time then
mp.osd_message("Identical frames, clearing sub-delay")
mp.set_property_native("sub-delay", 0)
start_time = nil
elseif start_time ~= nil then
-- Take current sub-delay into account
local sub_delay = mp.get_property_native("sub-delay")
local delta = start_time - playback_time + sub_delay
mp.set_property_native("sub-delay", delta)
mp.osd_message("Set sub-delay to " .. tostring(delta), 2)
start_time = nil
else
start_time = playback_time
mp.osd_message("Picked expected frame, now pick the actual frame", 2)
end
end
mp.add_key_binding("alt+z", "fix_subdelay_action", on_script_action)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment