Skip to content

fix(media-execution): tolerate AAC encoder delay in the final mux assertion - #298

Merged
rponeawa merged 1 commit into
hypit-ai:mainfrom
paulchen180616:fix/mux-aac-frame-tolerance
Sep 18, 2026
Merged

rponeawa merged 1 commit into
hypit-ai:mainfrom
paulchen180616:fix/mux-aac-frame-tolerance

Conversation

@paulchen180616

Copy link
Copy Markdown
Contributor

Closes #296.

The staged WAV is already asserted sample-exact a few lines earlier, so this assertion is about
what survives AAC. AAC cannot carry an arbitrary sample count: the encoder emits 1024-sample frames
and reports a priming delay that the MP4 muxer compensates with an edit list, so the presented span
lands a few samples away from the input.

Measured with ffmpeg 6.1 on a synthetic tone, independent of any project's material:

4,249,600 samples in -> 4,249,584 presented  (-16)
4,236,800 samples in -> 4,236,768 presented  (-32)

Padding the timeline to a whole number of AAC frames does not remove it, so this is not a
frame-alignment artifact and cannot be fixed upstream of the encoder.

Demanding exact equality therefore rejects every correct mux whose length is not a fixed point of
that round trip. The invariant AAC can actually hold is that no whole frame of audio went missing,
so the tolerance is one AAC frame rather than an arbitrary epsilon. Anything larger still means
genuine desync and still fails, and the message now reports the signed sample delta instead of
asserting a bare boolean.

pnpm check passes. pnpm test is unchanged by this commit; on this Windows machine
packages/cli/test/runtime-selection.test.ts fails identically on pristine v0.2.5, which looks
unrelated (8.3 short path vs process.cwd()).

🤖 Generated with Claude Code

…ertion

The staged WAV is already asserted sample-exact, so this assertion is about
what survives AAC. AAC cannot carry an arbitrary sample count: the encoder
emits 1024-sample frames and reports a priming delay that the MP4 muxer
compensates with an edit list, so the presented span lands a few samples away
from the input.

Measured with ffmpeg 6.1 on a synthetic tone, independent of any project's
material:

  4,249,600 samples in -> 4,249,584 presented  (-16)
  4,236,800 samples in -> 4,236,768 presented  (-32)

Padding the timeline to a whole number of AAC frames does not remove it, so
this is not a frame-alignment artifact and cannot be fixed upstream of the
encoder.

Demanding exact equality therefore rejects every correct mux whose length is
not a fixed point of that round trip. A real 88.5s vertical ad failed at step
54/55 this way with all generated material already paid for and stored.

The invariant AAC can actually hold is that no whole frame of audio went
missing, so the tolerance is one AAC frame rather than an arbitrary epsilon.
Anything larger still means genuine desync and still fails, and the message
now reports the signed sample delta instead of asserting a bare boolean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@rponeawa
rponeawa merged commit 5a367dd into hypit-ai:main Sep 18, 2026
4 checks passed
@rponeawa rponeawa mentioned this pull request Sep 18, 2026
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.

Final mux assertion rejects every correct mux: AAC cannot preserve an exact sample count

2 participants