Tutorial · Python · ~8 min
How to Convert Video to H.265/HEVC in Python
Encode a 4K clip to HEVC at a target VMAF in about ten lines of code — then watch the size difference versus H.264.
Step 1 — Sign up and get your API key
- Sign up (free tier included)
- Copy the API key from the dashboard
- pip install mlslabs
Step 2 — Submit an encode job
Cloud samples: football-match-4k.mp4 and movie-master-1080p.mp4.
Python
import mlslabs
client = mlslabs.Client("YOUR_API_KEY")
job = client.h265_encoding.submit(
input_url="s3://bucket/football-match-4k.mp4",
output_url="s3://bucket/hevc/",
profile="main10",
quality_target={"metric": "vmaf", "score": 92},
preset="sports", # sports | uhd | vod
)
print(job.job_id)Step 3 — Poll for completion
Python
job.wait()
print(job.status) # done | failedStep 4 — Download and verify
Bash
curl -L -o out-hevc.mp4 <output_url>
ffprobe -show_streams out-hevc.mp4 | grep codec_name
# => codec_name=hevc
# typical result on the 4K sample:
# H.264 38MB -> HEVC 21MB (same VMAF)Next steps
- Reduce streaming bandwidth costs
- Batch-transcode your library
- H.264 vs H.265 — what's actually different?
Keep exploring