百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

m3u-proxy

> 开发工具
开源

一项高性能的 IPTV 流媒体代理服务,支持故障转移并提供全面的 API 管理。包括利用硬件加速进行转码的功能

99 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一项高性能的 IPTV 流媒体代理服务,支持故障转移并提供全面的 API 管理。包括利用硬件加速进行转码的功能

m3u proxy

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.

Questions/issues/suggestions

Feel free to open an issue on this repo, or hit us up on Discord

Join us 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!

Features

Core Streaming

  • Pure HTTP Proxy: Zero transcoding, direct byte-for-byte streaming
  • Connection Sharing: Multiple viewers share one upstream provider connection (HLS, Transcoded, and live Direct/TS streams)
  • ⚡️ Truly Ephemeral: Provider connections open only when clients are consuming; close when the last client disconnects
  • HLS Support: Optimized playlist and segment handling (.m3u8)
  • Continuous Streams: Primary/subscriber broadcast for .ts, .mp4, .mkv, .webm, .avi live streams
  • Real-time URL Rewriting: Automatic playlist modification for proxied content
  • Full VOD Support: Per-client connections with byte-range requests and seeking
  • Strict Live TS Mode: Enhanced stability for live MPEG-TS with pre-buffering & circuit breaker

Performance & Reliability

  • ⚡ uvloop Integration: 2-4x faster async I/O operations
  • Seamless Failover: =3.10`
  • pip installed on your system: >=23
bash
git clone https://github.com/sparkison/m3u-proxy.git && cd m3u-proxy
pip install -r requirements.txt

2. Start the Server

bash
python main.py --debug

Server will start on http://localhost:8085

3. Create a Stream

…

API Documentation

Stream Management

Create Stream

bash
POST /streams
Content-Type: application/json

{
  "url": "stream_url",
  "failover_urls": ["backup_url1", "backup_url2"],
  "user_agent": "Custom User Agent String"  
}

List Streams

bash
GET /streams

Stream Information

bash
GET /streams/{stream_id}

Delete Stream

bash
DELETE /streams/{stream_id}

Trigger Failover

bash
POST /streams/{stream_id}/failover

Statistics & Monitoring

Comprehensive Stats

bash
GET /stats

Health Check

bash
GET /health

Client Information

bash
GET /clients
GET /clients/{client_id}

CLI Client Usage

The included CLI client (m3u_client.py) provides easy access to all proxy features:

bash
# 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 

Configuration

Environment Variables

…

API Authentication

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 disconnect

Stream 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.

Hardware Acceleration

m3u-proxy includes comprehensive hardware acceleration support for video transcoding operations using FFmpeg with GPU acceleration.

Supported Hardware

  • ** NVIDIA GPUs**: CUDA, NVENC, NVDEC (10-20x faster than CPU)
  • ⚡ Intel GPUs: VAAPI, QuickSync (QSV) (3-8x faster than CPU)
  • ** AMD GPUs**: VAAPI acceleration (3-5x faster than CPU)
  • ** CPU Fallback**: Software encoding when no GPU available

Automatic Detection

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=i965

Docker Setup Examples

Intel/AMD GPU Support

yaml
services:
  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 GPUs

NVIDIA GPU Support

yaml
services:
  m3u-proxy:
    image: sparkison/m3u-proxy:latest
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

Docker Run Commands

bash
# 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:latest

Programming Interface

The hardware acceleration is available through Python APIs:

python
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"
    ]

Performance Benefits

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

Supported Codecs

  • H.264/AVC: High compatibility, universal support
  • H.265/HEVC: Better compression, 4K/8K content
  • VP8/VP9: WebM containers, streaming optimized
  • AV1: Next-gen codec, best compression
  • MJPEG: Low latency, surveillance applications

For detailed hardware acceleration setup and troubleshooting, see Hardware Acceleration Guide.

Server Startup Options

python
# Main server with all features
python main.py

# With custom options
python main.py --port 8002 --debug --reload

Troubleshooting

Common Issues

  1. Stream Won't Load

    • Check original URL accessibility
    • Verify CORS headers if accessing from browser
    • Check server logs for detailed errors
  2. High Memory Usage

    • Reduce CLIENT_TIMEOUT for faster cleanup
    • Monitor client connections and cleanup inactive ones
    • Consider horizontal scaling for high loads
  3. Failover Not Working

    • Verify failover URLs are accessible
    • Check failover trigger conditions in logs
    • Test manual failover via API

Debug Mode

bash
# Enable detailed logging
export LOG_LEVEL=DEBUG
python main.py --debug

Integration Examples

HTML5 Video Player

xml

  

FFmpeg

bash
ffplay "http://localhost:8085/hls/{stream_id}/playlist.m3u8"

VLC

bash
vlc "http://localhost:8085/hls/{stream_id}/playlist.m3u8"

Event System & Webhooks

The proxy includes a comprehensive event system for monitoring and integration:

Webhook Configuration

bash
# 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
  }'

Available Events

  • stream_started - New stream created
  • stream_stopped - Stream ended
  • client_connected - Client joined stream
  • client_disconnected - Client left stream
  • failover_triggered - Switched to backup URL
  • connection_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

Webhook Payload Example

json
{
  "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"
  }
}

Demo Events

bash
# Try the event system demo
python demo_events.py

Full Documentation: See EVENT_SYSTEM.md for complete webhook integration guide.

Additional Documentation

  • Documentation Index - Complete, always-current list of all documentation

Development

Project Structure

…

Want to Contribute?

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:

  • Follow our coding style and best practices.
  • Be respectful, helpful, and open-minded.
  • Respect the CC BY-NC-SA license.
  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

⚖️ License

m3u editor is licensed under CC BY-NC-SA 4.0:

  • BY: Give credit where credit’s due.
  • NC: No commercial use.
  • SA: Share alike if you remix.

For full license details, see LICENSE.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonm3um3u-editorm3u-proxyproxy-server

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具