ReferenceError: SharedArrayBuffer is not defined means the page isn't cross-origin isolated. Send COOP and COEP, load ffmpeg.wasm 0.12's single-thread core, or run native ffmpeg on ReelSDK for $0.02 per compute minute.
ReferenceError: SharedArrayBuffer is not defined
We reproduced it with @ffmpeg/ffmpeg 0.12 and 0.11 in Chromium 158. Two headers fixed it, the single-thread core avoided it, and ReelSDK ran the same 2-second cut in about 4 seconds, no WebAssembly needed.
ErrorsUpdated
crossOriginIsolated: false typeof SharedArrayBuffer: "undefined" Uncaught ReferenceError: SharedArrayBuffer is not defined
Source: MDN: SharedArrayBuffer security requirements, checked November 2026.
Where it shows up
In the browser, the moment ffmpeg.wasm loads
You load the multithreaded ffmpeg.wasm core in a page that is not cross-origin isolated. Our test: @ffmpeg/ffmpeg 0.12.15 with @ffmpeg/core-mt 0.12.10 in Chromium 158, from a plain local server. ffmpeg.load() rejected with ReferenceError: SharedArrayBuffer is not defined and nothing ran.
The older API fails the same way: @ffmpeg/ffmpeg 0.11.6 with @ffmpeg/core 0.11.0 threw the identical error from ffmpeg.load(). In both runs self.crossOriginIsolated was false and typeof SharedArrayBuffer was "undefined".
Why it happens
Browsers only give shared memory to isolated pages
The multithreaded build shares memory between Web Workers through SharedArrayBuffer. Shared memory was switched off at the start of 2018 because of Spectre, and came back only for pages that opt in. MDN puts the rule plainly: your document must be in a secure context and cross-origin isolated.
A page is isolated when its response carries Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp. We tried each header alone: crossOriginIsolated stayed false and the error stayed. Without both, the global is missing, so the core's first use of it throws.
Causes and fixes
What we ran in Chromium 158
| Setup | Headers | Result |
|---|---|---|
| 0.12.15 with core-mt 0.12.10 | None | ReferenceError: SharedArrayBuffer is not defined |
| 0.11.6 with core 0.11.0 | None | The same ReferenceError |
| 0.12.15 with core-mt | COOP or COEP alone | The same ReferenceError |
| 0.12.15 with core-mt, default threads | COOP and COEP | Loaded, exec not done after 60 s |
| 0.12.15 with core-mt, -threads 4 | COOP and COEP | Done in about 6 s |
| 0.12.15 with core 0.12.10, one thread | None | Done in about 9 s |
Source: MDN: SharedArrayBuffer security requirements, checked November 2026.
The local fix
Send COOP and COEP, or load the single-thread core
Send both headers with the page. With them added, crossOriginIsolated turned true and core-mt loaded; Vite does the same through server.headers. One catch on our 24-core machine: with default threads, exec had not finished after a minute, while -threads 4 did the job in about 6 seconds.
If you can't set headers, load the single-thread @ffmpeg/core, which never touches SharedArrayBuffer: with no headers at all it did the same job in about 9 seconds. Mind that COEP blocks cross-origin images, scripts and video that do not allow embedding through CORS or a Cross-Origin-Resource-Policy header.
export default {
server: {
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
},
};// any Node server: both headers on the page and its scripts
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");import { FFmpeg } from "@ffmpeg/ffmpeg";
import { fetchFile } from "@ffmpeg/util";
// core-mt needs cross-origin isolation, the single-thread core does not
const multi = self.crossOriginIsolated;
const base = `${location.origin}/node_modules/@ffmpeg/${multi ? "core-mt" : "core"}/dist/esm`;
const ffmpeg = new FFmpeg();
await ffmpeg.load({
coreURL: `${base}/ffmpeg-core.js`,
wasmURL: `${base}/ffmpeg-core.wasm`,
...(multi ? { workerURL: `${base}/ffmpeg-core.worker.js` } : {}),
});
await ffmpeg.writeFile("in.mp4", await fetchFile("/in.mp4"));
await ffmpeg.exec(["-i", "in.mp4", "-t", "2", "-vf", "scale=720:-2", ...(multi ? ["-threads", "4"] : []), "out.mp4"]);Skip the binary
Or skip WebAssembly and run it on the API
POST /v1/ffmpeg runs native ffmpeg 8.1 on a fresh machine per job, so the browser needs no headers and no 32 MB core download. The same cut and scale came back as a 720x406 out.mp4 in about 4 seconds.
Compute is $0.02 per minute, billed per second, so the job cost under a fifth of a cent. Call it from your backend, not the page, so your API key stays private.
const res = await fetch("https://api.reelsdk.com/v1/ffmpeg?wait=60", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.REELSDK_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
"inputs": {
"in.mp4": "https://api.reelsdk.com/f/lib/demo/landscape.mp4"
},
"args": ["-i", "in.mp4", "-t", "2", "-vf", "scale=720:-2", "out.mp4"],
"outputs": ["out.mp4"]
}),
});
const { job } = await res.json();Pick the core at runtime
You can keep one code path: check self.crossOriginIsolated and load core-mt only when it is true. In our runs that page used the single-thread core without headers and core-mt with them, and both wrote the 720x406 clip.
Expect WebAssembly to be slower than native either way. ffmpeg.wasm's FAQ says core-mt can be around 2x faster than one thread; native ffmpeg did the same cut in about 2 seconds on our machine, against about 6 for core-mt.
FAQ
Questions, answered
Do I need both COOP and COEP?
Yes. With Cross-Origin-Opener-Policy alone, or Cross-Origin-Embedder-Policy alone, crossOriginIsolated stayed false and the error stayed. Only both together made SharedArrayBuffer available.
Why does ffmpeg.wasm hang after I add the headers?
On our 24-core machine, core-mt with default threads had not finished after a minute, while -threads 4 finished in about 6 seconds. Pass an explicit -threads value to exec.
Can I avoid the headers entirely?
Yes: load @ffmpeg/core instead of @ffmpeg/core-mt. It runs on one thread and needs no SharedArrayBuffer; it did our 2-second job in about 9 seconds with no headers.
Is there a file size limit?
ffmpeg.wasm's FAQ puts the hard limit at 2 GB per input, a WebAssembly limit, and the browser has to download about 32 MB of core first. The API takes input files up to 500 MB each, 1 GB per job.
- Error: Cannot find module '@ffmpeg/core'@ffmpeg/ffmpeg 0.11 loads its WebAssembly core from a package it does not install. Add @ffmpeg/core@0.11.0, or skip WebAssembly in Node.
- Error: spawn ffmpeg ENOENTNode cannot find an ffmpeg program on PATH. Install it, spawn the ffmpeg-static path, or send the same args to an API.
- ReelSDK vs ffmpeg.wasmffmpeg.wasm took 52 to 79 s to turn a 10-second 1080p clip into 720p in Chromium. ReelSDK ran the same arguments in 8 s for under a fifth of a cent, with no 2 GB memory ceiling.
- FFmpeg onlineRun your own ffmpeg command on your files in the browser, free and without installing or uploading anything.
- Resize videoRender 9:16, 1:1, 4:5 and 16:9 copies of one video in a single ffmpeg call, about 2 cents for all 4 from a 30 s clip.
- ReelSDK vs self-hosted FFmpegTranscoding a minute of 1080p to 720p takes about 24 seconds of compute: about 0.8 cents on ReelSDK, about a tenth of a cent on a busy 4 vCPU box. Below about 11,000 minutes a month, the API costs less than an always-on box.
- Resize a video with ffmpegScale a video with scale=w:h: keep the aspect ratio with -2, fit a 1080x1920 frame with pad, and fix the odd-size error.
- ffmpeg exited with code 1: Conversion failed!fluent-ffmpeg reports only ffmpeg's exit code and last line. The real cause is in stderr: print it, or use -v error to see it alone.
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
