Skip to content

fix(captions): put A/53 caption timestamps back on the source axis (#259) - #262

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/issue259-a53-source-axis
Jul 30, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/issue259-a53-source-axis

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

What

The A/53 caption observer was fed post-shift timestamps.

finalizeAndWriteVideo extracts the in-picture cc_data well below the pump's
packet.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 against currentTime, which folds
playlistShiftSeconds back in. Net effect, every A/53 caption is displaced by the
shift, 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

foldingShiftBack folds the shift back at the observation site, mirroring
segmentIndex(forSourcePts:), which already does this before comparing against
source-axis segment boundaries. NOPTS and an unresolved shift pass through.

Witness

No encoder emits A/53 from a synthetic source, so Scripts/fetch-fixtures.sh builds
one: 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.

Issue259A53CaptionAxisTests compares the observer's timestamps against the source
demuxer's for the same packets. Before the fix it fails by exactly the playlist shift:

observed [0, 512, 1024, 1536] expected [-1024, -512, 0, 512]
off the source axis by up to 0.083s (playlist shift -0.083s)

Full suite green (1329 tests), strict-concurrency build and tvOS Simulator build green.

Reported by @edde746.

)

`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
@superuser404notfound
superuser404notfound merged commit c67000e into main Jul 30, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/issue259-a53-source-axis branch July 30, 2026 17:43
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.

1 participant