Skip to content

feat(playback): draw embedded MKV bitmap subtitles from the stream - #734

Closed
Quick104 wants to merge 2 commits into
mainfrom
feat/native-bitmap-subtitles
Closed

Quick104 wants to merge 2 commits into
mainfrom
feat/native-bitmap-subtitles

Conversation

@Quick104

@Quick104 Quick104 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #457, Silo-Server/silo-server#1406
Validation tasks: changes #323 C4; changes #324 C4

When the phone or TV app direct-plays an MKV and the viewer picks an embedded image-based subtitle, the player doesn't draw it from the file it is already playing. A PGS track becomes a .sup sidecar, which the server extracts by reading the whole source file. A VobSub or DVB track has no sidecar at all, so the server burns it into a full video transcode. On large files on slow storage the extraction takes minutes and competes with the video stream (Silo-Server/silo-server#1406).

The apps now list the three bitmap families in their MKV native_embedded capability, so the server plans these tracks as native embedded subtitles and Media3 draws them from the original stream, as #457 did for text tracks.

Approach

  • The MKV native_embedded entry on original_http lists hdmv_pgs_subtitle, dvd_subtitle and dvb_subtitle. Media3 1.11's MatroskaExtractor publishes S_HDMV/PGS, S_VOBSUB and S_DVBSUB tracks with Format.id set to the Matroska TrackNumber, and DefaultSubtitleParserFactory decodes all three, so the existing container_track_id selection works unchanged.
  • validateForMedia3 accepts the server's short codec aliases (pgs, pgssub, dvdsub, vobsub, dvbsub).
  • A VobSub or DVB track committed as Embedded now resolves on the detail screen instead of being dropped.
  • codecToMimeType mapped dvd_subtitle and dvdsub to DVB subtitles. It now maps them to VobSub, and dvb_subtitle and dvbsub to DVB.
  • Phone and TV both get this through shared code. docs/playback/README.md lists the new codecs.
  • Server dependency: none. The server already plans subtitle.embedded for these codecs when a client lists them.

Validation

  • ./gradlew testDebugUnitTest: pass, 6,629 tests, 0 failures. New tests cover the advertised codecs, every server alias, selection by Matroska TrackNumber for each bitmap family, and a native bitmap plan mounting no .sup sidecar or burn-in fallback.
  • ./gradlew :android-shared:lintDebug :androidApp:lintDebug :androidTvApp:lintDebug: pass, no new findings.
  • :androidApp:assembleDebug and :androidTvApp:assembleDebug: pass.
  • Not run locally: the supply-chain scripts (no Ruby on the build machine; this change touches no build, dependency or workflow file), release bundles and release lint. CI runs them.
  • No device or emulator run.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-android/pr-734/

Risks

  • How Media3 positions, scales and times PGS, VobSub and DVB cues on real devices is unchecked. If a device draws them badly, dropping the codecs from the native_embedded entry sends these tracks back to the .sup sidecar and burn-in routes.
  • Cast is unaffected: it sends its own HLS-only capabilities, with no native_embedded entry.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated. Nobody has verified it by hand yet, and no device or emulator run happened.
  • Adversarial review: a separate Claude Code agent (claude-opus-5-5) reviewed the whole original branch, which included this change, read-only. For this change it checked the Matroska bitmap decode path, the track IDs and the VobSub MIME fix, and reported nothing to fix.

🤖 Generated with Claude Code

Note

Add native MKV bitmap subtitle support (PGS, VobSub, DVB) to playback

  • Adds hdmv_pgs_subtitle, dvd_subtitle, and dvb_subtitle to the MKV native embedded codec list in PlaybackProtocolV3.kt, with alias normalization for pgs, pgssub, dvdsub, vobsub, and dvbsub.
  • Fixes the MIME mapping in SubtitleManager.kt: DVD/VobSub aliases now map to the VobSub MIME type instead of the DVB MIME type.
  • Fixes OffsetSubtitleParserFactory to treat C.TIME_UNSET cue starts as sample-relative zero, so offset shifting and clamping work correctly for bitmap cues.
  • Loosens SubtitleTrack.matchesTypedCatalogIdentity so embedded identities match any non-external catalog track, letting remembered VobSub and DVB selections restore as embedded tracks.
  • Adds unit tests for codec capability tables, MIME resolution, Matroska TrackNumber-based selection, and offset shifting; documents the new behavior in README.md.
  • Behavioral Change: MKV PGS/VobSub/DVB tracks now play directly from the stream instead of falling back to sidecar or burn-in routes; DVB teletext remains a replan case.

Macroscope summarized 9eddbc8.

Advertise hdmv_pgs_subtitle, dvd_subtitle and dvb_subtitle in the MKV
native_embedded entry on original_http. Media3 1.11's MatroskaExtractor
exposes S_HDMV/PGS, S_VOBSUB and S_DVBSUB with Format.id set to the
TrackNumber, and DefaultSubtitleParserFactory decodes all three, so the
existing container_track_id selection works unchanged. The server already
plans subtitle.embedded for these codecs when the client lists them, which
replaces the PGS .sup whole-file extraction and the VobSub/DVB burn-in
transcode in direct play.

validateForMedia3 accepts the server's short aliases (pgs, pgssub, dvdsub,
vobsub, dvbsub). A VobSub or DVB track committed as Embedded now resolves
on the detail screen instead of being dropped. codecToMimeType mapped
dvd_subtitle/dvdsub to DVBSUBS; it now maps them to VOBSUB and maps
dvb_subtitle/dvbsub to DVBSUBS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 98 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dc0f3221-3f7c-4aab-8d03-183ab41a61b5
Commits

Reviewing files that changed from the base of the PR and between b29de77 and 9eddbc8.

Files selected for processing: 11
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SubtitleManager.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/subtitle/OffsetSubtitleParserFactory.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/NativeEmbeddedSubtitleTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/PlaybackCapabilityDetectorDolbyVisionTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/SubtitleManagerTrackSelectionTest.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/subtitle/OffsetSubtitleParserFactoryTest.kt
  • docs/playback/README.md
  • shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/PlaybackProtocolV3.kt
  • shared/src/commonMain/kotlin/org/siloserver/silo/playback/TrackSelectionFingerprint.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/model/playback/NativeEmbeddedSubtitleProtocolTest.kt
  • shared/src/commonTest/kotlin/org/siloserver/silo/playback/TrackSelectionFingerprintTest.kt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 30, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T17:11:48.123351Z 9eddbc8 New commits
🔒 Security Review ✅ Completed 2026-10-31T17:11:48.296706Z 9eddbc8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-kody

silo-kody Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026

Copy link
Copy Markdown

Evidence is missing for these visible playback effects:

  • Native MKV bitmap-subtitle playback (shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/PlaybackProtocolV3.kt, android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/SubtitleManager.kt): PGS, VobSub, and DVB subtitles now render from the stream instead of using extraction or burn-in. This shared behavior reaches Android phone, tablet, foldable (folded and open), and TV. Please add before-and-after playback captures of the same media and track on each device; include a recording to show cue timing and identify each device and build/commit.
  • Remembered VobSub/DVB selection restoration (shared/src/commonMain/kotlin/org/siloserver/silo/playback/TrackSelectionFingerprint.kt): an embedded selection can now be restored instead of dropped. This shared behavior reaches Android phone, tablet, foldable (folded and open), and TV. Please add before-and-after evidence of the selection/restore flow on each device, with a recording if needed to show the multi-step flow, and identify each device and build/commit.

The Evidence section says “being published” but contains no captures or evidence link.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added enhancement New feature or request evidence-required Needs before-and-after evidence before the Evidence check passes impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Oct 30, 2026
val NATIVE_EMBEDDED_SUBTITLE_CODECS: Map<String, List<String>> = mapOf(
"mp4" to listOf("mov_text"),
"mkv" to listOf("subrip", "ass"),
"mkv" to listOf("subrip", "ass", "hdmv_pgs_subtitle", "dvd_subtitle", "dvb_subtitle"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Subtitle offset handling fails for native MKV PGS/DVB bitmap cues because OffsetSubtitleParserFactory adds the user's sync offset to Media3's C.TIME_UNSET start-time sentinel, clamping away positive offsets and overflowing Long into an enormous future timestamp for a negative offset such as -100 ms. Handle sample-relative TIME_UNSET timestamps before applying offsets in the embedded parser pipeline so newly advertised native tracks respect subtitle delay and remain visible when advanced.

Prompt for LLM

File shared/src/commonMain/kotlin/org/siloserver/silo/model/playback/PlaybackProtocolV3.kt:

Line 675:

Subtitle offset handling fails for native MKV PGS/DVB bitmap cues because OffsetSubtitleParserFactory adds the user's sync offset to Media3's C.TIME_UNSET start-time sentinel, clamping away positive offsets and overflowing Long into an enormous future timestamp for a negative offset such as -100 ms. Handle sample-relative TIME_UNSET timestamps before applying offsets in the embedded parser pipeline so newly advertised native tracks respect subtitle delay and remain visible when advanced.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

is SubtitleIdentity.Embedded ->
!external &&
(!codec.isCatalogBitmapSubtitle() || isClientMountableBitmapCodecFamily(codec))
is SubtitleIdentity.Embedded -> !external

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Catalog restoration fails for native VobSub/DVB preferences because playbackSubtitleIdentity stores the inventory serverTrackId in media.trackId while catalogMediaIdentity leaves trackId null, causing matchesTypedCatalogIdentity to reject the newly accepted Embedded row at its subsequent track-ID comparison. Update catalog identity reconciliation so MobileVideoPlaybackStarter retains the remembered selection and TvPlayerSubtitlePolicy can rebuild it, and add a round-trip test using an actual native session row rather than media copied from encodeCatalogSubtitlePreference.

Prompt for LLM

File shared/src/commonMain/kotlin/org/siloserver/silo/playback/TrackSelectionFingerprint.kt:

Line 347:

Catalog restoration fails for native VobSub/DVB preferences because playbackSubtitleIdentity stores the inventory serverTrackId in media.trackId while catalogMediaIdentity leaves trackId null, causing matchesTypedCatalogIdentity to reject the newly accepted Embedded row at its subsequent track-ID comparison. Update catalog identity reconciliation so MobileVideoPlaybackStarter retains the remembered selection and TvPlayerSubtitlePolicy can rebuild it, and add a round-trip test using an actual native session row rather than media copied from encodeCatalogSubtitlePreference.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

The offset wrapper around the embedded subtitle parsers added the user's
sync offset to each cue's start. Media3's PGS and DVB parsers report no
start of their own (C.TIME_UNSET; the cue starts at its sample), so a
positive offset was clamped away and a negative one overflowed into a
time the cue never reaches. With MKV bitmap tracks now played from the
stream, a viewer who advanced subtitles lost them.

A missing start now counts as the sample-relative start 0 it stands for,
so the offset applies as it does to Matroska text tracks. The `.sup`
sidecar extractor ignores the parser's start and offsets the sample
itself, so it is unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9eddbc86c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// sample-relative start of 0. Adding the offset to the TIME_UNSET
// sentinel instead clamped a positive offset away and overflowed a
// negative one into a time the cue never reaches.
val start = if (cues.startTimeUs == C.TIME_UNSET) 0L else cues.startTimeUs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve negative offsets for sample-relative bitmap cues

When a viewer advances subtitles with a negative sync offset, the newly enabled native MKV PGS/DVB path ignores the adjustment: converting TIME_UNSET to zero makes rawStart negative, so the following clamp resets every cue to zero relative to its sample. For example, a cue sampled at 60 seconds with a −500 ms offset still appears at 60 seconds instead of 59.5 seconds. Media3's SubtitleTranscodingTrackOutput adds this relative start to the sample timestamp, so negative relative starts must be preserved rather than clamped as though they were absolute playback times. This regresses PGS synchronization compared with the previous .sup path, where PgsSupExtractor applies the offset to the actual sample timestamp.

Useful? React with 👍 / 👎.

@Quick104

Copy link
Copy Markdown
Contributor Author

Superseded by #770, which combines this change with the rest of the stack for review.

@Quick104 Quick104 closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request evidence-required Needs before-and-after evidence before the Evidence check passes impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant