Skip to content

fix(recording): the recording's zero is the lowest timestamp, not the arming keyframe (#560, #574) - #577

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/recording-origin-muxer-rebase
Sep 20, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/recording-origin-muxer-rebase

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Follow-up to #574, which is merged.

#574 latches the origin from the first packet written and subtracts it from every stream. That packet is the arming video keyframe, and an MPEG-TS interleaves the audio belonging to a picture ahead of the picture itself, so those audio packets carry timestamps EARLIER than the origin and have to be clamped to stay non-negative.

Measured on a source whose audio led by 100 ms: four AC-3 frames came out stamped at instant zero while the picture sat at zero as well, so the head of the recording lost exactly the offset the rebase exists to preserve.

The change

The muxer already does this, and correctly. avoid_negative_ts=make_zero peeks into the interleaving queue for the LOWEST timestamp across every stream, latches one offset from it and applies that same offset to all streams for the rest of the file. Nothing is clamped, the file still begins at zero, and the hand-rolled origin arithmetic goes away with it (53 lines).

Test plan

  • swift test, 3166 tests green including two new ones, end-to-end on the written file rather than on the arithmetic:
  • Timestamps also verified straight out of the TS PES headers, demuxer independent: audio at 0, 2880, 5760, ... and the picture at 9000, which is the source's own spacing.

🤖 Generated with Claude Code

https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F

… arming keyframe (#560, #574)

#574 rebased a recording onto zero by latching the origin from the first packet written and
subtracting it from every stream. That packet is the arming video keyframe, and a TS interleaves
the audio belonging to a picture ahead of the picture itself, so those audio packets are earlier
than the origin and have to be clamped to stay non-negative.

Measured on a source whose audio led by 100 ms: four AC-3 frames came out stamped at instant zero
while the picture sat at zero as well, so the head of the recording lost exactly the offset the
rebase is meant to preserve.

The muxer already does this correctly. `avoid_negative_ts=make_zero` peeks into the interleaving
queue for the lowest timestamp across every stream, latches one offset from it and applies that
same offset to all streams for the rest of the file. Nothing is clamped, the file still begins at
zero, and the hand-rolled origin arithmetic goes away with it.

The two unit tests are end-to-end on the written file rather than on the arithmetic: one records a
channel whose clock stands at 24549.835 s and reads the first timestamp back as zero, the other
records audio leading the arming keyframe by 100 ms and reads that lead back intact. The second
one fails on #574 as merged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F
@superuser404notfound
superuser404notfound merged commit bba7efa into main Sep 20, 2026
7 checks passed
@superuser404notfound
superuser404notfound deleted the fix/recording-origin-muxer-rebase branch September 30, 2026 21:22
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