Skip to content

fix(jellycompat): match the VTT time map to the MPEG-TS muxer shift - #1998

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/jellycompat-vtt-timestamp-map
Oct 7, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/jellycompat-vtt-timestamp-map

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1249
Validation tasks: none

Jellyfin clients that request AddVttTimeMap=true subtitles for an HLS transcode show every cue 10 s early. jellycompat writes X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0 for copied timestamps (and MPEGTS:<start> otherwise), but HLS transcodes write MPEG-TS with -copyts -max_delay 5000000, and ffmpeg's MPEG-TS muxer adds twice max_delay to every PTS. Video therefore starts at source time plus 10 s. Jellyfin writes MPEGTS:900000 for the same request.

Approach

  • The muxer delay is now one playback constant that feeds the ffmpeg -max_delay argument, and playback.HLSMPEGTSTimestampOffset90k derives the 90 kHz shift from it.
  • The subtitle route reads the play session's media source and adds that shift only when its HLS segments are MPEG-TS (encoded H.264, remux-ts-v1, copied MPEG-2), using the same playback.HLSOutputContainer decision the transcode makes. Those get MPEGTS:900000 with copied timestamps, as in Jellyfin, and the start position plus 900000 otherwise.
  • fMP4 sessions (remux-v1, remux-dv-v1, hevc-v1 and other copied-video routes) keep the source clock in tfdt and keep the previous map.
  • Direct play and progressive remux have no HLS segments and also keep the previous map. The route uses the session's started play method, and before any route starts, whether the source can be transcoded, because clients can fetch the subtitle before the master playlist.
  • docs/jellycompat-api.md states both cases.

Validation

  • go build, go vet, gofmt, make lint-changed: pass.
  • make test-go: the only failures are the hardware-acceleration, transcode and probe tests that also fail on main on the test machine (macOS, no VAAPI, QSV or NVIDIA devices). A few timing tests that failed once while the machine was loaded passed on three reruns.
  • make verify-settings-bindings-all, the other verify-* targets in CONTRIBUTING, and the router artifact test: pass.
  • An ffmpeg run with the transcode's timing arguments puts the first video PTS of the first MPEG-TS segment at 10.08 s from the start, and at 16.0 s after -ss 6. Without -max_delay it is 1.48 s.
  • Tests cover the MPEG-TS and fMP4 maps, with and without copied timestamps, the subtitle route's choice for each HLS route, and direct play, progressive remux, and a not-yet-started session that can't be transcoded.
  • The same ffmpeg timing check with copied H.264 and copied MPEG-2 video puts the first MPEG-TS segment at 10.08 s and 10.04 s (1.48 s and 1.44 s without -max_delay), so the shift also holds for remux-ts-v1 and MPEG-2 copy.
  • Not run against a Jellyfin client: none of the clients tested here requests AddVttTimeMap.

Evidence

Same request on both builds: a Jellyfin-style PlaybackInfo whose device profile only accepts an H.264 ts HLS transcode, then the session's first segment, then the embedded SubRip track as WebVTT with a time map.

GET http://<server>/Videos/<itemId>/<mediaSourceId>/Subtitles/2/0/Stream.vtt?CopyTimestamps=true&AddVttTimeMap=true&PlaySessionId=<playSessionId>

Before

WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0

00:00:10.000 --> 00:00:14.000
Cue at 0:10

After

WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

00:00:10.000 --> 00:00:14.000
Cue at 0:10

The first MPEG-TS segment of the same session (seg_00000.ts, 2 s) starts 10 s later than the source on both builds. That is the shift the new MPEGTS:900000 accounts for:

$ ffprobe -v error -select_streams v -show_entries stream=codec_name,start_time -of compact seg_00000.ts
stream|codec_name=h264|start_time=10.080000

The source's first video frame is at 0 s. With MPEGTS:0, a player places the "0:10" cue at segment PTS 10 s, which is source time 0 s, 10 s early. With MPEGTS:900000 it lands at source time 10 s.

Surface and build: jellycompat subtitle stream for an HLS transcode (TranscodingContainer: ts); before 7d4b831 (main), after 59a3bf1 (PR head). Test library with one synthetic 5-minute MPEG-4 Part 2 clip and an embedded SubRip track with a cue every 10 s.

Risks

Clients that build this subtitle URL themselves against an MPEG-TS session now get cues 10 s later than before, which is the correct position. fMP4, direct-play, and progressive-remux sessions are unchanged.

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, running in T3 Code
  • Tool(s): Claude Code subagents, Go toolchain, Docker, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: A separate Claude Code reviewer agent (claude-opus-5-5) read this branch's diff against main at medium effort, checking API compatibility, behaviour, tests and commit hygiene. It found that the first version applied the 10 s shift to every session, which would have made cues 10 s late on fMP4 routes. The shift now applies only to MPEG-TS sessions, and a test covers each route.

Note

Match VTT time map to MPEG-TS muxer shift in jellycompat subtitle delivery

  • Adds compatSubtitleSegmentPTSOffset90k, which returns a 900,000-tick (10-second) MPEG-TS offset for transcode sessions whose HLS output container is MPEG-TS, and zero for fMP4, direct play, progressive remux, and non-HLS paths.
  • HandleSubtitleStream passes the offset through all subtitle delivery paths, and windowSubtitleVTT now builds the MPEGTS value from it, adding the playback start position only when timestamps are not copied.
  • Adds a shared HLSMPEGTSTimestampOffset90k constant in transcode.go derived from the configured muxer maximum delay, and replaces the literal delay argument in buildFFmpegArgs with the shared constant.
  • Documents the container-specific timing contract in jellycompat-api.md and expands tests in playback_contract_test.go to cover copied/rebased timestamps, fMP4, and route-level container behavior.
  • Behavioral Change: MPEG-TS HLS subtitle VTT maps now include the 10-second muxer shift; fMP4 and non-HLS maps are unchanged.

Macroscope summarized b265d28.

With AddVttTimeMap=true, jellycompat subtitles wrote X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0 for copied timestamps and MPEGTS:<start> otherwise. HLS transcodes write MPEG-TS with -copyts and -max_delay 5000000, and ffmpeg's MPEG-TS muxer adds twice max_delay to every PTS, so video starts at source time plus 10 s. A player that applies the map shows every cue 10 s early. Jellyfin writes MPEGTS:900000 for the same request.

The muxer delay is now one playback constant that feeds the ffmpeg -max_delay argument, and playback.HLSMPEGTSTimestampOffset90k derives the 90 kHz shift from it. The subtitle route reads the play session's media source and adds that shift only when its HLS segments are MPEG-TS (encoded H.264, remux-ts-v1, copied MPEG-2), using the same playback.HLSOutputContainer decision the transcode makes. Those get MPEGTS:900000 with copied timestamps, as in Jellyfin, and the start position plus 900000 otherwise. fMP4 sessions (remux-v1, remux-dv-v1, hevc-v1, and other copied-video routes) keep the source clock in tfdt and keep the previous MPEGTS:0 or start-position map. The jellycompat API doc states both cases.

An ffmpeg run with the transcode's timing arguments puts the first video PTS of the first MPEG-TS segment at 10.08 s from the start and at 16.0 s after -ss 6; without -max_delay it is 1.48 s. Tests cover the MPEG-TS and fMP4 maps with and without copied timestamps, and the subtitle route's choice for each HLS route.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cddcf39a-9e06-414c-95d2-70c08f08ebc6
📥 Commits

Reviewing files that changed from the base of the PR and between c762177 and b265d28.

📒 Files selected for processing (5)
  • docs/jellycompat-api.md
  • internal/jellycompat/playback_contract_test.go
  • internal/jellycompat/streams.go
  • internal/jellycompat/subtitle_delivery.go
  • internal/playback/transcode.go
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-kody

silo-kody Bot commented Oct 5, 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 ❌

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Silo's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Evidence: none, no user-visible change. This PR was opened before the rule existed, so it hasn't had a chance to meet it yet.

Missing here: Before-and-after excerpts of the VTT subtitle response showing the X-TIMESTAMP-MAP change, or a client recording of subtitle timing.

The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in.


Generated by Claude Code

@Quick104
Quick104 marked this pull request as draft October 6, 2026 19:19
@Rhainland
Rhainland marked this pull request as ready for review October 6, 2026 20:04

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One finding below. I checked the rest of the change against the transcode and against ffmpeg, and it holds: the subtitle route picks the same container the transcode does, and Silo's bundled ffmpeg (7.1.4-Jellyfin) puts the first MPEG-TS segment at 10.08 s for copied H.264 and 10.04 s for copied MPEG-2 with -max_delay 5000000 (1.4x s without it), so the shift is right for remux-ts-v1 and MPEG-2 copy as well as encoded H.264.

…back

Direct play and progressive remux have no HLS segments, so the MPEG-TS
muxer shift does not apply to them. Use the session's started play
method, and before any route starts, whether the source can be
transcoded at all.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@silo-kody

silo-kody Bot commented Oct 7, 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 ❌

@Quick104

Quick104 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: b265d28b2 (the PR's 59a3bf10f plus one fix commit from this review).

The fix is right. With -copyts -max_delay 5000000, ffmpeg's MPEG-TS muxer starts every HLS segment 10 s after the source clock. The subtitle route now adds that shift to X-TIMESTAMP-MAP only for sessions whose segments are MPEG-TS. I checked:

  • The container decision in the subtitle route matches the one the transcode makes for the same source (compatSourceTargetVideoCodec, HLSRemuxMPEGTS, the source video codec), including copy with audio transcode, the Dolby Vision strip, encoded HEVC, and MPEG-2 copy.
  • Silo's bundled ffmpeg (7.1.4-Jellyfin) puts the first MPEG-TS segment at 10.08 s for copied H.264 and 10.04 s for copied MPEG-2 with -max_delay 5000000, and 1.48 s and 1.44 s without it. The shift holds for remux-ts-v1 and MPEG-2 copy, not only for encoded H.264.
  • Jellyfin's SubtitleController writes MPEGTS:900000 whenever AddVttTimeMap is set, so MPEG-TS sessions now match it.
  • The branch merges cleanly with current main, and main hasn't changed the transcode or compat code this depends on.

Addressed

  • Non-HLS sessions got the MPEG-TS shift (low). Direct play and progressive remux returned MPEGTS:900000 where they returned MPEGTS:0 before, although those streams never pass through the HLS muxer. Fixed in b265d28b2: the route uses the session's started play method, and before any route starts, whether the source can be transcoded. It can't rely on the play method alone, because clients can fetch a subtitle DeliveryUrl before the master playlist. Four handler test cases were added; three fail without the change. The doc paragraph covers it.

Remaining

  • Not tested with a Jellyfin client that requests AddVttTimeMap. The PR body says so too. Silo's own apps use native subtitle routes and aren't affected.
  • Related issue: #1249 is the [v1] Series certification epic, which is only loosely related to a jellycompat subtitle fix. A more specific issue, or N/A, would be clearer.

Validated features

No passed case is affected. I couldn't read the v1.0 board (this account's token lacks read:project), so I checked the Validation issues directly. Jellyfin compatibility (#1246) has no passed cases. The Silo app subtitle tasks (#1158, #1159, and the Apple and Android equivalents) use native routes this change doesn't touch. Validation tasks: none stands.

User manual and apps

  • User manual: unaffected. siloserver.org doesn't describe the VTT time map, and this fix makes the behavior correct rather than changing a documented feature.
  • Apple and Android: no change needed. Neither app uses this jellycompat route.

Verification

On this branch merged with current main: go vet and go test for internal/jellycompat and internal/playback pass, and gofmt is clean. CI on b265d28b2 passed.

Verdict

Fit: 9/10 · Readiness: 8/10 — conditional

  • Fit: a bounded correctness fix in the Jellyfin compatibility layer. It brings Silo's behavior in line with Jellyfin and reuses the transcode's own container decision, so it adds no parallel mechanism.
  • Readiness: the code and tests are sound, and CI on the new head passed. It stays below 9 because no Jellyfin client that uses the time map has been tested.

Review by Claude Code (claude-opus-5-5) in T3 Code, with one cross-provider round by Codex (gpt-6.1-sol, xhigh), read-only. Codex raised the non-HLS finding; I confirmed and fixed it. Its other checks found nothing.

@Quick104
Quick104 merged commit e78a89c into Silo-Server:main Oct 7, 2026
18 checks passed
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