Why video compression takes so long

Video2 min read

What the encoder is actually doing to every frame, why it runs on one thread here, and the things that genuinely make it faster.

In short

Compression decodes, transforms and re-encodes every frame — thousands of them — and in the browser it runs single-threaded. Minutes, not seconds, is normal. Trimming first is the only large speed-up.

Trimming a clip finishes in seconds. Compressing the same clip takes minutes. The difference is not arbitrary — they are doing very different amounts of work.

What compression has to do

Every frame has to be decoded from the source, transformed, and encoded again. A two-minute clip at 30fps is 3,600 frames, and each one involves motion estimation — searching the previous frames for matching blocks — which is the single most expensive operation in video encoding. That search is why the encoder is slow, and also why it is good.

Tools that only touch part of the file are fast for the same reason. Muting a video copies the picture through untouched and drops the audio track; nothing is decoded, so it takes seconds regardless of length.

Why it is single-threaded here

FFmpeg's multi-threaded WebAssembly build needs SharedArrayBuffer, which requires a security header that would block other things the page needs. Dexta uses the single-thread build instead, so the encode gets one CPU core rather than all of them. It is a real cost, and it is the trade that keeps everything else on the page working.

What actually makes it faster

In order of effect
ActionEffect
Trim firstDirectly proportional — half the length is half the time
Cap the resolutionFewer pixels per frame to encode
Keep the tab in the foregroundBrowsers throttle background tabs, which can stall an encode
Use a laptop rather than a phoneMore CPU headroom and far more memory
Close other heavy tabsThe encode is competing for the same core

Mistakes worth avoiding

  • Switching tabs and assuming it is still running at full speed. It probably is not.
  • Compressing the full clip when you only need thirty seconds of it.
  • Starting a long encode on a phone that is low on memory — it may run out and reload the page.