Live Cameras
Authenticated live video for job sites | CheckPoint Business Intelligence | private company project, sanitized
context
Sites have IP cameras on their local networks, and the platform's users wanted to watch them live inside the same web app they already sign in to, with the right role, from a browser or a phone. The cameras speak RTSP; browsers want HLS.
problem
HLS is hard to secure: a stream is one manifest plus a new segment every couple of seconds, and a browser's video element cannot send an Authorization header. Gating only the manifest leaves every segment open, and putting a token in the URL leaks it into logs and history. The stream servers also had to survive a node going down without breaking playback. And once it all worked, the video ran about ten seconds behind reality, which made a live feed look like a recording.
what I did
- Ran MediaMTX on two Ubuntu nodes under keepalived (VRRP), so a floating IP moves to the backup node if the primary goes down; cameras are pulled over RTSP on demand, so streams start only when someone watches.
- Gated every request in nginx with auth_request: a FastAPI endpoint validates the viewer's session and role before nginx serves the manifest or a segment, and manifest URLs are rewritten so segments go through the same check.
- Replaced the token in stream URLs with an HttpOnly stream cookie backed by Redis, so nothing secret appears in URLs, logs or browser history.
- Built the FastAPI camera API on SQL Server: CRUD, stream-session logging, a configuration audit log, and a health worker with a live log tail over server-sent events.
- Added NVR discovery and bulk enrollment over the recorder's HTTP API, with re-scans that report added, moved and missing channels and protection against locking out the recorder account, plus bounded PTZ nudges and presets for cameras that support them.
- Cut live latency from about 10 s to 1-2 s by tuning four layers that were multiplying each other: the camera's keyframe interval, the MediaMTX segment length that rounded up to the next keyframe, the number of segments hls.js parks behind the live edge, and the rewind window.
- Built the React live monitor with hls.js, snapshot thumbnails (RTSP + FFmpeg), a native-HLS fallback for iOS Safari, a stream-health view and the PTZ controls.
stack
MediaMTX keepalived nginx FastAPI Redis React hls.js FFmpeg SQL Server
outcome
- Live feeds reach signed-in users with the right role only, checked on every manifest and every segment, with no token in any URL.
- Two stream nodes behind a floating IP instead of a single server.
- Latency down from about 10 s to 1-2 s, and the rewind window from 33 s to 10 s.
- A recorder's cameras enrolled in bulk instead of one at a time; the camera, NVR, PTZ and health code ships with 80+ tests.
- Every stream session and every camera change is logged for audit.
Sanitized case study -- no client identifiers, hostnames, IP addresses, endpoints, or stream URLs.