mirror of
https://github.com/mpv-player/mpv
synced 2025-03-31 07:51:55 +00:00
TOOLS/autocrop.lua: simplify code
Refactor code that is no longer necessary after replacing vf=crop with video-crop. There is no change in behavior.
This commit is contained in:
parent
bc81b3d19e
commit
a08b75da2b
@ -55,10 +55,7 @@ local options = {
|
|||||||
|
|
||||||
require "mp.options".read_options(options)
|
require "mp.options".read_options(options)
|
||||||
|
|
||||||
local label_prefix = mp.get_script_name()
|
local cropdetect_label = mp.get_script_name() .. "-cropdetect"
|
||||||
local labels = {
|
|
||||||
cropdetect = string.format("%s-cropdetect", label_prefix)
|
|
||||||
}
|
|
||||||
|
|
||||||
timers = {
|
timers = {
|
||||||
auto_delay = nil,
|
auto_delay = nil,
|
||||||
@ -69,16 +66,6 @@ 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)
|
|
||||||
local filters = mp.get_property_native("vf")
|
|
||||||
for index, filter in pairs(filters) do
|
|
||||||
if filter["label"] == label then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function is_enough_time(seconds)
|
function is_enough_time(seconds)
|
||||||
|
|
||||||
-- Plus 1 second for deviation.
|
-- Plus 1 second for deviation.
|
||||||
@ -102,12 +89,15 @@ function is_cropable(time_needed)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function remove_filter(label)
|
function remove_cropdetect()
|
||||||
if is_filter_present(label) then
|
for _, filter in pairs(mp.get_property_native("vf")) do
|
||||||
mp.command(string.format('%s vf remove @%s', command_prefix, label))
|
if filter.label == cropdetect_label then
|
||||||
return true
|
mp.command(
|
||||||
|
string.format("%s vf remove @%s", command_prefix, filter.label))
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function restore_hwdec()
|
function restore_hwdec()
|
||||||
@ -118,9 +108,7 @@ function restore_hwdec()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function cleanup()
|
function cleanup()
|
||||||
|
remove_cropdetect()
|
||||||
-- Remove existing filter.
|
|
||||||
remove_filter(labels.cropdetect)
|
|
||||||
|
|
||||||
-- Kill all timers.
|
-- Kill all timers.
|
||||||
for index, timer in pairs(timers) do
|
for index, timer in pairs(timers) do
|
||||||
@ -154,7 +142,7 @@ function detect_crop()
|
|||||||
mp.command(
|
mp.command(
|
||||||
string.format(
|
string.format(
|
||||||
'%s vf pre @%s:cropdetect=limit=%s:round=%d:reset=0',
|
'%s vf pre @%s:cropdetect=limit=%s:round=%d:reset=0',
|
||||||
command_prefix, labels.cropdetect, limit, round
|
command_prefix, cropdetect_label, limit, round
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,13 +153,9 @@ end
|
|||||||
function detect_end()
|
function detect_end()
|
||||||
|
|
||||||
-- Get the metadata and remove the cropdetect filter.
|
-- Get the metadata and remove the cropdetect filter.
|
||||||
local cropdetect_metadata =
|
local cropdetect_metadata = mp.get_property_native(
|
||||||
mp.get_property_native(
|
"vf-metadata/" .. cropdetect_label)
|
||||||
string.format("vf-metadata/%s",
|
remove_cropdetect()
|
||||||
labels.cropdetect
|
|
||||||
)
|
|
||||||
)
|
|
||||||
remove_filter(labels.cropdetect)
|
|
||||||
|
|
||||||
-- Remove the timer of detect crop.
|
-- Remove the timer of detect crop.
|
||||||
if timers.detect_crop then
|
if timers.detect_crop then
|
||||||
|
Loading…
Reference in New Issue
Block a user