A browser cannot open an rtsp:// URL. The two usual ways to put an IP camera on a web page are to transcode it to HLS — several seconds of delay, plus a decoder and an encoder per camera — or to run a separate media server next to your application.

This post takes a third route: the .NET application itself becomes a WebRTC server, the camera's H.264 goes to the browser exactly as the camera sent it, and the camera's audio goes with it as Opus.

Two cameras in a browser grid, each playing over WebRTC from its own WHEPServerSinkBlock

IP camera --RTSP, H.264 + AAC--> [ RTSPRAWSourceBlock --H.264, not decoded------------------> WHEPServerSinkBlock ] --WebRTC--> browsers [ RTSPRAWSourceBlock --AAC/G.711--> DecodeBinBlock --PCM--> WHEPServerSinkBlock ] (your .NET application) 

What that buys you:

  • Sub-second latency — the browser plays WebRTC, not segments.
  • Almost no CPU for the video, for any number of viewers — the video is never decoded or encoded. The audio is decoded once per camera and encoded to Opus for each viewer. Each viewer still costs the camera's bitrate in network bandwidth.
  • Sound included — browsers take Opus over WebRTC, not the AAC or G.711 a camera sends, so the audio is decoded in the app and the block encodes it to Opus.
  • No media server — the WHEP server runs inside your process; the player is about 20 lines of JavaScript with no library.

WHEP (WebRTC-HTTP Egress Protocol) is small: one POST with the SDP offer, a 201 Created with the SDP answer and a Location header for the session, and a DELETE on that Location when the viewer leaves. Any WHEP player can use the endpoint.

The code uses VisioForge Media Blocks SDK .NET, a commercial SDK with a free trial (I work on it): the NuGet package VisioForge.DotNet.MediaBlocks plus the platform's VisioForge.CrossPlatform.Core.* and *.Adds runtime packages. It runs on Windows x64, macOS and Linux x64/arm64.

The code below is written against VisioForge.DotNet.MediaBlocks 2026.11.23, the first release with audio on the WHEP server. The complete project, ready to run, is the RTSP WHEP Camera Grid demo in the samples repository.

The one thing to know first: same origin

The WHEP server sends no CORS headers, so a browser accepts its answers only on a page served from the same address and port. Opening index.html from disk fails at the fetch of the offer.

The simple fix: the application runs a small HTTP server for the page and forwards every request under /whep/ to the WHEP server, which listens on loopback only. The browser talks to one origin. Only the HTTP exchange goes through the page server; the video travels over the WebRTC connection the offer and answer set up.

One camera: the complete server

A console program: it builds the pipeline, serves an embedded index.html on http://localhost:8080/ and forwards /whep/... to the WHEP server on 127.0.0.1:9100. The page is embedded in the .csproj with <EmbeddedResource Include="wwwroot\index.html" LogicalName="index.html" />.

using System; using System.IO; using System.Net; using System.Net.Http; using System.Threading.Tasks; using VisioForge.Core; using VisioForge.Core.MediaBlocks; using VisioForge.Core.MediaBlocks.Sinks; using VisioForge.Core.MediaBlocks.Sources; using VisioForge.Core.MediaBlocks.Special; using VisioForge.Core.Types.X.Sinks; using VisioForge.Core.Types.X.Sources; const string PageUrl = "http://localhost:8080/"; const string WhepServer = "http://127.0.0.1:9100"; await VisioForgeX.InitSDKAsync(); using var http = new HttpClient(); MediaBlocksPipeline? pipeline = null; HttpListener? pageServer = null; try { if (!WHEPServerSinkBlock.IsAvailable()) { Console.WriteLine("WHEPServerSinkBlock is not available: add the VisioForge.CrossPlatform.Core.*.Adds package for this platform."); return; } pipeline = new MediaBlocksPipeline(); pipeline.OnError += (s, e) => Console.WriteLine(e.Message); // Encoded H.264 straight from the camera, and its audio if it has any (CreateAsync turns audio off otherwise). var rtspSettings = await RTSPRAWSourceSettings.CreateAsync(new Uri("rtsp://192.168.1.64:554/stream1"), "admin", "password", audioEnabled: true); var rtsp = new RTSPRAWSourceBlock(rtspSettings); // The WHEP server listens on loopback only; browsers reach it through the page server below. var whep = new WHEPServerSinkBlock(new WHEPServerSinkSettings { ServerAddress = WhepServer }); whep.ConsumerAdded += (s, e) => Console.WriteLine($"Viewer connected: {e.PeerId}"); whep.ConsumerRemoved += (s, e) => Console.WriteLine($"Viewer left: {e.PeerId}"); pipeline.Connect(rtsp.VideoOutput, whep.VideoInput); // Browsers take Opus, not the camera's AAC or G.711: decode it here, the WHEP server encodes it to Opus. if (rtspSettings.AudioEnabled) { var audioDecoder = new DecodeBinBlock(renderVideo: false, renderAudio: true, renderSubtitle: false); pipeline.Connect(rtsp.AudioOutput, audioDecoder.Input); pipeline.Connect(audioDecoder.AudioOutput, whep.AudioInput); } // The page and the WHEP requests share one origin: whepserversink sends no CORS headers. pageServer = new HttpListener(); pageServer.Prefixes.Add(PageUrl); pageServer.Start(); _ = ServePageAsync(pageServer); if (await pipeline.StartAsync()) { Console.WriteLine($"Open {PageUrl} in a browser. Press Enter to stop."); Console.ReadLine(); } } catch (Exception ex) { // CreateAsync throws when the camera cannot be read; HttpListener.Start when the page port is taken. Console.WriteLine(ex.Message); } finally { pageServer?.Close(); if (pipeline != null) { await pipeline.StopAsync(); await pipeline.DisposeAsync(); } VisioForgeX.DestroySDK(); } async Task ServePageAsync(HttpListener server) { while (server.IsListening) { HttpListenerContext context; try { context = await server.GetContextAsync(); } catch (Exception ex) when (ex is HttpListenerException || ex is ObjectDisposedException) { return; } _ = HandleRequestAsync(context); } } async Task HandleRequestAsync(HttpListenerContext context) { var request = context.Request; var response = context.Response; try { var path = request.Url?.AbsolutePath ?? string.Empty; if (path == "/") { // The page embedded by the .csproj above. using var page = System.Reflection.Assembly.GetEntryAssembly()!.GetManifestResourceStream("index.html")!; using var html = new MemoryStream(); await page.CopyToAsync(html); await WriteAsync(response, "text/html", html.ToArray()); } else if (path.StartsWith("/whep/", StringComparison.Ordinal)) { // The offer and the session's DELETE go to the WHEP server unchanged. using var forward = new HttpRequestMessage(new HttpMethod(request.HttpMethod), WhepServer + path); if (request.HasEntityBody) { using var body = new MemoryStream(); await request.InputStream.CopyToAsync(body); forward.Content = new ByteArrayContent(body.ToArray()); forward.Content.Headers.TryAddWithoutValidation("Content-Type", request.ContentType); } using var reply = await http.SendAsync(forward); if (reply.Headers.Location != null) { // The session URL the player deletes when it leaves. response.Headers["Location"] = reply.Headers.Location.OriginalString; } response.StatusCode = (int)reply.StatusCode; await WriteAsync(response, reply.Content.Headers.ContentType?.ToString(), await reply.Content.ReadAsByteArrayAsync()); } else { response.StatusCode = 404; } } catch (Exception ex) { Console.WriteLine(ex.Message); response.StatusCode = 502; } finally { response.Close(); } } static async Task WriteAsync(HttpListenerResponse response, string? contentType, byte[] body) { if (contentType != null) { response.ContentType = contentType; } response.ContentLength64 = body.Length; await response.OutputStream.WriteAsync(body); } 
  • RTSPRAWSourceSettings.CreateAsync reads the camera's stream description before the pipeline is built, and throws when the camera is offline or the credentials are refused. With audioEnabled: true it keeps the camera's audio and turns AudioEnabled off when the camera sends none, so the audio is connected only then.
  • rtsp.VideoOutput → whep.Input is the whole video path: no decoder, no encoder.
  • rtsp.AudioOutput → DecodeBinBlock → whep.AudioInput is the audio path: the camera's AAC or G.711 is decoded once and the block encodes it to Opus for each viewer.
  • ConsumerAdded / ConsumerRemoved fire for each viewer, on a GStreamer thread — in a UI application, marshal to the UI thread without blocking it.

The browser side: a minimal WHEP player

Save it as wwwroot/index.html:

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Camera</title> <style> body { margin: 0; background: #111; color: #ddd; font-family: sans-serif; } figure { margin: 0; position: relative; background: #000; } video { width: 100%; aspect-ratio: 16 / 9; display: block; } figcaption { position: absolute; left: 8px; top: 6px; font-size: 13px; text-shadow: 0 0 3px #000; } </style> </head> <body> <figure> <video id="video" autoplay muted playsinline controls></video> <figcaption id="caption" data-name="Camera">Camera</figcaption> </figure> <script> // STUN/TURN servers for the viewer's side of the connection; empty is enough on a local network. const iceServers = []; // A minimal WHEP player: offer, POST it to the endpoint, apply the answer. async function play(endpoint, video, caption) { const pc = new RTCPeerConnection({ iceServers }); pc.addTransceiver('video', { direction: 'recvonly' }); pc.addTransceiver('audio', { direction: 'recvonly' }); // Video and audio arrive as two tracks; both go into the one stream the video element plays. video.srcObject = new MediaStream(); pc.ontrack = e => video.srcObject.addTrack(e.track); await pc.setLocalDescription(await pc.createOffer()); // Send the offer with all ICE candidates in it. await new Promise(resolve => { if (pc.iceGatheringState === 'complete') resolve(); else pc.onicegatheringstatechange = () => pc.iceGatheringState === 'complete' && resolve(); }); const response = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/sdp' }, body: pc.localDescription.sdp }); if (response.status !== 201) throw new Error(`${endpoint}: HTTP ${response.status}`); await pc.setRemoteDescription({ type: 'answer', sdp: await response.text() }); // End the session on the server when the page closes. const session = response.headers.get('Location'); addEventListener('pagehide', () => fetch(session, { method: 'DELETE', keepalive: true })); pc.onconnectionstatechange = () => caption.textContent = `${caption.dataset.name} - ${pc.connectionState}`; } const caption = document.getElementById('caption'); play('/whep/endpoint', document.getElementById('video'), caption).catch(e => caption.textContent = e.message); </script> </body> </html> 
  1. Receive-only video and audio transceivers: the page only watches and listens. A camera without audio leaves the audio part inactive and the video plays alone.
  2. Wait for ICE gathering to complete, so every candidate travels inside the single POST and no trickle-ICE PATCH is needed.
  3. POST the offer as application/sdp; the server answers 201 Created with the SDP answer.
  4. Apply the answer; ontrack adds each track, video and audio, to the stream the <video> element plays.
  5. DELETE the session on pagehide; keepalive: true lets the request go out while the page unloads.

muted lets playback start without a click; unmute it with the element's controls to hear the camera. The caption shows connecting, connected or failed — the first thing to look at when a tile stays black.

Several cameras

The camera grid demo: two cameras with their WHEP URLs, the grid page link and two viewer sessions

One WHEPServerSinkBlock serves one camera. For a grid, run one source → sink pair per camera (plus a DecodeBinBlock for each camera with audio), each WHEP server on its own loopback port (9100, 9101, …), and give each camera its own path on the page server: /cam/N/whep/... is forwarded to camera N, and the returned Location gets the same /cam/N prefix so that the browser's DELETE reaches the right camera. Point grid tiles at the cameras' H.264 sub-streams: bandwidth, not CPU, is the budget.

Limits to know before shipping

  • H.264 only. The block never encodes; H.265, MJPEG or raw video fail to connect. Switch the camera, or its sub-stream, to H.264.
  • Browser profile support. The stream reaches the browser untouched, so its WebRTC decoder must take the camera's profile. Chrome and Edge played a 1080p Main profile stream in our tests; a browser that takes only constrained baseline shows connected and a black tile.
  • Listening address. http:// only, default 127.0.0.1:9090. Keep it on loopback and expose the page server — behind nginx, IIS or Caddy for other machines, which is also where HTTPS terminates.
  • NAT. STUN and TURN are set on both sides: StunServer / TurnServer in WHEPServerSinkSettings, and iceServers in the page.
  • No authentication in the WHEP server: put the login or token check in the page server, before the forward.

WHEP server, WebRTC sink, WHIP or HLS?

  • WHEP server (this post) — the source is already H.264 (an IP camera) and the viewers are browsers on your network. Video passed through, audio encoded to Opus.
  • A WebRTC sink that encodes — raw or processed video (webcam, screen, overlays); it costs a video encoder per viewer.
  • WHIP — you already run a WebRTC media server (MediaMTX, Janus, Cloudflare Stream) and push one stream to it.
  • HLS — viewers on the open internet through a CDN, when several seconds of delay are acceptable.

The full guide, with the multi-camera routing code, the grid page, a troubleshooting table and an FAQ: Show RTSP IP Cameras in a Web Browser with WHEP in C#.