MPEG-TS Stream Proxy - Convert DASH (MPD) to MPEG-TS streams on-the-fly
5.0K
Convert DASH (MPD) streams to MPEG-TS format on-the-fly for direct streaming.
docker pull nirvana777/hls-converter:latest
docker run -d \
--name mpegts-proxy \
-p 8000:8000 \
nirvana777/hls-converter:latest
version: '3.8'
services:
mpegts-proxy:
image: nirvana777/hls-converter:latest
container_name: mpegts-proxy
ports:
- "8000:8000"
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
# Clone repository
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git
cd YOUR_REPO
# Install dependencies
pip install -r requirements.txt
# Install FFmpeg (Ubuntu/Debian)
sudo apt-get install ffmpeg
# Run service
python mpegts-proxy.py
# Direct streaming (outputs MPEG-TS)
curl "http://localhost:8000/stream?url=https://example.com/stream.mpd&name=MyStream" > output.ts
# Use in media player (VLC, ffplay, etc.)
vlc "http://localhost:8000/stream?url=https://example.com/stream.mpd"
ffplay "http://localhost:8000/stream?url=https://example.com/stream.mpd"
| Parameter | Required | Description |
|---|---|---|
url | Yes | DASH manifest URL (.mpd) |
name | No | Stream name for metadata (default: "Stream") |
curl http://localhost:8000/health
Response:
{
"status": "healthy",
"streams": 2,
"max_streams": 10,
"stream_details": [
{
"id": "a1b2c3d4",
"age": 120,
"clients": 2,
"alive": true
}
]
}
Configuration is done via code constants in mpegts-proxy.py:
manager = StreamManager(
max_streams=10, # Maximum concurrent streams
max_stream_age=3600 # Maximum stream lifetime (1 hour)
)
Cleanup intervals (in StreamManager._cleanup_loop):
βββββββββββ ββββββββββββ
β Client ββββββ HTTP GET /stream?url=... βββββΆβ aiohttp β
βββββββββββ β API β
β ββββββββββββ
β β
β ββββ MPEG-TS Stream βββ β
β βΌ
β ββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββ FFmpeg β
β Process β
ββββββββββββ
β
βΌ
βββββββββββββββββ
β DASH Source β
β (.mpd URL) β
βββββββββββββββββ
Key Features:
β’ Stream Reuse: Same URL = same FFmpeg process (multiple clients)
β’ Auto Cleanup: Dead/idle/old streams removed every 30s
β’ Process Monitoring: Health checks on FFmpeg processes
β’ Resource Limits: Max 10 concurrent streams (configurable)
/stream?url=<mpd_url>/healthmax_streams for your hardwarecurl http://localhost:8000/health | jq
# Container logs show stream lifecycle
docker logs -f mpegts-proxy
# Inside container
docker exec mpegts-proxy ps aux
docker stats mpegts-proxy
docker logs mpegts-proxy for FFmpeg errorsmax_streams in code/health to see if streams are stuckmax_streams/healthThis is not an HLS converter. Key differences:
| Feature | MPEG-TS Proxy | HLS Converter |
|---|---|---|
| Output format | MPEG-TS stream | HLS playlist + segments |
| Storage | No disk storage | Requires disk for segments |
| Volumes | None needed | /tmp/hls_segments required |
| API | Simple GET endpoint | POST to convert, GET playlist |
| Use case | Direct streaming | CDN distribution |
| Latency | Real-time | Segment duration delay |
β Good for:
β Not for:
Automated CI/CD pipeline:
Set in GitHub repository settings:
DOCKERHUB_USERNAME: Docker Hub usernameDOCKERHUB_TOKEN: Docker Hub access tokenPotential improvements:
MIT
Pull requests welcome! Ensure:
Content type
Image
Digest
sha256:162a41afdβ¦
Size
277.7 MB
Last updated
8 months ago
docker pull nirvana777/hls-converter