WebCodecs vs ffmpeg.wasm for video in the browser: speed, size, quality and the traps we hit

By Rundong LiPublished 12 min read

The short answer: on our test machine, transcoding 1080p video to 720p H.264 with WebCodecs took 10.5 seconds for five 20-second clips. ffmpeg.wasm took 199.4 seconds single-threaded and 49.2 seconds multithreaded. The WebCodecs stack is a 146 KB gzipped download; ffmpeg.wasm's core is 10.2 MB. The catch is quality: at the same file size, the hardware H.264 encoder Chrome used scored about 10 VMAF points below ffmpeg.wasm's x264, and it still trailed slightly at 2.5 times the bitrate.

We ran these tests while building the video tools on Pixohub, which process files on the visitor's device. The numbers below are from a clean rerun on 14 November 2026. The full harness, the clip list and every raw result are linked at the end so you can rerun it on your own hardware, which matters here: hardware encoders differ a lot between machines.

What we compared

  • WebCodecs via Mediabunny 1.62.1. Mediabunny demuxes and muxes in JavaScript and hands decoding and encoding to the browser's VideoDecoder and VideoEncoder. We ran it with Chrome's default (which picked the hardware H.264 encoder) and with hardwareAcceleration: "prefer-software".
  • ffmpeg.wasm 0.12.15 with @ffmpeg/core 0.12.10 (single-threaded) and @ffmpeg/core-mt 0.12.10 (multithreaded, 4 threads), encoding with libx264 -preset veryfast.
  • Native ffmpeg 9.0.2 on the same Mac, with libx264 veryfast and with Apple's h264_videotoolbox, as reference points.

The job was the same everywhere: scale 1080p to 1280 × 720, encode H.264 at a 2 Mbps target bitrate, copy the AAC audio, write MP4. The clips are five 20-second 1080p segments from Wikimedia Commons videos (all CC BY-SA 4.0): a street protest (25 fps), a macro shot of a snail (60 fps), an interview (30 fps), a screen recording (30 fps) and a folk dance (25 fps). The machine was an Apple M2 (8 cores, 24 GB) on macOS 26.5.2 with Chrome 157.0.8103.51, driven headless by Playwright 1.56.1.

Speed

Time to transcode each 20 s clip, 1080p → 720p H.264 at 2 Mbps. WebCodecs hardware and both ffmpeg.wasm columns are the median of 3 runs (runs varied by under 6%); software WebCodecs and native x264 ran once. ffmpeg.wasm times exclude loading the core (70–360 ms from localhost) but include copying the file in.
ClipWebCodecs (hardware)WebCodecs (software)ffmpeg.wasm MTffmpeg.wasm STNative x264
Protest, 25 fps1.6 s2.5 s9.6 s40.2 s2.5 s
Snail, 60 fps3.7 s3.7 s16.4 s66.7 s3.7 s
Interview, 30 fps1.9 s2.2 s9.6 s40.3 s2.4 s
Screen recording, 30 fps1.9 s1.8 s4.5 s15.1 s0.9 s
Folk dance, 25 fps1.5 s2.3 s9.2 s37.0 s2.1 s
Total10.5 s12.5 s49.2 s199.4 s11.5 s

WebCodecs was 19 times faster than single-threaded ffmpeg.wasm and 4.7 times faster than the multithreaded build. Multithreading made ffmpeg.wasm about 4 times faster than its single-threaded core, but it stayed several times slower than the same x264 preset running natively (49.2 s against 11.5 s in total). The browser's software H.264 path was nearly as fast as hardware here, because at 720p the decode and scale steps take a good share of the time.

File size and quality

All encoders landed close to the 2 Mbps target, so the files are about the same size and the quality difference is the encoder's. We scored every output with VMAF (libvmaf, model vmaf_v0.6.1) against its source, both scaled to 1920 × 1080.

Output size and VMAF (0–100, higher is better). The ffmpeg.wasm column is the single-threaded build; the multithreaded build produced files within 0.25% of the same size and VMAF within 0.15.
ClipWebCodecs (hardware)WebCodecs (software)ffmpeg.wasm (x264)Native x264Native VideoToolbox
Protest5.51 MB · 71.95.46 MB · 67.05.61 MB · 80.65.60 MB · 80.45.59 MB · 69.3
Snail5.53 MB · 79.15.41 MB · 77.35.48 MB · 86.05.45 MB · 85.85.66 MB · 68.2
Interview5.51 MB · 76.15.44 MB · 74.05.50 MB · 86.05.48 MB · 85.95.61 MB · 74.6
Screen recording1.11 MB · 82.20.94 MB · 81.81.36 MB · 88.01.36 MB · 88.02.58 MB · 87.3
Folk dance5.52 MB · 73.55.47 MB · 68.45.42 MB · 82.35.41 MB · 82.15.59 MB · 71.2
Median VMAF76.174.086.085.871.2

ffmpeg.wasm matched native x264 to within a fraction of a VMAF point, as it should: it is the same encoder compiled to WebAssembly, just slower. The WebCodecs outputs scored about 10 points lower at the same size. On a Mac, Chrome's hardware H.264 encoder is Apple's VideoToolbox, and native h264_videotoolbox scored in the same range (median 71.2), so this is the hardware encoder's rate control rather than something Mediabunny adds. Chrome's software path, which on macOS is OpenH264, was no better (74.0).

How much bitrate does WebCodecs need to catch up? We reran the hardware path at higher targets:

Hardware WebCodecs, same five clips. The screen recording stopped improving at 82.2 and stayed at about 1.15 MB however high the target went.
WebCodecs targetTypical file (20 s)Median VMAFvs ffmpeg.wasm at 2 Mbps (86.0)
2 Mbps5.5 MB76.1−9.9
3 Mbps8.0 MB81.0−5.0
4 Mbps10.5 MB82.7−3.3
5 Mbps13.0 MB84.2−1.8

So if your job is "make it as small as possible at a given quality", x264 still wins on this machine, by a margin you can measure in megabytes. If your job is "get this video under 25 MB quickly without uploading it", WebCodecs gets there in a couple of seconds where ffmpeg.wasm takes most of a minute. Hardware encoders on Windows (NVENC, Quick Sync, AMF) and on Android phones behave differently, so treat the quality gap as specific to Apple silicon until you've measured your own targets.

Download size

Sizes measured from the installed npm packages; gzip -9.
What the page loadsRawgzip
Mediabunny, transcode-only bundle (esbuild, minified)570 KB146 KB
@ffmpeg/ffmpeg wrapper + worker5.7 KB2.5 KB
@ffmpeg/core: ffmpeg-core.wasm + JS glue32.3 MB10.2 MB
@ffmpeg/core-mt: ffmpeg-core.wasm + JS glue + worker32.8 MB10.3 MB

The 70× difference matters twice: once for the visitor, who downloads 10 MB before anything happens, and once for hosting. Cloudflare Workers static assets are limited to 25 MiB per file, so the 32 MB .wasm can't be deployed next to the site there; you'd serve it from R2 or a CDN. Mediabunny is tree-shakable, so a page that only trims or extracts audio ships less than the figure above.

Big files and memory

The usual ffmpeg.wasm example reads the whole file into an ArrayBuffer and writes it into ffmpeg's in-memory file system. In desktop Chrome that worked for a 1.8 GB file, but a 2.7 GB file failed before ffmpeg saw it: File.arrayBuffer() threw "The requested file could not be read". ffmpeg.wasm 0.12 has a better option that many examples skip: mounting the picked file with WORKERFS, so ffmpeg reads it in place. That handled the 2.7 GB file without trouble:

await ff.createDir("/mnt");
await ff.mount("WORKERFS", { files: [file] }, "/mnt");
await ff.exec(["-i", `/mnt/${file.name}`, /* ... */ "out.mp4"]);

Mediabunny's BlobSource reads the input in slices by default, so input size isn't the limit there either. In both stacks the output is a different story: BufferTarget and ffmpeg's MEMFS keep the whole result in memory. For multi-gigabyte outputs, Mediabunny's StreamTarget can write to disk through the File System Access API. We haven't measured where phones give up.

Multithreaded ffmpeg.wasm needs COOP/COEP, and that blocks ads

@ffmpeg/core-mt uses SharedArrayBuffer, which browsers only expose to cross-origin isolated pages. That means serving the page with two headers:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp   # or: credentialless

Pixohub is funded by AdSense, so before choosing a stack we checked what isolation does to ads. We served a test page on localhost in each mode, loading the AdSense script and two ad frame URLs (with a dummy publisher id, so no real ad requests), and recorded what Chrome blocked:

Chrome 157, headless. Blocked frames failed with net::ERR_BLOCKED_BY_RESPONSE.
COEP modecrossOriginIsolatedadsbygoogle.jsAd frame (googleads.g.doubleclick.net)SafeFrame container<code>&lt;iframe credentialless&gt;</code>
NoneNoLoadsLoadsLoadsLoads
require-corpYesLoadsBlockedBlockedLoads
credentiallessYesLoadsBlockedBlockedLoads

The script itself is fine: it is served with Cross-Origin-Resource-Policy: cross-origin. The ad frames are not, because under COEP an embedded document must send its own COEP header, and Google's ad documents don't. An iframe with the credentialless attribute gets around that, but AdSense creates its own iframes, so you can't add the attribute. Google's own Publisher Tag documentation says it doesn't support COEP pages. In practice, multithreaded ffmpeg.wasm means either no ads on that page or isolating the processing page separately. WebCodecs needs no SharedArrayBuffer, so the question never comes up.

One more trap with the multithreaded core: leave the thread count to ffmpeg and it hangs. With no -threads flag, our first test sat with no progress until we killed it after 9 minutes. On the 8-core M2, -threads 2 and -threads 4 worked (12.0 s and 9.9 s on one clip), -threads 6 failed with "Cannot read properties of undefined (reading 'startsWith')", and 8 or 12 threads hung past a 3-minute timeout. Set it explicitly and test it on your own hardware.

Chrome stretches canvas frames whose width isn't a multiple of 4

Our first 480p outputs scored a VMAF of about 13, where 540p scored over 60. The picture looked right at a glance, but it was about 2 pixels too wide: the content matched the source scaled to 856 pixels and then cropped to 854. VMAF compares pixels in place, so a 2-pixel misalignment wrecks the score.

We narrowed it down with plain WebCodecs, no Mediabunny: draw each decoded frame onto an OffscreenCanvas with drawImage, wrap it with new VideoFrame(canvas), encode it with VideoEncoder and write raw H.264. To measure the stretch, we compared the output against the source scaled to slightly different widths and took the best PSNR.

Chrome 157 on macOS, hardware encoder. At 854 we also tried the software encoder and got the same 2-pixel stretch, so it happens before encoding.
Frame widthWidth ÷ 4Best-matching source widthStretched?
850 (canvas)212.5852Yes, +2 px
852 (canvas)213852No
854 (canvas)213.5856Yes, +2 px
854 (I420 buffer)213.5854No
856 (canvas)214856No
864 (canvas)216864No
1270 (canvas)317.51272Yes, +2 px

Every canvas-backed frame whose width isn't a multiple of 4 came out stretched; at 854 the software encoder did the same. The same 854-pixel picture copied into an I420 buffer of exactly 854 pixels encoded correctly. So the problem is in how Chrome converts an RGBA canvas frame for the encoder, not in the encoder and not in Mediabunny (which draws through a canvas when it resizes). With widths that are multiples of 4, the 480p VMAF went from 13.2 to 58.0. The fix is to round output widths to a multiple of 4 (we use 16, which also suits encoders that work in macroblocks) and crop the few extra pixels evenly instead of stretching. The 16:9 "480p" width of 854 is exactly the size people pick, so this is easy to hit.

60 fps video comes out at double the bitrate

When we converted a 60 fps clip from MOV to MP4, the result was twice the size we asked for. The cause: if VideoEncoderConfig.framerate is missing, Chrome's H.264 encoders budget the bitrate as if the video were 30 fps. Mediabunny only passes framerate when you set frameRate in the conversion options. The same encode at a 4 Mbps target (10.0 MB for 20 seconds):

1080p H.264, audio dropped. Target 4 Mbps × 20 s = 10.0 MB.
Clipframerate not setframerate setSoftware encoder, not set
Snail, 60 fps20.03 MB10.05 MB19.76 MB
Interview, 30 fps10.04 MB10.04 MB9.92 MB
Protest, 25 fps8.38 MB10.05 MB8.29 MB

The output bitrate scales with frame rate ÷ 30: double at 60 fps, 16% short at 25 fps. For a "compress to 10 MB" tool that is the difference between working and not. Pass the real frame rate:

// Mediabunny
await Conversion.init({ input, output, video: { codec: "avc", frameRate: fps, quality: new Quality({ bitrate: 2_000_000 }) } });

// Plain WebCodecs
encoder.configure({ codec: "avc1.640028", width, height, bitrate: 2_000_000, framerate: fps });

iPhone and Safari: video yes, audio only from Safari 26

Safari has had VideoEncoder and VideoDecoder since 16.4, but AudioEncoder and AudioDecoder only arrived in Safari 26 (iOS 26, and macOS Sonoma and later with Safari 26). That shaped our design more than speed did. Anything that can copy the audio track as-is (compressing or trimming an MP4 with AAC audio) works on iOS 16.4 and up. Anything that has to decode audio (extracting MP3, re-encoding audio, decoding an audio codec the output container can't hold) needs iOS 26. Feature-detect each one separately rather than checking for VideoEncoder and assuming the rest. Firefox for Android doesn't ship WebCodecs at the time of writing, so a fallback message (or ffmpeg.wasm) is still needed there. We haven't measured iPhone speeds; this section is from Apple's release notes and our feature checks, not a benchmark.

Which one to use

  • WebCodecs (with Mediabunny or similar) when speed and page weight matter: compress to a size limit, trim, change container, extract audio. Pass the frame rate, keep widths at multiples of 4, and feature-detect audio separately.
  • ffmpeg.wasm when you need x264's quality per byte, filters or codecs that WebCodecs doesn't offer, or support for browsers without WebCodecs. Mount inputs with WORKERFS, and if you use the multithreaded core, plan for COOP/COEP and set -threads explicitly.
  • Measure on your users' hardware. The quality gap here is Apple's VideoToolbox; other hardware encoders will land elsewhere.

We chose WebCodecs through Mediabunny for Pixohub's video compressor, trimmer, video to MP3 and MOV to MP4 converter, with the fixes above. They run in the browser with no upload, and each page lists its own measured results.

How we tested, and how to rerun it

Everything is on GitHub at MonsterInstitute/webcodecs-vs-ffmpeg-wasm (MIT; a copy is also on this site and as one zip): prep.sh downloads the five Commons videos and cuts the clips; src/bench.js is the browser side (Mediabunny, ffmpeg.wasm single- and multithreaded, the big-file tests); run.mjs drives headless Chrome with a fresh page per job; serve.mjs serves the page with or without COOP/COEP; native.sh runs the native references; vmaf.py scores the outputs; src/wtest.js and stretch3.sh are the 854-pixel test; coep/test.mjs is the ad test; results.json has every number in this article.

npm install && npm run build
./prep.sh                                  # clips/*.mp4
ISOLATE=1 PORT=8791 node serve.mjs &       # COOP/COEP on, needed for ffmpeg.wasm MT
node run.mjs jobs.json results.jsonl 8791
bash native.sh > native.jsonl
python3 vmaf.py out clips > vmaf.json      # ffmpeg built with libvmaf

VMAF method: each output and its source are scaled to 1920 × 1080 with bicubic filtering at the output's frame rate, and every 5th frame is scored. Clips: each Commons video was first encoded to H.264 at 17 Mbps (26 Mbps for 60 fps), like a camera upload, then seconds 10–30 were re-encoded at CRF 14 so every clip starts on a key frame with no edit list. Our first run cut clips with stream copy, and the leftover pre-roll frames shifted ffmpeg.wasm's output by 5 frames, which made its VMAF look terrible; if your VMAF numbers look implausible, check frame counts first.

Limits: one machine, one browser, five clips, H.264 only. Timing used a fresh page per job but a warm disk cache. Native times are single runs and include process start. We didn't test VP9 or AV1 encoding (Chrome offered both only in software here), Windows or Android hardware encoders, or phones. Test clips: "Strike For Climate Brussels 1" by Jan Ainali, "Snail traversing a leaf" by Sikander Iqbal, "Akanksha DEF India – VisibleWikiWomen at APC gathering 2024" by Mariana Fossatti, "Incubator app walkthrough" by HakanIST and "Lëtzebuerger Volleksdanz 30-09-2023" by GilPe, all CC BY-SA 4.0 on Wikimedia Commons.

Tools mentioned in this article

More from the blog