Tutorial · Python · ~10 min

Compress 4K Video Without Losing Quality

4K files are heavy. HEVC at a quality target keeps the picture and halves the bill.

Python4K CompressionAPI

Why this matters

4K at H.264 bitrates is a storage and bandwidth problem; HEVC delivers the same visual quality at roughly half the bitrate — the reason UHD streaming runs on it.

Quality-targeted encoding (CRF/VMAF) makes the trade-off explicit: pick a score, get the smallest file that hits it.

How it works

Submit the 4K master with codec=hevc and a CRF/VMAF target; the job returns size, bitrate, and a VMAF estimate against the source.

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

Python
import requests, time

API = "https://api.mlslabs.io/v1/encode/jobs"
headers = {"X-API-Key": "YOUR_API_KEY"}
payload = {"input": "s3://bucket/4k.mov", "codec": "hevc", "crf": 26}

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

  • HEVC CRF 26 ≈ H.264 CRF 23 visually — start there and compare.
  • Keep 10-bit when the source is 10-bit; banding on gradients is the tell-tale of 8-bit HEVC.
  • Verify with the VMAF report, not eyeballs — 4K artifacts hide in motion.

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

Is HEVC worth it for 4K delivery?

Yes — half the bitrate for the same score is the standard math; check HEVC patent licensing terms for commercial distribution.

Does playback need specific hardware?

Modern devices decode HEVC in silicon; older browsers need fallback renditions.

Can I get both H.264 and HEVC rungs from one job?

Yes — encode a mixed ladder in a single request.