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)

  1. DNS: point api.example.com and ingest.example.com to the server.
  2. Firewall: open 80/tcp, 443/tcp, 1935/tcp, 8889/tcp, 8189/udp, 8890/udp. Nothing else.
  3. Copy the project to /opt/dubstream and create .env from .env.example:
  4. your provider keys (SARVAM_API_KEY, GEMINI_API_KEY);
  5. four new random secrets: run python3 -c "import secrets;print(secrets.token_urlsafe(32))" four times;
  6. 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) and FDS_TRUSTED_PROXIES=172.30.0.10 (the Caddy container's address in docker-compose.yml).
  7. Edit Caddyfile (your domain, your e-mail for Let's Encrypt).
  8. In mediamtx.yml set webrtcAdditionalHosts: [<server public IP>].
  9. docker compose up -d --build
  10. Create the first client: docker compose exec api python manage.py create-tenant --name "Acme School", then docker compose exec api python manage.py create-key --tenant ten_....
  11. Check: https://api.example.com/readyz shows "ok": true; open /studio and 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

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

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