Every time I needed to drop a short screen recording into a GitHub issue (10 MB free cap), Discord (20 MB free cap), or an email attachment (25 MB), the workflow was annoying: upload a 100 MB .mov to an online converter, sit in a queue, and download
it back — even when the clip showed internal code or private footage I didn't want on a third-party server.
Modern browsers already ship with hardware-accelerated H.264 encoders via **WebCodecs**. So I built **[SizeClip](https://sizeclip.com/?utm_source=devto&utm_medium=article&utm_campaign=launch)** — a free, no-upload browser tool that re-encodes a video to
land just under an exact target size (10 MB, 20 MB, 25 MB, or custom).
Here are the engineering lessons and real benchmark numbers from building it.
---
## 1. WebCodecs vs. ffmpeg.wasm: ~20× faster, and no COOP/COEP headaches
My first prototype benchmarked four approaches in the browser on a 30-second synthetic 1080p clip (30.6 MB → 10 MB target, desktop Chromium):
| Method | Result | Resolution | Time |
|---|---|---|---|
| **WebCodecs (Hardware)** | 9.67 MB | 720p | **2.9 s** |
| **WebCodecs (Software)** | 9.10 MB | 720p | **3.2 s** |
| **ffmpeg.wasm (single-threaded)** | 9.17 MB | 720p | **68.2 s** |
| **ffmpeg.wasm (multi-threaded)** | Hung (>8 min, canceled) | — | — |
On a real Android phone (Galaxy, Chrome), a 28-second vertical 1080×1920 HEVC recording (44.22 MB → 10 MB) finished in **13.5 seconds** (9.26 MB).
An underrated bonus: **WebCodecs does not need Cross-Origin Isolation (`COOP`/`COEP`) headers**, unlike multi-threaded `SharedArrayBuffer` builds of `ffmpeg.wasm`. That keeps hosting, third-party embeds, and deployment simple.
I still keep single-threaded `ffmpeg.wasm` (~31 MB one-time CDN download, for files up to 1 GB) as an automatic fallback chain:
1. Hardware WebCodecs (via Mediabunny for demux/mux)
2. Software WebCodecs (if hardware fails mid-encode)
3. Single-threaded `ffmpeg.wasm` (if the browser lacks WebCodecs or can't decode the input, e.g. HEVC on some browsers)
---
## 2. How to actually hit an exact MB target without real two-pass rate control
WebCodecs encoders are one-pass, so if you set the exact theoretical bitrate, busy scenes can overshoot the limit. Here is the sizing math SizeClip uses:
1. **Safety margin + container overhead:** Aim for **95%** of the decimal MB target (`targetMB × 1,000,000 × 0.95`), subtract 64 KB for the MP4 container and ~3% for muxing overhead.
2. **Audio budget:** Reserve 128 / 96 / 64 / 32 kbps based on total budget, but **never exceed ~1.1× the source's own audio bitrate** (re-encoding a 48 kbps voice track at 128 kbps just wastes space).
3. **Resolution steps by remaining video bitrate (shorter side, never upscaling):**
- `≥ 2.5 Mbps` → 1080p
- `1.2–2.5 Mbps` → 720p
- `0.6–1.2 Mbps` → 480p
- `< 0.6 Mbps` → 360p
4. **60 fps → 30 fps step when bits per pixel get thin:** If a high-fps source drops below `0.06` bits/pixel/frame, it encodes at 30 fps (25 fps for 50 fps sources) so each frame gets twice the bits. Users can override both resolution and frame rate
under *More options*.
5. **Source bitrate cap (~85%):** Never spend more than ~85% of the source's video bitrate, so picking a 100 MB target on a 50 MB file won't inflate it.
6. **Automatic retry passes (up to 3 total):** If the muxed MP4 still exceeds the target, SizeClip scales the bitrate down by the overshoot ratio and re-encodes, locking the first pass's frame rate so retries don't unexpectedly flip 60 fps to 30 fps.
On a 40-second synthetic 1080p clip (51.6 MB, desktop Chromium):
- 20 MB target → **18.7 MB** at 1080p in **8.7 s**
- 8 MB target → **7.44 MB** at 720p in **3.9 s**
---
## 3. Honest limitations
- **Low-bitrate quality:** Hardware H.264 encoders at very low bitrates look softer than a slow two-pass `libx264` encode in desktop `ffmpeg`. SizeClip trades a little compression efficiency for speed and zero uploads.
- **Memory limit:** Output is buffered in browser memory, so very large targets on phones can hit RAM limits (the UI warns above 300 MB).
- **Safari / iOS testing:** I've only tested desktop Chrome and an Android phone on real hardware so far. Real-device Safari/iOS feedback is very welcome.
- **Closed source:** The repository is private for now, though you can verify in DevTools' Network tab that zero video bytes leave your device.
---
## Try it out
If you ever need to shrink a bug recording under [GitHub's 10 MB video limit](https://sizeclip.com/github-video-compressor/) or [compress a video without uploading](https://sizeclip.com/compress-video-without-uploading/) it to a server, give
**[SizeClip](https://sizeclip.com/?utm_source=devto&utm_medium=article&utm_campaign=launch)** a try — free, no account, no watermark.
I'd love feedback from anyone trying tricky files (especially on Safari/iOS or Firefox) or noticing cases where the size targeting misses.
Top comments (0)