Tutorial · Python · ~10 min
Build an Adaptive Bitrate Ladder
Four renditions, one job. The ABR ladder that keeps every viewer buffer-free without burning bandwidth.
Why this matters
Adaptive streaming needs multiple renditions — the player picks the one that fits the connection. A well-built ladder balances quality at each rung and total storage cost.
Encoding each rung separately is error-prone and slow; one API call with a ladder spec produces all renditions consistently.
How it works
Define resolution/bitrate pairs (1080p/5M, 720p/2.8M, 480p/1.4M, 360p/800k), submit once, and get per-rung MP4s plus HLS/DASH manifests.
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.mp4", "codec": "h264", "ladder": [[1920, 5000000], [1280, 2800000], [854, 1400000], [640, 800000]]}
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
- Don't waste rungs: 4–5 well-spaced renditions cover nearly all connections.
- Anchor the top rung to your source quality; encode the bottom rung for 2G connections.
- Use keyframe alignment — the API aligns segment boundaries across rungs automatically.
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
Does it output HLS or DASH?
Both — request fMP4 with HLS or DASH manifests; CMAF output is available.
Can I customize segment duration?
Yes — 2–10s segments, default 6s.
How are keyframes aligned?
The encoder forces segment-aligned keyframes across all rungs, so players switch cleanly.
Keep exploring