feat(mp4): add the rsot box for redundant sample original timing - #589
Merged
Merged
Conversation
ISO/IEC 14496-12:2026 Section 8.8.18 adds the RedundantSampleOriginalTimingBox, a traf child that documents that the first sample of a track fragment is a copy of the previous sample and how long that sample has already been presented, and that the fragment's last sample was truncated to fit the fragment and how long it was meant to last. Its NOTE 1 names the case it is meant for: adaptive streaming where fixed-duration segments are not aligned with variable frame rate media such as text, so a cue that spans a boundary is restated as a duplicated redundant sample. With rsot_elapsed_duration set, that first sample shall carry sample_depends_on=2 and sample_has_redundancy=1, and a receiver that already has the previous sample extends it rather than presenting the copy again. Both durations are optional and independent, so the box size follows from the flags; decode rejects any other size rather than reading as far as it goes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Adds the Redundant Sample Original Timing Box (
rsot), new in ISO/IEC 14496-12:2026§8.8.18, as a
trafchild.What it is
It documents two things about the edges of a track fragment:
elapsed_duration(flag0x2) — the first sample of the fragment is a copy of theprevious sample, and has already been presented for this long. A receiver that already
has the previous sample extends that sample by this one's duration and ignores
elapsed_duration; one that tunes in here instead presents it as if it had already runfor
elapsed_duration. When this flag is set, that first sample shall carrysample_depends_on = 2andsample_has_redundancy = 1.original_duration(flag0x1) — the last sample of the fragment was truncated torespect fragmentation constraints, and was originally authored this long.
The spec's NOTE 1 names the case it exists for: "In adaptive streaming context where media
segments of fixed duration are not aligned with variable frame rate media such as text,
possible duplicated redundant samples may happen at segment boundaries." That is the
subtitle-cue-across-a-chunk-boundary case — a
wvttcue orstppdocument restated in thenext fragment, where the container previously had no way to say "this is a continuation,
and it really runs until T".
API
Inforenders:Two decisions worth a look
CreateRsotBoxderives the flags from its non-zero arguments rather than taking aseparate flags argument. §8.8.18.3 says a signalled duration "shall be different from
0", so zero cannot mean anything else, and this makes an inconsistent flags/field pair
unconstructible. Both zero gives a legal 12-byte box with no flags set.
Decode rejects a box whose size does not match its flags. Since both fields are
optional and independent, the size follows exactly from the flags once they are read, so
any other size means a malformed box. Without the check a truncated
rsotdecodedsilently with a zeroed duration. This follows the
clliconvention(
invalid box size %d) rather thantfhd, which does no size check.Files
mp4/rsot.goRsotBoxwith the fullBoxinterface,DecodeRsot/DecodeRsotSR,CreateRsotBox,HasOriginalDuration,HasElapsedDurationmp4/box.go,mp4/boxsr.go"rsot"indecodersanddecodersSRmp4/traf.goTrafBox.Rsotplus theAddChildcasemp4/rsot_test.goboxDiffAfterEncodeAndDecode, byte-exact hex goldens,changeBoxSizeAndAssertError, and atrafround trip checking the named linkCHANGELOG.mdFollows the "How to implement a new box" guide in the README.
go test ./...,gofmtandgolangci-lintare clean.🤖 Generated with Claude Code