Skip to content

fix(mux): share fMP4 sample resolution - #6864

Merged
kixelated merged 8 commits into
mainfrom
quest/m1/cut-audit/fmp4-sample-resolver
Oct 27, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m1/cut-audit/fmp4-sample-resolver

Conversation

@kixelated

@kixelated kixelated commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

fMP4 import and CMAF decode resolve sample offsets separately and accept empty samples, so a fragment of zero-size samples costs output allocations and groups without owning any input bytes. Import also reads an absolute base_data_offset as mdat-relative.

This PR does not fully resolve the hostile-input issue. mp4-atom 0.16.2 still materializes one TrunEntry per sample for a field-less trun (up to 4096 per run, so ~4.1 million entries from a 16 KB moof) before the resolver sees it. That parser allocation stays open until the counted representation lands in kixelated/mp4-atom, is released, and is adopted here; the rewritten quest quest/m1/cut-audit/fmp4-sample-resolver.md tracks exactly that.

Approach

  • One lazy resolver (sample::Resolver) validates nonempty, in-bounds, disjoint sample ranges and non-final durations for media import, subtitle import, and CMAF decode, without allocating from the sample count.
  • Output is allocated only after each sample validates; bytes are claimed before edit lists drop samples.
  • Boxes between moof and mdat are counted, across input chunks. CMAF decode now slices disjoint runs in decode order instead of requiring contiguous runs.
  • An absolute base_data_offset is refused with a typed error. ffmpeg's -movflags cmaf already implies default_base_moof (checked: tfhd flags 0x2003a), so the repo's ffmpeg pipelines are unaffected.

Impact

  • Public API: adds fmp4::Error::EmptySample and UnsupportedBaseDataOffset to the non-exhaustive error enum. No signature changes.
  • MoQ wire: unchanged. Empty media samples and absolute file addressing are refused on input.

Choices made

  • ✅ Land the shared resolver now; leave the counted trun representation, its mp4-atom release, and adoption here to the quest (maintainer, this session).
  • ✅ Counted representation over refusal upstream: kixelated/mp4-atom#248 refuses field-less runs and breaks the valid AV1, BBB, and ESDS fixtures.
  • ✅ Refuse absolute base_data_offset rather than track absolute source positions; supporting it would add source-seek state for no current consumer.

Validation

  • Baseline reproduction failed because empty samples were accepted; new tests cover empty samples (explicit and default sizes), absolute bases, out-of-range and overlapping offsets, decode-order runs, intervening boxes across 7-byte input chunks, and final-only missing durations.
  • Interleaved container benchmark extended to 1-byte samples across 1/4 tracks and 1/16 runs.
  • Merged latest main; just check passed in full (Rust check and Clippy, 4083 tests including 224 fMP4, markdown, shell, quest, and the other lint modules). The earlier build-wrapper failure did not recur.
  • quest check --base origin/main passed.

Follow-ups

  • Counted field-less trun entries: the remaining parser bound, in kixelated/mp4-atom, its 0.17.0 release, and adoption here (breaking through moq-mux's mp4_atom re-export).

(Written by Claude Opus 5.5)

kixelated and others added 2 commits October 25, 2026 22:51
Co-Authored-By: GPT-6 <noreply@openai.com>
@kixelated kixelated changed the title One fMP4 sample resolver for import and decode fix(mux): share fMP4 sample resolution Oct 26, 2026
kixelated and others added 2 commits October 25, 2026 23:14
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
@kixelated
kixelated marked this pull request as ready for review October 26, 2026 17:35
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cae7f099-241c-4efe-90c3-536c29703bac
Commits

Reviewing files that changed from the base of the PR and between baf4333 and aecd740.

Files selected for processing: 1
  • quest/m1/cut-audit/README.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

Walkthrough

The PR adds a shared fMP4 sample resolver that validates sample metadata and payload ranges. The importer tracks bytes from each moof, including intervening atoms. Import, decode, and text extraction use resolved samples. Tests cover empty samples, absolute base_data_offset values, malformed ranges, separated runs, and chunked input. Benchmarks cover one-byte and full-payload samples. Planning documents update the audit scope and related finding link.

Priority: Normal

Merge Risk: Minimal · up to aecd7

The reviewed change does not present an established merge-blocking risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description clearly explains the shared fMP4 sample resolver, validation changes, API impact, testing, and remaining parser limitation.
Title check Passed The title is concise and accurately identifies the main change: sharing fMP4 sample resolution in the mux component.
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T03:54:57.868961Z aecd740 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed e10f95ccde17d36cce8e566db2e0cf461379c9e2 against base 849aab9e8151f3f4e66b67485a51ae9c51d94221.

No new actionable findings. The shared lazy resolver is the right direction: all three readers validate and claim bytes before allocating output or applying edits, while import now accounts for intervening boxes across chunks. Explicitly refusing absolute addressing is simpler than introducing source-position state for unsupported inputs.

The already-documented field-less trun parser-allocation issue remains open; this bounds downstream output, not parsing. Keep the counted upstream representation/release/adoption follow-up separate rather than adding another local sample cap.

Verification: GitHub-only inspection of the diff, surrounding callers, and regression tests; no tests executed. The returned head-commit Check runs were skipped, so I have not independently verified the author's reported just check pass.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary for e10f95ccde17d36cce8e566db2e0cf461379c9e2:

  • Reviews on this head: Codex reacted with a thumbs up (no findings), and the automated OpenAI review reported no new actionable findings. No unresolved threads.
  • Required checks passed; only the optional CodeQL Rust analysis was still running.
  • quest check --base origin/main (base 802aa29d7f) passed: the PR rewrites quest/m1/cut-audit/fmp4-sample-resolver.md to the remaining counted trun work.
  • No changes made at merge time. The field-less trun parser allocation stays open and is tracked by that quest, as the description states.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 26, 2026
…p4-sample-resolver

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Requeue after merge_conflict: merged origin/main into the branch (baf4333). Only quest files conflicted: quest/m1/cut-audit/README.md keeps this PR's rewritten "Counted field-less trun entries" entry and drops the avc1 and element-teardown entries that main already finished; quest/m2/media-fuzz.md keeps this PR's link to the PR and main's unlinked avc1 wording. No code conflicts. just check passed in full (4091 tests) and quest check --base origin/main passed.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: aecd740b83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merged latest main (aecd740). Only quest/m1/cut-audit/README.md conflicted: rtmp-amf0-budget landed on main, so its Required entry is gone and this PR's rewritten fmp4-sample-resolver entry stays. just check passed in full (4117 tests; every selected lane ran, including toml), quest check --base origin/main passed, and Codex found no issues on this head. Landing.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 27, 2026
Merged via the queue into main with commit b13427f Oct 27, 2026
11 checks passed
@kixelated
kixelated deleted the quest/m1/cut-audit/fmp4-sample-resolver branch October 27, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant