summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-09-10 00:49:34 +0200
committerDudemanguy <random342@airmail.cc>2023-09-20 19:08:19 +0000
commit6b963857c0e8769e4949eb7d83f82d9c0713a7cb (patch)
treee9b222e78a9938da405c7d8a5ca1791dc2d53e6c /TOOLS
parent20e584f60bdac96ed915151cf0f92d8282c0a0b3 (diff)
downloadmpv-6b963857c0e8769e4949eb7d83f82d9c0713a7cb.tar.bz2
mpv-6b963857c0e8769e4949eb7d83f82d9c0713a7cb.tar.xz
TOOLS/autocrop.lua: use VO crop always
There is no reason not to and this significantly reduces script complexity.
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lua/autocrop.lua59
1 files changed, 12 insertions, 47 deletions
diff --git a/TOOLS/lua/autocrop.lua b/TOOLS/lua/autocrop.lua
index b6144aeea1..139b04d23e 100644
--- a/TOOLS/lua/autocrop.lua
+++ b/TOOLS/lua/autocrop.lua
@@ -72,13 +72,11 @@ local options = {
detect_min_ratio = 0.5,
detect_seconds = 1,
suppress_osd = false,
- use_vo_crop = true,
}
read_options(options)
local label_prefix = mp.get_script_name()
local labels = {
- crop = string.format("%s-crop", label_prefix),
cropdetect = string.format("%s-cropdetect", label_prefix)
}
@@ -123,14 +121,6 @@ function is_cropable(time_needed)
end
function remove_filter(label)
- if options.use_vo_crop and label == labels.crop then
- if mp.get_property('video-crop') ~= "" then
- mp.command(string.format("%s set video-crop ''", command_prefix))
- return true
- end
- return false
- end
-
if is_filter_present(label) then
mp.command(string.format('%s vf remove @%s', command_prefix, label))
return true
@@ -140,13 +130,8 @@ end
function cleanup()
- -- Remove all existing filters.
- for key, value in pairs(labels) do
- -- No need to remove initial crop in vo_crop mode
- if not (options.use_vo_crop and value == labels.crop) then
- remove_filter(value)
- end
- end
+ -- Remove existing filter.
+ remove_filter(labels.cropdetect)
-- Kill all timers.
for index, timer in pairs(timers) do
@@ -231,7 +216,6 @@ function detect_end()
else
mp.msg.error("Got empty crop data.")
mp.msg.info("You might need to increase detect_seconds.")
- return
end
apply_crop(meta)
@@ -240,39 +224,19 @@ end
function apply_crop(meta)
-- Verify if it is necessary to crop.
- local is_effective = meta.x > 0 or meta.y > 0
- or meta.w < meta.max_w or meta.h < meta.max_h
+ local is_effective = meta.w and meta.h and meta.x and meta.y and
+ (meta.x > 0 or meta.y > 0
+ or meta.w < meta.max_w or meta.h < meta.max_h)
if not is_effective then
- mp.msg.info("No area detected for cropping.")
- return
- end
-
- -- Verify it is not over cropped.
- local is_excessive = meta.w < meta.min_w and meta.h < meta.min_h
-
- if is_excessive then
- mp.msg.info("The area to be cropped is too large.")
- mp.msg.info("You might need to decrease detect_min_ratio.")
- return
- end
-
- if options.use_vo_crop then
- -- Apply crop.
- mp.command(string.format("%s set video-crop %sx%s+%s+%s",
- command_prefix, meta.w, meta.h, meta.x, meta.y))
+ -- Clear any existing crop.
+ mp.command(string.format("%s set file-local-options/video-crop ''", command_prefix))
return
end
- -- Remove existing crop.
- remove_filter(labels.crop)
-
-- Apply crop.
- mp.command(
- string.format("%s vf pre @%s:lavfi-crop=w=%s:h=%s:x=%s:y=%s",
- command_prefix, labels.crop, meta.w, meta.h, meta.x, meta.y
- )
- )
+ mp.command(string.format("%s set file-local-options/video-crop %sx%s+%s+%s",
+ command_prefix, meta.w, meta.h, meta.x, meta.y))
end
function on_start()
@@ -323,7 +287,8 @@ function on_toggle()
end
-- Cropped => Remove it.
- if remove_filter(labels.crop) then
+ if mp.get_property("video-crop") ~= "" then
+ mp.command(string.format("%s set file-local-options/video-crop ''", command_prefix))
return
end
@@ -333,7 +298,7 @@ function on_toggle()
return
end
- -- Neither => Do delectcrop.
+ -- Neither => Detect crop.
detect_crop()
end