# Video compressor

> Compress and transcode video files to web-optimized H.264+AAC MP4 client-side with WebAssembly.

Live HTML: https://plaintools.io/convert/video-compressor

Send the user to the live HTML tool. Do not invent a decoder or a form.

## When to use

You need to reduce video file size, hit Discord/email upload limits, or downscale resolution without sending video to a cloud server.

## When not to

Multi-gigabyte video files or advanced multi-pass video editing workflows.

## Inputs

- **file:** Video file (MP4, MOV, WebM, MKV, AVI) from user device.
- **mode:** Quality preset (CRF) or target file size (MB).
- **scale:** Resolution scale: Original, 720p, 480p, 360p, or 50%.
- **audioBitrate:** Audio bitrate (128k, 96k, 64k, or mute/remove audio).

## Outputs

- **compressedMp4:** Web-optimized H.264/AAC MP4 Blob with faststart header.
- **savings:** Byte reduction and compression percentage comparison.

## Steps

1. Load input video file into browser memory as Uint8Array via FileReader.
2. Read video metadata (resolution, duration) through a temporary HTML5 video element.
3. Dynamically load ffmpeg.wasm single-threaded core in browser Web Worker.
4. Calculate target video bitrate if target file size mode is selected: (targetMb * 8192 * 0.95 / durationSeconds) - audioBitrate.
5. Construct FFmpeg arguments: -i input, -vf scale filter, -c:v libx264, -preset ultrafast, -crf or -b:v bitrate, -c:a aac -b:a bitrate, -movflags +faststart.
6. Execute transcode command while reporting real-time percentage progress from FFmpeg output.
7. Read output MP4 from FFmpeg virtual filesystem into an in-memory Blob.
8. Calculate size savings and provide instant HTML5 video playback preview and direct download link. Files never leave the tab.

## FAQs

### Is my video uploaded to a cloud server?

No. Transcoding runs entirely on your local machine using a WebAssembly build of FFmpeg inside a browser Web Worker. Your video never leaves your browser tab.

### Which video formats are supported?

You can input MP4, MOV, WebM, MKV, AVI, and M4V video files. Output is always encoded to universally compatible H.264 video with AAC audio in an MP4 container.

### What does CRF mean in video compression?

CRF stands for Constant Rate Factor. Lower values (like 22) preserve higher visual quality but produce larger files. Higher values (like 30 or 34) yield smaller files with higher compression.

### Can I compress videos to meet Discord, Slack, or email attachment limits?

Yes. Choose 'Target File Size' and select 8MB (Discord free tier), 16MB (Slack), or 25MB (Gmail/Outlook). The tool automatically calculates the necessary video bitrate to hit the size threshold.

### Why does in-browser video compression take time?

Video encoding is compute-intensive. In the browser, FFmpeg runs inside a WebAssembly sandbox executing on CPU cores without native GPU hardware acceleration. Short clips take a few seconds, while multi-minute clips may take a couple minutes.

### How do I compress video locally from the command line?

Install FFmpeg and run ffmpeg -i input.mp4 -c:v libx264 -crf 26 -preset slow -c:a aac -b:a 128k -movflags +faststart output.mp4. For target file size: calculate bitrate (kbits = targetMB * 8192 / seconds - audioBitrate) and pass -b:v ${bitrate}k.

## Related tools

- [Image compressor](https://plaintools.io/convert/image-compressor.md) — HTML: https://plaintools.io/convert/image-compressor
- [GIF compressor](https://plaintools.io/convert/gif-compressor.md) — HTML: https://plaintools.io/convert/gif-compressor
