Shipping a client-side video-to-MP3 converter with ffmpeg.wasm feels magical on a desktop development machine: drop a 600 MB .mov clip into Chrome, pass -vn -codec:a libmp3lame, and get a crisp MP3 in seconds with zero server bandwidth.
Then real users arrive on iPhone Safari—where Apple's QuickTime .mov format actually originates—and hit a hard wall:
ReferenceError: SharedArrayBuffer is not defined Here is the production architecture we used to keep multi-threaded ffmpeg.wasm blazing fast on desktop while seamlessly supporting iOS Safari and mobile browsers with zero server uploads.
1. Use credentialless COEP So Analytics & CDNs Don't Break
Multi-threaded WebAssembly (pthread) requires cross-origin isolation to unlock SharedArrayBuffer. Most tutorials tell you to set Cross-Origin-Embedder-Policy: require-corp, which immediately breaks third-party scripts or CDN assets that lack explicit Cross-Origin-Resource-Policy headers.
On Chromium and Firefox, credentialless enables SharedArrayBuffer while still permitting standard cross-origin <script> requests:
/* Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: credentialless X-Content-Type-Options: nosniff 2. Detecting Missing SharedArrayBuffer & Falling Back to Web Audio + LAME
Because mobile WebKit still restricts credentialless isolation on many iOS builds, checking typeof SharedArrayBuffer !== "undefined" at runtime lets you route desktop users to ffmpeg.wasm (which handles Matroska .mkv, .webm, and ProRes) while routing iOS Safari users to hardware-accelerated AudioContext.decodeAudioData() + chunked lamejs:
function hasSharedArrayBuffer() { try { return typeof SharedArrayBuffer !== "undefined"; } catch { return false; } } async function decodeAndEncodeMp3Fallback(file, kbps = 192, onProgress) { const arrayBuffer = await file.arrayBuffer(); const AudioCtx = window.AudioContext || window.webkitAudioContext; const ctx = new AudioCtx(); const audioBuffer = await ctx.decodeAudioData(arrayBuffer); await ctx.close(); const channels = Math.min(2, audioBuffer.numberOfChannels); const encoder = new window.lamejs.Mp3Encoder(channels, audioBuffer.sampleRate, kbps); const left = audioBuffer.getChannelData(0); const right = channels > 1 ? audioBuffer.getChannelData(1) : left; const chunkSize = 1152 * 32; const chunks = []; for (let i = 0; i < audioBuffer.length; i += chunkSize) { const len = Math.min(chunkSize, audioBuffer.length - i); const l16 = floatTo16BitPCM(left, i, len); const r16 = channels > 1 ? floatTo16BitPCM(right, i, len) : null; const mp3buf = channels > 1 ? encoder.encodeBuffer(l16, r16) : encoder.encodeBuffer(l16); if (mp3buf.length > 0) chunks.push(mp3buf); onProgress?.(Math.round(((i + len) / audioBuffer.length) * 100)); // Yield to the main thread so mobile Safari's progress bar stays smooth! await new Promise((r) => setTimeout(r, 0)); } const flush = encoder.flush(); if (flush.length > 0) chunks.push(flush); return new Blob(chunks, { type: "audio/mpeg" }); } function floatTo16BitPCM(float32, offset, length) { const out = new Int16Array(length); for (let i = 0; i < length; i++) { const s = Math.max(-1, Math.min(1, float32[offset + i])); out[i] = s < 0 ? s * 0x8000 : s * 0x7fff; } return out; } Notice the await new Promise((r) => setTimeout(r, 0)) inside the 1152 * 32 MP3 frame loop: yielding every ~0.8 seconds of audio prevents iOS Safari's watchdog from killing the tab on 10-minute Camera Roll videos and keeps the progress bar fluid. You can test both engines live on movtomp3.com or directly in mobile Safari on the iPhone Video to MP3 Converter.
3. Writing Zero-Dependency 16-Bit RIFF/WAV Headers in 25 Lines
When users extract audio for Premiere Pro, DaVinci Resolve, or Logic Pro, lossy MP3 introduces an unnecessary generation of compression. Packing a standard 44-byte RIFF WAVE header around interleaved 16-bit PCM takes zero external libraries:
export function audioBufferToWavBlob(audioBuffer) { const numCh = Math.min(2, audioBuffer.numberOfChannels); const sr = audioBuffer.sampleRate; const frames = audioBuffer.length; const blockAlign = numCh * 2; const buf = new ArrayBuffer(44 + frames * blockAlign); const view = new DataView(buf); const writeAscii = (off, str) => { for (let i = 0; i < str.length; i++) view.setUint8(off + i, str.charCodeAt(i)); }; writeAscii(0, "RIFF"); view.setUint32(4, 36 + frames * blockAlign, true); writeAscii(8, "WAVE"); writeAscii(12, "fmt "); view.setUint32(16, 16, true); view.setUint16(20, 1, true); // PCM = 1 view.setUint16(22, numCh, true); view.setUint32(24, sr, true); view.setUint32(28, sr * blockAlign, true); view.setUint16(32, blockAlign, true); view.setUint16(34, 16, true); // 16-bit writeAscii(36, "data"); view.setUint32(40, frames * blockAlign, true); let offset = 44; for (let i = 0; i < frames; i++) { for (let c = 0; c < numCh; c++) { const s = Math.max(-1, Math.min(1, audioBuffer.getChannelData(c)[i])); view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true); offset += 2; } } return new Blob([buf], { type: "audio/wav" }); } Key Takeaways
- Always pass
-vntoffmpeg.wasmwhen extracting audio—skipping H.264/HEVC video decoding makes extraction 8–15x faster on Mac/Windows screen recordings and OBS.mkvcaptures. - Pair
COEP: credentiallesswith a chunkedAudioContext+lamejsfallback so Safari and mobile visitors get real local conversion instead of an error banner. - Revoke temporary
URL.createObjectURL(blob)handles when the user resets the queue so multi-file sessions don't leak browser RAM.


