Repository navigation
fix(recording): the recording's zero is the lowest timestamp, not the arming keyframe (#560, #574) - #577
Merged
Conversation
… 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
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.
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_zeropeeks 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:first[0] == lead-> 0 instead of 9000).🤖 Generated with Claude Code
https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F