From e3f496dbf5c57ce4f33b3a48e19b44cb4b53245d Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 16 Jun 2024 21:10:02 +0200 Subject: [PATCH] select.lua: don't use sub-start to preselect subtitle lines There is no need to compare sub-start now that we don't check for exact matches with ffmpeg's timestamps. time-pos can always be used. Comparing time-pos removes the need for the workaround of sub-start of embedded subtitles being earlier than ffmpeg's timestamps, as time-pos is always slightly after sub-start. Removing this workaround also fixes a bug present since 4059d1832b, which started comparing numerical values of timestamps instead of strings to determine the preselected subtitle line, where the line after the current one is preselected when sub-start is greater than ffmpeg's timestamps because they have been rounded, e.g. sub-start 10.001 is > than ffmpeg's 10.00. This will also allow considering --sub-delay in the comparisons, as comparing sub-start - sub-delay would preselect the wrong lines. --- player/lua/select.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/player/lua/select.lua b/player/lua/select.lua index 504f578f47..be963f6474 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -232,8 +232,7 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () local sub_lines = {} local sub_times = {} local default_item - local sub_start = mp.get_property_native("sub-start", - mp.get_property_native("time-pos")) + local time_pos = mp.get_property_native("time-pos") local duration = mp.get_property_native("duration", math.huge) -- Strip HTML and ASS tags. @@ -243,19 +242,11 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) .. " " .. line:gsub(".*]", "", 1) - if sub_times[#sub_times] <= sub_start then + if sub_times[#sub_times] <= time_pos then default_item = #sub_times end end - -- Handle sub-start of embedded subs being slightly earlier than - -- ffmpeg's timestamps. - sub_start = mp.get_property_native("sub-start") - if sub_start and default_item and sub_times[default_item] < sub_start and - sub_lines[default_item + 1] then - default_item = default_item + 1 - end - input.select({ prompt = "Select a line to seek to:", items = sub_lines,