Skip to content

A53/CEA-608 cue times are on the item axis but stored as container seconds #259

Open

Description

@edde746

What happened?

A53 / CEA-608 cues appear to be timed on the item (post-shift) axis while stored in a field documented as container seconds, which would displace them by playlistShiftSeconds.

HLSSegmentProducer.swift:2482   packet.pointee.pts -= activeShift      -> now ITEM axis
HLSSegmentProducer.swift:2862   observe(extracted, packet.pointee.pts, ...)
ClosedCaptions.swift:299        ingestA53(..., ptsSeconds: Double(pts) * scale, ...)
ClosedCaptions.swift:207        SubtitleCue(id: id, startTime: pts, ...)
PlayerState.swift:683           /// (start/end in container seconds)

The comment at HLSSegmentProducer.swift:2845-2846 says the timestamps are "still in the source time base", which is true of the units but not of the axis — the shift was subtracted upstream at :2482.

Magnitude measured on Fixtures/restart-witness-av.mp4: 83.3 ms, two frames at 24fps. Not a fixed constant — the shift is recomputed on every producer restart, so it would change after a seek.

One caveat on the evidence: the value flow is read from source and the shift magnitude is measured, but I have not reproduced the visible offset. The fixture carries no CEA-608, and provisionalDwell may mask it.

Steps to reproduce

  1. Play a source with embedded A53 / CEA-608 captions (H.264 or HEVC SEI) through the native path, so HLSVideoEngine remuxes it.
  2. Compare a cue's SubtitleCue.startTime against the source PTS of the picture it belongs to.
  3. Expect a discrepancy of playlistShiftSeconds; seek, and expect it to change.

Suggested regression witness: attach a53CaptionObserverForSession and assert the A53 pts matches the source axis rather than the post-shift one.

AetherEngine version or commit SHA

5098b39 (6.0.1)

Host app

Custom / my own integration

Platform

macOS

OS version

macOS 26.4

Device / chip

Apple M5 Pro

Playback path

Native (HLS remux → AVPlayer)

Source media

Fixtures/restart-witness-av.mp4 for the shift measurement (MP4 / H.264 High -bf 3 320x180 24fps / AAC mono / SDR BT.709). No A53-bearing source on hand.

Error codes / log lines

None — this is a timing discrepancy, not a failure. Found by reading the value flow and measuring the shift with swift test; the code path is platform-independent.

Activity

  1. superuser404notfound commented on Jul 30, 2026

    @superuser404notfound
    Owner

    Confirmed, and it does reproduce. Thanks for tracing this from source, the read was right at every step.

    The missing piece was a caption-bearing clip, so I built one. Scripts/fetch-fixtures.sh now injects user_data_registered_itu_t_t35 SEI into a synthetic H.264 clip: a cc_data on every access unit, plus a complete pop-on sequence every 2 s held inside a single access unit, so the caption is atomic there and survives B-frame reordering. FFmpeg's own CEA-608 decoder reads the captions back out of it, so the fixture is spec-correct rather than merely parser-compatible.

    Against that clip the observer's timestamps land exactly one shift off the source axis:

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

    Two frames at 24 fps, matching the magnitude you measured.

    On the provisionalDwell caveat: it does not mask this. The dwell only extends a cue's end, the start is still the displaced pts, and every cue in the buffer moves by the same amount, so the result is a shift rather than a smear.

    Fix is in #262. foldingShiftBack folds the shift back at the observation site, mirroring segmentIndex(forSourcePts:), which already does exactly that before comparing against the source-axis segment boundaries. Worth recording alongside it: both sibling feeds were already correct, which is why nothing pointed at this. The demuxable c608 tap gets its packet at the top of the read loop, before the rebase, and the software path reads decoded-frame side data where no shift exists at all. So the comment you flagged was accurate about the time base and wrong only about the axis.

    It also gets worse than the 83 ms on that clip. The shift is firstActualVideoDts - desiredFirstVideoTfdt, recomputed per producer session, so a restart landing off its planned keyframe has been measured in seconds, and a source whose first DTS is not near zero (broadcast MPEG-TS, the case the A/53 path exists for) carries it from the first packet.

    Will note the release here once it ships.

  2. added a commit that references this issue on Jul 30, 2026
  3. superuser404notfound commented on Jul 30, 2026

    @superuser404notfound
    Owner

    Shipped in 6.1.4 (80dd69c9, fix in 52e33b7c).

    The witness clip lives in Scripts/fetch-fixtures.sh as a53-captions.mp4 if it is useful on your side: Issue259A53CaptionAxisTests compares the observer's timestamps against the source demuxer's for the same packets, and the whole thing is one swift test away since the fixture generator only needs ffmpeg.

    Leaving this open for a retest against a real A/53 source, since everything on this end was measured on a synthetic one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions