diff options
Diffstat (limited to 'player/lua/stats.lua')
-rw-r--r-- | player/lua/stats.lua | 1008 |
1 files changed, 811 insertions, 197 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 6054480e9c..0085c22638 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -9,19 +9,20 @@ local mp = require 'mp' local options = require 'mp.options' local utils = require 'mp.utils' +local input = require 'mp.input' -- Options local o = { -- Default key bindings - key_oneshot = "i", - key_toggle = "I", key_page_1 = "1", key_page_2 = "2", key_page_3 = "3", key_page_4 = "4", + key_page_0 = "0", -- For pages which support scrolling key_scroll_up = "UP", key_scroll_down = "DOWN", + key_search = "/", scroll_lines = 1, duration = 4, @@ -30,30 +31,36 @@ local o = { persistent_overlay = false, -- whether the stats can be overwritten by other output print_perfdata_passes = false, -- when true, print the full information about all passes filter_params_max_length = 100, -- a filter list longer than this many characters will be shown one filter per line instead + show_frame_info = false, -- whether to show the current frame info + term_width_limit = -1, -- overwrites the terminal width + term_height_limit = -1, -- overwrites the terminal height debug = false, -- Graph options and style plot_perfdata = true, plot_vsync_ratio = true, plot_vsync_jitter = true, + plot_tonemapping_lut = false, skip_frames = 5, global_max = true, flush_graph_data = true, -- clear data buffers when toggling plot_bg_border_color = "0000FF", plot_bg_color = "262626", plot_color = "FFFFFF", + plot_bg_border_width = 0.5, -- Text style - font = "sans", + font = "", font_mono = "monospace", -- monospaced digits are sufficient font_size = 8, - font_color = "FFFFFF", + font_color = "", border_size = 0.8, - border_color = "262626", + border_color = "", shadow_x_offset = 0.0, shadow_y_offset = 0.0, - shadow_color = "000000", + shadow_color = "", alpha = "11", + vidscale = true, -- Custom header for ASS tags to style the text output. -- Specifying this will ignore the text style values above and just @@ -77,13 +84,30 @@ local o = { no_ass_b0 = "\027[0m", no_ass_it1 = "\027[3m", no_ass_it0 = "\027[0m", + + bindlist = "no", -- print page 4 to the terminal on startup and quit mpv } options.read_options(o) +o.term_width_limit = tonumber(o.term_width_limit) or -1 +o.term_height_limit = tonumber(o.term_height_limit) or -1 +if o.term_width_limit < 0 then + o.term_width_limit = nil +end +if o.term_height_limit < 0 then + o.term_height_limit = nil +end + local format = string.format local max = math.max local min = math.min +-- Scaled metrics +local font_size = o.font_size +local border_size = o.border_size +local shadow_x_offset = o.shadow_x_offset +local shadow_y_offset = o.shadow_y_offset +local plot_bg_border_width = o.plot_bg_border_width -- Function used to record performance data local recorder = nil -- Timer used for redrawing (toggling) and clearing the screen (oneshot) @@ -94,6 +118,8 @@ local cache_recorder_timer = nil local curr_page = o.key_page_1 local pages = {} local scroll_bound = false +local searched_text +local tm_viz_prev = nil -- Save these sequences locally as we'll need them a lot local ass_start = mp.get_property_osd("osd-ass-cc/0") local ass_stop = mp.get_property_osd("osd-ass-cc/1") @@ -107,15 +133,6 @@ local function init_buffers() end local cache_ahead_buf, cache_speed_buf local perf_buffers = {} --- Save all properties known to this version of mpv -local property_list = {} -for p in string.gmatch(mp.get_property("property-list"), "([^,]+)") do property_list[p] = true end --- Mapping of properties to their deprecated names -local property_aliases = { - ["decoder-frame-drop-count"] = "drop-frame-count", - ["frame-drop-count"] = "vo-drop-frame-count", - ["container-fps"] = "fps", -} local function graph_add_value(graph, value) graph.pos = (graph.pos % graph.len) + 1 @@ -123,25 +140,15 @@ local function graph_add_value(graph, value) graph.max = max(graph.max, value) end --- Return deprecated name for the given property -local function compat(p) - while not property_list[p] and property_aliases[p] do - p = property_aliases[p] - end - return p -end - - -local function set_ASS(b) - if not o.use_ass or o.persistent_overlay then - return "" - end - return b and ass_start or ass_stop -end - - local function no_ASS(t) - return set_ASS(false) .. t .. set_ASS(true) + if not o.use_ass then + return t + elseif not o.persistent_overlay then + -- mp.osd_message supports ass-escape using osd-ass-cc/{0|1} + return ass_stop .. t .. ass_start + else + return mp.command_native({"escape-ass", tostring(t)}) + end end @@ -160,19 +167,34 @@ local function text_style() return "" end if o.custom_header and o.custom_header ~= "" then - return set_ASS(true) .. o.custom_header + return o.custom_header else - return format("%s{\\r}{\\an7}{\\fs%d}{\\fn%s}{\\bord%f}{\\3c&H%s&}" .. - "{\\1c&H%s&}{\\alpha&H%s&}{\\xshad%f}{\\yshad%f}{\\4c&H%s&}", - set_ASS(true), o.font_size, o.font, o.border_size, - o.border_color, o.font_color, o.alpha, o.shadow_x_offset, - o.shadow_y_offset, o.shadow_color) + local style = "{\\r\\an7\\fs" .. font_size .. "\\bord" .. border_size + + if o.font ~= "" then + style = style .. "\\fn" .. o.font + end + + if o.font_color ~= "" then + style = style .. "\\1c&H" .. o.font_color .. "&\\1a&H" .. o.alpha .. "&" + end + + if o.border_color ~= "" then + style = style .. "\\3c&H" .. o.border_color .. "&\\3a&H" .. o.alpha .. "&" + end + + if o.shadow_color ~= "" then + style = style .. "\\4c&H" .. o.shadow_color .. "&\\4a&H" .. o.alpha .. "&" + end + + return style .. "\\xshad" .. shadow_x_offset .. + "\\yshad" .. shadow_y_offset .. "}" end end local function has_vo_window() - return mp.get_property("vo-configured") == "yes" + return mp.get_property_native("vo-configured") and mp.get_property_native("video-osd") end @@ -196,31 +218,34 @@ local function generate_graph(values, i, len, v_max, v_avg, scale, x_tics) end local x_max = (len - 1) * x_tics - local y_offset = o.border_size - local y_max = o.font_size * 0.66 + local y_offset = border_size + local y_max = font_size * 0.66 local x = 0 - -- try and center the graph if possible, but avoid going above `scale` - if v_avg then - scale = min(scale, v_max / (2 * v_avg)) - end + if v_max > 0 then + -- try and center the graph if possible, but avoid going above `scale` + if v_avg and v_avg > 0 then + scale = min(scale, v_max / (2 * v_avg)) + end + scale = scale * y_max / v_max + end -- else if v_max==0 then all values are 0 and scale doesn't matter - local s = {format("m 0 0 n %f %f l ", x, y_max - (y_max * values[i] / v_max * scale))} + local s = {format("m 0 0 n %f %f l ", x, y_max - scale * values[i])} i = ((i - 2) % len) + 1 for p = 1, len - 1 do if values[i] then x = x - x_tics - s[#s+1] = format("%f %f ", x, y_max - (y_max * values[i] / v_max * scale)) + s[#s+1] = format("%f %f ", x, y_max - scale * values[i]) end i = ((i - 2) % len) + 1 end s[#s+1] = format("%f %f %f %f", x, y_max, 0, y_max) - local bg_box = format("{\\bord0.5}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0", - o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max) - return format("%s{\\r}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s", + local bg_box = format("{\\bord%f}{\\3c&H%s&}{\\1c&H%s&}m 0 %f l %f %f %f 0 0 0", + plot_bg_border_width, o.plot_bg_border_color, o.plot_bg_color, y_max, x_max, y_max, x_max) + return format("%s{\\rDefault}{\\pbo%f}{\\shad0}{\\alpha&H00}{\\p1}%s{\\p0}{\\bord0}{\\1c&H%s}{\\p1}%s{\\p0}%s", o.prefix_sep, y_offset, bg_box, o.plot_color, table.concat(s), text_style()) end @@ -266,8 +291,26 @@ local function append_property(s, prop, attr, excluded) return append(s, ret, attr) end +local function sorted_keys(t, comp_fn) + local keys = {} + for k,_ in pairs(t) do + keys[#keys+1] = k + end + table.sort(keys, comp_fn) + return keys +end -local function append_perfdata(s, dedicated_page) +local function scroll_hint(search) + local hint = format("(hint: scroll with %s/%s", o.key_scroll_up, o.key_scroll_down) + if search then + hint = hint .. " and search with " .. o.key_search + end + hint = hint .. ")" + if not o.use_ass then return " " .. hint end + return format(" {\\fs%s}%s{\\fs%s}", font_size * 0.66, hint, font_size) +end + +local function append_perfdata(header, s, dedicated_page, print_passes) local vo_p = mp.get_property_native("vo-passes") if not vo_p then return @@ -275,7 +318,7 @@ local function append_perfdata(s, dedicated_page) local ds = mp.get_property_bool("display-sync-active", false) local target_fps = ds and mp.get_property_number("display-fps", 0) - or mp.get_property_number(compat("container-fps"), 0) + or mp.get_property_number("container-fps", 0) if target_fps > 0 then target_fps = 1 / target_fps * 1e9 end -- Sums of all last/avg/peak values @@ -292,7 +335,7 @@ local function append_perfdata(s, dedicated_page) -- Pretty print measured time local function pp(i) -- rescale to microseconds for a saner display - return format("%05d", i / 1000) + return format("%5d", i / 1000) end -- Format n/m with a font weight based on the ratio @@ -303,20 +346,23 @@ local function append_perfdata(s, dedicated_page) end -- Calculate font weight. 100 is minimum, 400 is normal, 700 bold, 900 is max local w = (700 * math.sqrt(i)) + 200 - return format("{\\b%d}%02d%%{\\b0}", w, i * 100) + return format("{\\b%d}%2d%%{\\b0}", w, i * 100) end -- ensure that the fixed title is one element and every scrollable line is -- also one single element. - s[#s+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}", + local h = dedicated_page and header or s + h[#h+1] = format("%s%s%s%s{\\fs%s}%s{\\fs%s}%s", dedicated_page and "" or o.nl, dedicated_page and "" or o.indent, - b("Frame Timings:"), o.prefix_sep, o.font_size * 0.66, - "(last/average/peak μs)", o.font_size) + b("Frame Timings:"), o.prefix_sep, font_size * 0.66, + "(last/average/peak μs)", font_size, + dedicated_page and scroll_hint() or "") - for frame, data in pairs(vo_p) do + for _,frame in ipairs(sorted_keys(vo_p)) do -- ensure fixed display order + local data = vo_p[frame] local f = "%s%s%s{\\fn%s}%s / %s / %s %s%s{\\fn%s}%s%s%s" - if dedicated_page then + if print_passes then s[#s+1] = format("%s%s%s:", o.nl, o.indent, b(frame:gsub("^%l", string.upper))) @@ -324,7 +370,7 @@ local function append_perfdata(s, dedicated_page) s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono, pp(pass["last"]), pp(pass["avg"]), pp(pass["peak"]), - o.prefix_sep .. o.prefix_sep, p(pass["last"], last_s[frame]), + o.prefix_sep .. "\\h\\h", p(pass["last"], last_s[frame]), o.font, o.prefix_sep, o.prefix_sep, pass["desc"]) if o.plot_perfdata and o.use_ass then @@ -339,8 +385,8 @@ local function append_perfdata(s, dedicated_page) -- Print sum of timing values as "Total" s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono, pp(last_s[frame]), - pp(avg_s[frame]), pp(peak_s[frame]), "", "", o.font, - o.prefix_sep, o.prefix_sep, b("Total")) + pp(avg_s[frame]), pp(peak_s[frame]), + o.prefix_sep, b("Total"), o.font, "", "", "") else -- for the simplified view, we just print the sum of each pass s[#s+1] = format(f, o.nl, o.indent, o.indent, o.font_mono, @@ -351,32 +397,157 @@ local function append_perfdata(s, dedicated_page) end end -local function append_general_perfdata(s, offset) - local perf_info = mp.get_property_native("perf-info") or {} - local count = 0 - for _, data in ipairs(perf_info) do - count = count + 1 +-- command prefix tokens to strip - includes generic property commands +local cmd_prefixes = { + osd_auto=1, no_osd=1, osd_bar=1, osd_msg=1, osd_msg_bar=1, raw=1, sync=1, + async=1, expand_properties=1, repeatable=1, set=1, add=1, multiply=1, + toggle=1, cycle=1, cycle_values=1, ["!reverse"]=1, change_list=1, +} +-- commands/writable-properties prefix sub-words (followed by -) to strip +local name_prefixes = { + define=1, delete=1, enable=1, disable=1, dump=1, write=1, drop=1, revert=1, + ab=1, hr=1, secondary=1, current=1, +} +-- extract a command "subject" from a command string, by removing all +-- generic prefix tokens and then returning the first interesting sub-word +-- of the next token. For target-script name we also check another token. +-- The tokenizer works fine for things we care about - valid mpv commands, +-- properties and script names, possibly quoted, white-space[s]-separated. +-- It's decent in practice, and worst case is "incorrect" subject. +local function cmd_subject(cmd) + cmd = cmd:gsub(";.*", ""):gsub("%-", "_") -- only first cmd, s/-/_/ + local TOKEN = '^%s*["\']?([%w_!]*)' -- captures+ends before (maybe) final " + local tok, sname, subw + + repeat tok, cmd = cmd:match(TOKEN .. '["\']?(.*)') + until not cmd_prefixes[tok] + -- tok is the 1st non-generic command/property name token, cmd is the rest + + sname = tok == "script_message_to" and cmd:match(TOKEN) + or tok == "script_binding" and cmd:match(TOKEN .. "/") + if sname and sname ~= "" then + return "script: " .. sname end - offset = max(1, min((offset or 1), count)) - local i = 0 - for _, data in ipairs(perf_info) do - i = i + 1 - if i >= offset then - append(s, data.text or data.value, {prefix="["..tostring(i).."] "..data.name..":"}) + -- return the first sub-word of tok which is not a useless prefix + repeat subw, tok = tok:match("([^_]*)_?(.*)") + until tok == "" or not name_prefixes[subw] + return subw:len() > 1 and subw or "[unknown]" +end - if o.plot_perfdata and o.use_ass and data.value then - buf = perf_buffers[data.name] - if not buf then - buf = {0, pos = 1, len = 50, max = 0} - perf_buffers[data.name] = buf - end - graph_add_value(buf, data.value) - s[#s+1] = generate_graph(buf, buf.pos, buf.len, buf.max, nil, 0.8, 1) +-- key names are valid UTF-8, ascii7 except maybe the last/only codepoint. +-- we count codepoints and ignore wcwidth. no need for grapheme clusters. +-- our error for alignment is at most one cell (if last CP is double-width). +-- (if k was valid but arbitrary: we'd count all bytes <0x80 or >=0xc0) +local function keyname_cells(k) + local klen = k:len() + if klen > 1 and k:byte(klen) >= 0x80 then -- last/only CP is not ascii7 + repeat klen = klen-1 + until klen == 1 or k:byte(klen) >= 0xc0 -- last CP begins at klen + end + return klen +end + +local function get_kbinfo_lines() + -- active keys: only highest priority of each key, and not our (stats) keys + local bindings = mp.get_property_native("input-bindings", {}) + local active = {} -- map: key-name -> bind-info + for _, bind in pairs(bindings) do + if bind.priority >= 0 and ( + not active[bind.key] or + (active[bind.key].is_weak and not bind.is_weak) or + (bind.is_weak == active[bind.key].is_weak and + bind.priority > active[bind.key].priority) + ) and not bind.cmd:find("script-binding stats/__forced_", 1, true) + and bind.section ~= "input_forced_console" + and ( + searched_text == nil or + (bind.key .. bind.cmd):lower():find(searched_text, 1, true) + ) + then + active[bind.key] = bind + end + end + + -- make an array, find max key len, add sort keys (.subject/.mods[_count]) + local ordered = {} + local kspaces = "" -- as many spaces as the longest key name + for _, bind in pairs(active) do + bind.subject = cmd_subject(bind.cmd) + if bind.subject ~= "ignore" then + ordered[#ordered+1] = bind + _,_, bind.mods = bind.key:find("(.*)%+.") + _, bind.mods_count = bind.key:gsub("%+.", "") + if bind.key:len() > kspaces:len() then + kspaces = string.rep(" ", bind.key:len()) + end + end + end + + local function align_right(key) + return kspaces:sub(keyname_cells(key)) .. key + end + + -- sort by: subject, mod(ifier)s count, mods, key-len, lowercase-key, key + table.sort(ordered, function(a, b) + if a.subject ~= b.subject then + return a.subject < b.subject + elseif a.mods_count ~= b.mods_count then + return a.mods_count < b.mods_count + elseif a.mods ~= b.mods then + return a.mods < b.mods + elseif a.key:len() ~= b.key:len() then + return a.key:len() < b.key:len() + elseif a.key:lower() ~= b.key:lower() then + return a.key:lower() < b.key:lower() + else + return a.key > b.key -- only case differs, lowercase first + end + end) + + -- key/subject pre/post formatting for terminal/ass. + -- key/subject alignment uses spaces (with mono font if ass) + -- word-wrapping is disabled for ass, or cut at 79 for the terminal + local LTR = string.char(0xE2, 0x80, 0x8E) -- U+200E Left To Right mark + local term = not o.use_ass + local kpre = term and "" or format("{\\q2\\fn%s}%s", o.font_mono, LTR) + local kpost = term and " " or format(" {\\fn%s}", o.font) + local spre = term and kspaces .. " " + or format("{\\q2\\fn%s}%s {\\fn%s}{\\fs%d\\u1}", + o.font_mono, kspaces, o.font, 1.3*font_size) + local spost = term and "" or format("{\\u0\\fs%d}", font_size) + + -- create the display lines + local info_lines = {} + local subject = nil + for _, bind in ipairs(ordered) do + if bind.subject ~= subject then -- new subject (title) + subject = bind.subject + append(info_lines, "", {}) + append(info_lines, "", { prefix = spre .. subject .. spost }) + end + if bind.comment then + bind.cmd = bind.cmd .. " # " .. bind.comment + end + append(info_lines, bind.cmd, { prefix = kpre .. no_ASS(align_right(bind.key)) .. kpost }) + end + return info_lines +end + +local function append_general_perfdata(s) + for i, data in ipairs(mp.get_property_native("perf-info") or {}) do + append(s, data.text or data.value, {prefix="["..tostring(i).."] "..data.name..":"}) + + if o.plot_perfdata and o.use_ass and data.value then + buf = perf_buffers[data.name] + if not buf then + buf = {0, pos = 1, len = 50, max = 0} + perf_buffers[data.name] = buf end + graph_add_value(buf, data.value) + s[#s] = s[#s] .. generate_graph(buf, buf.pos, buf.len, buf.max, nil, 0.8, 1) end end - return offset end local function append_display_sync(s) @@ -393,8 +564,10 @@ local function append_display_sync(s) {prefix="DS:" .. o.prefix_sep .. " - / ", prefix_sep=""}) end - append_property(s, "mistimed-frame-count", {prefix="Mistimed:", nl=""}) - append_property(s, "vo-delayed-frame-count", {prefix="Delayed:", nl=""}) + append_property(s, "mistimed-frame-count", {prefix="Mistimed:", nl="", + indent=o.prefix_sep .. o.prefix_sep}) + append_property(s, "vo-delayed-frame-count", {prefix="Delayed:", nl="", + indent=o.prefix_sep .. o.prefix_sep}) -- As we need to plot some graphs we print jitter and ratio on their own lines if not display_timer.oneshot and (o.plot_vsync_ratio or o.plot_vsync_jitter) and o.use_ass then @@ -410,8 +583,10 @@ local function append_display_sync(s) append_property(s, "vsync-jitter", {prefix="VSync Jitter:", suffix=o.prefix_sep .. jitter_graph}) else -- Since no graph is needed we can print ratio/jitter on the same line and save some space - local vratio = append_property(s, "vsync-ratio", {prefix="VSync Ratio:"}) - append_property(s, "vsync-jitter", {prefix="VSync Jitter:", nl="" or o.nl}) + local vr = append_property(s, "vsync-ratio", {prefix="VSync Ratio:"}) + append_property(s, "vsync-jitter", {prefix="VSync Jitter:", + nl=vr and "" or o.nl, + indent=vr and o.prefix_sep .. o.prefix_sep}) end end @@ -426,9 +601,13 @@ local function append_filters(s, prop, prefix) n = n .. " (disabled)" end + if f.label ~= nil then + n = "@" .. f.label .. ": " .. n + end + local p = {} - for key,value in pairs(f.params) do - p[#p+1] = key .. "=" .. value + for _,key in ipairs(sorted_keys(f.params)) do + p[#p+1] = key .. "=" .. f.params[key] end if #p > 0 then p = " [" .. table.concat(p, " ") .. "]" @@ -481,12 +660,14 @@ local function add_file(s) append_property(s, "chapter-list/" .. tostring(ch_index) .. "/title", {prefix="Chapter:", nl=ed_cond and "" or o.nl}) append_property(s, "chapter-list/count", - {prefix="(" .. tostring(ch_index + 1) .. "/", suffix=")", nl="", + {prefix="(" .. tostring(ch_index + 1) .. " /", suffix=")", nl="", indent=" ", prefix_sep=" ", no_prefix_markup=true}) end local fs = append_property(s, "file-size", {prefix="Size:"}) - append_property(s, "file-format", {prefix="Format/Protocol:", nl=fs and "" or o.nl}) + append_property(s, "file-format", {prefix="Format/Protocol:", + nl=fs and "" or o.nl, + indent=fs and o.prefix_sep .. o.prefix_sep}) local demuxer_cache = mp.get_property_native("demuxer-cache-state", {}) if demuxer_cache["fw-bytes"] then @@ -503,70 +684,291 @@ local function add_file(s) end -local function add_video(s) - local r = mp.get_property_native("video-params") - -- in case of e.g. lavi-complex there can be no input video, only output +local function crop_noop(w, h, r) + return r["crop-x"] == 0 and r["crop-y"] == 0 and + r["crop-w"] == w and r["crop-h"] == h +end + + +local function crop_equal(r, ro) + return r["crop-x"] == ro["crop-x"] and r["crop-y"] == ro["crop-y"] and + r["crop-w"] == ro["crop-w"] and r["crop-h"] == ro["crop-h"] +end + + +local function append_resolution(s, r, prefix, w_prop, h_prop, video_res) if not r then - r = mp.get_property_native("video-out-params") + return + end + w_prop = w_prop or "w" + h_prop = h_prop or "h" + if append(s, r[w_prop], {prefix=prefix}) then + append(s, r[h_prop], {prefix="x", nl="", indent=" ", prefix_sep=" ", + no_prefix_markup=true}) + if r["aspect"] ~= nil and not video_res then + append(s, format("%.2f:1", r["aspect"]), {prefix="", nl="", indent="", + no_prefix_markup=true}) + append(s, r["aspect-name"], {prefix="(", suffix=")", nl="", indent=" ", + prefix_sep="", no_prefix_markup=true}) + end + if r["sar"] ~= nil and video_res then + append(s, format("%.2f:1", r["sar"]), {prefix="", nl="", indent="", + no_prefix_markup=true}) + append(s, r["sar-name"], {prefix="(", suffix=")", nl="", indent=" ", + prefix_sep="", no_prefix_markup=true}) + end + if r["s"] then + append(s, format("%.2f", r["s"]), {prefix="(", suffix="x)", nl="", + indent=o.prefix_sep, prefix_sep="", + no_prefix_markup=true}) + end + -- We can skip crop if it is the same as video decoded resolution + if r["crop-w"] and (not video_res or + not crop_noop(r[w_prop], r[h_prop], r)) then + append(s, format("[x: %d, y: %d, w: %d, h: %d]", + r["crop-x"], r["crop-y"], r["crop-w"], r["crop-h"]), + {prefix="", nl="", indent="", no_prefix_markup=true}) + end + end +end + + +local function pq_eotf(x) + if not x then + return x; + end + + local PQ_M1 = 2610.0 / 4096 * 1.0 / 4 + local PQ_M2 = 2523.0 / 4096 * 128 + local PQ_C1 = 3424.0 / 4096 + local PQ_C2 = 2413.0 / 4096 * 32 + local PQ_C3 = 2392.0 / 4096 * 32 + + x = x ^ (1.0 / PQ_M2) + x = max(x - PQ_C1, 0.0) / (PQ_C2 - PQ_C3 * x) + x = x ^ (1.0 / PQ_M1) + x = x * 10000.0 + + return x +end + + +local function append_hdr(s, hdr, video_out) + if not hdr then + return end + + local function should_show(val) + return val and val ~= 203 and val > 0 + end + + -- If we are printing video out parameters it is just display, not mastering + local display_prefix = video_out and "Display:" or "Mastering display:" + + local indent = "" + + if should_show(hdr["max-cll"]) or should_show(hdr["max-luma"]) then + append(s, "", {prefix="HDR10:"}) + if hdr["min-luma"] and should_show(hdr["max-luma"]) then + -- libplacebo uses close to zero values as "defined zero" + hdr["min-luma"] = hdr["min-luma"] <= 1e-6 and 0 or hdr["min-luma"] + append(s, format("%.2g / %.0f", hdr["min-luma"], hdr["max-luma"]), + {prefix=display_prefix, suffix=" cd/m²", nl="", indent=indent}) + indent = o.prefix_sep .. o.prefix_sep + end + if should_show(hdr["max-cll"]) then + append(s, hdr["max-cll"], {prefix="MaxCLL:", suffix=" cd/m²", nl="", + indent=indent}) + indent = o.prefix_sep .. o.prefix_sep + end + if hdr["max-fall"] and hdr["max-fall"] > 0 then + append(s, hdr["max-fall"], {prefix="MaxFALL:", suffix=" cd/m²", nl="", + indent=indent}) + end + end + + indent = o.prefix_sep .. o.prefix_sep + + if hdr["scene-max-r"] or hdr["scene-max-g"] or + hdr["scene-max-b"] or hdr["scene-avg"] then + append(s, "", {prefix="HDR10+:"}) + append(s, format("%.1f / %.1f / %.1f", hdr["scene-max-r"] or 0, + hdr["scene-max-g"] or 0, hdr["scene-max-b"] or 0), + {prefix="MaxRGB:", suffix=" cd/m²", nl="", indent=""}) + append(s, format("%.1f", hdr["scene-avg"] or 0), + {prefix="Avg:", suffix=" cd/m²", nl="", indent=indent}) + end + + if hdr["max-pq-y"] and hdr["avg-pq-y"] then + append(s, "", {prefix="PQ(Y):"}) + append(s, format("%.2f cd/m² (%.2f%% PQ)", pq_eotf(hdr["max-pq-y"]), + hdr["max-pq-y"] * 100), {prefix="Max:", nl="", + indent=""}) + append(s, format("%.2f cd/m² (%.2f%% PQ)", pq_eotf(hdr["avg-pq-y"]), + hdr["avg-pq-y"] * 100), {prefix="Avg:", nl="", + indent=indent}) + end +end + + +local function append_img_params(s, r, ro) if not r then return end - append(s, "", {prefix=o.nl .. o.nl .. "Video:", nl="", indent=""}) - if append_property(s, "video-codec", {prefix_sep="", nl="", indent=""}) then - append_property(s, "hwdec-current", {prefix="(hwdec:", nl="", indent=" ", - no_prefix_markup=true, suffix=")"}, {no=true, [""]=true}) + append_resolution(s, r, "Resolution:", "w", "h", true) + if ro and (r["w"] ~= ro["dw"] or r["h"] ~= ro["dh"]) then + if ro["crop-w"] and (crop_noop(r["w"], r["h"], ro) or crop_equal(r, ro)) then + ro["crop-w"] = nil + end + append_resolution(s, ro, "Output Resolution:", "dw", "dh") end - append_property(s, "avsync", {prefix="A-V:"}) - if append_property(s, compat("decoder-frame-drop-count"), - {prefix="Dropped Frames:", suffix=" (decoder)"}) then - append_property(s, compat("frame-drop-count"), {suffix=" (output)", nl="", indent=""}) + + local indent = o.prefix_sep .. o.prefix_sep + r = ro or r + + local pixel_format = r["hw-pixelformat"] or r["pixelformat"] + append(s, pixel_format, {prefix="Format:"}) + append(s, r["colorlevels"], {prefix="Levels:", nl="", indent=indent}) + if r["chroma-location"] and r["chroma-location"] ~= "unknown" then + append(s, r["chroma-location"], {prefix="Chroma Loc:", nl="", indent=indent}) end - if append_property(s, "display-fps", {prefix="Display FPS:", suffix=" (specified)"}) then - append_property(s, "estimated-display-fps", - {suffix=" (estimated)", nl="", indent=""}) - else - append_property(s, "estimated-display-fps", - {prefix="Display FPS:", suffix=" (estimated)"}) + + -- Group these together to save vertical space + append(s, r["colormatrix"], {prefix="Colormatrix:"}) + append(s, r["primaries"], {prefix="Primaries:", nl="", indent=indent}) + append(s, r["gamma"], {prefix="Transfer:", nl="", indent=indent}) +end + + +local function append_fps(s, prop, eprop) + local fps = mp.get_property_osd(prop) + local efps = mp.get_property_osd(eprop) + local single = fps ~= "" and efps ~= "" and fps == efps + local unit = prop == "display-fps" and " Hz" or " fps" + local suffix = single and "" or " (specified)" + local esuffix = single and "" or " (estimated)" + local prefix = prop == "display-fps" and "Refresh Rate:" or "Frame Rate:" + local nl = o.nl + local indent = o.indent + + if fps ~= "" and append(s, fps, {prefix=prefix, suffix=unit .. suffix}) then + prefix = "" + nl = "" + indent = "" end - if append_property(s, compat("container-fps"), {prefix="FPS:", suffix=" (specified)"}) then - append_property(s, "estimated-vf-fps", - {suffix=" (estimated)", nl="", indent=""}) - else - append_property(s, "estimated-vf-fps", - {prefix="FPS:", suffix=" (estimated)"}) + + if not single and efps ~= "" then + append(s, efps, + {prefix=prefix, suffix=unit .. esuffix, nl=nl, indent=indent}) end +end + +local function add_video_out(s) + local vo = mp.get_property_native("current-vo") + if not vo then + return + end + + append(s, "", {prefix=o.nl .. o.nl .. "Display:", nl="", indent=""}) + append(s, vo, {prefix_sep="", nl="", indent=""}) + append_property(s, "display-names", {prefix_sep="", prefix="(", suffix=")", + no_prefix_markup=true, nl="", indent=" "}) + append(s, mp.get_property_native("current-gpu-context"), + {prefix="Context:", nl="", indent=o.prefix_sep .. o.prefix_sep}) + append_property(s, "avsync", {prefix="A-V:"}) + append_fps(s, "display-fps", "estimated-display-fps") + if append_property(s, "decoder-frame-drop-count", + {prefix="Dropped Frames:", suffix=" (decoder)"}) then + append_property(s, "frame-drop-count", {suffix=" (output)", nl="", indent=""}) + end append_display_sync(s) - append_perfdata(s, o.print_perfdata_passes) + append_perfdata(nil, s, false, o.print_perfdata_passes) - if append(s, r["w"], {prefix="Native Resolution:"}) then - append(s, r["h"], {prefix="x", nl="", indent=" ", prefix_sep=" ", no_prefix_markup=true}) + if mp.get_property_native("deinterlace-active") then + append_property(s, "deinterlace", {prefix="Deinterlacing:"}) end - append_property(s, "current-window-scale", {prefix="Window Scale:"}) - if r["aspect"] ~= nil then - append(s, format("%.2f", r["aspect"]), {prefix="Aspect Ratio:"}) + + local scale = nil + if not mp.get_property_native("fullscreen") then + scale = mp.get_property_native("current-window-scale") end - append(s, r["pixelformat"], {prefix="Pixel Format:"}) - if r["hw-pixelformat"] ~= nil then - append(s, r["hw-pixelformat"], {prefix_sep="[", nl="", indent=" ", - suffix="]"}) + + local od = mp.get_property_native("osd-dimensions") + local rt = mp.get_property_native("video-target-params") + r = rt or {} + + -- Add window scale + r["s"] = scale + r["crop-x"] = od["ml"] + r["crop-y"] = od["mt"] + r["crop-w"] = od["w"] - od["ml"] - od["mr"] + r["crop-h"] = od["h"] - od["mt"] - od["mb"] + + if not rt then + r["w"] = r["crop-w"] + r["h"] = r["crop-h"] + append_resolution(s, r, "Resolution:", "w", "h", true) + return end - -- Group these together to save vertical space - local prim = append(s, r["primaries"], {prefix="Primaries:"}) - local cmat = append(s, r["colormatrix"], {prefix="Colormatrix:", nl=prim and "" or o.nl}) - append(s, r["colorlevels"], {prefix="Levels:", nl=cmat and "" or o.nl}) + append_img_params(s, r) + append_hdr(s, r, true) +end + + +local function add_video(s) + local r = mp.get_property_native("video-params") + local ro = mp.get_property_native("video-out-params") + -- in case of e.g. lavfi-complex there can be no input video, only output + if not r then + r = ro + end + if not r then + return + end - -- Append HDR metadata conditionally (only when present and interesting) - local hdrpeak = r["sig-peak"] or 0 - local hdrinfo = "" - if hdrpeak > 1 then - hdrinfo = " (HDR peak: " .. format("%.2f", hdrpeak) .. ")" + append(s, "", {prefix=o.nl .. o.nl .. "Video:", nl="", indent=""}) + local track = mp.get_property_native("current-tracks/video") + if track and append(s, track["codec-desc"], {prefix_sep="", nl="", indent=""}) then + append(s, track["codec-profile"], {prefix="[", nl="", indent=" ", prefix_sep="", + no_prefix_markup=true, suffix="]"}) + if track["codec"] ~= track["decoder"] then + append(s, track["decoder"], {prefix="[", nl="", indent=" ", prefix_sep="", + no_prefix_markup=true, suffix="]"}) + end + append_property(s, "hwdec-current", {prefix="HW:", nl="", + indent=o.prefix_sep .. o.prefix_sep, + no_prefix_markup=false, suffix=""}, {no=true, [""]=true}) + end + local has_prefix = false + if o.show_frame_info then + if append_property(s, "estimated-frame-number", {prefix="Frame:"}) then + append_property(s, "estimated-frame-count", {indent=" / ", nl="", + prefix_sep=""}) + has_prefix = true + end + local frame_info = mp.get_property_native("video-frame-info") + if frame_info and frame_info["picture-type"] then + local attrs = has_prefix and {prefix="(", suffix=")", indent=" ", nl="", + prefix_sep="", no_prefix_markup=true} + or {prefix="Picture Type:"} + append(s, frame_info["picture-type"], attrs) + has_prefix = true + end + if frame_info and frame_info["interlaced"] then + local attrs = has_prefix and {indent=" ", nl="", prefix_sep=""} + or {prefix="Picture Type:"} + append(s, "Interlaced", attrs) + end end - append(s, r["gamma"], {prefix="Gamma:", suffix=hdrinfo}) + if mp.get_property_native("current-tracks/video/image") == false then + append_fps(s, "container-fps", "estimated-vf-fps") + end + append_img_params(s, r, ro) + append_hdr(s, ro) append_property(s, "packet-video-bitrate", {prefix="Bitrate:", suffix=" kbps"}) append_filters(s, "vf", "Filters:") end @@ -574,19 +976,44 @@ end local function add_audio(s) local r = mp.get_property_native("audio-params") - -- in case of e.g. lavi-complex there can be no input audio, only output - if not r then - r = mp.get_property_native("audio-out-params") - end |