How I built a video compressor that runs entirely in the browser (ffmpeg.wasm)
Most "online video compressors" work the same way: you upload your file to someone's server, wait, and download the result. That's slow for big files and a privacy problem for personal ones. For MyClipDownloader I wante
Most "online video compressors" work the same way: you upload your file to someone's server, wait, and download the result. That's slow for big files and a privacy problem for personal ones.
For MyClipDownloader I wanted the opposite: the file never leaves your device. All the work happens in the browser tab using ffmpeg.wasm. Here's what I learned building it.
Why ffmpeg.wasm
FFmpeg compiled to WebAssembly gives you the real thing in a browser: the same codecs and filters, and the same command-line arguments. It's slower than native FFmpeg, but for clips of a few minutes it's perfectly usable, and you get:
- No upload time: processing starts instantly, even on a slow connection
- No server costs for heavy video encoding
- Privacy by design: there's nothing to store, leak or delete
The hard part: hitting an exact file size
People don't think in bitrates. They think "Discord's limit is 10 MB" or "this email attachment must be under 25 MB". So the compressor offers size targets of 8, 10, 25 and 50 MB instead of quality sliders.
To hit a target you work backwards from the size:
total bits available = target size Γ 8
reserve a safety margin (I hold back ~8%) for container overhead
audio gets a fixed share (~12% of the budget)
video bitrate = remaining bits Γ· duration in seconds
Then comes the step most people skip: choosing the resolution from the bitrate. If you squeeze a 1080p video into 300 kbps, you get a blocky mess. A smaller frame at the same bitrate looks much better. So the encoder picks the output width from the bitrate it ended up with: a high bitrate keeps the full resolution, and as it drops the frame shrinks step by step.
Two edge cases became their own clear messages instead of silent failures:
- Already fits: if the file is already under the target, re-encoding would only make it worse, so the tool says so.
- Target too small: if a 20-minute video is asked to fit in 8 MB, the bitrate would be unwatchable. Better to tell the user than to produce garbage.
Videos that don't know how long they are
Size targeting depends on knowing the duration. Some files, especially WebM recordings from browsers and screen recorders, don't store a duration at all. Without it, the bitrate math divides by nothing.
The fix: when the container has no duration, read the actual packet timestamps from the stream and measure the duration from those. It's a little slower, but it means those recordings compress correctly instead of failing.
Memory is the real limit
WebAssembly runs inside the browser's memory limits, and video is big. Things that helped:
- Clean up the virtual file system between jobs (delete inputs and outputs once they're done)
- Fail early with a clear message instead of letting the tab crash
- Keep the default output as plain H.264 MP4, which plays everywhere and encodes predictably
What else runs on the same engine
Once the engine existed, the other tools were mostly different FFmpeg arguments:
- Trimmer: cut a clip without uploading it
- Video β GIF: palette generation for clean, small GIFs
- GIF β video, video β MP3, video β MP4
Try it
The compressor is free, needs no account, and works in English, EspaΓ±ol, PortuguΓͺs, FranΓ§ais, ζ₯ζ¬θͺ and ΰΉΰΈΰΈ’:
π https://myclipdownloader.com/video-compressor/
If you've built anything with ffmpeg.wasm, I'd love to hear what you ran into, especially around memory limits and mobile browsers.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.