How to play an RTSP camera stream in a browser with low latency

Place a media gateway where it can reach the camera. Let it pull the RTSP stream and send video to the browser over WebRTC. Start with one feed, then measure the delay from the lens to the screen with a single recording.

Low-latency camera candidate: AXIS P1385

This 2 MP indoor box camera supports RTSP and H.264. Axis lists up to 50/60 fps with wide dynamic range (WDR) off and up to 25/30 fps with WDR on. Its low latency mode reduces image processing time with a trade-off in image quality. Model datasheet · PDF

For the baseline, plan a single LAN stream at 1080p, H.264 and 50 fps in 50 Hz mode, with WDR off. In System → Plain config → ImageSource → ImageSource/I0/Sensor, turn on Low latency mode. Use the steps below to measure P50 and P95 and keep the original recording. AXIS P1385 low latency mode guide

Connect the camera to the browser

  1. IP cameraServes a main or secondary RTSP stream
  2. Media gatewayPulls the feed, checks codecs and sends WebRTC media
  3. BrowserNegotiates the receive track, decodes and displays it

1. Verify the RTSP source from the gateway host

Get the stream URL from the device manual and open it in VLC on the gateway host. Check that the picture keeps updating and record the codec, resolution, frame rate and audio track in the codec information panel. Start with one camera on a local network.

Axis documents this VAPIX URL format for an H.264 stream: rtsp://CAMERA_HOST/axis-media/media.amp?videocodec=h264&audio=0. This example disables audio. Replace CAMERA_HOST with the device address and provide credentials on the gateway. Axis VAPIX streaming guide

2. Register a pull stream in ZLMediaKit

Use a WebRTC-enabled gateway. From its management network, send the following form fields to the pull-proxy endpoint. Supply the gateway API secret and the real camera URL on the server. This example names the feed live/front. Check the return code, then look up the stream in getMediaList and confirm it has a video track. ZLMediaKit pull-proxy API

POST /index/api/addStreamProxy
vhost=__defaultVhost__
app=live
stream=front
url=<RTSP_URL>
secret=<GATEWAY_API_SECRET>

If the camera offers H.264 Constrained Baseline, try it first and check the negotiated browser codec and profile. Compatible encoded video can be repacketized without a decode–encode cycle. For an H.265-only feed or an incompatible H.264 profile, change the camera output or configure transcoding and repeat the test. Check audio separately. For an RTSP feed carrying AAC, start with video only and plan a compatible audio output such as Opus. MDN WebRTC codecs

3. Open the stream in the target browser

In the target browser, open /webrtc/?app=live&stream=front&type=play on the HTTPS gateway. Check live and front in the URL box, select play and click Start. The player posts an SDP offer to the endpoint below and sets the answer as its remote description. In a custom player, handle the peer connection’s track event and attach a MediaStream containing the received track to the video element’s srcObject. ZLMediaKit playback URL rules · MDN track event

POST /index/api/webrtc?app=live&stream=front&type=play

Check the browser’s ICE connection state and the actual picture. If signaling succeeds but video is blank, verify the gateway advertises a media address and port reachable by the viewer. Then check whether received bytes and decoded frames increase. Start muted when debugging autoplay and let the viewer enable audio. ZLMediaKit WebRTC setup

Where does the delay come from?

Slow first frame
Record the time of the play request, ICE connection and first visible frame. Check the camera’s keyframe interval and the gateway’s wait for a decodable frame. Remeasure peak bitrate after changing the interval.
Latency grows while playing
Inspect gateway queues, transcoder CPU and the browser jitter buffer. For the same inbound video track, ΔjitterBufferDelay ÷ ΔjitterBufferEmittedCount gives average buffering time in seconds over the sampling interval. Skip intervals with a zero denominator or a track change. W3C WebRTC statistics
Freezes or skips after packet loss
Label network conditions on each hop. On an RTSP-over-TCP connection, retransmission of lost data can hold up later data. With UDP, frames can be lost instead. Record browser-side packet loss, decoded frames, freezes and recovery. Change one variable per run.
Estimate upload bandwidth for multiple cameras ↗

Measure camera-to-browser screen latency

  1. Define the runs. Record the model, firmware, gateway version, browser, frame rate, bitrate and transport. Test the LAN baseline first, then test bandwidth limits, loss and handovers in separate runs. Agree on run duration, sampling interval, valid-sample criteria and acceptance thresholds in advance.
  2. Record both readings together. Point the IP camera at a running millisecond timer. Display that feed in the target browser. Use a second camera to record the source timer and the browser screen in the same frame. Check both readings are legible and log the display refresh rates and recording frame rate.
  3. Read frames at the agreed interval. Subtract the timer shown in the browser from the source timer in the same recording frame. Save both readings and the recording timecode. Keep rows for freezes, timeouts and unreadable digits. Record the status and leave unavailable values blank.
  4. Summarize samples and failures. For each condition, report total observations, valid count, counts by failure type, median (P50), P95 and maximum. For nearest-rank P95, sort valid values and select rank ⌈0.95 × valid count⌉, starting at one. If a group has no valid values, mark its percentiles unavailable. Record first-frame and reconnection times separately, with their start and end events. Exposure, display refresh and the recording frame interval limit the precision.

Active Silicon’s camera application note illustrates the same-frame timer technique. For acceptance, associate each observation with the device configuration, network condition and original recording. Camera timing application note · PDF