-- Display some stats.
--
-- Please consult the readme for information about usage and configuration:
-- https://github.com/Argon-/mpv-stats
--
-- Please note: not every property is always available and therefore not always
-- visible.
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_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,
redraw_delay = 1, -- acts as duration in the toggling case
ass_formatting = true,
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 = "",
font_mono = "monospace", -- monospaced digits are sufficient
font_size = 8,
font_color = "",
border_size = 0.8,
border_color = "",
shadow_x_offset = 0.0,
shadow_y_offset = 0.0,
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
-- use this string instead.
custom_header = "",
-- Text formatting
-- With ASS
ass_nl = "\\N",
ass_indent = "\\h\\h\\h\\h\\h",
ass_prefix_sep = "\\h\\h",
ass_b1 = "{\\b1}",
ass_b0 = "{\\b0}",
ass_it1 = "{\\i1}",
ass_it0 = "{\\i0}",
-- Without ASS
no_ass_nl = "\n",
no_ass_indent = "\t",
no_ass_prefix_sep = " ",
no_ass_b1 = "\027[1m",
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)
local display_timer = nil
-- Timer used to update cache stats.
local cache_recorder_timer = nil
-- Current page and <page key>:<page function> mappings
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")
-- Ring buffers for the values used to construct a graph.
-- .pos denotes the current position, .len the buffer length
-- .max is the max value in the corresponding buffer
local vsratio_buf, vsjitter_buf
local function init_buffers()
vsratio_buf = {0, pos = 1, len = 50, max = 0}
vsjitter_buf = {0, pos = 1, len = 50, max = 0}
end
local cache_ahead_buf, cache_speed_buf
local perf_buffers = {}
local function graph_add_value(graph, value)
graph.pos = (graph.pos % graph.len) + 1
graph[graph.pos] = value
graph.max = max(graph.max, value)
end
local function no_ASS(t)
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_nati
|