Skip to content

Instantly share code, notes, and snippets.

@syehoonkim
Created June 16, 2025 00:23
Show Gist options
  • Select an option

  • Save syehoonkim/d2d74002a79eb261930ca38a27e591e1 to your computer and use it in GitHub Desktop.

Select an option

Save syehoonkim/d2d74002a79eb261930ca38a27e591e1 to your computer and use it in GitHub Desktop.
mpv.io audio channels levelmenter
local mp = require 'mp'
local msg = require 'mp.msg'
function setup_volume_meter()
local tracks = mp.get_property_native("track-list")
if not tracks then
msg.warn("No track list found.")
return
end
local input_labels = {}
local input_count = 0
local has_video = false
for _, track in ipairs(tracks) do
if track.type == "audio" then
input_count = input_count + 1
local label = string.format("[aid%d]", track.id)
table.insert(input_labels, label)
elseif track.type == "video" then
has_video = true
end
end
if input_count == 0 then
msg.warn("No audio tracks found.")
return
end
local filter_graph
if input_count == 1 then
if has_video then
filter_graph = "[aid1]asplit[ao][as];[as]showvolume=r=29.97:h=70:w=300[vvol];[vid1]format=pix_fmts=yuv420p[vf];[vf][vvol]overlay[vo]"
else
filter_graph = "[aid1]asplit[ao][as];[as]showvolume=r=29.97:h=480:w=640[vo]"
end
else
local merged_inputs = table.concat(input_labels, "")
if has_video then
filter_graph = string.format(
"%samerge=inputs=%d,asplit[ao][as];[as]showvolume=r=29.97:h=70:w=300[vvol];[vid1]format=pix_fmts=yuv420p[vf];[vf][vvol]overlay[vo]",
merged_inputs, input_count
)
else
filter_graph = string.format(
"%samerge=inputs=%d,asplit[ao][as];[as]showvolume=r=29.97:h=480:w=640[vo]",
merged_inputs, input_count
)
end
end
mp.set_property("lavfi-complex", filter_graph)
msg.info("Applied lavfi-complex: " .. filter_graph)
end
mp.register_event("file-loaded", setup_volume_meter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment