ffmpeg-wasm: The FFmpeg Build That Only Demuxes

Diffusion Studio's WebAssembly module reads video containers and hands decoding to the browser, trading FFmpeg's monolith for one surgical job.

6 min read • View on GitHub • More from diffusionstudio

A wide editorial illustration of a cavernous engine room dominated by an enormous ornate machine covered in pipes, gears, pressure gauges, and exhaust stacks. From a small access hatch on its side, gloved hands lift out one small precision-machined brass component and dock it into a sleek browser window frame standing beside the machine. The image explains the article's central idea: FFmpeg is a giant does-everything machine, and this build extracts a single small part (the demuxer) and hands it to the browser.
FFmpeg does everything. This build extracts one small part and hands it to the browser.
Key Takeaways

FFmpeg is the Swiss Army chainsaw of media. It decodes, encodes, filters, scales, transcodes, muxes, and streams, across more than a hundred codecs and dozens of container formats. It is the tool you reach for when you do not know which tool to reach for.

FFmpeg Does Everything. This Build Does One Thing.

This repository compiles a single subsystem of it. The name is ffmpeg-wasm, but the code inside lib/web-demuxer/ does one job: read a container and pull apart the streams inside it. There is no decoder here. There is no encoder. There is no filter graph. The build stops the moment the container has been read.

That is the inversion worth sitting with. The least glamorous part of the media toolchain, the part that just parses bytes and reads headers, is the only part that survived the move to the browser. Everything flashier was already there waiting.

Demuxing vs Decoding: The Split That Explains Everything

Two jobs live inside every video file. Demuxing is reading the container, the box that holds the tracks, and separating the interleaved video and audio packets back into their own streams. Decoding is taking each compressed packet and turning it into pixels or audio samples.

For most of the history of browser video, both jobs ran in the same place. You either handed the file to a <video> tag and hoped the browser supported the codec, or you shipped a full transcoder like ffmpeg.wasm to do everything in WebAssembly.

Then browsers gained WebCodecs, a native, hardware-accelerated decoding API. The decoder moved out of FFmpeg's job description and into the browser. The demuxer did not. Browsers still cannot open an MP4 and hand you back the raw tracks.

So the browser can now finish the job. It just cannot start it. That gap is the entire reason this repo exists.

Read the Container, Hand Off the Rest

The demuxer's output is small and specific. For each input file it produces separate video and audio tracks, and for each track it produces a codec string: a short tag like avc1.64001f for H.264 or mp4a.40.2 for AAC.

Step a packet through the pipeline, then flip the toggle to see where FFmpeg ends and the browser begins.

Those strings look like noise. They are the handshake. WebCodecs will not decode anything until you tell it exactly what is in the stream, and the codec string is how FFmpeg's internal identifiers get translated into the vocabulary the browser understands. The files video_codec_string.c and audio_codec_string.c are the lookup tables that do the translation.

Once the demuxer hands over the tracks and the strings, FFmpeg's work is done. The browser takes it from there, on native decoders, in hardware, without a single line of C running in your tab.

Why Not Just Use ffmpeg.wasm?

ffmpeg.wasm is the famous one. It compiles the whole of FFmpeg to WebAssembly and lets you transcode, convert, and record in the browser. If you want a transcoder, that is the tool, and it has the community to match.

This repo exists because Diffusion Studio needed a demuxer, not a transcoder. When the browser does the decoding, shipping the rest of FFmpeg is dead weight: code you carry, parse, and instantiate for a job the browser already handles in hardware.

The other reason is licensing. FFmpeg is LGPL by default, but the moment you enable certain components it becomes GPL, and a GPL binary is a harder thing to ship inside a product. This build is scoped and framed around LGPL v2.1, and the README says so in its first line.

FFmpeg LGPL v2.1 build steps for generating a wasm module using emscripten.

diffusionstudio/ffmpeg-wasm, GitHub project description · diffusionstudio/ffmpeg-wasm

One clarification the comparison below makes explicit: the license of the build recipe is not the license of the binary. A wrapper or build script can be MIT while the FFmpeg binary it produces carries its own obligations. The Hacker News discussion of ffmpeg.wasm returns to this distinction again and again, and it applies here just as much.

diffusionstudio/ffmpeg-wasmffmpeg.wasmdiffusionstudio/ffmpeg-jsKagami/ffmpeg.js
ScopeDemuxer only, selected formatsGeneral-purpose transcode and convertTypeScript command API over FFmpegHistorical asm.js-era port
What runs whereContainer parsing in WASM, decode in WebCodecsEverything in WASMEverything in WASMEverything in asm.js
Build approachEmscripten plus Docker (ARM64 dev container)Prebuilt WASM and JS distributionShips a base and an extended binaryPrebuilt asm.js
License framingLGPL v2.1 build stepsMIT wrapper, FFmpeg license still appliesLGPL base, optional GPL and nonfreeHistorical
Primary languageC with JS glueJS and TSTypeScriptJS

The wrapper's license never determines the binary's license. That single sentence is the intellectual payload of the whole table.

What's Actually in the Box

The repo is a recipe, not a library. There is no npm package here, no published API, no release to install. There is a Makefile, a compose.yaml, an ARM64 development container, and a pair of commands.

# 1. start the docker container
npm run dev:docker:arm64

# 2. build the demuxer for the specified formats
npm run build:wasm
A close-up editorial illustration of two hands holding a single strip of film that is split cleanly down its length into two parallel ribbons. The upper ribbon carries tiny picture frames and the lower ribbon carries a jagged waveform, and a small brass comb has just passed between them so the two ribbons peel apart toward labeled sockets at the edge of the frame. The image makes demuxing physical: the comb is the demuxer, and the two ribbons are the separated video and audio streams.
The demuxer is a comb. It passes between the streams and the picture and sound peel apart.

The C source is where the actual work is. web_demuxer.c is the entry point. video_codec_string.c and audio_codec_string.c are the quiet heroes: small lookup tables that map FFmpeg's internal codec identifiers to the strings WebCodecs expects. post.js is the Emscripten glue that exposes the compiled demuxer to JavaScript.

That is the whole artifact. A build path, a demuxer, two translation tables, and the glue to call it from the browser.

What the Demuxer Pattern Doesn't Solve

The demuxer pattern is elegant, but it does not make WebAssembly fast. The sibling project diffusionstudio/ffmpeg-js documents the constraints plainly, and they apply to any WASM media work.

Read that list again and it stops sounding like a set of complaints. It is the case for the architecture. Every constraint is a reason the demuxer hands off instead of doing the work itself. The boundary between FFmpeg and the browser is not a limitation to work around. It is the design.