This document explains how to use hardware-accelerated video processing in m3u-proxy using the integrated GPU detection and FFmpeg optimization.
The m3u-proxy container now includes automatic hardware acceleration detection that:
- 🔍 Auto-detects GPU hardware (NVIDIA, Intel, AMD)
- ⚡ Configures optimal FFmpeg settings automatically
- 🚀 Provides easy Python APIs for hardware-accelerated transcoding
- 📊 Falls back gracefully to CPU when no GPU is available
- Requirements: NVIDIA Container Toolkit
- Acceleration: CUDA, NVENC, NVDEC
- Best For: High-performance transcoding with multiple concurrent streams
- Docker Setup: Use
deploy.resources.reservations.deviceswithdriver: nvidia
- Requirements:
/dev/dridevices passed to container - Acceleration: VAAPI, QuickSync (QSV)
- Best For: Efficient transcoding with good quality/performance balance
- Docker Setup: Mount
/dev/dri:/dev/dri
- Requirements:
/dev/dridevices passed to container - Acceleration: VAAPI
- Best For: Open-source acceleration solution
- Docker Setup: Mount
/dev/dri:/dev/dri
# docker-compose.yml
services:
m3u-proxy:
image: m3u-proxy:latest
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
ports:
- "8085:8085"# docker-compose.yml
services:
m3u-proxy:
image: m3u-proxy:latest
devices:
- /dev/dri:/dev/dri
ports:
- "8085:8085"# NVIDIA GPU
docker run -d --name m3u-proxy \
--gpus all \
-p 8085:8085 \
m3u-proxy:latest
# Intel/AMD GPU
docker run -d --name m3u-proxy \
--device /dev/dri:/dev/dri \
-p 8085:8085 \
m3u-proxy:latest
# CPU Only (no special setup needed)
docker run -d --name m3u-proxy \
-p 8085:8085 \
m3u-proxy:latestfrom hwaccel import hw_accel, get_ffmpeg_hwaccel_args, is_hwaccel_availableif is_hwaccel_available():
print(f"🚀 Hardware acceleration available: {hw_accel.get_type()}")
else:
print("💻 Using CPU-only processing")# Basic hardware acceleration args
basic_args = hw_accel.get_basic_args()
# Transcoding with specific codec
h264_args = get_ffmpeg_hwaccel_args("h264")
h265_args = get_ffmpeg_hwaccel_args("h265")
# Build FFmpeg command
cmd = ["ffmpeg"] + h264_args + ["-i", "input.m3u8", "output.mp4"]import asyncio
import subprocess
from hwaccel import get_ffmpeg_hwaccel_args, hw_accel
async def transcode_stream(input_url: str, output_path: str):
# Get optimal hardware acceleration settings
hwaccel_args = get_ffmpeg_hwaccel_args("h264")
cmd = ["ffmpeg", "-y"] + hwaccel_args + [
"-i", input_url,
"-c:v", "h264_nvenc" if hw_accel.get_type() == "nvidia" else "h264_vaapi",
"-preset", "fast",
"-b:v", "2M",
"-c:a", "aac",
output_path
]
process = await asyncio.create_subprocess_exec(*cmd)
await process.communicate()
return process.returncode == 0The hardware detection script creates these environment variables:
HW_ACCEL_AVAILABLE:trueif hardware acceleration is availableHW_ACCEL_TYPE: Type of acceleration (nvidia,intel,amd,vaapi,cpu)HW_ACCEL_DEVICE: Device identifier (cuda,vaapi, or empty)
These are also saved to /tmp/hwaccel.env for easy access.
When the container starts, it automatically:
- 🔍 Detects available GPU hardware using
lspci - 🔧 Checks device accessibility (
/dev/nvidia*,/dev/dri/*) - ⚡ Tests FFmpeg capabilities for detected hardware
- 📊 Generates optimal settings and saves configuration
- 🚀 Starts your application with hardware acceleration ready
- 10-20x faster encoding vs CPU
- Multiple concurrent streams (4+ simultaneously)
- Lower CPU usage (90%+ reduction)
- Hardware-optimized presets (fast, medium, slow)
- 3-8x faster encoding vs CPU
- Better quality/bitrate efficiency
- Lower power consumption
- Good for 1-2 concurrent streams
- Universal compatibility
- High quality encoding (slower)
- Single stream recommended
- Uses software encoders (libx264, libx265)
# Check if GPU devices are available
docker run --rm m3u-proxy:latest ls -la /dev/dri /dev/nvidia*
# Check hardware detection logs
docker logs <container-name> | grep "🔍"# Test NVIDIA container runtime
docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi
# Check NVIDIA driver on host
nvidia-smi# Check DRI devices on host
ls -la /dev/dri/
# Test VAAPI in container
docker run --rm --device /dev/dri:/dev/dri m3u-proxy:latest vainfoThe container startup will show hardware detection results:
📦 m3u-proxy starting up...
🐍 Python version: Python 3.12.3
🎬 FFmpeg version: 8.0
🔍 Running hardware acceleration check...
🔍 Hardware detection: NVIDIA GPU (GeForce RTX 3080)
✅ FFmpeg NVIDIA acceleration: AVAILABLE
🔰 NVIDIA GPU: GeForce RTX 3080
✅ Hardware acceleration configuration loaded
🚀 Starting m3u-proxy application...
The hardware acceleration is designed to integrate seamlessly with your existing streaming proxy logic. Simply import the module and use the provided functions to get optimal FFmpeg arguments for any transcoding operations.
The system automatically handles:
- Hardware detection and capability testing
- Optimal encoder selection (NVENC, VAAPI, CPU)
- Fallback scenarios when hardware isn't available
- Performance tuning based on detected GPU type