一项高性能的 IPTV 流媒体代理服务,支持故障转移并提供全面的 API 管理。包括利用硬件加速进行转码的功能
A high-performance HTTP proxy server for IPTV content with true live proxying, per-client connection management, and seamless failover support. Built with FastAPI and optimized for efficiency.
Feel free to open an issue on this repo, or hit us up on Discord
Join our Discord server to ask questions and get help, help others, suggest new ideas, and offer suggestions for improvements! You can also try out and help test new features!
pip installed on your system: >=23git clone https://github.com/sparkison/m3u-proxy.git && cd m3u-proxy
pip install -r requirements.txtpython main.py --debugServer will start on http://localhost:8085
…POST /streams
Content-Type: application/json
{
"url": "stream_url",
"failover_urls": ["backup_url1", "backup_url2"],
"user_agent": "Custom User Agent String"
}GET /streamsGET /streams/{stream_id}DELETE /streams/{stream_id}POST /streams/{stream_id}/failoverGET /statsGET /healthGET /clients
GET /clients/{client_id}The included CLI client (m3u_client.py) provides easy access to all proxy features:
# Create a stream with failover
python m3u_client.py create "https://primary.m3u8" --failover "https://backup1.m3u8" "https://backup2.m3u8"
# List all active streams
python m3u_client.py list
# View comprehensive statistics
python m3u_client.py stats
# Monitor in real-time (updates every 5 seconds)
python m3u_client.py monitor
# Check health status
python m3u_client.py health
# Get detailed stream information
python m3u_client.py info
# Trigger manual failover
python m3u_client.py failover
# Delete a stream
python m3u_client.py delete …When API_TOKEN is set in the environment, all management endpoints require authentication via the X-API-Token header. This includes:
/ - Root endpoint/streams - Create, list, get, delete streams/stats/* - All statistics endpoints/clients - Client management/health - Health check endpoint/webhooks - Webhook management/streams/{stream_id}/failover - Failover control/hls/{stream_id}/clients/{client_id} - Client disconnectStream endpoints (the actual streaming URLs) do NOT require authentication since they are accessed by media players that identify streams via stream_id.
Example with authentication:
…To disable authentication, simply leave API_TOKEN unset or set it to an empty string.
m3u-proxy includes comprehensive hardware acceleration support for video transcoding operations using FFmpeg with GPU acceleration.
The container automatically detects available hardware on startup:
Running hardware acceleration check...
✅ Device /dev/dri/renderD128 is accessible.
Intel GPU: Intel GPU (Device ID: 0x041e)
✅ FFmpeg VAAPI acceleration: AVAILABLE
For older Intel GPUs, try: LIBVA_DRIVER_NAME=i965services:
m3u-proxy:
image: sparkison/m3u-proxy:latest
devices:
- /dev/dri:/dev/dri
environment:
- LIBVA_DRIVER_NAME=i965 # For older Intel GPUs
# - LIBVA_DRIVER_NAME=iHD # For newer Intel GPUsservices:
m3u-proxy:
image: sparkison/m3u-proxy:latest
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]# Intel/AMD GPU
docker run -d --name m3u-proxy \
--device /dev/dri:/dev/dri \
-e LIBVA_DRIVER_NAME=i965 \
-p 8085:8085 \
sparkison/m3u-proxy:latest
# NVIDIA GPU
docker run -d --name m3u-proxy \
--gpus all \
-p 8085:8085 \
sparkison/m3u-proxy:latestThe hardware acceleration is available through Python APIs:
from hwaccel import get_ffmpeg_hwaccel_args, is_hwaccel_available
# Check if hardware acceleration is available
if is_hwaccel_available():
# Get optimized FFmpeg arguments
hwaccel_args = get_ffmpeg_hwaccel_args("h264")
# Example: Hardware-accelerated transcoding
cmd = ["ffmpeg"] + hwaccel_args + [
"-i", "input_stream.m3u8",
"-c:v", "h264_vaapi", # Hardware encoder
"-preset", "fast",
"-b:v", "2M",
"output_stream.mp4"
]| Hardware | Encoding Speed | Concurrent Streams | CPU Usage Reduction |
|---|---|---|---|
| NVIDIA GPU | 10-20x faster | 4-8 streams | 95%+ |
| Intel GPU | 3-8x faster | 2-4 streams | 90%+ |
| AMD GPU | 3-5x faster | 2-3 streams | 85%+ |
| CPU Only | Baseline | 1 stream | N/A |
For detailed hardware acceleration setup and troubleshooting, see Hardware Acceleration Guide.
# Main server with all features
python main.py
# With custom options
python main.py --port 8002 --debug --reloadStream Won't Load
High Memory Usage
CLIENT_TIMEOUT for faster cleanupFailover Not Working
# Enable detailed logging
export LOG_LEVEL=DEBUG
python main.py --debug
ffplay "http://localhost:8085/hls/{stream_id}/playlist.m3u8"vlc "http://localhost:8085/hls/{stream_id}/playlist.m3u8"The proxy includes a comprehensive event system for monitoring and integration:
# Add webhook to receive events
curl -X POST "http://localhost:8085/webhooks" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-server.com/webhook",
"events": ["stream_started", "client_connected", "failover_triggered"],
"timeout": 10,
"retry_attempts": 3
}'stream_started - New stream createdstream_stopped - Stream endedclient_connected - Client joined stream client_disconnected - Client left streamfailover_triggered - Switched to backup URLconnection_idle_warning - Connected client idle past CONNECTION_IDLE_ALERT_THRESHOLD (default 600s)connection_idle_error - Connected client idle past CONNECTION_IDLE_ERROR_THRESHOLD (default 1800s); likely connection leak{
"event_id": "uuid",
"event_type": "stream_started",
"stream_id": "abc123",
"timestamp": "2025-09-25T22:38:34.392830",
"data": {
"primary_url": "http://example.com/stream.m3u8",
"user_agent": "MyApp/1.0"
}
}# Try the event system demo
python demo_events.pyFull Documentation: See EVENT_SYSTEM.md for complete webhook integration guide.
…Whether it’s writing docs, squashing bugs, or building new features, your contribution matters! ❤️
We welcome PRs, issues, ideas, and suggestions!
Here’s how you can join the party:
m3u editor is licensed under CC BY-NC-SA 4.0:
For full license details, see LICENSE.
暂无开放 Issues,或尚未同步最近议题。