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.
- The demuxer is the only piece of FFmpeg that browsers still need, because WebCodecs already decodes video in hardware.
- Diffusion Studio's build compiles one subsystem to WebAssembly and hands the decoding back to the browser instead of shipping the whole transcoder.
- Scoping the build to LGPL v2.1 is the quiet reason the repo exists in this shape, since a GPL binary is harder to ship inside a product.
- The repository is a build recipe, not a library, and it says so in three commands.
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.
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.
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-wasm | ffmpeg.wasm | diffusionstudio/ffmpeg-js | Kagami/ffmpeg.js | |
|---|---|---|---|---|
| Scope | Demuxer only, selected formats | General-purpose transcode and convert | TypeScript command API over FFmpeg | Historical asm.js-era port |
| What runs where | Container parsing in WASM, decode in WebCodecs | Everything in WASM | Everything in WASM | Everything in asm.js |
| Build approach | Emscripten plus Docker (ARM64 dev container) | Prebuilt WASM and JS distribution | Ships a base and an extended binary | Prebuilt asm.js |
| License framing | LGPL v2.1 build steps | MIT wrapper, FFmpeg license still applies | LGPL base, optional GPL and nonfree | Historical |
| Primary language | C with JS glue | JS and TS | TypeScript | JS |
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
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.
- WebAssembly memory is capped at 2 GB, which limits how much of a file you can hold at once.
- There is no hardware acceleration inside WASM. That is precisely why decoding belongs in WebCodecs and not in the module.
- Encoding and decoding in WASM are slow. Moving them out of WASM is the fix, not a workaround.
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.





