Skip to content

feat: allow passing binary data directly to load()#937

Open
JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
JacobiusMakes:feat/allow-binary-load-config
Open

feat: allow passing binary data directly to load()#937
JacobiusMakes wants to merge 1 commit intoffmpegwasm:mainfrom
JacobiusMakes:feat/allow-binary-load-config

Conversation

@JacobiusMakes
Copy link
Copy Markdown

Summary

  • Adds coreData, wasmData, and workerData options to FFMessageLoadConfig accepting ArrayBuffer | Uint8Array | Blob
  • When binary data is provided, it takes precedence over the corresponding URL option and is converted to a Blob URL internally via URL.createObjectURL()
  • Zero changes to the web worker — binary data is transparently resolved to Blob URLs before being sent

Motivation

Closes #865

Environments like userscript extensions (Greasemonkey/Violentmonkey) can fetch WASM binaries via GM_xmlHttpRequest (which bypasses CORS), but cannot pass the result to ffmpeg.wasm because load() only accepts URL strings. This change lets callers pass pre-fetched binary content directly:

const wasmBinary = await GM_xmlHttpRequest({ url: WASM_CDN, responseType: 'arraybuffer' });

const ffmpeg = new FFmpeg();
await ffmpeg.load({
  coreURL: 'blob:...',       // or coreData
  wasmData: wasmBinary,      // ArrayBuffer, Uint8Array, or Blob
});

Implementation

The conversion happens in the main thread (classes.ts) before the config is sent to the worker via postMessage. A small toBlobURL helper creates a Blob URL from the binary data using the appropriate MIME type (text/javascript for core/worker JS, application/wasm for WASM). The worker receives plain URL strings as before, so no worker-side changes are needed.

Test plan

  • Verify existing URL-based load() still works (no regression)
  • Verify load({ wasmData: new Uint8Array(...) }) loads successfully
  • Verify load({ wasmData: new Blob([...]) }) loads successfully
  • Verify load({ coreData: ..., wasmData: ... }) with both binary options works
  • Verify binary data takes precedence when both wasmURL and wasmData are provided
  • TypeScript compilation passes with no errors

🤖 Generated with Claude Code

Add support for passing ArrayBuffer, Uint8Array, or Blob directly
to load() via new coreData, wasmData, and workerData config options.
When provided, binary data takes precedence over URL strings and is
converted to Blob URLs internally, enabling use cases where fetch is
unavailable (e.g. userscripts with CORS restrictions).

Closes ffmpegwasm#865

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

Deploy Preview for ffmpegwasm canceled.

Name Link
🔨 Latest commit ad665df
🔍 Latest deploy log https://app.netlify.com/projects/ffmpegwasm/deploys/69c6130bfdedda0008d28f1c

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.

Provide a way to pass the WASM and Core file content directly to the library instead of URLs.

1 participant