A simple REST API for executing FFmpeg commands remotely. No more asking your users to install FFmpeg locally.
When building CLI tools that require FFmpeg, the biggest friction point is installation. Users don't want to deal with installing FFmpeg and its dependencies. This API removes that friction entirely—just send your media file and FFmpeg command, get the processed result back.
Requirements:
- FFmpeg must be installed on the server running this API
Convert a video to H.264 with audio normalization and scale to 720p:
import requests
# Upload the video file and get the processed result back directly
with open("input_video.mp4", "rb") as f:
response = requests.post(
"http://localhost:8000/run",
files={"file": f},
data={
"cmd": "ffmpeg -i <input> -c:v libx264 -preset medium -crf 23 -vf scale=-2:720 -c:a aac -b:a 128k -af loudnorm output.mp4",
"return_file": "true"
}
)
# Save the processed file locally
with open("output.mp4", "wb") as f:
f.write(response.content)
print("File saved as output.mp4")Response: Binary file content that gets saved directly.
Extract audio from a video and convert to MP3:
import requests
# Upload the video file and get a URL to download the result
with open("input_video.mp4", "rb") as f:
response = requests.post(
"http://localhost:8000/run",
files={"file": f},
data={
"cmd": "ffmpeg -i <input> -vn -c:a libmp3lame -q:a 2 output.mp3"
}
)
result = response.json()
print(f"Download your file from: {result['output_url']}")Response:
{
"cmd": "ffmpeg -i /uploads/xyz/input.mp4 -vn -c:a libmp3lame -q:a 2 /outputs/xyz/output.mp3",
"stdout": "",
"stderr": "ffmpeg version 4.4.2...",
"returncode": 0,
"output_url": "http://localhost:8000/static/xyz/output.mp3"
}Extract a thumbnail at 5 seconds, scale it, and apply sharpening:
import requests
# Upload the video and extract a thumbnail
with open("video.mp4", "rb") as f:
response = requests.post(
"http://localhost:8000/run",
files={"file": f},
data={
"cmd": "ffmpeg -i <input> -ss 00:00:05 -vframes 1 -vf scale=1280:-2,unsharp=5:5:1.0:5:5:0.0 thumbnail.jpg"
}
)
result = response.json()
print(f"Thumbnail URL: {result['output_url']}")
print(f"Status: {'Success' if result['returncode'] == 0 else 'Failed'}")Response:
{
"cmd": "ffmpeg -i /uploads/abc/video.mp4 -ss 00:00:05 -vframes 1 -vf scale=1280:-2,unsharp=5:5:1.0:5:5:0.0 /outputs/abc/thumbnail.jpg",
"stdout": "",
"stderr": "ffmpeg version 4.4.2...",
"returncode": 0,
"output_url": "http://localhost:8000/static/abc/thumbnail.jpg"
}- Python 3.8 or higher
- FFmpeg installed on your system (see Installing FFmpeg below)
- uv package manager (recommended) or pip
FFmpeg must be installed on the server where you run this API.
Ubuntu/Debian:
sudo apt update
sudo apt install ffmpegFedora:
sudo dnf install ffmpegArch Linux:
sudo pacman -S ffmpegUsing Homebrew:
brew install ffmpeg-
Using Chocolatey (recommended):
choco install ffmpeg
-
Manual Installation:
- Download from ffmpeg.org
- Extract the archive
- Add the
binfolder to your system PATH
Verify installation:
ffmpeg -version-
Clone the repository:
git clone https://github.com/kevinnadar22/ffmpegapi.git cd ffmpegapi -
Install dependencies:
uv sync
Or with pip:
pip install -r requirements.txt
-
Run the API:
python run.py
The API will start on
http://localhost:8000 -
Test the installation:
pytest tests/
docker-compose upThe API will be available at http://localhost:8000
Run the test suite to ensure everything works:
pytest tests/For verbose output:
pytest tests/ -vThis project uses pre-commit hooks to maintain code quality. If you're contributing:
-
Install pre-commit hooks:
pre-commit install
-
The hooks will automatically run before each commit to check:
- Code formatting
- Linting
- Type checking
- Other quality checks
-
Run hooks manually (optional):
pre-commit run --all-files
All contributions must pass pre-commit checks before being merged.
For complete interactive API documentation, visit http://localhost:8000/docs when the server is running.
Kevin Nadar
🌐 Website: mariakevin.in 💻 GitHub: @kevinnadar22
No more FFmpeg installation headaches for your users. Just upload, process, and download.