Self-hosting & deployment
Status: the Docker files below are written and their parts were tested on a Windows PC (same code, same MediaMTX version). A deployment on a real cloud server with a domain has not been done yet. Do it once on a staging server before the first client.
What runs
| Process | Job | Ports |
|---|---|---|
api (Python, FastAPI) |
API, Studio, viewer pages, guides, playback files, MediaMTX permission hook, starts one worker per stream | 8200 (behind the proxy) |
worker (one per live stream) |
ingest split, engines, dub tracks, packaging, re-streams | none |
mediamtx |
receives RTMP / SRT / WebRTC (WHIP) | 1935/tcp, 8890/udp, 8889/tcp, 8189/udp |
caddy |
HTTPS for the API (automatic Let's Encrypt certificates) | 80, 443 |
Server size
Per live stream: about 0.3 CPU core when the picture is copied (measured on 24 Nov: 0.25 of one core and about 200 MB RAM for
one Hindi stream, all processes together); budget 1.5-2 cores if video_transcode is on or the source is LiveKit or a browser
(the picture is re-encoded; not measured yet), and outgoing traffic to the engines (small: audio only). Viewers load files over HTTPS: about
2.7 Mbit/s each (2.5 video + audio). Put a CDN in front of /play for more than ~100 viewers.
A good start: 8 vCPU / 16 GB in an India region (data stays in India for Sarvam; e.g. Azure Central India, AWS ap-south-1), SSD with 100 GB per 40 hours of recordings kept.
Steps (Ubuntu 24.04 with Docker)
- DNS: point
api.example.comandingest.example.comto the server. - Firewall: open 80/tcp, 443/tcp, 1935/tcp, 8889/tcp, 8189/udp, 8890/udp. Nothing else.
- Copy the project to
/opt/dubstreamand create.envfrom.env.example: - your provider keys (
SARVAM_API_KEY,GEMINI_API_KEY); - four new random secrets: run
python3 -c "import secrets;print(secrets.token_urlsafe(32))"four times; FDS_PUBLIC_BASE_URL=https://api.example.com,FDS_INGEST_HOST=ingest.example.com,FDS_WHIP_BASE_URL=https://ingest.example.com:8889(WHIP needs TLS on 8889; see below) andFDS_TRUSTED_PROXIES=172.30.0.10(the Caddy container's address indocker-compose.yml).- Edit
Caddyfile(your domain, your e-mail for Let's Encrypt). - In
mediamtx.ymlsetwebrtcAdditionalHosts: [<server public IP>]. docker compose up -d --build- Create the first client:
docker compose exec api python manage.py create-tenant --name "Acme School", thendocker compose exec api python manage.py create-key --tenant ten_.... - Check:
https://api.example.com/readyzshows"ok": true; open/studioand run the sample stream.
Keep FDS_MASTER_KEY safe and backed up. Without it, stored LiveKit secrets, re-stream URLs and webhook secrets cannot be read.
HTTPS for ingest
- RTMP: plain RTMP is common. For RTMPS set
rtmpEncryption: optionaland certificate paths inmediamtx.ymlandFDS_RTMPS=1. - WHIP (browser camera): browsers require HTTPS for the WHIP address if the page is HTTPS. Set
webrtcEncryption: truewith the same certificate (Caddy's certificates are in thecaddy_datavolume), or put 8889 behind Caddy. - SRT: set a passphrase in
mediamtx.ymlif needed.
Updating
git pull && docker compose up -d --build. Running streams keep running while the API restarts (the API finds its workers again
on start). Updating the worker code affects new streams only.
Backups
data/dubstream.db (accounts, keys, streams, usage). SQLite in WAL mode: copy with sqlite3 data/dubstream.db ".backup x.db".
Monitoring
/healthz(process alive) and/readyz(database + media server) for your uptime monitor.logs/anddata/streams/<id>/worker.log; every API answer hasX-Request-Id.python manage.py usagefor minutes and engine cost per client.
Scaling beyond one server
The API keeps the rate limiter in memory and the data in SQLite: one API server. For more, move to Postgres (the schema is
plain SQL), the limiter to Redis, put several worker servers behind a queue, and serve /play from shared storage or a CDN origin.
Not needed for the first clients: by the measurement above one 8-core server should carry 10-20 copied streams at once with
room to spare (an estimate; not load-tested with many streams yet).
Running on a Windows PC (demo)
py -3.13 -m venv .venv; .\.venv\Scripts\pip install -r requirements.txt
copy .env.example .env # fill it in
.\run_local.ps1 # starts MediaMTX + API on http://localhost:8200
.\stop_local.ps1 # stops everything
Viewers on other networks can watch through a tunnel to port 8200 (e.g. ngrok). Sending video from another network needs a public server (RTMP and WebRTC cannot go through a normal web tunnel).