Repository navigation
fix(captions): put A/53 caption timestamps back on the source axis (#259) - #262
Merged
Merged
Conversation
) `finalizeAndWriteVideo` extracts the in-picture cc_data long after the pump has rebased the packet: `packet.pointee.pts -= activeShift` runs in the read loop and the finalize call sits below it, so the timestamps the A/53 observer received were on the output (item) axis while the comment above the call still described them as source. Everything downstream reads them as source PTS. The tap's cue buffer feeds `subtitleCues`, and the host renders that against `currentTime`, which folds `playlistShiftSeconds` back in, so every A/53 caption was displaced by the shift. `NativeSubtitleCueStore` states the same contract from the other side: it keeps cues on the source axis and subtracts the shift at query time. The two sibling feeds were already right, which is what makes this a slip rather than a convention. The demuxable c608 tap (#77) gets its packet at the top of the read loop, before the rebase; the software path's `ingestA53Ordered` reads decoded-frame side data, where no shift exists at all. The shift is not a constant. It is `firstActualVideoDts - desiredFirstVideoTfdt`, recomputed on every producer restart, so the error moved after each seek. On the witness clip it is two frames at 24 fps (83 ms); on a restart that lands off its planned keyframe it has been measured in seconds, and a source whose first DTS is not near zero (broadcast MPEG-TS, the reason #131 exists) carries it from the first packet. `foldingShiftBack` folds it back at the observation site, mirroring `segmentIndex(forSourcePts:)`, which does the same thing before comparing against the source-axis segment boundaries. NOPTS and an unresolved shift pass through. The regression witness needed a source, and no encoder emits A/53 from a synthetic one. `Scripts/fetch-fixtures.sh` now builds it: an H.264 clip with a cc_data SEI on every access unit, a complete pop-on caption every 2 s held inside a single access unit so it survives B-frame reordering, and B-frames left on so the producer has a non-zero shift to get wrong. FFmpeg's own CEA-608 decoder reads the captions back out of it. The test compares the observer's timestamps against the source demuxer's for the same packets, and fails by exactly the shift without the fold. Reported by edde746, who traced the value flow and measured the shift magnitude from source without a caption-bearing clip on hand. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The A/53 caption observer was fed post-shift timestamps.
finalizeAndWriteVideoextracts the in-picturecc_datawell below the pump'spacket.pointee.pts -= activeShift, so the timestamps handed out were on the output(item) axis. Every consumer treats them as source PTS: the tap's cue buffer feeds
subtitleCues, and the host renders that againstcurrentTime, which foldsplaylistShiftSecondsback in. Net effect, every A/53 caption is displaced by theshift, and since the shift is recomputed per producer session, the displacement
changes after each seek.
The two sibling feeds were already correct: the demuxable c608 tap (#77) is handed its
packet before the rebase, and the software path reads decoded-frame side data where no
shift exists.
Fix
foldingShiftBackfolds the shift back at the observation site, mirroringsegmentIndex(forSourcePts:), which already does this before comparing againstsource-axis segment boundaries. NOPTS and an unresolved shift pass through.
Witness
No encoder emits A/53 from a synthetic source, so
Scripts/fetch-fixtures.shbuildsone: an H.264 clip with a
cc_dataSEI on every access unit, a complete pop-on captionevery 2 s held inside a single access unit (so it survives B-frame reordering), and
B-frames left on so the producer has a non-zero shift to get wrong. FFmpeg's own
CEA-608 decoder reads the captions back out of it.
Issue259A53CaptionAxisTestscompares the observer's timestamps against the sourcedemuxer's for the same packets. Before the fix it fails by exactly the playlist shift:
Full suite green (1329 tests), strict-concurrency build and tvOS Simulator build green.
Reported by @edde746.