Skip to content

refactor(mux): streaming writes, memory reduction, and E2E test suite#508

Open
puemos wants to merge 2 commits intomasterfrom
feat/reduce-muxing-memory
Open

refactor(mux): streaming writes, memory reduction, and E2E test suite#508
puemos wants to merge 2 commits intomasterfrom
feat/reduce-muxing-memory

Conversation

@puemos
Copy link
Copy Markdown
Owner

@puemos puemos commented Mar 4, 2026

Summary

Muxing pipeline refactor

  • Sequential load-write-release in streamToMp4Blob: loads video data, writes to FFmpeg FS, releases, then does the same for audio — never holding both in memory simultaneously
  • Replaced Blob + fetchFile with direct Uint8Array writes to FFmpeg FS, eliminating a redundant full-size copy per media stream
  • Blob URL revocation via downloads.onChanged listener — frees output blob memory after download completes or is interrupted
  • Extracted writeMediaToFFmpegFS and muxExec from muxStreams for testability; muxStreams remains as a backward-compatible wrapper

Bug fixes

  • Data stream filtering (-map 0-map 0:v -map 0:a?) — prevents data/metadata streams from leaking into output (Save = 0 Bytes with 5.4.0 on Firefox #509)
  • -shortest only with separate video + audio — was previously always added, causing truncation on single-input muxes
  • Exit code checkingmuxExec now throws on non-zero ffmpeg exit codes with a descriptive message

Test suite

  • Unit tests (ffmpeg-muxer.test.ts): arg construction, cleanup, error handling for all mux paths
  • Integration tests (mux-pipeline.integration.test.ts): IndexedDB → FFmpeg mock pipeline with real TS fixtures
  • E2E tests (mux-pipeline-e2e.test.ts): real ffmpeg via host adapter, output verified by ffprobe snapshots (sha256, byte size, duration, codec, dimensions, channels, frame count). Auto-skips on CI. Output files saved to fixtures/e2e-output/ for manual inspection.

Closes #492 #509 #496
Related: #496, #204, #258, #509

Test plan

  • 102 tests passing across 13 test files
  • E2E: concat muxed v+a segments → MP4 (snapshot-verified)
  • E2E: separate video + audio → MP4 (snapshot-verified)
  • E2E: muxed-with-data-stream filtered → no data streams (Save = 0 Bytes with 5.4.0 on Firefox #509)
  • E2E: audio-only → AAC MP4 (snapshot-verified)
  • E2E: video + subtitles → MKV (snapshot-verified)
  • E2E: garbage input → rejects with error
  • E2E tests auto-skip on CI (no ffmpeg) — no CI breakage

puemos added 2 commits March 4, 2026 15:43
Sequential load-write-release pattern in streamToMp4Blob avoids holding
both video and audio buffers simultaneously. Replaced Blob+fetchFile
with direct Uint8Array writes to FFmpeg FS, eliminating redundant copies.
Added blob URL revocation via downloads.onChanged listener.
Replace the bash verify-muxing.sh with TypeScript E2E tests that call
the real writeMediaToFFmpegFS and muxExec through a host ffmpeg adapter,
producing real output files verified by ffprobe snapshots (sha256, size,
duration, stream details). Tests auto-skip on CI where ffmpeg is absent.
@puemos puemos changed the title perf: reduce memory during muxing/save phase perf: reduce muxing memory + E2E mux pipeline tests Mar 6, 2026
@puemos puemos changed the title perf: reduce muxing memory + E2E mux pipeline tests refactor(mux): streaming writes, memory reduction, and E2E test suite Mar 6, 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.

After the download has completed it uses too much of memory to perform muxing

1 participant