summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2021-10-15 17:54:09 +0200
committerDudemanguy <random342@airmail.cc>2023-02-27 17:03:38 +0000
commit0772d0263ce0b09257fd6df4e9891bb4cd61b35c (patch)
tree387ad5ab90bd4f22651fd0d28fe557bb4be58ac1 /TOOLS
parentae6a22ddec3f41cf144d694ad6069d55ce769f1a (diff)
downloadmpv-0772d0263ce0b09257fd6df4e9891bb4cd61b35c.tar.bz2
mpv-0772d0263ce0b09257fd6df4e9891bb4cd61b35c.tar.xz
TOOLS/autocrop.lua: log a more accurate warning
This reorders some code and checks the image track-list sub-property instead of the albumart one, so that when playing audio without enough playtime-remaining and images, the "autocrop only works for videos." warning is logged instead of the "Not enough time to detect crop." one. It also avoids repeating this warning twice in the code. As of e16d0dd15d current-tracks returns a video track even when lavfi-complex is used, so the track-list loop in is_cropable can be replaced with just checking current-tracks/video while still cropping videos with lavfi-complex.
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lua/autocrop.lua30
1 files changed, 12 insertions, 18 deletions
diff --git a/TOOLS/lua/autocrop.lua b/TOOLS/lua/autocrop.lua
index 3683b9f02a..19ba87653b 100644
--- a/TOOLS/lua/autocrop.lua
+++ b/TOOLS/lua/autocrop.lua
@@ -107,14 +107,18 @@ function is_enough_time(seconds)
return playtime_remaining and time_needed < playtime_remaining
end
-function is_cropable()
- for _, track in pairs(mp.get_property_native('track-list')) do
- if track.type == 'video' and track.selected then
- return not track.albumart
- end
+function is_cropable(time_needed)
+ if mp.get_property_native('current-tracks/video/image') ~= false then
+ mp.msg.warn("autocrop only works for videos.")
+ return false
end
- return false
+ if not is_enough_time(time_needed) then
+ mp.msg.warn("Not enough time to detect crop.")
+ return false
+ end
+
+ return true
end
function remove_filter(label)
@@ -142,18 +146,9 @@ function cleanup()
end
function detect_crop()
-
- -- If it's not cropable, exit.
- if not is_cropable() then
- mp.msg.warn("autocrop only works for videos.")
- return
- end
-
- -- Verify if there is enough time to detect crop.
local time_needed = options.detect_seconds
- if not is_enough_time(time_needed) then
- mp.msg.warn("Not enough time to detect crop.")
+ if not is_cropable(time_needed) then
return
end
@@ -282,8 +277,7 @@ function on_start()
-- Verify if there is enough time for autocrop.
local time_needed = options.auto_delay + options.detect_seconds
- if not is_enough_time(time_needed) then
- mp.msg.warn("Not enough time for autocrop.")
+ if not is_cropable(time_needed) then
return
end