Tutorial · Python · ~8 min
How to Convert Video to H.264 in Python
Convert a video to H.264 with a quality target instead of a blind bitrate — and see the size difference the perceptual engine makes.
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 encoding job
Cloud sample: sports-football.mp4. No footage of your own needed.
Python
import mlslabs
client = mlslabs.Client("YOUR_API_KEY")
job = client.h264_encoding.submit(
input_url="s3://bucket/sports-football.mp4",
output_url="s3://bucket/h264/",
quality_target={"metric": "vmaf", "score": 93},
preset="streaming", # streaming | archive | gaming
)
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.mp4 <output_url>
ffprobe -show_streams out.mp4 | grep codec_name
# => codec_name=h264
# compare: same clip, standard x264 vs perceptual encode
ls -lh x264.mp4 out.mp4 # out.mp4 is typically 15-30% smaller at equal VMAFNext steps
- Batch-compress a whole library
- Build an adaptive bitrate ladder
- Chain: Super Resolution → encode
- Migrate from FFmpeg
Keep exploring