config redshift

This commit is contained in:
vincent 2018-11-09 21:08:25 +01:00
parent 9305f48e57
commit 3c7f840169
3 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,2 @@
ctrl+z sub-step -1
ctrl+x sub-step +1

View File

@ -0,0 +1,70 @@
--[[
How to use:
The shortcut to adjust timing is set to ctrl+w by default.
Edit your input.conf and bind "sub-step 1" and "sub-step -1" to two keys, e.g.:
ctrl+z sub-step -1
ctrl+x sub-step 1
Start the video, and manually synchronize the first subtitle to audio (waiting
for someone to speak and then selecting the right subtitle with ctrl+z/ctrl+x
works best). Then hit ctrl+w to mark the first point. Go on to a later time
where someone speaks, and synchronize the right subtitle again. Then hit ctrl+w
again to mark this as the second point. The script will choose a sub-delay
and sub-speed value that makes the two points you marked show the subtitles
as you timed them when hitting the shortcut.
Technically, this assumes:
sub_time = (vid_time - sub_delay) / sub_speed
which is probably what mpv does internally. Using two points in time, we can
compute the required sub_delay and sub_speed to get to the two points to display
the 2 subtitle events at the marked times with the same delay.
]]
sub_time_1 = nil
vid_time_1 = nil
sub_time_2 = nil
vid_time_2 = nil
function sub_set_time()
local sub_delay = mp.get_property_native("sub-delay")
local vid_time = mp.get_property_native("playback-time")
local sub_speed = mp.get_property_native("sub-speed")
local sub_time = (vid_time - sub_delay) / sub_speed
if sub_time_1 == nil then
vid_time_1 = vid_time
sub_time_1 = sub_time
mp.osd_message("Mark time 1")
return
end
if sub_time_2 ~= nil then
sub_time_1 = sub_time_2
vid_time_1 = vid_time_2
end
if sub_time_1 == sub_time or vid_time_1 == vid_time then
return
end
sub_time_2 = sub_time
vid_time_2 = vid_time
-- sub_time_1 = (vid_time_1 - delay) / speed
-- sub_time_2 = (vid_time_2 - delay) / speed
local new_speed = (vid_time_2 - vid_time_1) / (sub_time_2 - sub_time_1)
local new_delay = vid_time_2 - sub_time_2 * new_speed
print("delay=" .. tostring(new_delay) .. " speed=" .. tostring(new_speed))
mp.set_property_native("sub-delay", new_delay)
mp.set_property_native("sub-speed", new_speed)
end
mp.add_key_binding("ctrl+w", "sub-set-time", sub_set_time)

View File

@ -0,0 +1,44 @@
-- Toggle redshift when viewing videos with mpv
if os.execute("pgrep -x redshift >/dev/null") ~= 0
then
return
end
-- Consider that redshift is enabled when starting
rs_enabled = true
function rs_toggle()
os.execute("pkill -x -USR1 redshift")
end
function rs_disable()
if rs_enabled
then
rs_toggle()
rs_enabled = false
mp.msg.log("info", "Disabling redshift")
end
end
function rs_enable()
if not rs_enabled
then
rs_toggle()
rs_enabled = true
mp.msg.log("info", "Reenabling redshift")
end
end
function rs_handler()
if mp.get_property("video") ~= "no"
then
rs_disable()
else
rs_enable()
end
end
mp.register_event("file-loaded", rs_handler)
mp.register_event("shutdown", rs_enable)