Skip to content

Stream MP4 exports directly to disk - #79

Merged
blixvip merged 1 commit into
blixvip:mainfrom
Aaqibhafeezkhan:issue-34-stream-mp4-to-disk
Nov 17, 2026
Merged

blixvip merged 1 commit into
blixvip:mainfrom
Aaqibhafeezkhan:issue-34-stream-mp4-to-disk

Conversation

@Aaqibhafeezkhan

Copy link
Copy Markdown
Contributor

Summary

Streams exported MP4 files directly to disk using the File System Access API, avoiding the need to hold the complete encoded video in memory.

Changes

  • Uses showSaveFilePicker() to select the output destination before rendering.
  • Integrates the existing FileSystemWritableFileStreamTarget from mp4-muxer.
  • Uses non-fast-start muxing for disk-based exports.
  • Closes the writable stream after finalization.
  • Preserves the existing ArrayBuffer download fallback.
  • Handles save-dialog cancellation and aborts failed writes.
  • Adds regression tests for streaming, fallback and cancellation behavior.

Existing export settings and audio/video encoding remain unchanged.

Closes #34

@Aaqibhafeezkhan Aaqibhafeezkhan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Uses the existing vendored muxer capability.
  • Disk streaming avoids the complete MP4 ArrayBuffer.
  • Existing fallback retained.
  • Picker cancellation handled.
  • Writable stream closed after finalization.
  • Failed writes aborted.
  • Regression tests added.
  • Single focused commit.
  • Original files and unrelated changes preserved.

@blixvip

blixvip commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @Aaqibhafeez Khan, this is a clean way to get large exports off the tab's memory. Choosing the save location up front and streaming through FileSystemWritableFileStreamTarget means a long export no longer has to hold the whole MP4 in memory first.

npm test (52 passing) and npm run check both pass on this branch. A maintainer will take a closer look before anything is merged, because #34's done-when list needs a real Chrome run (tab memory on a long reference, output playing in VLC and QuickTime, and the download fallback), and the new tests check the source text rather than the export itself. We'll reply here.

@blixvip
blixvip merged commit 14f61fd into blixvip:main Nov 17, 2026
1 check passed
@blixvip

blixvip commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @Aaqibhafeezkhan, this is merged! Long exports no longer have to hold the whole MP4 in the tab: when the browser offers showSaveFilePicker, the muxer now streams straight into the chosen file, and the old in-memory download stays as the fallback.

I ran it in real Chrome against the 30 s showcase reference with the picker pointed at an Origin Private File System handle. The stream path wrote a 22.7 MB file with a clean ftyp / mdat / moov layout, the file loads and seeks in a <video> element with the right duration, the JS heap stayed flat during the render, cancelling the picker restores the Download button without pausing the preview, and the fallback path still produces a download. A failed write also aborted the pending file cleanly. Still to do on the owner's side: the VLC/QuickTime and Task Manager checks from #34, which need a desktop session.

Next step if you want another one: good first issue #30, "Move the export crop math into a module and test it directly" (#30). You've just been in exportPreview, so that one is right next door.

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.

Stream exported MP4s to disk instead of holding the whole file in memory

2 participants