Gdynia LIVE: a live camera in the browser

An IP camera over WebRTC, one Rust binary and no transcoding
Adam Dmitruczuk 4 min read DevOps Web
Gdynia LIVE: a live camera in the browser

gdynia.puniserv.pl shows a live view of the bay and Gdynia. It works in the browser, on a phone too, with no app and no plugins.

The site started as an experiment. I wanted to check if I could write a camera proxy that runs on a server with few resources and shares the video safely. Viewers connect to the server, not to the camera, and they do not see its address or password. The first version was in Node.js, then I rewrote it in Rust.

How it works

The IP camera sends video over RTSP. A Rust server receives it and passes it to browsers over WebRTC. Nothing is re-encoded on the way, so the server barely uses the CPU.

  • RTSP input: the retina library, no ffmpeg.
  • Output: webrtc-rs, H.264 codec, 1920×1080, 25 frames per second.
  • Page: one HTML file with plain JS, no framework.
  • The viewer counter in the corner goes over WebSocket.

The whole server is about 650 lines of Rust and one binary run by systemd.

The camera connects only when someone watches

When the first viewer opens the page, the server connects to the camera. When the last one leaves, it waits 5 seconds and disconnects. Next viewers get the same stream, so the camera always has one connection, no matter how many viewers there are.

A new viewer does not get video right away, only from the next keyframe. Without that the picture could be broken at the start.

When the camera drops off the network, the server tries to reconnect every 0.5 s, then less and less often, at most every 10 s. The page does the same on its side and shows "Connecting..." instead of a black screen.

Three versions

  1. 2024: Node.js. ffmpeg converted the video to MPEG-1 and the browser decoded it in JS (jsmpeg).
  2. April 2026: Rust and WebRTC, but still with ffmpeg, which encoded the video to VP8.
  3. July 2026: no ffmpeg. The camera sends H.264 anyway, so the server passes it on unchanged.

From 640×480 to 1080p

For a long time the video was only 640×480. The camera has two streams: the main one in 2560×1440 and a small one in 640×480. The main one was in H.265, which WebRTC in browsers does not support well, so the server took the small one.

ONVIF, the standard camera API, described the main stream as H.264. Only ffprobe showed it was H.265. The vendor's app had no codec switch. ONVIF did the job: setting the encoder to H.264 turned H.265 off, and I set the resolution to 1920×1080 so it would not clog the uplink.

Slip-ups

  • Full disk on the server. The program wrote logs to a file, writing to a full disk ended with a panic in Rust, and the error message had nowhere to go either. The service restarted in a loop with no log at all. A test found the cause: the same binary worked when its output went to a pipe and crashed when it went to a file. In November the disk filled up a second time, now the system journal has a 100 MB limit.
  • Connection leak. webrtc-rs does not free UDP ports until you call close() explicitly. After a few hundred page loads the process hit the open files limit and stopped accepting viewers. Now every connection is closed, also when the negotiation fails.

A photo every 5 minutes

A side project came out of it. Every 5 minutes the camera takes a 2560×1440 photo and sends it over FTP. Then I copy them to my laptop. From 23 June to 18 November that is more than 42 thousand photos.

A Python script computes the average sky colour and brightness of every photo, and ffmpeg puts them together into a timelapse.

Calendar of the sky over Gdynia from June to November 2026

Sky calendar: one vertical strip is one day, the vertical axis is the hour, the colour is the sky. You can see the days getting shorter and the clock change at the end of October.

32 vertical strips of the view over Gdynia at noon, from June to November

Half a year in one frame: 32 strips, each one the sunniest noon of its period, from June to November.

AI

The move to retina, 1080p, the ONVIF script and the new page were done by Claude Code in one session: 7 of 20 commits in the repository. The full disk diagnosis too, together with the pipe vs file test.

I have no further plans for now. The experiment worked: the proxy runs on a small server and the camera always has only one connection.

If you need camera video on your site without a paid streaming service, write to me.

PUNISERV Adam Dmitruczuk · VAT ID 5882404209 · REGON 222097861 · phone 795881065 · Full CV: adam.puniserv.pl · Privacy policy