1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-29 14:50:14 +00:00

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.
This commit is contained in:
Guido Cella 2021-10-15 17:54:09 +02:00 committed by Dudemanguy
parent ae6a22ddec
commit 0772d0263c

View File

@ -107,14 +107,18 @@ function is_enough_time(seconds)
return playtime_remaining and time_needed < playtime_remaining return playtime_remaining and time_needed < playtime_remaining
end end
function is_cropable() function is_cropable(time_needed)
for _, track in pairs(mp.get_property_native('track-list')) do if mp.get_property_native('current-tracks/video/image') ~= false then
if track.type == 'video' and track.selected then mp.msg.warn("autocrop only works for videos.")
return not track.albumart return false
end
end end
if not is_enough_time(time_needed) then
mp.msg.warn("Not enough time to detect crop.")
return false return false
end
return true
end end
function remove_filter(label) function remove_filter(label)
@ -142,18 +146,9 @@ function cleanup()
end end
function detect_crop() 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 local time_needed = options.detect_seconds
if not is_enough_time(time_needed) then if not is_cropable(time_needed) then
mp.msg.warn("Not enough time to detect crop.")
return return
end end
@ -282,8 +277,7 @@ function on_start()
-- Verify if there is enough time for autocrop. -- Verify if there is enough time for autocrop.
local time_needed = options.auto_delay + options.detect_seconds local time_needed = options.auto_delay + options.detect_seconds
if not is_enough_time(time_needed) then if not is_cropable(time_needed) then
mp.msg.warn("Not enough time for autocrop.")
return return
end end