<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sizeclip-123</title>
    <description>The latest articles on DEV Community by Sizeclip-123 (@_34ef60d7e11689bf698ff).</description>
    <link>https://dev.to/_34ef60d7e11689bf698ff</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4253452%2Fbe8f5643-ff32-4020-8fd2-a77c09412010.png</url>
      <title>DEV Community: Sizeclip-123</title>
      <link>https://dev.to/_34ef60d7e11689bf698ff</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_34ef60d7e11689bf698ff"/>
    <language>en</language>
    <item>
      <title>Why I ditched ffmpeg.wasm for WebCodecs to build a zero-upload exact-size video compressor</title>
      <dc:creator>Sizeclip-123</dc:creator>
      <pubDate>Thu, 19 Nov 2026 09:15:09 +0000</pubDate>
      <link>https://dev.to/_34ef60d7e11689bf698ff/why-i-ditched-ffmpegwasm-for-webcodecs-to-build-a-zero-upload-exact-size-video-compressor-1h06</link>
      <guid>https://dev.to/_34ef60d7e11689bf698ff/why-i-ditched-ffmpegwasm-for-webcodecs-to-build-a-zero-upload-exact-size-video-compressor-1h06</guid>
      <description>&lt;p&gt;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 &lt;code&gt;.mov&lt;/code&gt; to an online converter, sit in a queue, and download&lt;br&gt;
    it back — even when the clip showed internal code or private footage I didn't want on a third-party server.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Modern browsers already ship with hardware-accelerated H.264 encoders via **WebCodecs**. So I built **[SizeClip](https://sizeclip.com/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;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 (&amp;gt;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
   - `&amp;lt; 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&amp;amp;utm_medium=article&amp;amp;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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;(&lt;a href="https://sizeclip.com" rel="noopener noreferrer"&gt;https://sizeclip.com&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>webperf</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
