History

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.

Guido Cella committed 2 years ago

Commit e3f496d1 parent 4ec060f1 file · +2 −11Browse files

Showing the changes to player/lua/select.lua (1 of 1 file). Show all

Unified · Split

player/lua/select.lua+2−11
@@ -232,8 +232,7 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () · 231 unmodified lines
232 local sub_lines = {}232 local sub_lines = {}
233 local sub_times = {}233 local sub_times = {}
234 local default_item234 local default_item
235 local sub_start = mp.get_property_native("sub-start",235 local time_pos = mp.get_property_native("time-pos")
236 mp.get_property_native("time-pos"))
237 local duration = mp.get_property_native("duration", math.huge)236 local duration = mp.get_property_native("duration", math.huge)
238 237
239 -- Strip HTML and ASS tags.238 -- Strip HTML and ASS tags.
@@ -243,19 +242,11 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () · 3 unmodified lines
243 sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) ..242 sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) ..
244 " " .. line:gsub(".*]", "", 1)243 " " .. line:gsub(".*]", "", 1)
245 244
246 if sub_times[#sub_times] <= sub_start then245 if sub_times[#sub_times] <= time_pos then
247 default_item = #sub_times246 default_item = #sub_times
248 end247 end
249 end248 end
250 249
251 -- Handle sub-start of embedded subs being slightly earlier than
252 -- ffmpeg's timestamps.
253 sub_start = mp.get_property_native("sub-start")
254 if sub_start and default_item and sub_times[default_item] < sub_start and
255 sub_lines[default_item + 1] then
256 default_item = default_item + 1
257 end
258
259 input.select({250 input.select({
260 prompt = "Select a line to seek to:",251 prompt = "Select a line to seek to:",
261 items = sub_lines,252 items = sub_lines,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t