# Media libraries for OMNIvour for Windows (FFmpeg + LAME, LGPL)

The Windows app converts video and audio locally with the same FFmpeg and LAME as the Mac
(`apps/macos/FFmpeg/`), LGPL only, with H.264, HEVC and AAC encoded by Windows Media Foundation.
The recipe follows the WebP codec's (`../libwebp/`): llvm-mingw (UCRT) in the pinned Debian
container, so it runs on any Docker host and in CI, and the output is pinned by hash.

## What gets built

`build.sh` downloads the pinned tarballs from `versions.env`, checks their SHA-256, checks that
FFmpeg's `COPYING.LGPLv2.1` equals `licenses/LGPL-2.1.txt` and LAME's `COPYING` equals
`licenses/LGPL-2.0.txt`, and cross-compiles for two architectures:

- `dist/win-x64/` and `dist/win-arm64/`: `avcodec-62.dll`, `avformat-62.dll`, `avutil-60.dll`,
  `avfilter-11.dll`, `swscale-9.dll`, `swresample-6.dll`, `libmp3lame-0.dll`, `ffmpeg.exe`,
  `ffprobe.exe`. Shared libraries, so they stay separate, replaceable files.
- `dist/MANIFEST.json`: licence (from FFmpeg's own `config.h`), notice files, versions, source and
  toolchain hashes, container image, build tool versions, and each file's SHA-256, size, machine and
  imported DLLs.

`--disable-everything` plus explicit lists keeps only the demuxers, muxers, codecs, parsers,
bitstream filters and filters the app uses (the decoder, parser, bitstream filter and filter lists
equal the Mac's). `--disable-autodetect` keeps every optional library out; `--disable-network`
removes network protocols, and only the `file` and `pipe` protocols are built. WebM, OGG and Opus
outputs stay cloud-only (no libvpx, libvorbis or libopus; no `webm`, `ogg` or `opus` muxer).

Differences from the Mac recipe:

- Encoders: `h264_mf`, `hevc_mf` and `aac_mf` (Media Foundation, `--enable-mediafoundation`)
  replace `h264_videotoolbox`, `hevc_videotoolbox` and `aac_at`; there is no hardware decoding
  (`--enable-hwaccel` is not used).
- No zlib (llvm-mingw has none): the rare MOV or MKV file with compressed headers fails locally.
- Threads: `--disable-pthreads --enable-w32threads`, so nothing imports `libwinpthread-1.dll`.
- x64 builds FFmpeg's assembly with nasm (the Mac's x86_64 slice has none).
- `--enable-d3d11va`: FFmpeg 8.1.3's `mfenc.c` does not compile without it (it uses the D3D11
  hardware context types unconditionally). Only the D3D11 hardware context is built; no hwaccel is
  enabled, and the manifest records every file's imports. No file imports Media Foundation or
  Direct3D statically: FFmpeg loads `mfplat.dll` and `d3d11.dll` (avcodec) and `d3d11.dll`,
  `dxgi.dll`, `dxgidebug.dll` (avutil's D3D11 context) at runtime.
- No native C compiler in the container: `--host-cc` is the target clang (configure only
  compile-checks it), and FFmpeg's one host program that runs, `ffbuild/bin2c` (it embeds
  `fftools/resources/graph.html` and `graph.css`), is replaced by a Python stand-in that writes
  exactly what `bin2c.c` writes (`make BIN2C=...`). Any other host program would fail the build.

### Self-checks

Per architecture and pass, on the generated configuration: `config.h` states
`FFMPEG_LICENSE "LGPL version 2.1 or later"` (the manifest licence is mapped from it, never a
constant) and `CONFIG_GPL`, `CONFIG_NONFREE`, `CONFIG_VERSION3`, `CONFIG_NETWORK` are 0, with none of
x264, x265, fdk-aac, libvpx, libvorbis or libopus; `config_components.h` enables exactly the
pinned set of every component kind: protocols `file` and `pipe`, the ten demuxers, twelve muxers
and nine encoders, the decoders, parsers, bitstream filters and filters the configure lists name
plus what FFmpeg pulls in itself (the `h263` decoder, the `ac3` parser, `pgs_frame_merge` and the
two `vp9_superframe` bitstream filters, `atrim`, `crop`, `hflip`, `rotate`, `transpose`, `trim`,
`vflip`), and no hwaccel, input or output device. On every output
file: the expected machine (AMD64 or ARM64); ASLR (`DYNAMIC_BASE`, `HIGH_ENTROPY_VA`) and DEP
(`NX_COMPAT`); a zero link timestamp; no import of a network, TLS or pthreads DLL (`ws2_32`,
`wsock32`, `mswsock`, `wininet`, `winhttp`, `urlmon`, `secur32`, `crypt32`, `iphlpapi`, `dnsapi`,
`netapi32`, `libwinpthread-1`); no build path (`/tmp/`, `/home/`, `/root/`, the container mount or the
download directory; the one allowed hit is FFmpeg's own temp-file template `/tmp/%sXXXXXX` in
`avutil`); and `ffmpeg.exe` carries the LGPL notice.

### Reproducibility

FFmpeg embeds its full configure line (prefix, data dir, include and library paths) in every
library, so two builds are byte-identical only at the same absolute path. Each architecture is
therefore built twice from fresh source trees at one fixed, neutral path (`/omnivour-ffmpeg-build`,
which is the only path the files carry); pass 1's files are copied aside and every file of pass 2
must equal them. The rest comes from `-ffile-prefix-map`, `-Wl,--no-insert-timestamp`,
`SOURCE_DATE_EPOCH=0` and `-Wl,-s` (strips debug info, which in llvm-mingw's CRT startup objects
carries the toolchain's own build paths).

## Build

From the repository root, on any machine with Docker (Linux containers):

```sh
. apps/windows/ffmpeg/versions.env
docker run --rm -v "$PWD:/src" -w /src/apps/windows/ffmpeg "$CONTAINER_IMAGE" sh -c 'sh prepare.sh && sh build.sh'
sh apps/windows/gates/ffmpeg.sh
sh apps/windows/ffmpeg/verify.sh
```

In Git Bash on Windows, prefix the `docker run` with `MSYS_NO_PATHCONV=1` so the `-v` and `-w`
paths are passed through unchanged. `prepare.sh` installs curl and xz, plus make, nasm and Python 3
at the exact Debian versions `versions.env` pins (`APT_*`, also recorded in the manifest); the
compiler is the pinned llvm-mingw release that `build.sh` downloads. LAME 4.0's configure insists on
pkg-config, so `build.sh` puts a stand-in that finds no optional libraries on the path (as on the
Mac).

`verify.sh` runs on a Windows PC (Git Bash) and writes nothing: `dist/` holds exactly the
manifest's files, each hashes to `MANIFEST.json` and is the right PE machine; the x64 `ffmpeg.exe` states the GNU Lesser General
Public License version 2.1 or later (`-L`), has no `--enable-gpl|nonfree|version3` and has
`--disable-network` (`-buildconf`), lists exactly `file` and `pipe` for input and output
(`-protocols`), lists exactly the nine pinned encoders, with no GPL, nonfree or cloud-only one
(`-encoders`), and exactly the twelve pinned muxers, with no WebM, OGG or Opus one (`-muxers`);
`ffprobe.exe` runs.
The arm64 files are inspected, not executed.

The gate checks `dist/` against `MANIFEST.json` whenever `dist/` is present. CI
(`.forgejo/workflows/windows-ffmpeg.yml`) rebuilds in the same container when this directory, its
gate, the LGPL texts or the notices change, and requires the same manifest.

## Source offer

The notices name the upstream tarballs, their SHA-256 and this recipe as the complete corresponding
source, published at https://omnivour.app/source (`SOURCE_OFFER_URL` in `versions.env`; the page is
`apps/web/src/app/source/`, and its test keeps the hosted copies of this folder equal to it). The
gate fails once the package identity is no longer the development placeholder (`DEVELOPMENT
IDENTITY` in `OMNIvour/Package.appxmanifest`) unless the URL is in `versions.env` and in the notices.

## Bumping a version (quarterly review; next 2027-02-01)

1. Change the version, URL and SHA-256 in `versions.env` together, and the same values in
   `apps/macos/FFmpeg/versions.env` (the gate requires them equal). Verify the FFmpeg tarball
   against its upstream `.asc` (FFmpeg release signing key,
   `FCF9 86EA 15E6 E293 A564  4F10 B432 2F04 D676 58D8`) and the LAME tarball against a second
   independent source such as the Homebrew formula. The toolchain and container image follow
   `../libwebp/versions.env` (the gate requires them equal); read the build tools' versions with
   `apt-cache policy make nasm python3` inside the image and update `APT_*`.
2. Build as above, then `cp apps/windows/ffmpeg/dist/MANIFEST.json apps/windows/ffmpeg/MANIFEST.json`.
   If a library's soname changed, update the gate's file list and the notices.
3. If upstream `COPYING.LGPLv2.1` or LAME's `COPYING` changed, stop: `build.sh` fails until the
   licence texts in `licenses/` match, and those files are shared with the Mac.
4. Update the versions and hashes in `THIRD_PARTY_NOTICES.md`, run `verify.sh` and the Windows gates.

`dist/` is gitignored: the files are rebuilt from this recipe, and `MANIFEST.json` pins them.
