How alexxit/go2rtc works
Project Type and Purpose
• It’s a monolithic, full-stack Go streaming server.
• Purpose: Ingest many camera/video/audio sources, perform on-the-fly transcoding via FFmpeg, and export streams via protocols (RTSP, WebRTC, HLS, MJPEG, MP4, RTMP, WebTorrent, HomeKit).
Top-Level Components
• Clients
– Web UI (HTML/JS in www/)
– REST/WebSocket API clients (browsers, Home Assistant, CLI examples)
– RTSP clients (e.g. FFmpeg, VLC, Home Assistant)
– WebRTC peers (browsers, OBS via WHIP)
– RTMP targets (YouTube, Telegram)
• go2rtc Server (single Go binary)
A. API Module (internal/api + www static assets + openapi.yaml)
B. Stream Manager (internal/streams)
C. Source Plugins (internal/{rtsp,rtmp,http,onvif,ffmpeg,homekit,…})
D. Output Modules
– RTSP Server (internal/rtsp)
– RTMP Server (internal/rtmp)
– WebRTC Server (internal/webrtc + Pion libraries)
– HLS Server (internal/hls)
– MP4/MSE Server (internal/mp4)
– MJPEG Server (internal/mjpeg)
– WebTorrent (internal/webtorrent)
– HomeKit Proxy (internal/homekit)
E. FFmpeg Manager (internal/ffmpeg) — spawns external ffmpeg processes
F. ngrok Integration (internal/ngrok) for NAT traversal
• External Dependencies
– FFmpeg CLI
– STUN/TURN servers
– ngrok service
– Home Assistant, Docker containers, hardware devices
Relationships and Data Flows
• Clients → API Module
– Configuration, “Add Stream,” status, UI assets
• API Module ↔ Stream Manager
– Control plane: start/stop streams, publish endpoints
• Stream Manager → Source Plugins
– Pull or subscribe to media from cameras and devices
• Source Plugins → Internal Media Pipeline
– Normalizes incoming tracks (audio/video)
– Negotiates codecs, may hand off to FFmpeg Manager for transcoding
• Media Pipeline → Output Modules
– Streams data to clients via RTSP/RTMP/WebRTC/HLS/MP4/MJPEG/WebTorrent/HomeKit
• Output Modules → Clients/External Services
– RTSP: clients at rtsp://…
– WebRTC: peer connections (UDP/TCP)
– HLS/MP4/MJPEG: HTTP endpoints
– RTMP: push to external RTMP URLs
– ngrok & STUN/TURN assist WebRTC NAT traversal
Architectural Patterns and Principles
• Layered modular monolith – clear separation of control plane (API) and data plane (streams)
• Plugin-style source/output modules under internal/ and pkg/
• Event-driven lifecycle – streams started on-demand, stopped when idle
• Zero-config “auto” streams via Home Assistant import or empty config
Technologies and Frameworks
• Go modules for: HTTP API (internal/api), WebSocket, RTSP, WebRTC (Pion), HLS, MJPEG, MP4, ngrok
• FFmpeg CLI spawned on demand for transcoding via internal/ffmpeg
• Static web UI in www/ served by API module
• OpenAPI spec in api/openapi.yaml for client integration
• Docker build definitions in docker/
• Examples in examples/ demonstrating client usage