π Production-ready FFmpeg with NVIDIA CUDA acceleration in Docker
A comprehensive Docker solution providing FFmpeg with NVIDIA GPU acceleration through a beautiful web interface and RESTful API. Built for high-performance video processing with hardware-accelerated encoding, decoding, and advanced video effects.
- π¬ Hardware Accelerated: NVENC/NVDEC for lightning-fast processing
- π Beautiful Web Interface: Professional dashboard with real-time monitoring
- π§ RESTful API: Complete video processing through HTTP endpoints
- π Production Ready: Gunicorn WSGI server with health checks
- π Advanced Effects: Concatenation, fades, text overlays, blur, mixing
- π΅ Audio Processing: Extract, convert, and enhance audio
- π Format Conversion: Support for MP4, MOV, AVI, WebM, and more
- π Performance Monitoring: Real-time statistics and GPU monitoring
- π‘οΈ Enterprise Security: Non-root execution, input validation, resource limits
This solution has been thoroughly tested and optimized for:
- CPU: Intel Core i9 13th Generation
- GPU: NVIDIA GeForce RTX 4090 (24GB VRAM)
- OS: Windows 11 (latest updates)
- Docker: Docker Desktop with WSL2
- CUDA: Version 12.3.1
- Driver: NVIDIA Driver 576.52
- Performance: 300-500+ FPS (1080p H.264 encoding)
- Windows 11 with WSL2 enabled
- Docker Desktop with GPU support
- NVIDIA RTX series GPU (RTX 20/30/40 series recommended)
- Latest NVIDIA drivers
- At least 8GB free disk space
-
Clone the repository
git clone https://github.com/yourusername/ffmpeg-cuda-docker-api.git cd ffmpeg-cuda-docker-api -
Build the Docker image
docker build -t ffmpeg-cuda-api:latest . -
Run the container
docker run -d --name ffmpeg-cuda-api --gpus all \ -p 15959:5000 \ -v /mnt/h/Downloads:/workspace \ --restart unless-stopped \ ffmpeg-cuda-api:latest
-
Access the web interface
- Open: http://localhost:15959/
- From other containers: http://host.docker.internal:15959/
- Web Interface: http://localhost:15959/
- Health Check: http://localhost:15959/health
- API Documentation: http://localhost:15959/
When accessing from other Docker containers, use:
http://host.docker.internal:15959/
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Web interface and documentation |
/health |
GET | API health and system status |
/files |
GET | List available video files |
/info |
GET | FFmpeg capabilities and GPU info |
/stats |
GET | Performance statistics |
/encode |
POST | Video processing and encoding |
curl -X POST http://localhost:15959/encode \
-H "Content-Type: application/json" \
-d '{
"input": "video.mp4",
"output": "encoded.mp4",
"preset": "fast"
}'# Add text overlay with custom font
curl -X POST http://localhost:15959/encode \
-H "Content-Type: application/json" \
-d '{
"input": "video.mp4",
"output": "titled.mp4",
"video_filter": "drawtext=text='\''My Video'\'':fontfile=/workspace/fonts/arial.ttf:fontsize=64:fontcolor=white:x=(w-text_w)/2:y=50"
}'
# Concatenate multiple videos
curl -X POST http://localhost:15959/encode \
-H "Content-Type: application/json" \
-d '{
"input": "concat:video1.mp4|video2.mp4|video3.mp4",
"output": "combined.mp4"
}'
# 4K upscaling with blur effect
curl -X POST http://localhost:15959/encode \
-H "Content-Type: application/json" \
-d '{
"input": "1080p.mp4",
"output": "4k_blurred.mp4",
"scale": "3840x2160",
"video_filter": "gblur=sigma=5:enable='\''between(t,10,15)'\''"
}'ffmpeg-cuda-docker-api/
βββ Dockerfile # Production Docker configuration
βββ ffmpeg_api.py # Enhanced Flask API with web interface
βββ start_api.sh # Production startup script
βββ gunicorn.conf.py # Gunicorn production configuration
# Git ignore rules
Place custom fonts in your mounted directory:
H:\Downloads\fonts\arial.ttf
H:\Downloads\fonts\custom_font.ttf
# Optional environment variables
-e FFMPEG_THREADS=4 # Number of encoding threads
-e CUDA_VISIBLE_DEVICES=0 # Specific GPU to use
-e API_WORKERS=2 # Number of Gunicorn workers- 1080p H.264: 300-500+ FPS
- 4K H.264: 100-200+ FPS
- HEVC encoding: 150-300+ FPS
- Memory usage: 2-4GB VRAM typical
- Processing time: 2-5 seconds for typical videos
- Use
preset=fastfor speed,preset=slowfor quality - Enable hardware acceleration with
hwaccel=cuda - Monitor GPU usage with
/infoendpoint - Use appropriate CRF values (18-28)
# Clone repository
git clone https://github.com/yourusername/ffmpeg-cuda-docker-api.git
cd ffmpeg-cuda-docker-api
# Build development image
docker build -t ffmpeg-cuda-api:dev .
# Run with development settings
docker run -it --gpus all \
-p 15959:5000 \
-v $(pwd):/app \
-v /mnt/h/Downloads:/workspace \
ffmpeg-cuda-api:dev bashThe Flask API supports hot-reloading for development:
# Inside container
python3 ffmpeg_api.py# Container health
docker inspect ffmpeg-cuda-api --format='{{.State.Health.Status}}'
# API health
curl http://localhost:15959/health# API statistics
curl http://localhost:15959/stats
# GPU monitoring
curl http://localhost:15959/info# Follow logs
docker logs -f ffmpeg-cuda-api
# Recent logs
docker logs --tail 100 ffmpeg-cuda-apiThis project is licensed under the MIT License - see the LICENSE file for details.
- FFmpeg team for the incredible multimedia framework
- NVIDIA for CUDA and hardware acceleration support
- Docker community for containerization best practices
- Flask team for the excellent web framework
- FFmpeg - Multimedia framework
- NVIDIA Video Codec SDK - Hardware acceleration
- Docker - Containerization platform