Last active
February 28, 2024 03:58
-
-
Save hooke007/1ead3a9b9196d5de69e8d37add889efb to your computer and use it in GitHub Desktop.
[mpv-script] 自动均衡多声道音频
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
--[[ | |
-- 旧实现和 https://github.com/mpv-player/mpv/issues/11541 的问题一致 | |
function check_achannels() | |
local channel_count = mp.get_property_number("audio-params/channel-count") | |
if channel_count and channel_count > 2 then | |
mp.commandv("af", "pre", "@vocal:loudnorm") | |
else | |
mp.commandv("af", "remove", "@vocal") | |
end | |
end | |
mp.observe_property("audio-params/channel-count", "number", check_achannels) | |
]] | |
-- 改用此版本可按预期工作 | |
function check_af(add) | |
local af_list = mp.get_property("af") | |
if af_list:find("@vocal:") then | |
if add == 1 then | |
return | |
else | |
mp.commandv("af", "remove", "@vocal") | |
end | |
else | |
if add == 1 then | |
mp.commandv("af", "pre", "@vocal:loudnorm") | |
else | |
return | |
end | |
end | |
end | |
function check_achannels(prop, value) | |
if prop == "path" or prop == "aid" then | |
local achannels = mp.get_property_number("audio-params/channel-count", 0) | |
--print("achannels: " .. achannels) | |
--print("af: " .. mp.get_property("af")) | |
if achannels > 2 then | |
check_af(1) | |
else | |
check_af(0) | |
end | |
end | |
end | |
mp.observe_property("path", "string", check_achannels) | |
mp.observe_property("aid", "number", check_achannels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment