Compress, trim and convert video in the browser with FFmpeg WASM

6 min read
video
ffmpeg
guide

Uploading a 400 MB screen recording to a random website just to cut thirty seconds off the front has always been a bad trade. With WebAssembly builds of FFmpeg, you no longer have to: the same encoder that ships on your laptop runs inside the tab.

What actually runs locally

The FFmpeg tools here load a WASM build into a worker, write your file into a virtual filesystem, run the command, and hand back the output blob. The file never leaves the machine, which is why the tools keep working offline once the module is cached.

Presets that make files smaller

Most oversized videos are oversized for one of three reasons: the bitrate is too high, the resolution is larger than anyone will watch, or the codec is old.

  • Re-encode with H.264 at CRF 23 for a good default. Lower CRF means better quality and a bigger file; 18 is close to visually lossless, 28 is noticeably soft.
  • Scale down before you fiddle with bitrate. 1080p to 720p typically halves the size on its own.
  • Drop the audio track when the clip is a silent UI demo.
  • Use `-preset slow` when you can wait: slower presets buy real size savings at the same quality.

A typical command looks like this:

ffmpeg -i input.mp4 -vf scale=-2:720 -c:v libx264 -crf 23 -preset slow -c:a aac -b:a 128k output.mp4

Trimming without re-encoding

If you only need a slice and the cut points can move slightly, stream copy is instant because nothing is decoded:

ffmpeg -ss 00:00:12 -to 00:00:47 -i input.mp4 -c copy clip.mp4

Cuts land on keyframes, so the start may shift by a second or two. Drop `-c copy` when you need frame-accurate boundaries.

GIFs are not a compression strategy

A three-second GIF is often larger than the MP4 it came from. Generate a palette first if you need a GIF for a README, but prefer a muted, looping MP4 or WebM anywhere that supports video.

Where the limits are

WASM runs slower than a native binary — roughly two to five times, depending on the codec — and memory is bounded by the tab. Clips up to a few hundred megabytes are comfortable; a feature-length 4K file is not. For those, copy the generated command out of the tool and run it locally.

Tools from this article

← All articles