Skip to content

media: include the final AAC transport packet in duration - #4033

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

dylanmtaylor merged 1 commit into
storytold:mainfrom
Terra854:fix/adts-audio-duration

Conversation

@Terra854

@Terra854 Terra854 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Audio-only AAC transport streams now include the final packet’s playable samples in the reported clip duration.

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

The shared MPEG route used the last audio PTS as the clip end. ADTS packet positions already use the rebased native audio clock, including gaps. For audio-only transport streams with a fixed AAC ADTS packet length established during open, include the end of that span in the duration calculation. The change reuses the existing sample index and reads no additional packets.

adts_transport_duration_includes_the_final_packet generates contiguous and gapped streams with a nonzero PTS origin. The old probe ended the contiguous clip at 2,048 samples. It now reports 3,072 samples, includes the later gap in the gapped case, and the final packet decodes to audible samples.

Verification

Summary by CodeRabbit

  • Bug Fixes
    • Improved duration reporting for audio-only MPEG-TS sources with ADTS AAC, including playback through the final audio packet.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Audio track entries now store an optional fixed packet sample count. For audio-only MPEG-TS sources, finish_container_source extends duration through the final ADTS AAC packet. A test checks playback and reported duration for two possible final-packet timestamps.

Changes: ADTS AAC duration handling

Layer / File(s) Summary
Track packet metadata and end-time calculation
crates/media/src/craft_source.rs
Audio track entries store optional fixed packet sample counts. The ADTS AAC end-time calculation uses packet start times and the fixed sample count. The MXF PCM initializer sets the field to None.
MPEG-TS duration extension and validation
crates/media/src/craft_source.rs
Audio-only MPEG-TS sources extend duration through the latest ADTS AAC track end. A test checks playback and reported duration for two possible final-packet timestamps.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Change: Bug fix

Suggested reviewers: dylanmtaylor, fredapps

Merge Risk: Minimal · up to 069cc

This change makes the reported duration of audio-only AAC transport streams include the final packet's playable samples. Other sources keep their existing duration calculation. No merge-blocking risk was identified.

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: include the final AAC transport packet in duration" matches the main change. The summary says finish_container_source now extends duration for audio-only MPEG-TS ADTS AAC sources to …
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: include the final AAC transport packet in duration" matches the main change. The summary says finish_container_source now extends duration for audio-only MPEG-TS ADTS AAC sources to the end of the final packet, and the objectives describe the same fix. The title is specific and concise, and it names the affected component (media) and the change.

Finishing Touches

Generate unit tests (beta)

  • 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

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 775b157 and 069cc9d.

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 4e97ebe 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