-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfix-avsync.lua
More file actions
32 lines (27 loc) · 940 Bytes
/
fix-avsync.lua
File metadata and controls
32 lines (27 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--[[
Fixed A/V sync when switching the audio output device with using audio filters
available at: https://github.com/dyphire/mpv-scripts
]]--
local msg = require "mp.msg"
local function is_protocol(path)
return type(path) == 'string' and (path:find('^%a[%w.+-]-://') ~= nil or path:find('^%a[%w.+-]-:%?') ~= nil)
end
local function fix_avsync()
local paused = mp.get_property_bool("pause")
msg.info("fix A/V sync.")
mp.commandv("frame-back-step")
if paused then
return
else
mp.set_property_bool("pause", false)
end
end
mp.observe_property("current-ao", "native", function(_, device)
local aid = mp.get_property_number("aid")
local has_af = mp.get_property("af", "") ~= ""
local path = mp.get_property("path")
local time = mp.get_property_native("time-pos")
if device and aid and has_af and time > 0 and not is_protocol(path) then
fix_avsync()
end
end)