Skip to content

media: preserve Matroska presentation duration - #4032

Merged
dylanmtaylor merged 1 commit into
storytold:mainfrom
Terra854:fix/matroska-presentation-duration
Nov 21, 2026
Merged

dylanmtaylor merged 1 commit into
storytold:mainfrom
Terra854:fix/matroska-presentation-duration

Conversation

@Terra854

@Terra854 Terra854 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Matroska clips without a declared duration keep their full presentation interval when pictures are stored out of display order.

Part of storytold/craft-libs#778 and storytold/craft-libs#781. Scoped claim

The shared reader indexes blocks in coding order. When Segment Duration was absent, EffectCraft used the end of the last indexed block, which can be earlier than the end of a reference picture. Take the maximum sample end for the selected track and keep the existing precedence for valid declared duration. RFC 9559, Duration and coding order · Cluster Blocks

matroska_duration_follows_presentation_order generates an H.264 Matroska clip with timestamp order 0, 80, 40 ms. The public probe returned 80 ms before the fix. It now returns 120 ms without the declaration, honors a distinct declared value when present, and the last presented picture decodes at 80 ms.

Verification

Summary by CodeRabbit

  • Bug Fixes
    • Matroska duration is now inferred from the latest presentation time across all samples, improving duration reporting for videos with reordered frames.
    • When no duration is declared, retrieving the final presented picture now works correctly.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

matroska_duration now infers duration from the greatest presentation end across all samples. A Matroska regression test covers declared duration precedence and B-frame presentation ordering.

Changes: Matroska duration inference

Layer / File(s) Summary
Duration inference and regression test
crates/media/src/craft_source.rs
matroska_duration uses the greatest pts + duration across samples. The regression test checks declared duration precedence, inferred duration with H.264 B-frames, and retrieval of the final presented frame.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: dylanmtaylor, fredapps

Merge Risk: Minimal · up to 705a8

Matroska clips without a declared duration now report their full presentation length when pictures are stored out of display order. Declared durations keep their precedence. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "media: preserve Matroska presentation duration" matches the main change. The raw summary says matroska_duration now uses the maximum presentation end across samples instead of the last samp…
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.
Full details: Title check

Explanation

The title "media: preserve Matroska presentation duration" matches the main change. The raw summary says matroska_duration now uses the maximum presentation end across samples instead of the last sample in coding order, and the objectives say the PR takes the maximum sample end when no valid duration is declared. The title names the affected format and the affected value. It is specific and short, and it does not describe the code change in detail, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.1)

Clippy execution timed out
Clippy (1.99.1) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5f435d4 and 705a84d.

Files selected for processing: 1

  • crates/media/src/craft_source.rs

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

@dylanmtaylor
dylanmtaylor merged commit 8bc329a into storytold:main Nov 21, 2026
10 checks passed
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.

2 participants