Repository navigation
fix(playback): align subtitle rendition cues when the source clock doesn't start at zero - #2649
Conversation
…esn't start at zero Subtitle segment N cut its cues from [N·d, (N+1)·d), but a generation's video segment N covers [O + (N−K)·d, …): O is the generation's first video frame on the source clock, which is the video's start time for the first generation and the container's start plus the seek for a seek restart. On a source whose clock starts at 7 s every cue landed several segments late, and with a large start offset all of them fell into the open-ended last segment. Each generation now reads O once from the first video PTS of its own first output segment (the probe the copy path already used, extended to MPEG-TS and parsed as JSON), caches it on its cue span, and cuts windows from it. MPEG-TS windows take the cue clock's epoch across the 33-bit rollover. A generation whose origin can't be read keeps the old grid. Closes #2648 Co-Authored-By: Claude Opus 5.5 <[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:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
The epoch was chosen per window relative to the first cue, so a generation whose observed origin sat an epoch below its cues lost the correction once its windows ran more than half a timestamp range (about 13 h) past it, and those segments came back empty. Resolve the epoch on the origin and add the segment's offset after it. Co-Authored-By: Claude Opus 5.5 <[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:
|
…cue's side The epoch was the first within half a timestamp range below the first cue, which moved a zero-clock generation up an epoch when its first cue came more than about 13 h in. A generation starts no later than its first cue (give or take a cue already showing), so take the latest epoch that keeps it there. Co-Authored-By: Claude Opus 5.5 <[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:
|
Main added subtitle rendition cue spans (Silo-Server#2620, Silo-Server#2649) to TranscodeSession beside this branch's group assembler and plan seek anchor. Keep both; neither depends on the other. Main's wider static checks (Silo-Server#2522) apply to this branch's code, which the merge commit must pass: - fMP4 decode times go through readFMP4DecodeTime, which rejects a version 1 time past MaxInt64. putFMP4DecodeTime rejects a negative one, and trimTrafStart range-checks the sample count it writes. - Conversions that read the format's signed 32-bit fields, and the box size of one segment's boxes, carry reasoned nolints. - Assembled segments read through filepath.Clean. Their 0644 writes and the plan record's, beside FFmpeg's own output, and the ffprobe call, carry reasoned nolints. - strconv.Itoa for -hls_time. - The planned-session test's polls and its length carry reasoned nolints. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main added subtitle rendition cue spans (Silo-Server#2620, Silo-Server#2649) to TranscodeSession beside this branch's copyPlanRejected. Keep both; neither depends on the other. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge main at f75cdf3. The merge has no textual conflict, but main's subtitle renditions (Silo-Server#2649) added liveProducedHead, which calls the old three-value readManifestFile and compares the inherited playlist itself. This branch moved that comparison into readManifestFile, so the new caller now passes the inherited playlist and treats os.ErrNotExist as "no progress yet", with the same result as before.
Problem
Closes #2648
Related issue: N/A
Validation tasks: none
When a transcode carries an embedded text subtitle as an HLS subtitle rendition (#2620), cues go into the wrong subtitle segments if the source's clock doesn't start at 0. Players load each cue several segments after its video, so the subtitle shows late or not at all. With a large start offset, every cue falls into the last segment. MPEG-TS captures and files remuxed from them often start seconds or hours in. This affects Apple and Android clients that send
hls_subtitle_renditions_v1.The rendition's cue file keeps the source clock (
-copyts), so a cue at 1 s in a file that starts at 7 s is written as00:08.000. Subtitle segment N was cut from[N·d, (N+1)·d)measured from 0. Video segment N actually starts at the generation's first video frame plus(N−K)·d, where K is the segment the generation started at.Approach
Each FFmpeg generation now reads its origin once: the first video PTS of its own first output segment, less the shift the
X-TIMESTAMP-MAPalready declares. Subtitle segments are cut from that origin. The read uses the ffprobe call that copy-mode manifests already make on generated output, extended to MPEG-TS and parsed as JSON. It opens one local segment and never the source. Concurrent requests share one read per generation, and the result is cached on the generation's cue span. If the origin can't be read, the segment falls back to today's grid. For a file whose clock starts at 0 the windows are the same as before.Why measure the output instead of storing the source's start time, as the issue suggested: the origin differs between generations. For a file whose audio starts at 3 s and video at 7 s, the first generation's grid starts at 7 s (the first encoded frame), while a seek restart's grid starts at the container's 3 s plus the seek. One stored value can't describe both. Reading the output also needs no migration and no new recipe or token field, and it works for files scanned before this change.
Other details:
Transcode nodes serve the rendition from the same session code, so they get the fix without changes. Jellycompat doesn't use renditions. The clients need no change: the wire format, playlists, and timestamp map are the same.
docs/architecture/playback-protocol-v3.mdnow describes the window.Validation
gofmt,go vet ./...,make lint-changed(0 issues),make lint-router-recovery,make verify-playback-fixtures: pass.make test-go: pass exceptinternal/mediasampleTestRunStatsWithRealFFmpeg, which fails the same way on main with the local FFmpeg 6.1.1.-race.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/issue-2648/
Risks
X-TIMESTAMP-MAPshift stays fixed, so cues show that much early.Checklist
AI Disclosure
Note
Fix subtitle cue alignment in generated WebVTT segments for non-zero source clocks
probeSegmentVideoPTSprobe reads the first video packet PTS from generated segments (MPEG-TS or fMP4) via ffprobe, sandboxed to the output directory.subtitleSpanOriginobserves the generation origin once per span, caches it, retries after five seconds on failure, and discards observations that overlap a restart or a later generation's overwrite in subtitle_rendition.go.subtitleSegmentDocumentandsubtitleWindowEpochin subtitle_rendition.go if cue placement regresses.Macroscope summarized 3439ccb.