What I do
I reduce MP4 file sizes by re-encoding with smart defaults. The key insight: most screencasts and talking-head videos are over-encoded at 60fps. Dropping to 30fps and tuning the encoder gives 20-50% file size reduction with no perceptible quality difference.
Bundled scripts: @compress_video.py
When to use me
- You have an MP4 that's too large for sharing/uploading
- You recorded a screencast at 60fps and want to cut it in half
- You need "good enough" quality at a fraction of the size
- You want to batch-compress training videos, demos, or recordings
How to use
CLI (quick)
# Analyze only
python compress_video.py input.mp4 --probe-only
# Default compression (high quality)
python compress_video.py input.mp4 output.mp4
# Aggressive compression for small files
python compress_video.py input.mp4 -p aggressive
# Screencast (code/EDA tools): drop 60→30fps, stillimage tune
python compress_video.py input.mp4 -p balanced --tune stillimage --fps 30
# Downscale to 1080p
python compress_video.py input.mp4 -p balanced --resolution 1920x1080
Python API
from compress_video import compress, probe
# Probe first
info = probe("input.mp4")
print(f"{info['width']}x{info['height']} @ {info['fps']:.0f}fps")
# Compress with defaults
compress("input.mp4", "output.mp4")
# Compress with aggressive settings
compress("input.mp4", "output.mp4", profile="aggressive",
fps=24, tune="stillimage")
Requirements
- Python 3.8+
- ffmpeg installed and on PATH (with
ffprobe)
Compression profiles
| Profile | x264 CRF | x265 CRF | Use case |
|---|---|---|---|
lossless | 18 | 20 | Archival, maximum quality |
high (default) | 23 | 25 | Visually lossless, safe default |
balanced | 26 | 28 | Good quality, smaller files |
aggressive | 28 | 30 | Small files, minor gradient loss |
Key strategies
| Technique | Typical saving | Quality impact |
|---|---|---|
| 60fps → 30fps | ~25% | Imperceptible for screencasts |
| H.264 CRF 23 (from CRF 18) | ~20% | None to most viewers |
| H.264 → H.265 (libx265) | ~30-40% | None (same CRF) |
--tune stillimage | ~5-10% | Better for code/slides |
| Downscale 3200→1920 | ~50% | Sharpness loss on zoom |
Examples
Reduce a 125 MB screencast by 30-50%
# Quick default run (uses libx264, drops 60→30fps)
python compress_video.py recording.mp4 recording_compressed.mp4
# 125 MB → 97 MB (-22%)
# With stillimage tune (better for code/screencasts)
python compress_video.py recording.mp4 -p balanced --tune stillimage --fps 30
# 125 MB → ~80 MB (-35%)
# Full HEVC with slower preset
python compress_video.py recording.mp4 --codec h265 --preset slow --fps 30
# 125 MB → ~60 MB (-50%, but encodes ~slower)
Batch process a folder
Get-ChildItem *.mp4 | ForEach-Object {
python compress_video.py $_.Name "$($_.BaseName)_compressed.mp4"
}