1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-17 21:27:08 +00:00

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.
This commit is contained in:
Guido Cella 2023-09-21 11:48:22 +02:00 committed by Dudemanguy
parent 252347731a
commit f4de509f01

View File

@ -85,6 +85,8 @@ timers = {
detect_crop = nil detect_crop = nil
} }
local hwdec_backup
local command_prefix = options.suppress_osd and 'no-osd' or '' local command_prefix = options.suppress_osd and 'no-osd' or ''
function is_filter_present(label) function is_filter_present(label)
@ -128,6 +130,13 @@ function remove_filter(label)
return false return false
end end
function restore_hwdec()
if hwdec_backup then
mp.set_property("hwdec", hwdec_backup)
hwdec_backup = nil
end
end
function cleanup() function cleanup()
-- Remove existing filter. -- Remove existing filter.
@ -140,6 +149,8 @@ function cleanup()
timers[index] = nil timers[index] = nil
end end
end end
restore_hwdec()
end end
function detect_crop() function detect_crop()
@ -149,6 +160,13 @@ function detect_crop()
return return
end 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. -- Insert the cropdetect filter.
local limit = options.detect_limit local limit = options.detect_limit
local round = options.detect_round local round = options.detect_round
@ -181,6 +199,8 @@ function detect_end()
timers.detect_crop = nil timers.detect_crop = nil
end end
restore_hwdec()
local meta = {} local meta = {}
-- Verify the existence of metadata. -- Verify the existence of metadata.