# Building the 20mb.net video engine

The engine served by https://20mb.net (`/assets/engine/ffmpeg-9.1-ffw.<hash>.wasm`
and `.mjs`) is built from exactly the files published at https://20mb.net/source/.

## Toolchain

- Docker, base image `emscripten/emsdk:7.0.1` (Emscripten 7.0.1, Ubuntu 24.04),
  plus `autoconf automake libtool pkg-config meson ninja-build patch xz-utils` from Ubuntu.
- The Emscripten runtime sources linked into the module (musl, libc++,
  libc++abi, compiler-rt, dlmalloc and the JavaScript library) are published as
  `emscripten-7.0.1-runtime-source.tar.xz`.

## Components

| Library | Version | Archive | Notes |
|---|---|---|---|
| FFmpeg | 9.1 | ffmpeg-9.1.tar.xz (+ .asc signature) | unmodified; configure line in `ffmpeg-configuration.txt` |
| x264 | stable b35605a (0.165.3222) | x264-b35605a.tar.gz (`git archive` of commit b35605ace3ddf7c1a5d67a2eb553f034aef41d55) | `version.sh` replaced by `x264-version.sh` (git metadata is not in archives); `-fno-tree-vectorize -m32` removed from config.mak |
| libvpx | 1.17.0 | libvpx-1.17.0.tar.gz | encoders only |
| Opus | 1.6.1 | opus-1.6.1.tar.gz | |
| LAME | 4.0 | lame-4.0.tar.gz | encoder only |
| dav1d | 1.5.5 | dav1d-1.5.5.tar.xz | `dependency('threads')` replaced by an empty dependency in meson.build (single-threaded build) |
| zimg | 3.0.6 | zimg-3.0.6.tar.gz | built with `-include exception`, without `-pthread` |
| zlib | 1.3.2 | zlib-1.3.2.tar.gz | |
| ffw (our transcoder) | 1.0 | `ffw/ffw.c` | MIT |

Common flags for every component: `-O3 -msimd128 -fwasm-exceptions` (see `scripts/env.sh`).
No source file of any library is modified; the build-system adjustments are
listed above and done by the `Dockerfile` with `sed`.

## Rebuild

```sh
# from the project root, with the archives in engine/sources/
docker build -f engine/Dockerfile engine --target dist --output type=local,dest=engine/dist
```

Output: `ffw.wasm`, `ffw.mjs`, `versions.json`, `ffmpeg-configuration.txt`.
A rebuild with the same toolchain image produces a functionally identical
module (byte-identical output is not guaranteed).

## License

The combined module is distributed under the GNU General Public License,
version 2 or (at your option) any later version. Component licenses: see
https://20mb.net/licenses/.
