WebRTC — playback and live broadcasting in the browser
Updated 05 Oct 2026WebRTC plays a channel straight in the browser — no app, no plugin — with a much smaller delay than HLS. Castreon gives you a ready-made player page, the code to embed it in your website and a standard WHEP address for your own players. When the profile has several qualities, every viewer gets the one that suits their connection.
It also works the other way: a channel can receive a live broadcast over WebRTC (WHIP) — from OBS, from other WHIP software or straight from the browser, with a camera or a shared screen.
Available from Castreon 1.0.4, on the Enterprise plan.
Turn on playback for a channel
- Open the channel → Edit → Add output and choose WebRTC as the Type.
- Optionally set Maximum viewers per channel (0 = no limit).
- When the profile has at least two H.264 qualities, leave Several qualities in the player on (next to Active) — see below. When it is off, or the profile has only one quality, choose the Quality sent.
- Save. The WebRTC addresses appear on the channel page, under Delivery.
Nothing runs while nobody is watching: WebRTC starts with the first viewer and stops 30 seconds after the last one.
The addresses
For a channel with the short name channel1:
| Row in Delivery | Address | For |
|---|---|---|
| WebRTC · player | http://<domain>/whep/channel1/player |
anyone — it opens in any modern browser |
| WebRTC · iframe | the code that embeds the player in a web page | your website |
| WebRTC · WHEP | http://<domain>/whep/channel1 |
your own WebRTC player or app (WHEP standard) |
<domain> is the Public domain in Settings → Instance — see M3U export and public domain. If you set a Token for players, the panel already adds it to the addresses for operators and administrators, and the player passes it on by itself. The same Allowed addresses as for HLS apply.
The player starts without sound, because browsers only allow automatic playback when muted; the viewer turns the sound on with Sound on.
Several qualities in the player
With a profile that has at least two H.264 qualities — for example the recipe ABR ladder (multiple qualities): 1080p, 720p and 480p — every viewer receives one of them:
- Automatically: Castreon measures each viewer's connection all the time. When the connection can no longer carry the current quality, it goes down; after a stable stretch it tries the quality above. If a try does not hold, it goes back and waits longer before the next one.
- By hand: the player has a quality menu at the top right (Auto, 1080p, 720p, 480p, with the bitrate of each). A quality picked there stays until the viewer chooses Auto again.
The change happens at the next keyframe of the profile (a few seconds at most), without a broken picture. The qualities are the ones the profile already encodes, so there is no extra encoding; only the H.264 qualities are used. Other WHEP players get the automatic choice as well; a player that does not report its connection stays on a medium quality (the best one up to about 3.5 Mb/s).
If you change the profile or the option while people are watching, the players reconnect by themselves within a few seconds, with the new qualities.
Server settings
Settings → WebRTC:
- Port (UDP + TCP) — empty means 33478; one port for all viewers and broadcasts. Open it in the firewall for both UDP and TCP — the panel shows the exact command, for example
ufw allow 33478/udp && ufw allow 33478/tcp. - Public IP — only when the server sits behind a 1:1 NAT (some clouds give the server a private address). Leave it empty when the public address is on the server itself.
- Maximum viewers per server — 0 means no limit; it applies immediately.
The port and the public IP apply after restarting the service (sudo systemctl restart castreon). When a restart is needed, the panel says so.
Delay and picture
- From a source that arrives continuously (UDP, SRT, RIST, DVB, WHIP), the delay is about one to two seconds.
- From an HLS or DASH source, the stream arrives in segments of a few seconds. Castreon holds the picture a little and sends it evenly, so the delay is a few seconds. Right after the start there can be one short pause while Castreon measures the source; after that the picture runs smoothly.
- Browsers play H.264 without B-frames. When the channel is already encoded in H.264 by Castreon, the picture is copied as it is. Otherwise (passthrough, HEVC) Castreon converts it for browsers — count on about one to two processor cores for a Full HD channel. Several qualities in the player are always copied.
- The sound is converted to Opus, the format of WebRTC.
Live source: broadcast from OBS or from the browser (WHIP)
Add the source
- Open the channel → Edit → Add source and choose WebRTC (WHIP).
- Save. Castreon creates the WHIP address (
http://<domain>/whip/channel1) and a Stream key. Both appear in the editor, with a copy button.
The key works like a password: whoever has it can broadcast on the channel. New key creates another one — after saving, the old key no longer works. Accounts that can only view the channel see the key masked.
The broadcast becomes the source of the channel like any other: the profile, the outputs and the failover work the same. While nobody is broadcasting, the WHIP source has no signal: the channel waits and picks the broadcast up within seconds after it starts. With a backup source, the channel plays the backup meanwhile and returns to the broadcast at the next check of the main source (the failover settings of the channel). A channel has one WHIP source and one broadcast at a time — a new broadcast replaces the previous one. A broadcast that sends nothing for 20 seconds is closed.
From OBS (30 or newer)
Settings → Stream: Service = WHIP, Server = the WHIP address, Bearer Token = the stream key. Under Output, use an H.264 encoder and a keyframe interval of 2 seconds. Castreon takes the H.264 picture as it is and converts the Opus sound to AAC for the channel.
Other software that can broadcast over WHIP is set up the same way: the WHIP address and the key as the Bearer token.
From the browser
On the channel page, the WebRTC source (WHIP) card shows whether a broadcast is coming in, from which address and software, the picture and the sound. Broadcast from the browser opens a window where you choose the Source (camera and microphone, or a shared screen) and the Quality (720p or 1080p), then Start broadcasting. Keep the window open while you broadcast — closing it stops the broadcast.
Browsers only allow the camera and the screen on an HTTPS page (or on localhost, for example through an SSH tunnel) — see the next section. Browsers that cannot send H.264 send VP8; Castreon converts it to H.264, which costs processor time.
HTTPS for the panel
Castreon serves the panel over plain HTTP. For HTTPS, put a web server with a certificate in front of it. The simplest is Caddy, which obtains the certificate by itself — /etc/caddy/Caddyfile:
tv.example.com {
reverse_proxy 127.0.0.1:33400
}
With nginx, use proxy_pass http://127.0.0.1:33400; and proxy_buffering off; (the panel receives live updates). Then set the Public domain in Settings → Instance to https://tv.example.com, so the addresses under Delivery and the WHIP address use HTTPS too. The picture and the sound of WebRTC still travel directly over the WebRTC port, not through the web server.
On the channel page
While somebody is watching, the WebRTC card shows the viewers and the limit, whether the picture is copied or converted, the Qualities (with the measured bitrate and how many viewers each has), the Buffer (how long Castreon holds the picture to send it evenly), how much was sent, the Short stalls and the list of viewers — with the Quality each one receives, whether it was chosen automatically or in the player, and the estimated bandwidth.
For monitoring, /metrics also publishes the WebRTC metrics (castreon_webrtc_…) — see Metrics and Grafana. The automatic check in Settings → Support warns you when the WebRTC port could not be opened or when a channel cannot send its picture over WebRTC — see Automatic check and diagnostic report.
If it does not work
- The player keeps trying to connect — the port is closed in the firewall (it must be open for UDP and TCP), or the server is behind NAT and the Public IP is not set.
- The player shows “WebRTC is available on the Enterprise plan” — the license of the server does not include WebRTC.
- The player shows “channel is not running — retrying…” — the channel could not start; check that it is active and that its source works (WebRTC starts it on demand).
- The picture pauses now and then — the source arrives irregularly. Castreon increases its reserve by itself after the first pause; if Short stalls keeps growing, look at the source.
- There is no quality menu in the player — the profile has only one H.264 quality, or Several qualities in the player is off.
- OBS cannot connect — check the WHIP address and the key (after New key and saving, only the new key works) and that the WebRTC port is open for UDP and TCP.
- Broadcast from the browser asks for HTTPS — open the panel over HTTPS (see above) or through an SSH tunnel on
localhost.