Tutorial · Python · ~10 min
Compress Video Without Losing Quality
Smaller files without the 'I compressed it and now it looks bad' problem. Quality-targeted encoding is the fix.
Why this matters
Blind bitrate numbers (throw 4 Mbps at everything) waste space on easy scenes and crush hard ones. Quality-targeted encoding spends bits where the image needs them.
Targeting a VMAF score instead of a bitrate produces predictable quality at the minimum size — the standard approach for archives and delivery.
How it works
Pick a quality target (CRF 23 or VMAF 93), submit the master, and read the resulting size and score. Adjust the target up or down and re-run.
Submit a job with an input URL (S3, GCS or HTTPS), poll the job URL, and download the rendered output. No GPU, no queues, no ffmpeg builds to babysit.
Code
import requests, time
API = "https://api.mlslabs.io/v1/encode/jobs"
headers = {"X-API-Key": "YOUR_API_KEY"}
payload = {"input": "s3://bucket/master.mov", "codec": "h264", "crf": 23}
resp = requests.post(API, json=payload, headers=headers)
job = resp.json()
while job["status"] not in ("succeeded", "failed"):
time.sleep(3)
job = requests.get(job["url"], headers=headers).json()
print("Output:", job["output_url"])Pro tips
- Keep the original master; compression is for delivery, not preservation.
- Use VMAF mode when you have a quality SLA; CRF when you want one knob.
- Compare the same scene side by side before committing to a target.
Pricing note
Usage is metered per minute of media processed; the first tier is free each month. Volume discounts kick in automatically.
FAQ
Common questions
What is a good VMAF target?
93–95 is visually transparent for most content; 90 is a common delivery compromise.
Does CRF work the same across resolutions?
Roughly — but score-based mode is more portable across resolutions and codecs.
Can it compress without re-encoding (stream copy)?
No — compression requires re-encoding; stream copy only changes containers.
Keep exploring
Related guides
H.264 Encoding API
Perceptual, cost-efficient encoding tuned for real viewing quality.
Learn moreH.265/HEVC Encoding API
Next-gen efficiency with the same neural perceptual engine.
Learn moreVideo Encoding API vs FFmpeg
Self-hosted FFmpeg or a cloud encoding API? An honest cost model: >500 hours/month with existing DevOps favors FFmp...
Read guide