Skip to content

feat: include future secondary subtitle overlaps - #177

Draft
kuator wants to merge 7 commits into
Ajatt-Tools:masterfrom
kuator:feat/full-track-secondary-overlap
Draft

feat: include future secondary subtitle overlaps#177
kuator wants to merge 7 commits into
Ajatt-Tools:masterfrom
kuator:feat/full-track-secondary-overlap

Conversation

@kuator

@kuator kuator commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Why

The subtitle observer only knows secondary cues that mpv has already displayed. If the selected primary subtitle window extends beyond the current playback position, later secondary cues that overlap that window are missing from both the card and its OSD preview.

What changed

  • Look ahead on demand with sub-step 1 secondary instead of parsing or extracting the subtitle track.
  • Capture each stepped cue's raw timestamps and normalize them with the original secondary-sub-delay and audio-delay.
  • Restore secondary-sub-delay after lookahead, including when stepping fails.
  • Use the same time-overlap resolver for card export and the OSD preview.
  • Require 75% overlap when the shorter cue is under one second, and 50% otherwise.
  • Ignore subtitle observer callbacks while lookahead temporarily changes the visible secondary cue.

This performs no file I/O and launches no subprocess. For embedded tracks, lookahead is naturally limited to cues inside mpv's subtitle prefetch range.

Verification

  • luajit tests/run.lua
  • Real mpv probe with external SRT tracks: repeated stepping exposed all test cues and exact raw timestamps, then restored the original delay.
  • Real mpv probe with embedded SRT tracks: stepping exposed the prefetched cues and restored the original delay.
  • Regression tests retain the incidental-overlap cases and the 50%/75% thresholds.

@kuator
kuator force-pushed the feat/full-track-secondary-overlap branch from a96890e to 928ad11 Compare August 9, 2026 17:03
@tatsumoto-ren

tatsumoto-ren commented Aug 9, 2026

Copy link
Copy Markdown
Member

Extracting a subtitle file from a video can take a few seconds and requires resources, so until now we didn't want to implement it in mpvacious. Plus, it requires writing a lot of code. Before settling on this solution, let's try a proven method. In our sub-transition script we look ahead by changing sub-delay via mp.commandv("no-osd", "sub-step", 1), which causes the next subtitle line to appear. So you can grab the next subtitle this way, then restore sub-delay with mp.set_property_number("sub-delay", initial_sub_delay).

sub-step <skip> [<flags>]

    Change subtitle timing such, that the subtitle event after the next <skip> subtitle events is displayed. <skip> can be negative to step backwards.

    Secondary argument:

    primary (default)
        Steps through the primary subtitles.
    secondary
        Steps through the secondary subtitles.

for secondary subs, use the secondary argument, then restore secondary-sub-delay instead of sub-delay.

@kuator kuator changed the title feat: include complete secondary subtitle overlaps feat: include future secondary subtitle overlaps Aug 9, 2026
@kuator

kuator commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Implemented the sub-step approach in eea9b58. I removed the full-track parser/extractor and now step through the secondary track on demand, capture each cue using its raw timestamps, normalize with the original secondary/audio delays, and restore secondary-sub-delay afterward. The existing 50%/75% overlap filter is unchanged and is applied after cue discovery. luajit tests/run.lua passes. I also probed this in mpv with both external and embedded SRT tracks; state restoration worked in both cases. As expected, embedded lookahead is limited to mpv鈥檚 prefetch range.

@kuator
kuator force-pushed the feat/full-track-secondary-overlap branch from 89c24f9 to eea9b58 Compare August 9, 2026 19:47
@kuator

kuator commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

I think I should try using this for a few days before it becomes reviewable

@kuator

kuator commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

I think I have to make it handle backwards subtitle overlaps as well, because sometimes I jump into the middle of a primary cue and mpvacious doesn't see a backward secondary cue

@tatsumoto-ren

Copy link
Copy Markdown
Member

Simply rewinding back and forth is enough for mpvacious to memorize subtitle lines. shift+h and shift+l are mentioned in README as aliases for seek back and seek forward.

@kuator

kuator commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Simply rewinding back and forth is enough for mpvacious to memorize subtitle lines. shift+h and shift+l are mentioned in README as aliases for seek back and seek forward.

Okay, I'll roll back the change

@kuator
kuator force-pushed the feat/full-track-secondary-overlap branch from 7412daf to 6ddc4f8 Compare August 11, 2026 04:59
@kuator
kuator force-pushed the feat/full-track-secondary-overlap branch from 6ddc4f8 to 81ca880 Compare August 11, 2026 05:34
@kuator

kuator commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Removed the backwards seek

@tatsumoto-ren

Copy link
Copy Markdown
Member

Removed the backwards seek

sub-step is a pretty clever hack that can be applied in both directions if you actually need it. My comment was more about whether this is something the users might need or not.

You can probably edit scan_secondary_forward() to include direction as a parameter, so you don't have to duplicate much code.

Also, consider splitting this PR into smaller ones if possible.

Please comment when this PR is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants