Last active
November 1, 2023 15:12
-
-
Save hooke007/64072737cd6cb0af7520853cc3beb6d0 to your computer and use it in GitHub Desktop.
[mpv-script] uosc的辅助脚本
This file contains 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/hooke007/MPV_lazy/tree/main/portable_config/scripts/uosc | |
用于: | |
实时简易快速切换 --cscale --scale --dscale --tscale 的各值 | |
快速预览各用户着色器(仅解析 `~~/shaders/` 目录) | |
input.conf 示例: | |
Alt+o script-binding opt_helper/menu_load # 打开辅助菜单 | |
]] | |
local utils = require("mp.utils") | |
local scr = mp.get_script_name() | |
local str_val0 = "script-message-to " .. scr .." refresh" | |
local str_val = " ; " .. str_val0 | |
local str_val1 = "no-osd set cscale bilinear ; no-osd set scale bilinear ; no-osd set dscale \"\" ; no-osd set tscale mitchell ; no-osd set glsl-shaders \"\"" | |
local dir_hooks = mp.command_native({"expand-path", "~~/shaders"}) .. "/" | |
-- 查询全部 `--xscale=help` | |
-- 分类方式 https://github.com/mpv-player/mpv/blob/master/video/out/filter_kernels.c | |
local opt_xscale = { | |
"bilinear", -- baseline | |
-- kernel type | |
---- Spline filters | |
"spline16", | |
"spline36", | |
"spline64", | |
---- Sinc filters | |
"sinc", | |
"lanczos", -- default of scale | |
"ginseng", | |
---- Jinc filters | |
"jinc", | |
"ewa_lanczos", | |
"ewa_hanning", | |
"ewa_ginseng", | |
"ewa_lanczossharp", | |
"ewa_lanczos4sharpest", | |
"ewa_lanczossoft", | |
"haasnsoft", | |
---- Cubic filters | |
"bicubic", | |
"bicubic_fast", -- sp | |
"hermite", -- default of dscale | |
"catmull_rom", | |
"mitchell", | |
"robidoux", | |
"robidouxsharp", | |
"ewa_robidoux", | |
"ewa_robidouxsharp", | |
---- Miscellaneous filters | |
"box", | |
"nearest", | |
"oversample", -- sp | |
"triangle", | |
"gaussian", | |
-- window type | |
--"box", -- dup | |
--"triangle", -- dup | |
"bartlett", | |
"cosine", | |
"hanning", | |
"tukey", | |
"hamming", | |
"quadric", | |
"welch", | |
"kaiser", | |
"blackman", | |
--"gaussian", -- dup | |
--"sinc", -- dup | |
--"jinc", -- dup | |
"sphinx", | |
} | |
local opt_tscale = { | |
"linear", -- baseline | |
-- kernel type | |
---- Spline filters | |
"spline16", | |
"spline36", | |
"spline64", | |
---- Sinc filters | |
"sinc", | |
"lanczos", | |
"ginseng", | |
---- Cubic filters | |
"bicubic", | |
"hermite", | |
"catmull_rom", | |
"mitchell", | |
"robidoux", | |
"robidouxsharp", | |
---- Miscellaneous filters | |
"box", | |
"nearest", | |
"oversample", -- sp baseline2 (default) | |
"triangle", | |
"gaussian", | |
-- window type | |
--"box", -- dup | |
--"triangle", -- dup | |
"bartlett", | |
"cosine", | |
"hanning", | |
"tukey", | |
"hamming", | |
"quadric", | |
"welch", | |
"kaiser", | |
"blackman", | |
--"gaussian", -- dup | |
--"sinc", -- dup | |
"sphinx", | |
} | |
local subitems_01 = {} | |
local subitems_02 = {} | |
local subitems_03 = {} | |
local subitems_04 = {} | |
function get_subitems(var01, var02, var03, var04) | |
for i = 1, #var01 do | |
table.insert(var02, { | |
title = var01[i], | |
value = "set " .. var03 .. " " .. var04 .. var01[i] .. str_val | |
}) | |
end | |
end | |
get_subitems(opt_xscale, subitems_01, "cscale", "") | |
get_subitems(opt_xscale, subitems_02, "scale", "") | |
get_subitems(opt_xscale, subitems_03, "dscale", "") | |
get_subitems(opt_tscale, subitems_04, "tscale", "") | |
local usr_hooks = {} | |
local subitems_05 = {} | |
function check_file(file, extensions) | |
for _, ext in ipairs(extensions) do | |
if file:sub(-#ext) == ext then | |
return true | |
end | |
end | |
return false | |
end | |
function get_hooks(directory) | |
local extensions = { ".glsl", ".hook" } | |
local files = utils.readdir(directory, "files") | |
if files == nil then | |
return "None" | |
end | |
local file_list = {} | |
for _, file in ipairs(files) do | |
if check_file(file, extensions) then | |
table.insert(file_list, file) | |
end | |
end | |
return file_list | |
end | |
usr_hooks = get_hooks(dir_hooks) | |
if usr_hooks == "None" then | |
subitems_05 = {{ hint = "unavailable user hooks", value = "ignore" }} | |
else | |
get_subitems(usr_hooks, subitems_05, "glsl-shaders", "~~/shaders/") | |
end | |
function create_menu_data() | |
return { | |
type = "unknown", | |
title = "list-options helper", | |
keep_open = true, | |
items = { | |
{ | |
title = "--cscale", | |
hint = mp.get_property("cscale") == "" and "--scale" or mp.get_property("cscale"), | |
items = subitems_01, | |
}, | |
{ | |
title = "--scale", | |
hint = mp.get_property("scale"), | |
items = subitems_02, | |
}, | |
{ | |
title = "--dscale", | |
hint = mp.get_property("dscale") == "" and "--scale" or mp.get_property("dscale"), | |
items = subitems_03, | |
}, | |
{ | |
title = "--tscale", | |
hint = mp.get_property("tscale"), | |
items = subitems_04, | |
}, | |
{ | |
title = "Shader", | |
hint = "(single preview)", | |
items = subitems_05, | |
}, | |
{ | |
title = "REFRESH", | |
value = str_val0, | |
}, | |
{ | |
title = "RESET", | |
value = str_val1 .. " ; " .. str_val0, | |
}, | |
} | |
} | |
end | |
mp.add_key_binding(nil, "menu_load", function() | |
local json = utils.format_json(create_menu_data()) | |
mp.commandv("script-message-to", "uosc", "open-menu", json) | |
end) | |
mp.register_script_message("refresh", function() | |
local json = utils.format_json(create_menu_data()) | |
mp.commandv("script-message-to", "uosc", "update-menu", json) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment