Skip to content

fix(moq-mux): a TS export pads AAC to a rate its slots can carry - #9609

Merged
kixelated merged 5 commits into
mainfrom
quest/m1/ts-aac-export-rate
Nov 25, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m1/ts-aac-export-rate

Conversation

@kixelated

@kixelated kixelated commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/ts-aac-export-rate.md and deletes it.

Problem

moq export ts of an MPEG-TS AAC source packed as FFmpeg packs it by default (186 ms of AAC per PES, no nulls) failed with MPEG-TS output missed a decode deadline on PID 256 at 158726 b/s. Reproduced on main with the real binaries (just test ts --source <ffmpeg stereo 44.1 kHz 128 kb/s AAC>) and in process.

The quest guessed an undercounted rate estimate. It isn't one. The recorded rate (158.7 kb/s) is the audio's own packing with no spare, and the export cannot lay that audio in it:

  • An audio frame goes out no further ahead than its decoder buffer takes to fill at Rx (14 ms), which is under a 25 ms slot. So a slot carries a whole frame (3 packets) plus the PAT and PMT the grid repeats every 100 ms and a clock packet: 5 to 6 packets, 300 to 360 kb/s.
  • The schedule also held a PES that packs several frames to arrive whole by its first frame's decode time, so a short PES at the join followed by a full one needed a burst of several times the audio rate (500 kb/s measured).

Approach

  • schedule.rs: each packet of a packed PES is due at the decode time of the frame it starts in (Unit::decode_at/by_at), as the T-STD removes a frame at its own time. Occupancy is still gated per frame. Measured on the paced in-process export: the least working rate falls from about 500 kb/s to 300 kb/s.
  • export.rs: a catalog rate is raised to audio_floor, the slots' need from the catalog's AAC bitrates: a frame at twice the bitrate (variable-rate peaks), plus PAT, PMT and a clock packet per slot. The floor is bounded by each entry's decoder buffer and by the rate limit, since the catalog is untrusted. An explicit --mux-rate is still honored as given. The 128 kb/s source above now exports at 481 kb/s.

Impact

  • No public API or wire change. The --mux-rate help, Export::with_mux_rate docs and doc/bin/ts.md now say the recorded rate is raised for AAC.
  • Behavior: a padded export of AAC raises a catalog rate that is below the floor above (a mux rate in the PMT/PCR and the output bitrate rise to it). Other padded exports are unchanged.

Alternatives

  • Raise the rate on a miss, mid-stream. Rejected: the slot is already half laid when it fails, and it would revise the tables for every source that hits it.
  • Fall back to unpadded output when the recorded rate is too low. Rejected: it drops the CBR the recorded rate asks for.
  • A fixed worst-case floor from the decoder buffer (1.2 Mb/s for stereo AAC). Rejected: 8x the audio.

Validation

  • Reproduced on main: just test ts --source of FFmpeg stereo 44.1 kHz 128 kb/s AAC fails in the subscriber, "needed rate 211366 b/s" at 158726 b/s. On this head it passes every check, including the independent T-STD model (peak B fill 44%, no overflow or underflow, which checks the per-frame deadline) and TBsys/Bsys. just test ts, ts --full and ts --headroom pass.
  • New an_ffmpeg_aac_source_exports_with_default_settings feeds a 5 s FFmpeg-packed AAC fixture (test_data/ffmpeg_aac.ts) paced on its PCRs into the default export (500 ms delay, no rate given). It fails on main with the error above, and needs both changes: the floor alone fails at 481 kb/s, the deadline change alone at 159 kb/s.
  • Sweep (not committed): 30 sources (six AAC layouts from 32 to 192 kb/s, each cut at four start offsets). Floor at 1x frame size: 8 fail, 1.5x: 5, 2x: 0 fail.
  • just check passes on the final head (11,5xx tests); the review found assert_next_offline no longer blocks cargo test -p moq-mux on this base, so no local removal was needed for the last runs (earlier runs applied chore: run pre-0.22 recurring audits, fix moq-net fuzz build, and file blockers #9505's one-line removal locally, uncommitted).
  • Review round 1 findings fixed: hostile bitrate/sample-rate hints (floor bounded by the decoder buffer and the rate limit; tests the_aac_floor_*), and heap ranking by the next packet's deadline.

Overlap

  • moq-dev/moq#9551 (unpadded table slots, schedule.rs): no conflict, and it changes the unpadded path, which this does not touch.
  • moq-dev/moq#9561 (100 ms audio groups): ffmpeg's PES already spans over 100 ms, so TS AAC grouping is unchanged and the fix holds. Both edit revision_test.rs's reexport_frames and conflict there: it gains an opening argument there and a rate argument here, so whichever lands second keeps both.

Caused by

Decisions

Taken with no one to ask (afk), each with my recommendation, for review:

  • Floor applies to AAC only, and only with a catalog bitrate; an explicit --mux-rate is not floored (it fails loud as before). Recommendation: keep.
  • A 2x frame margin for variable-rate peaks (1x fails 8 of 30 sources). Recommendation: keep.
  • The floor and the per-frame deadline ship together, since each alone fails the test. Recommendation: keep.

Follow-ups

  • A padded TS export carries any audio at its recorded rate: other codecs and entries without a bitrate (added here). Open decision: size from the decoder buffer per codec, or from the first frames (recommended in its Plan).
  • Observed, not investigated: a padded in-process export at a rate far under the audio's (50 kb/s for 32 kb/s AAC, 30 s delay) never returned in 60 s instead of erroring.

Models

Size: S
Implementer: Claude Code, claude-sonnet-5-5, unknown effort (arm B)

🤖 Generated with Claude Code

(Written by Claude Sonnet 5.5)

Review

Rewritten by quest review after each round.

  • Head: c026292

  • Base: origin/main at 420b8dc

  • Risk: medium, If the default TS export's padding or packet scheduling is wrong, users exporting AAC TS sources with default settings get a different multiplex rate or a missed-deadline error, and only after the next release cut publishes it; a revert of this change undoes it fully. The exported container format and public API are unchanged (the `--mux-rate` override path is untouched and the catalog-rate path only gains a floor), so it is not a wire or format break, which keeps it out of high.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session c42d5ea7-7bcf-4e45-8674-96a96181d802

  • Reviewer: Codex, gpt-6.2-sol, medium effort

  • Session: 01a21400-b73a-75c1-a2d6-bc7dcdf4c358, round 2

  • Score: 10/10, The head is ready to land because the capped AAC floor keeps padding enabled when the recorded rate is valid.

  • Rounds: 3; first round 2 (high 1, medium 1); findings 2 (medium 2): fixed 2, refuted 0, open 0

  • Findings: none

  • The last round's findings, at ba2ff02:

    • Fixed: medium, rs/moq-mux/src/container/ts/export.rs:2457: Keep a valid recorded rate when the AAC floor exceeds the limit; The cap at `rs/moq-mux/src/container/ts/export.rs:129` keeps the maximum of the AAC floor and a valid recorded rate within the sanitizer’s accepted range at line 2462.

kixelated and others added 3 commits November 25, 2026 04:46
`moq export ts` of an MPEG-TS AAC source packed as FFmpeg packs it by default failed with
"MPEG-TS output missed a decode deadline". The source's recorded multiplex rate is its audio's
own, with no nulls, but the export sends a frame no more than a slot ahead and leads some slots
with the PAT, the PMT and a clock packet, so a slot has to carry all of them.

- A padded export raises a catalog rate to what its AAC entries' bitrates need per slot.
- A packed PES's later frames are due at their own decode times, not the first's, which they
  were held to whole.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…trate-less sources

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A TS AAC source exports to TS with default settings fix(moq-mux): a TS export pads AAC to a rate its slots can carry Nov 25, 2026
kixelated and others added 2 commits November 25, 2026 10:38
…ext packet

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 25, 2026 19:03
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 02fa2d55-323d-412e-b4d4-f3e3fa59a68a
Commits

Reviewing files that changed from the base of the PR and between 9ad7001 and c026292.

Files selected for processing: 10

  • doc/bin/ts.md
  • quest/m1/ts-aac-export-rate.md
  • quest/m2/ts-export-audio-rate.md
  • rs/moq-cli/src/args.rs
  • rs/moq-mux/src/container/ts/export.rs
  • rs/moq-mux/src/container/ts/export_test.rs
  • rs/moq-mux/src/container/ts/revision_test.rs
  • rs/moq-mux/src/container/ts/schedule.rs
  • rs/moq-mux/src/container/ts/test_data/README.md
  • rs/moq-mux/src/container/ts/test_data/ffmpeg_aac.ts
  • 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

@kixelated
kixelated added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 67ba1b6 Nov 25, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/ts-aac-export-rate branch November 25, 2026 19:31
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.

1 participant