Repository navigation
fix(jellycompat): match the VTT time map to the MPEG-TS muxer shift - #1998
Conversation
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.
|
Warning Review limit reachedYou'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. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (5)
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. Comment |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
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 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
left a comment
There was a problem hiding this comment.
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 — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Review summaryReviewed head: The fix is right. With
Addressed
Remaining
Validated featuresNo passed case is affected. I couldn't read the v1.0 board (this account's token lacks User manual and apps
VerificationOn this branch merged with current VerdictFit: 9/10 · Readiness: 8/10 — conditional
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. |
Problem
Related issue: #1249
Validation tasks: none
Jellyfin clients that request
AddVttTimeMap=truesubtitles for an HLS transcode show every cue 10 s early. jellycompat writesX-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0for copied timestamps (andMPEGTS:<start>otherwise), but HLS transcodes write MPEG-TS with-copyts -max_delay 5000000, and ffmpeg's MPEG-TS muxer adds twicemax_delayto every PTS. Video therefore starts at source time plus 10 s. Jellyfin writesMPEGTS:900000for the same request.Approach
-max_delayargument, andplayback.HLSMPEGTSTimestampOffset90kderives the 90 kHz shift from it.remux-ts-v1, copied MPEG-2), using the sameplayback.HLSOutputContainerdecision the transcode makes. Those getMPEGTS:900000with copied timestamps, as in Jellyfin, and the start position plus 900000 otherwise.remux-v1,remux-dv-v1,hevc-v1and other copied-video routes) keep the source clock intfdtand keep the previous map.docs/jellycompat-api.mdstates 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 onmainon 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 otherverify-*targets in CONTRIBUTING, and the router artifact test: pass.-ss 6. Without-max_delayit is 1.48 s.-max_delay), so the shift also holds forremux-ts-v1and MPEG-2 copy.AddVttTimeMap.Evidence
Same request on both builds: a Jellyfin-style
PlaybackInfowhose device profile only accepts an H.264tsHLS transcode, then the session's first segment, then the embedded SubRip track as WebVTT with a time map.Before
After
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 newMPEGTS:900000accounts for: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. WithMPEGTS:900000it 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
AI Disclosure
mainat 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
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.HandleSubtitleStreampasses the offset through all subtitle delivery paths, andwindowSubtitleVTTnow builds the MPEGTS value from it, adding the playback start position only when timestamps are not copied.HLSMPEGTSTimestampOffset90kconstant in transcode.go derived from the configured muxer maximum delay, and replaces the literal delay argument inbuildFFmpegArgswith the shared constant.Macroscope summarized b265d28.