<?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: mengyuxuan</title>
    <description>The latest articles on DEV Community by mengyuxuan (@mengyuxuan).</description>
    <link>https://dev.to/mengyuxuan</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%2F4041464%2Fa7983a53-ea41-4f63-b0d1-4adfab57e3c1.jpg</url>
      <title>DEV Community: mengyuxuan</title>
      <link>https://dev.to/mengyuxuan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mengyuxuan"/>
    <language>en</language>
    <item>
      <title>I built a video compressor with zero backend — your files never leave the tab</title>
      <dc:creator>mengyuxuan</dc:creator>
      <pubDate>Wed, 22 Jul 2026 08:07:50 +0000</pubDate>
      <link>https://dev.to/mengyuxuan/i-built-a-video-compressor-with-zero-backend-your-files-never-leave-the-tab-13b6</link>
      <guid>https://dev.to/mengyuxuan/i-built-a-video-compressor-with-zero-backend-your-files-never-leave-the-tab-13b6</guid>
      <description>&lt;p&gt;Drop a 200 MB screen recording into most "free video compressor" sites and here's what actually happens: the file uploads to someone's server, gets transcoded there, and you download the result. Your video sat on a stranger's disk. The site paid for bandwidth and CPU, so it pays that back with aggressive ads or a paywall at 3 files a day.&lt;/p&gt;

&lt;p&gt;I wanted the opposite: the compression runs &lt;strong&gt;in your browser tab&lt;/strong&gt;, the file never leaves your machine, and because there's no server doing the work, the whole thing is genuinely free to run.&lt;/p&gt;

&lt;p&gt;That's &lt;a href="https://videocompress.dev" rel="noopener noreferrer"&gt;videocompress.dev&lt;/a&gt;. This post is how it works under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  The core constraint: no upload, ever
&lt;/h2&gt;

&lt;p&gt;The entire architecture falls out of one rule — &lt;strong&gt;the video bytes stay client-side&lt;/strong&gt;. That immediately kills the "rent a beefy transcoding server" design and forces the work into the browser. Two APIs can do it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;WebCodecs&lt;/strong&gt; — a low-level browser API that talks to the OS's hardware video encoder/decoder. Fast, uses almost no CPU, native-quality H.264.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ffmpeg.wasm&lt;/strong&gt; — the full FFmpeg compiled to WebAssembly. Works literally everywhere, but it's a software encoder running in a WASM sandbox, so it's slower.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;WebCodecs is the better experience when it's available. It isn't always. So the app probes the browser and picks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Picking an engine at runtime
&lt;/h2&gt;

&lt;p&gt;The selection logic is deliberately boring — a pure function that's trivial to unit test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;CompressionEngine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webcodecs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ffmpeg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;EngineCaps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;hasWebCodecsApi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// VideoEncoder + VideoDecoder exist&lt;/span&gt;
  &lt;span class="nl"&gt;inputReadable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// we can actually demux + decode this file&lt;/span&gt;
  &lt;span class="nl"&gt;canEncodeTarget&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// the target H.264 config is encodable here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decideEngine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;EngineCaps&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;CompressionEngine&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasWebCodecsApi&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;inputReadable&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;caps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canEncodeTarget&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webcodecs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ffmpeg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important detail is the third capability. Having the WebCodecs &lt;em&gt;API&lt;/em&gt; isn't enough — the browser also has to be able to demux the specific container you dropped in and encode the target config. So before committing, the app asks &lt;a href="https://www.npmjs.com/package/mediabunny" rel="noopener noreferrer"&gt;&lt;code&gt;mediabunny&lt;/code&gt;&lt;/a&gt; whether it can read the input's primary video track and whether &lt;code&gt;VideoEncoder.isConfigSupported()&lt;/code&gt; accepts the output config.&lt;/p&gt;

&lt;p&gt;Any &lt;code&gt;false&lt;/code&gt;, anything unprobed, anything that throws → fall back to ffmpeg.wasm. WebCodecs is the fast path you &lt;em&gt;earn&lt;/em&gt; by passing every check; ffmpeg is the floor that always catches you. Users on the happy path get hardware speed; everyone else still gets a working compressor. Nobody gets a broken page.&lt;/p&gt;

&lt;h2&gt;
  
  
  The actual "compression": it's bitrate math
&lt;/h2&gt;

&lt;p&gt;"Compress this to 25 MB for email" sounds like a quality knob, but under the hood it's arithmetic. A video file's size is roughly &lt;code&gt;bitrate × duration&lt;/code&gt;. If you know the target size and the duration, you can solve for the bitrate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AUDIO_KBPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TARGET_SIZE_SAFETY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.94&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// aim slightly under so we don't overshoot&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;computeTargetVideoKbps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;targetSizeMB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;durationSec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;removeAudio&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;targetSizeMB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;durationSec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;removeAudio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;audioKbps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;removeAudio&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AUDIO_KBPS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;safeTargetMB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;targetSizeMB&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;TARGET_SIZE_SAFETY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;videoKbps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;safeTargetMB&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;durationSec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;audioKbps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;videoKbps&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things I learned the hard way and baked in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The 6% safety margin (&lt;code&gt;0.94&lt;/code&gt;).&lt;/strong&gt; Encoders don't hit a bitrate target exactly; they hover around it. If you aim for exactly 25 MB you'll ship 26 and blow the email limit. Aiming for ~23.5 lands under it reliably.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subtract the audio budget first.&lt;/strong&gt; The size cap is for the &lt;em&gt;whole file&lt;/em&gt;. Spend 128 kbps on audio and the video has to fit in what's left — otherwise your "target size" mode quietly ignores the audio track and overshoots.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The other mode is quality-based, which maps straight to H.264's CRF (constant rate factor):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;QUALITY_CRF&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;high&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;balanced&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;small&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lower CRF = better quality + bigger file. 23 is a genuinely good default for most footage; 28 is where you go when "smaller" matters more than "pristine."&lt;/p&gt;

&lt;h2&gt;
  
  
  Why "no server" changes the whole economics
&lt;/h2&gt;

&lt;p&gt;This is the part I think other devs will appreciate. Because the transcode happens in the tab:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hosting is basically free.&lt;/strong&gt; The app is 100% static — it's just HTML, JS, and a WASM blob on a CDN. No transcoding boxes, no per-video cost, no scaling worries. A traffic spike costs bandwidth on static assets, nothing more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Privacy is architectural, not a promise.&lt;/strong&gt; Plenty of sites &lt;em&gt;say&lt;/em&gt; "we delete your files." Here there's nothing to delete because nothing was ever sent. Open DevTools → Network tab and compress a file: zero upload requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It works offline&lt;/strong&gt; once the page and core are cached.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The one gotcha: &lt;code&gt;@ffmpeg/core-mt&lt;/code&gt; (the multithreaded build) needs &lt;code&gt;SharedArrayBuffer&lt;/code&gt;, which needs cross-origin isolation (COOP/COEP headers), which breaks a lot of third-party embeds. I chose the &lt;strong&gt;single-thread&lt;/strong&gt; &lt;code&gt;@ffmpeg/core&lt;/code&gt; on purpose — slightly slower, but no header gymnastics and full compatibility with everything else on the page. Know your tradeoff before you reach for the MT build.&lt;/p&gt;

&lt;h2&gt;
  
  
  The stack
&lt;/h2&gt;

&lt;p&gt;Nothing exotic, deliberately:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Next.js 16&lt;/strong&gt; (App Router) + &lt;strong&gt;React 19&lt;/strong&gt; + &lt;strong&gt;TypeScript&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tailwind CSS 4&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;@ffmpeg/ffmpeg&lt;/code&gt; 0.12&lt;/strong&gt; for the fallback path, &lt;strong&gt;&lt;code&gt;mediabunny&lt;/code&gt;&lt;/strong&gt; for WebCodecs demux/probing&lt;/li&gt;
&lt;li&gt;Static export — every page is SSG, deployable to Vercel / Cloudflare Pages / Netlify free tiers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The compression parameter functions (the bitrate/CRF math above) are pure and covered by &lt;code&gt;node --test&lt;/code&gt; unit tests. When the thing that matters is "did we compute the right bitrate," you want that logic testable without spinning up a browser or a real encoder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it / read it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The tool: &lt;strong&gt;&lt;a href="https://videocompress.dev" rel="noopener noreferrer"&gt;videocompress.dev&lt;/a&gt;&lt;/strong&gt; — drop a file in, pick a target size or quality, download. No account, no upload, no watermark.&lt;/li&gt;
&lt;li&gt;If you're building something similar, the WebCodecs-with-ffmpeg-fallback pattern and the bitrate math are the two pieces worth stealing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you end up shipping in-browser media processing, I'd genuinely like to hear how you handled the engine-selection edge cases — the "API exists but can't encode &lt;em&gt;this&lt;/em&gt;" gap is where most of the real bugs live. Drop a comment.&lt;/p&gt;

</description>
      <category>compress</category>
      <category>video</category>
      <category>free</category>
    </item>
  </channel>
</rss>
