mirror of https://github.com/mpv-player/mpv
TOOLS/lua/autocrop: handle case of user hitting hotkey while cropdetection already running
This commit is contained in:
parent
74984aaff1
commit
c91373a202
|
@ -25,6 +25,7 @@
|
||||||
--
|
--
|
||||||
-- to mpv's arguments. This may be desirable to allow cropdetect more
|
-- to mpv's arguments. This may be desirable to allow cropdetect more
|
||||||
-- time to collect data.
|
-- time to collect data.
|
||||||
|
require "mp.msg"
|
||||||
|
|
||||||
script_name=mp.get_script_name()
|
script_name=mp.get_script_name()
|
||||||
cropdetect_label=string.format("%s-cropdetect",script_name)
|
cropdetect_label=string.format("%s-cropdetect",script_name)
|
||||||
|
@ -51,10 +52,17 @@ function del_filter_if_present(label)
|
||||||
end
|
end
|
||||||
|
|
||||||
function autocrop_start()
|
function autocrop_start()
|
||||||
-- if there's a crop filter, just remove it and exit
|
-- exit if cropdetection is already in progress
|
||||||
|
if timer then
|
||||||
|
mp.msg.warn("already cropdetecting!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- if there's a crop filter, remove it and exit
|
||||||
if del_filter_if_present(crop_label) then
|
if del_filter_if_present(crop_label) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- insert the cropdetect filter
|
-- insert the cropdetect filter
|
||||||
ret=mp.command(
|
ret=mp.command(
|
||||||
string.format(
|
string.format(
|
||||||
|
@ -63,11 +71,10 @@ function autocrop_start()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
-- wait to gather data
|
-- wait to gather data
|
||||||
mp.add_timeout(detect_seconds, do_crop)
|
timer=mp.add_timeout(detect_seconds, do_crop)
|
||||||
end
|
end
|
||||||
|
|
||||||
function do_crop()
|
function do_crop()
|
||||||
require 'mp.msg'
|
|
||||||
-- get the metadata
|
-- get the metadata
|
||||||
local cropdetect_metadata = mp.get_property_native(
|
local cropdetect_metadata = mp.get_property_native(
|
||||||
string.format('vf-metadata/%s', cropdetect_label)
|
string.format('vf-metadata/%s', cropdetect_label)
|
||||||
|
@ -100,6 +107,7 @@ function do_crop()
|
||||||
end
|
end
|
||||||
-- remove the cropdetect filter
|
-- remove the cropdetect filter
|
||||||
del_filter_if_present(cropdetect_label)
|
del_filter_if_present(cropdetect_label)
|
||||||
|
timer=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
mp.add_key_binding("C","auto_crop",autocrop_start)
|
mp.add_key_binding("C","auto_crop",autocrop_start)
|
||||||
|
|
Loading…
Reference in New Issue