Skip to content

libass 7a: embedded text subtitle tracks render through libass - #730

Merged
GLinnik21 merged 23 commits into
mainfrom
libass-7a-embedded-switch
Oct 15, 2026
Merged

GLinnik21 merged 23 commits into
mainfrom
libass-7a-embedded-switch

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

Plan PR 7a (libass-text-subs, §7 row 7a): embedded text tracks (SubRip, WebVTT, mov_text, SAMI, ...) render through libass instead of the bespoke caption draw.

  • ff.rs / ff_subs.rs: SubKind::Text(TextDialect) replaces Plain/MovText; begin_ass_sources registers a text track as TrackHeader::Text(dialect) (§0 D1, §1.5).
  • ass_source::push_text converts each cue (text_ass::convert), keeps it as a raw cue and derives the track's events as a newest-wins view (D10). ReadOrder only increases; raw cues survive seek and same-file reopen (§1.5). Restyle is lazy and only for a selected track (§2.5).
  • Nothing produces into SHARED.sub_cues any more, so a text cue is never drawn twice. push_subtitle_cue is deleted (its last caller went).
  • Docs: docs/ass-subtitles.md, player/CLAUDE.md, tests/README.md, transcoder.rs comment.

Review findings fixed here

  • Raw dedup key is now (start, end, packet_identity): a 64-bit hash of the packet bytes BEFORE the charset step. The old text key could differ after the stateful detector locked or after a reopen (a worse guess could replace correct text), and it held a second copy of every cue's text outside the byte budget.
  • A cue the budget retires on arrival (backward-seek re-read) no longer bumps the revision or logs sub cue.
  • Docs: sub_cues is described as dead until PR 10; transcoder.rs comment names TextDialect::Plain.
  • New check-ffmpeg test: durationless packets (default end start + 4 s) go through the real decode into push_text and the first cue is clipped to the second's start (the fixture's packets have duration zeroed after the demuxer reads them, since ffmpeg always writes BlockDuration).
  • Red-first: the retire-on-arrival test was watched failing with the guard disabled.

Not changed / notes

  • Finding 7b (the 62 s history test passes floor_ms to Store::push_text, not the public fn's subtitle_floor_ns()): accepted, same as the authored path.
  • Behaviour change for TV comparisons: make_ass_stress.py now gives the ASS stress fixtures the default disposition, so the player selects the track without a menu pick. Compare against measurements.md baselines with that in mind.
  • Open risk: SRTs with 1-frame overlaps clip almost every previous cue, so the view prefix changes and the engine re-appends the window. The "assup max > 3 ms -> PR 7c" decision waits on the TV matrix.

Gates (committed tree, git status --short empty before and after)

  • make check: exit 0; last lines test result: ok. 1324 passed; 0 failed; 0 ignored and test result: ok. 1736 passed; 0 failed; 47 ignored
  • cargo +nightly check --lib --no-default-features: Finished, no warnings
  • make check-ass: test result: ok. 45 passed; 0 failed
  • make check-ffmpeg: test result: ok. 9 passed; 0 failed

TV (webOS 4.5 dev set, ARM_PROFILE=release, mock guest, panel off, muted)

Fixtures: SRT/WebVTT in MKV and mov_text in MP4 over a 1080p24 clip, with the subtitle track set as default.

  • Scripts: Latin, CJK, Thai (stacked marks), Devanagari (conjuncts and matras) and Arabic (joined, RTL) all render with no tofu. Lines wrap at 760 px, the same width as the old renderer.
  • SRT styling: <i>, <b> and <font color> work. {\an8} puts a sign at the top while dialogue stays at the bottom. A top sign that outlasts four bottom cues stays up the whole time.
  • Overlaps:
    • Same-start cues: newest wins; the OLD cue never shows, either inside or after the NEW cue's window.
    • A 1-frame overlap and duration-less cues show one cue at a time.
  • WebVTT and mov_text render like SRT.
  • fps: 60 (59-61) on every fixture after open, dropped=0 and carried=0. The 43-51 in the first 2 s matches the subs-off baseline at player open.
  • srt-rapid (a cue every 100 ms, FRAMEDROP armed):
    • Worker: 11-12 renders/s, all served by render-ahead (jobs=0+N, ahead_hit=N), p95 9.2-11.3 ms. This is off the UI thread.
    • Publish: 3.1-3.4 MB/s.
    • assup over 482 uploads: p50 0.7 ms, p95 1.2 ms, max 4.3 ms.
    • Player frames over budget were all open transitions (clearx2), or back-buffer waits with assup ≤ 4.3 ms inside (total 15.7-18.5 ms, clear 8.9-14.1 ms).
  • srt-long (multi-line cues lasting tens of seconds): 2-3 renders per 10-20 s window. Before PR 2 it rendered every frame.

assup max > 3 ms triggers PR 7c/7d (bucketed glTexSubImage2D upload, plan §4.5). They follow this PR.

Not covered on this pass: the size, position and tone rungs and the subtitle offset (these need the player menu), and HUD up/down. The app binary disappeared from the worktree before the HUD run. They move to the PR 7b/7d TV gate.

Closes #478

🤖 Generated with Claude Code

GLinnik21 and others added 21 commits October 15, 2026 03:28
Pins libunibreak 8.0 and enables ASS_FEATURE_WRAP_UNICODE support; patches libass
0.17.5 so one font holds more than ten faces (apply_patches under
GIT_CEILING_DIRECTORIES with a post-apply hash assertion, pinned in
ci/libass-dependencies.json); facade ABI 3 adds features, cache limits, line
spacing, replace_track (used by the windowed-slide branch) and stats; the
ass_set_fonts scan runs once per renderer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-failed-replace guard, source-change doc)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne branch and published alignment classes (libass text subs, PR 6a)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le carried by Origin::Text, aligns beside the published frame by serial, bounded alive_at (libass text subs, PR 6a)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts their bottom regions with the HUD (libass text subs, PR 6)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nknown classes never lift a top cue, separate line regions rise together, allocation-free draw (libass text subs, PR 6 review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps Origin::Text, the restyle branch and the alignment classes alongside
PR 4's configure(), replace_track and facade ABI 3. set_wrap_unicode and
set_line_spacing lose their cfg(test): the restyle branch calls them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-origin

# Conflicts:
#	docs/ass-subtitles.md
#	rust-modules/media/src/player/ass/tests.rs
… cues, newest-wins view, lazy restyle)

SubKind::Plain/MovText become SubKind::Text(TextDialect); begin_ass_sources (and so the side
reader) registers every text track with its dialect. SubCue::Text goes to ass_source::push_text
instead of the bespoke caption store: the cue is converted by text_ass, deduplicated on its raw
key, given a never-reused ReadOrder, and the track's events become the newest-wins view of its
raw cues. Raw cues survive retain_for_reload + a same-file begin, so a held cue the reopened
demuxer does not resend stays up. A changed size/position pick re-synthesizes the selected
track's header once (revision bump, same id). The `sub cue [a..bms] len=N` line stays.

make_ass_stress.py also builds SubRip, mov_text and WebVTT fixtures and sets the default
subtitle disposition on every generated track.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d on arrival, delete push_subtitle_cue, fix docs, duration-less packet test

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

arabic subtitles

2 participants