2014-04-29 12:11:39 +00:00
|
|
|
-- This script enables live control of the dynamic range compression
|
|
|
|
-- (drc) audio filter while the video is playing back. This can be
|
|
|
|
-- useful to avoid having to stop and restart mpv to adjust filter
|
|
|
|
-- parameters. See the entry for "drc" under the "AUDIO FILTERS"
|
|
|
|
-- section of the man page for a complete description of the filter.
|
|
|
|
--
|
|
|
|
-- This script registers the key-binding "\" to toggle the filter between
|
|
|
|
--
|
|
|
|
-- * off
|
|
|
|
-- * method=1 (single-sample smoothing)
|
|
|
|
-- * method=2 (multi-sample smoothing)
|
|
|
|
--
|
|
|
|
-- It registers the keybindings ctrl+9/ctrl+0 to decrease/increase the
|
|
|
|
-- target ampltiude. These keys will insert the filter at the default
|
|
|
|
-- target amplitude of 0.25 if it was not previously present.
|
|
|
|
--
|
|
|
|
-- OSD feedback of the current filter state is displayed on pressing
|
|
|
|
-- each bound key.
|
|
|
|
|
2014-05-06 16:59:59 +00:00
|
|
|
script_name = mp.get_script_name()
|
2014-04-26 17:26:04 +00:00
|
|
|
|
|
|
|
function print_state(params)
|
2014-04-27 01:07:46 +00:00
|
|
|
if params then
|
2014-05-04 19:59:21 +00:00
|
|
|
mp.osd_message(script_name..":\n"
|
|
|
|
.."method = "..params["method"].."\n"
|
|
|
|
.."target = "..params["target"])
|
2014-04-27 01:07:46 +00:00
|
|
|
else
|
2014-05-04 19:59:21 +00:00
|
|
|
mp.osd_message(script_name..":\noff")
|
2014-04-27 01:07:46 +00:00
|
|
|
end
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function get_index_of_drc(afs)
|
2014-04-27 01:07:46 +00:00
|
|
|
for i,af in pairs(afs) do
|
2014-05-06 16:59:59 +00:00
|
|
|
if af["label"] == script_name then
|
2014-04-27 01:07:46 +00:00
|
|
|
return i
|
|
|
|
end
|
|
|
|
end
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function append_drc(afs)
|
2014-05-06 16:59:59 +00:00
|
|
|
afs[#afs+1] = {
|
|
|
|
name = "drc",
|
|
|
|
label = script_name,
|
|
|
|
params = {
|
|
|
|
method = "1",
|
|
|
|
target = "0.25"
|
2014-04-27 01:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-04 19:59:21 +00:00
|
|
|
print_state(afs[#afs]["params"])
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function modify_or_create_af(fun)
|
2014-05-06 16:59:59 +00:00
|
|
|
afs = mp.get_property_native("af")
|
|
|
|
i = get_index_of_drc(afs)
|
2014-04-27 01:07:46 +00:00
|
|
|
if not i then
|
|
|
|
append_drc(afs)
|
|
|
|
else
|
2014-05-06 16:59:59 +00:00
|
|
|
fun(afs, i)
|
2014-04-27 01:07:46 +00:00
|
|
|
end
|
2014-05-06 16:59:59 +00:00
|
|
|
mp.set_property_native("af", afs)
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function drc_toggle_method_handler()
|
2014-04-27 01:07:46 +00:00
|
|
|
modify_or_create_af(
|
2014-05-06 16:59:59 +00:00
|
|
|
function (afs, i)
|
2014-05-04 19:59:21 +00:00
|
|
|
new_method=(afs[i]["params"]["method"]+1)%3
|
2014-05-06 16:59:59 +00:00
|
|
|
if new_method == 0 then
|
|
|
|
table.remove(afs, i)
|
2014-04-27 01:07:46 +00:00
|
|
|
print_state(nil)
|
|
|
|
else
|
2014-05-06 16:59:59 +00:00
|
|
|
afs[i]["params"]["method"] = tostring((afs[i]["params"]["method"])%2+1)
|
2014-05-04 19:59:21 +00:00
|
|
|
print_state(afs[i]["params"])
|
2014-04-27 01:07:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function drc_scale_target(factor)
|
2014-04-27 01:07:46 +00:00
|
|
|
modify_or_create_af(
|
|
|
|
function (afs)
|
2014-05-06 16:59:59 +00:00
|
|
|
afs[i]["params"]["target"] = tostring(afs[i]["params"]["target"]*factor)
|
2014-05-04 19:59:21 +00:00
|
|
|
print_state(afs[i]["params"])
|
2014-04-27 01:07:46 +00:00
|
|
|
end
|
|
|
|
)
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function drc_louder_handler()
|
2014-04-27 01:07:46 +00:00
|
|
|
drc_scale_target(2.0)
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function drc_quieter_handler()
|
2014-04-27 01:07:46 +00:00
|
|
|
drc_scale_target(0.5)
|
2014-04-26 17:26:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- toggle between off, method 1 and method 2
|
2014-05-06 16:59:59 +00:00
|
|
|
mp.add_key_binding("\\", "drc_toggle_method", drc_toggle_method_handler)
|
2014-04-26 17:26:04 +00:00
|
|
|
-- increase or decrease target volume
|
2014-05-06 16:59:59 +00:00
|
|
|
mp.add_key_binding("ctrl+9", "drc_quieter", drc_quieter_handler)
|
|
|
|
mp.add_key_binding("ctrl+0", "drc_louder", drc_louder_handler)
|