Mediatavio
YouTube to MP3PriceBlogPrivacy

Video engineering

FFmpeg vs WebCodecs: A Browser Video Pipeline

Native codecs for supported devices. A WebAssembly fallback for everything else.

By Mediatavio Engineering

What we are comparing

This article compares FFmpeg running as single-threaded WebAssembly inside a browser with the browser's native WebCodecs API. It is not a comparison against desktop or server FFmpeg, which can also use hardware encoders.

Mediatavio uses this hybrid pipeline in Video Converter, Video Compressor, Video Trimmer, Video Cropper and compatible exports from Video to Audio.

The technical difference

CapabilityFFmpeg WebAssemblyWebCodecs with Mediabunny
Codec implementationSoftware codecs compiled into WebAssemblyNative browser codecs; hardware acceleration when available
Container handlingBuilt-in demuxers and muxersMediabunny reads and writes containers; WebCodecs alone does not
CompatibilityDepends on codecs included in our FFmpeg buildDepends on browser, operating system, codec and configuration
MemoryInput and output files in the WebAssembly filesystemBlob-backed input and bounded codec queues; final output is still buffered
StartupDownload, verify and initialize the WebAssembly engineLoad the media library and initialize native codecs
DeploymentStandard browser WebAssembly and Worker supportHTTPS or localhost, Worker and required codec support

A mobile browser exposing VideoEncoder does not guarantee that it can encode a particular H.264 profile or resolution. We validate the actual conversion and fall back if the required tracks cannot be exported.

Measured results

Measurements are recorded on one test environment. They are examples, not a speed guarantee for other computers, browsers or phones.

Environment: Windows x64, VS Code integrated Chromium 150.0.7871.250 / Electron 43.8.3, 14 reported logical processors. Input: a 12-second synthetic animation, 640 by 360 pixels, 30 fps, VP8, 1,033,406 bytes, without audio. Both outputs use WebM, VP8, the source resolution, 30 fps and a target bitrate of 394,264 bits per second.

Export wall-clock time, in seconds. Three consecutive runs per backend.
MeasurementWebCodecsFFmpeg WebAssembly
Run 10.96873.0943
Run 20.73803.0453
Run 30.72483.0565
Median0.73803.0565
Output size, bytes604,820601,282-608,611
Output duration12.00 s12.00 s

The median speed ratio was 4.14 in this test. Native timing includes creating a new Worker and producing the output buffer. FFmpeg timing includes copying input into its filesystem, executing the export and reading the output buffer; the same initialized engine was reused. Its separately measured initialization took 1.0468 seconds from a local copy of the 32,232,419-byte engine. Internet download, account requests and input generation are excluded.

This is a small synthetic-video benchmark, not a camera-footage quality comparison. The native and WebAssembly encoders use different rate-control implementations; FFmpeg also receives maximum-rate and buffer-size settings. Similar file sizes do not prove equal visual quality. No PSNR, SSIM, VMAF, peak-memory or battery measurements were taken.

Read the raw benchmark data. The reproduction script generates the input and runs both paths three times. A device with native VP8 encoding support is required.

const {runVideoBenchmark} = await import('/video-tools/benchmark.mjs');
const results = await runVideoBenchmark();
console.log(results);

The integrated test browser disables some audio codecs by product policy. These timing measurements use video without an audio track. Real-device audio compatibility and mobile thermal behavior need separate testing. Hardware acceleration was not independently verified.

How the fallback works

Read containerValidate codecsDecode and transformEncode and mux

WebCodecs runs in a terminable Worker. We crop, scale and correct frame rate before encoding, and mux the result into the requested container. Compatible audio is copied without re-encoding when no precise trim is requested. We never silently omit an audio track to make a native export succeed.

If decoding, encoding or muxing is unsupported or fails, the original FFmpeg export is attempted with the same user settings. Cancelling terminates the current Worker and prevents stale results from becoming downloads.

Our native route currently targets MP4, MOV, MKV and WebM video exports, plus compatible WAV, AAC, M4A and Ogg audio extraction. AVI, WMV, OGV, 3GP, MP3, FLAC and original-encoding mode remain on the FFmpeg route. Availability still depends on the source codec and the device.

Choosing the right route

For common video files, try Video Converter or Video Compressor. Native codecs avoid downloading the full WebAssembly engine when the device supports the job. Use Video Trimmer for precise cuts and Video Cropper for framing changes.

Original encoding is a different optimization: copying packets avoids re-encoding entirely, but cuts may follow nearby keyframes and the destination container must support the original codecs. It should not be compared with a full transcode as though both perform the same work.

Keep the page in the foreground during export, especially on mobile. Locking a phone or switching away may suspend processing. Lower resolution or shorter clips can reduce memory pressure on either route.

References