From f4de509f01f2322487e42dffd73cb8bd1118655c Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Thu, 21 Sep 2023 11:48:22 +0200 Subject: [PATCH] TOOLS/autocrop.lua: switch to auto-copy hwdec during cropdetect I didn't set file-local-options/hwdec because you have to store the hwdec value to restore it after cropdetect anyway, and if the user manually changes hwdec after cropdetect, the new value isn't reset when changing file. --- TOOLS/lua/autocrop.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/TOOLS/lua/autocrop.lua b/TOOLS/lua/autocrop.lua index d7e3e0b858..780e9e2d48 100644 --- a/TOOLS/lua/autocrop.lua +++ b/TOOLS/lua/autocrop.lua @@ -85,6 +85,8 @@ timers = { detect_crop = nil } +local hwdec_backup + local command_prefix = options.suppress_osd and 'no-osd' or '' function is_filter_present(label) @@ -128,6 +130,13 @@ function remove_filter(label) return false end +function restore_hwdec() + if hwdec_backup then + mp.set_property("hwdec", hwdec_backup) + hwdec_backup = nil + end +end + function cleanup() -- Remove existing filter. @@ -140,6 +149,8 @@ function cleanup() timers[index] = nil end end + + restore_hwdec() end function detect_crop() @@ -149,6 +160,13 @@ function detect_crop() return end + local hwdec_current = mp.get_property("hwdec-current") + if hwdec_current:find("-copy$") == nil and hwdec_current ~= "no" and + hwdec_current ~= "crystalhd" and hwdec_current ~= "rkmpp" then + hwdec_backup = mp.get_property("hwdec") + mp.set_property("hwdec", "auto-copy-safe") + end + -- Insert the cropdetect filter. local limit = options.detect_limit local round = options.detect_round @@ -181,6 +199,8 @@ function detect_end() timers.detect_crop = nil end + restore_hwdec() + local meta = {} -- Verify the existence of metadata.