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

Chromium 158, @ffmpeg/ffmpeg 0.12.15 with @ffmpeg/core-mt 0.12.10, no COOP or COEP
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

What we ran in Chromium 158
SetupHeadersResult
0.12.15 with core-mt 0.12.10NoneReferenceError: SharedArrayBuffer is not defined
0.11.6 with core 0.11.0NoneThe same ReferenceError
0.12.15 with core-mtCOOP or COEP aloneThe same ReferenceError
0.12.15 with core-mt, default threadsCOOP and COEPLoaded, exec not done after 60 s
0.12.15 with core-mt, -threads 4COOP and COEPDone in about 6 s
0.12.15 with core 0.12.10, one threadNoneDone 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.

vite.config.js
export default {
  server: {
    headers: {
      "Cross-Origin-Opener-Policy": "same-origin",
      "Cross-Origin-Embedder-Policy": "require-corp",
    },
  },
};
server.mjs
// 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");
load.js
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.

convert.mjsTry it
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();
The same 2-second cut and scale on the API, at 720x406.Input: landscape.mp4

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.

Ready to build?

Ship video from your app today

Your first $0.50 is free, and one key covers every endpoint.

Moonlit lake with a lit cabin under the mountains