mpv/scripts/visualizer.lua: improve compatiblity with other scripts
Writing to lavfi-complex even when no visualization is desired can cause
conflicts with other scripts, as can be seen in
https://github.com/mfcc64/mpv-scripts/issues/36
Since each file needs to be evaluated individually if the visualizer
should be used for it. There is no benefit in keeping lavfi-complex set
across file boundaries and only adds the requirement that it has to be
reset if the next file shouldn't use the visualizer.
Setting lavfi-complex as a file-local-option avoids the need to reset it
via the script, and can help avoid conflicts with other scripts.
Additionally using the visualizer for files without audio doesn't make
sense, therefore the visualizer can be skipped for any files without
audio tracks.
@@ -287,8 +287,8 @@ local function get_visualizer(name, quality, vtrack)
return ""
end
-local function select_visualizer(vtrack)
- if opts.mode == "off" then
+local function select_visualizer(vtrack, atrack)
+ if atrack == nil or opts.mode == "off" then
return ""
elseif opts.mode == "force" then
return get_visualizer(opts.name, opts.quality, vtrack)
@@ -328,10 +328,10 @@ local function visualizer_hook()
end
end
- local lavfi = select_visualizer(vtrack)
+ local lavfi = select_visualizer(vtrack, atrack)
--prevent endless loop
- if lavfi ~= mp.get_property("options/lavfi-complex", "") then
- mp.set_property("options/lavfi-complex", lavfi)
+ if lavfi ~= "" and lavfi ~= mp.get_property("lavfi-complex", "") then
+ mp.set_property("file-local-options/lavfi-complex", lavfi)
end
end