How TinyGIF Runs FFmpeg in the Browser
Résumé
Pixel shares how TinyGIF converts and compresses GIFs entirely in the browser, keeping files on the user’s device. The announcement explains how a 30.7 MiB FFmpeg Wasm binary is split into smaller pieces to meet Cloudflare Workers’ 25 MiB asset limit, plus the privacy, cost, and device-performance trade-offs.
DEV Community
Converting GIFs in the browser with ffmpeg.wasm — and splitting a 30.7 MiB binary to fit Cloudflare Workers
Most "free GIF converter" sites ask you to upload a clip and wait out a spinner. I didn't want that for TinyGIF. The tools should shrink and convert GIFs so they pass a platform limit — a Discord emoji, a chat upload, a Twitch emote — without the file ever leaving the device. I'm Danny, and I built TinyGIF. The interesting problem wasn't "can FFmpeg run in a tab?" The ffmpeg.wasm project already answered that. It was this: the single-thread @ffmpeg/core build we ship is 30.7 MiB, and Cloudflare Workers rejects any one static asset larger than 25 MiB. Here's how that Wasm file is cut into pieces, fetched in parallel, and glued back into a module the browser can compile. Why do this in the browser? Three reasons, all from the same decision. Privacy. The file is read from disk, processed in memory, and offered back as a download. TinyGIF's about page puts it plainly: there is no server that could receive the file. Close the tab and it's gone. Cost. A transcode farm is a per-file bill. Because the heavy work runs on the visitor's machine, there is no server-side encode to pass on, which is why the tools can stay free, with no account, no watermark and no daily cap. Honest limits. Discord, Twitch and Kick publish specific byte and pixel rules, and they don't all mean the same thing by "KB" or "MB". Once the work is in the browser, the same page can encode the file and check it against a sourced, dated table before you download. The trade-off is real: the first FFmpeg conversion has to download the converter, and phones have less memory than desktops. The site shows a progress bar for that first load (it happens once) and tells you when a file is too big for the device instead of freezing. Two Wasm engines, not one It's tempting to say "we compress GIFs with ffmpeg.wasm." That isn't quite right, and the distinction matters if you're building something similar. Existing GIFs are compressed with gifsicle, compiled to WebAssembly from gifsicle 1.96.4 (gifsicle-wasm) and run in the browser with command-line arguments. The GIF compressor walks a fixed sequence and stops as soon as the file fits: lossless frame-differencing first, then stepped lossy compression, fewer colours, fewer frames, and only then smaller dimensions. Video becomes a GIF with FFmpeg. The video to GIF converter uses @ffmpeg/core 0.12.10, the single-thread build, in a Web Worker. It accepts MP4, WebM and MOV, lets you trim a range, pick a width and frame rate, and builds a 256-colour palette from the clip before rendering. If the result is still over a Discord limit, "Make it smaller" runs the same gifsicle compressor on the output — still in the tab. The licences page lists versions and GPL obligations. The rest of this article is about getting that FFmpeg core onto the edge. The 25 MiB wall TinyGIF is a static Astro site served as Cloudflare Workers static assets: HTML and hashed files at the edge, and the visitor's browser does the transcode. It also has a hard cap. Cloudflare's docs list Individual Static Asset file size: 25 MiB on both the free and paid Workers plans (25 MiB is 26,214,400 bytes). A single ffmpeg-core.wasm drop-in does not fit. The core TinyGIF actually ships is 32,232,419 bytes, about 30.7 MiB. That figure comes from the live converter manifest at /ffmpeg/manifest.json, which also records the package version (0.12.10) and a short content hash. Split the binary, fetch the parts in parallel, glue them back At build time the Wasm file is cut into parts, each safely under 25 MiB. At run time the browser downloads every part, concatenates them in order, and compiles the result as application/wasm. Today the live manifest looks like this: {
"version": "0.12.10",
"hash": "9f57947a5b",
"size": 32232419,
"parts": [
{ "name": "ffmpeg-core.0.12.10.9f57947a5b.0.wasm", "size": 12582912 },
{ "name": "ffmpeg-core.0.12.10.9f57947a5b.1.wasm", "size": 12582912 },
{ "name": "ffmpeg-core.0.12.10.9f57947a5b.2.wasm", "size": 7066595 }
]
}
Th...

Powered by Readybot.io