Python + FFmpeg without installing FFmpeg
You're building a Python application that needs to process video. Maybe it's a Django app handling uploads, or a data pipeline extracting frames, or a script that batch-converts a folder of MOV files.
The usual approach is installing FFmpeg locally and calling it with subprocess.run(). That works until you deploy to a platform that doesn't have FFmpeg, or the binary is compiled without the codec you need, or your Docker image bloats to 800MB. If you've been through the self-hosted vs hosted FFmpeg debate, you know the pain.
The API approach is simpler: requests.post() with a JSON body. The only dependency is requests.
Configuration
This helper function handles submission and polling. Every example below uses it.
Convert video formats
MOV to MP4 is the most common conversion:
MP4 to WebM for web playback:
Any format to any format. The FFmpeg command is identical to what you'd run locally — if you already know FFmpeg commands, you already know the API.
Resize video
Scale to 720p while maintaining aspect ratio:
The -2 in scale=-2:720 means "calculate width automatically while keeping it divisible by 2." FFmpeg requires even dimensions for H.264.
Resize for Instagram (1080x1080 square with padding):
Resize for TikTok (1080x1920 vertical):
Trim and cut video
For a full walkthrough of keyframe-accurate cutting, input vs output seeking, and batch trimming, see the FFmpeg trim video guide.
Extract a 30-second clip starting at 1 minute:
Using -c copy makes this nearly instant because it copies without re-encoding. If you need frame-accurate trimming, re-encode:
Extract audio
MP4 to MP3:
Extract as WAV (lossless):
Add a watermark
Overlay a PNG logo in the bottom-right corner:
W-w-10 means "main video width minus logo width minus 10px padding." Same for height. For responsive scaling, opacity control, text watermarks, and animated overlays, see the FFmpeg watermark guide.
Generate thumbnails
For advanced frame extraction — scene detection, keyframe-only mode, and batch processing across hundreds of videos — see the FFmpeg frame extraction guide.
Extract a single frame at the 5-second mark:
Batch processing
Process multiple videos concurrently using ThreadPoolExecutor:
10 concurrent workers means 10 videos processing at once. Each runs in its own isolated container, so there's no resource contention between jobs. This is particularly useful for e-commerce video automation where you might need to process hundreds of product videos in a single run.
Error handling
Build robust error handling around the helper:
This handles API errors, FFmpeg failures, and timeouts. Use this version in production.
Django integration example
If you're using Django, here's a view that accepts a video URL and returns the processed result:
This gives you a video processing endpoint in about 20 lines. No FFmpeg binary on your server.
FAQ
Do I need to install FFmpeg on my server?
No. The whole point of an API approach is that FFmpeg runs on RenderIO's infrastructure. Your Python code sends HTTP requests — it doesn't call any local binary.
What Python version do I need?
Python 3.7 or later. The code uses f-strings and requests. If you're on 3.10+, you could also use httpx with async support for better concurrency.
How long do output files stay available?
Output URLs are pre-signed and expire after a set period. Download the file or store it in your own S3/R2 bucket right after processing completes.
Can I process videos larger than 1GB?
Yes, but processing time increases with file size. For very large files, consider trimming first (which is near-instant with -c copy) and then processing the smaller clip. See the curl examples for trimming commands.
What happens if the FFmpeg command has a syntax error?
The API returns a 400 status with details about what went wrong. The run_ffmpeg_safe function above catches this and raises a readable exception.
Next steps
If you want the same setup in JavaScript, the Node.js tutorial covers fetch, webhooks, and Express integration. For a quick reference of common commands, the FFmpeg cheat sheet has 50 copy-paste examples.
The Starter plan at $9/mo includes 500 commands. Get your API key to start building.