Fix fMP4 zero-duration samples#1933
Conversation
Treat explicit zero MP4 sample durations as unknown during fMP4 decode/import, then infer missing export durations from a successor frame when PTS order is monotonic. Also include formatter output required by just check. Co-Authored-By: OpenAI Codex <codex@openai.com>
Run just fix after the fMP4 zero-duration fix and keep the markdown formatter output. Co-Authored-By: OpenAI Codex <codex@openai.com>
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
infer_missing_durations/pts_monotoniclogic disables PTS-based inference for the whole fragment if any timestamp pair is out of order; consider scoping monotonicity to local neighbors so well-behaved regions still benefit from PTS-derived durations. - In the fMP4 import path, treating zero durations as
Noneand erroring on any non-final sample with missing duration (MissingSampleDuration) changes behavior; if certain inputs intentionally use zero-length samples mid-fragment, it may be useful to handle them explicitly or surface a more descriptive error to distinguish malformed from intentional gaps.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `infer_missing_durations`/`pts_monotonic` logic disables PTS-based inference for the whole fragment if any timestamp pair is out of order; consider scoping monotonicity to local neighbors so well-behaved regions still benefit from PTS-derived durations.
- In the fMP4 import path, treating zero durations as `None` and erroring on any non-final sample with missing duration (`MissingSampleDuration`) changes behavior; if certain inputs intentionally use zero-length samples mid-fragment, it may be useful to handle them explicitly or surface a more descriptive error to distinguish malformed from intentional gaps.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
WalkthroughThe pull request adds missing/zero sample duration inference to the fMP4 pipeline in 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@js/watch/README.md`:
- Line 73: The Markdown table row for the `visible` option is being split into
too many columns because the pipe characters inside the value list are
interpreted as delimiters. Update the `visible` row in the README table so the
values are escaped or otherwise rendered as a single cell, keeping the table
consistent with the 4-column layout used by the surrounding rows.
In `@rs/moq-mux/src/container/fmp4/import.rs`:
- Around line 569-579: The duration normalization in the fMP4 import path is
dropping explicit zero values in a way that can fall back to inherited non-zero
defaults. Update the logic in the import routine that mutates
`traf_mut.tfhd.default_sample_duration` and each `trun_mut.entries` duration so
zero is only cleared when no non-zero `trex`/`tfhd` default can apply, or
resolve inherited durations first before removing the override. Keep the fix
localized to the import flow that handles `traf_mut`, `tfhd`, and `trun_mut`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4a54ca79-3fc5-485c-862f-750b7fc2d0d2
📒 Files selected for processing (27)
.github/justfiledemo/boy/justfiledemo/justfiledemo/pub/justfiledemo/relay/justfiledemo/sub/justfiledemo/web/justfiledoc/bin/cli.mdflake.nixgo/justfileinfra/apt/justfileinfra/justfileinfra/rpm/justfilejs/CLAUDE.mdjs/justfilejs/watch/README.mdjustfilekt/justfilenix/modules/moq-relay.nixpy/justfilers/CLAUDE.mdrs/justfilers/moq-mux/src/container/fmp4/export.rsrs/moq-mux/src/container/fmp4/import.rsrs/moq-mux/src/container/fmp4/mod.rsswift/justfiletest/justfile
| if traf_mut.tfhd.default_sample_duration == Some(0) { | ||
| traf_mut.tfhd.default_sample_duration = None; | ||
| } | ||
| for trun_mut in &mut traf_mut.trun { | ||
| // Reserve the data_offset field; the real value is filled in below. | ||
| trun_mut.data_offset = Some(0); | ||
| for entry in &mut trun_mut.entries { | ||
| if entry.duration == Some(0) { | ||
| entry.duration = None; | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Avoid letting defaults replace an explicit zero duration.
Clearing tfhd.default_sample_duration == Some(0) or entry.duration == Some(0) can expose a non-zero fallback default from trex/tfhd, so a sample that import treated as “missing duration” may be republished with a real duration. Only strip the zero when no non-zero default can apply, or materialize inherited durations before removing the zero override.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rs/moq-mux/src/container/fmp4/import.rs` around lines 569 - 579, The duration
normalization in the fMP4 import path is dropping explicit zero values in a way
that can fall back to inherited non-zero defaults. Update the logic in the
import routine that mutates `traf_mut.tfhd.default_sample_duration` and each
`trun_mut.entries` duration so zero is only cleared when no non-zero
`trex`/`tfhd` default can apply, or resolve inherited durations first before
removing the override. Keep the fix localized to the import flow that handles
`traf_mut`, `tfhd`, and `trun_mut`.
Run nixfmt from the Nix dev shell so flake.nix and nix/modules/moq-relay.nix match the formatter used by just ci. Co-Authored-By: OpenAI Codex <codex@openai.com>
Restore the justfile, Nix, and markdown formatter churn so the PR diff only contains the fMP4 zero-duration fix. Co-Authored-By: OpenAI Codex <codex@openai.com>
Summary
Tests
(Written by Codex)