Skip to content

fix: round mux duration to the PCM sample boundary - #339

Merged
rponeawa merged 1 commit into
hypit-ai:mainfrom
kapelame:fix/round-mux-sample-duration
Sep 23, 2026
Merged

rponeawa merged 1 commit into
hypit-ai:mainfrom
kapelame:fix/round-mux-sample-duration

Conversation

@kapelame

Copy link
Copy Markdown
Contributor

Fixes #338.

A valid 149-frame export at 30000/1001 fps finishes visual/audio rendering but fails in request-media-mux: its ideal duration is 238638.4 PCM samples, while the audio planner correctly produces 238638 integer samples. The producer's exact cross-product comparison rejects that required rounding before the local mux handler runs.

Reuse mediaFrameRangeSamples to enforce the existing rounded 48 kHz boundary used by audio planning, range rendering, and downstream mux validation. Audio that differs by even one sample is still rejected. This does not change AAC encoding or the post-mux handling fixed by #298 and #317.

Validation on macOS arm64, Node 24.19.0, FFmpeg 8.1.1:

  • New producer regression tests: 3 failures on the unchanged implementation; all pass with the fix. Cases cover 30 fps, 24000/1001, 30000/1001, 60000/1001, rounding both directions, and rejection of ±1 sample.
  • node --import tsx --test packages/media-pipeline/test/*.test.ts packages/media/test/frame-range.test.ts: 15 passed.
  • pnpm check: passed.
  • pnpm test: 1051 passed, 22 existing environment-gated tests skipped, 0 failed.
  • Actual local Chrome/FFmpeg Build: the same 149-frame authored preview fails before this change and exports successfully afterward; ffprobe confirms 149 frames at 30000/1001, and the complete MP4 decodes without errors.
  • Independent review additionally checked 70 valid rate/count combinations, rejection of 140 adjacent sample counts, invalid/overflow boundaries, and the exported file's complete decode.

The change is limited to the producer validation and its regression tests.

@rponeawa
rponeawa merged commit 59d5e29 into hypit-ai:main Sep 23, 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.

[Bug] NTSC exports fail before mux when PCM duration needs rounding

2 participants