Tech

IP camera streaming

Cameras are everywhere. In parking lots, parks, stores, airports, on the roads, and even in our homes.

A typical IP camera captures video, compresses it using a widely supported codec such as H.264, and streams it over a network using RTSP, HTTP, or a proprietary protocol.

We're particularly interested in cameras that support RTSP. It's an open, widely adopted protocol supported by the vast majority of traditional IP cameras right out of the box.

Overview

To access a stream from an IP camera, all you need is its RTSP URL. It typically looks something like rtsp://192.168.1.10/cam1.sdp. The URL tells the player two important things: the camera's IP address (192.168.1.10) and the path where the stream is available (cam1.sdp).

rtsp://192.168.1.10/cam1.sdp

Of course, an IP address can just as easily be replaced with a hostname, and the stream path can be almost anything: rtsp://home.local/alice. There's no universal naming convention for stream paths. Each camera manufacturer may use its own.

Check your camera's RTSP settings or documentation to find the correct address and stream path. Got your RTSP URL? Great. It's time to play your stream.

How RTSP – WebRTC playback works

Browsers and mobile apps cannot play RTSP, so the Media Server works as a gateway. The viewer's application uses an SDK to open a session with the Media Server and plays a stream whose name is the camera's RTSP URL.

The Media Server connects to the camera as an RTSP client, receives its video and delivers it to the viewer over WebRTC with low latency. Only the server has to reach the camera; the viewers never connect to it.

Later viewers of the same URL receive the stream the server already pulls, so the camera serves one connection however many people watch. When the last viewer leaves, the server disconnects from the camera.

Now let's see how to play an IP camera stream with each SDK.

The code looks a little different on each platform, but in every SDK it is ordinary playback: the RTSP URL is simply the name of the stream.

Web SDK

In a browser, the Web SDK plays the camera stream over WebRTC in the element you pass to it:

session
  .createStream({
    name: 'rtsp://192.168.1.10/cam1.sdp',
    display: remoteVideo,
  })
  .play();

The camera's RTSP URL is the stream name: name: 'rtsp://…'.

Explore Web SDK↗

Android SDK

On Android the app creates a stream with the RTSP URL as its name and plays it:

StreamOptions options =
    new StreamOptions("rtsp://192.168.1.10/cam1.sdp");

Stream stream = session.createStream(options);
stream.play();

The camera's RTSP URL is the stream name: new StreamOptions("rtsp://…").

Explore Android SDK↗

iOS SDK

On iOS the SDK plays the camera stream in the view you pass to it:

let options = FPWCSApi2StreamOptions()
options.name = "rtsp://192.168.1.10/cam1.sdp"
options.display = remoteView

let stream = try session.createStream(options)
try stream.play()

The camera's RTSP URL is the stream name: options.name = "rtsp://…".

Explore iOS SDK↗

Explore playback options

How to pull an RTSP stream without playback

Sometimes the camera stream is needed on the server before anyone watches it: to record it, to transcode it, or to have it ready the moment the first viewer opens the page. Your backend can tell the Media Server to pull the stream through the REST API, with no player involved.

The backend calls /rtsp/startup with the camera's RTSP URL and a localStreamName. The Media Server connects to the camera and publishes its video under that name, so viewers play it like any other stream, and the server can record or restream it.

REST API

A single request from your backend starts pulling the camera stream:

const api = 'https://media.example.com:8444/rest-api/v3';

await fetch(`${api}/rtsp/startup`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    uri: 'rtsp://192.168.1.10/cam1.sdp',
    localStreamName: 'stream1',
  }),
});

The camera stream is published on the server as stream1: viewers play it by this name, like any other stream.

Explore REST API↗

How to push an RTSP stream from IP camera

Some cameras and hardware or software encoders work the other way round: instead of waiting for the server to connect, they push their stream to it. The Media Server accepts RTP streams published over RTSP, with TCP interleaved or UDP transport, on port 554 by default.

The camera connects to the server and announces its stream with an RTSP ANNOUNCE request to a URL like rtsp://media.example.com:554/stream1, then sends the stream. The last part of the URL becomes the stream name: the server publishes the camera video as stream1, and viewers play it like any other stream.

The camera can send H.264, H.265 or VP8 video with AAC or Opus audio. H.265 is transcoded to H.264 or VP8 for playback.

FFmpeg

FFmpeg can stand in for a camera: it publishes a video over RTSP the same way a camera or an encoder pushes its stream.

ffmpeg -re -i camera.mp4 \
  -c:v copy -c:a libopus -ar 48000 -ac 2 \
  -f rtsp -rtsp_transport tcp \
  rtsp://media.example.com:554/stream1

The stream is published as stream1, the last part of the URL. -rtsp_transport tcp sends the media interleaved over the RTSP connection.

Explore documentation↗

IP camera streaming demo

No setup, no installation. Press Play and watch an IP camera stream: the Media Server pulls it from the camera over RTSP and delivers it to your browser over WebRTC with low latency.

Try Live Demo↗

Launch your IP camera streaming server

LLcast will deploy a dedicated Media Server just for you. Pull your IP cameras over RTSP or let them push their streams, and play them in any browser or mobile app over WebRTC with low latency. Connect your own cameras and record them.