TodayTools

Real Time Streaming Protocol

How RTSP works

Watching an IP camera

Donate
L7ApplicationPort 554TCP
What brings you here?

Watch it happen

How much detail

A player on a laptop opens an IP camera's live view, with a password, then closes it.

Arjun's laptop
Home router
IP camera
Wi-FiCableSetupRequestResponseControlDataClose

6 steps, 21 packets

First up: Connect and ask. Press Play to watch it happen, one step at a time.

0 of 60/6

What is RTSP?

RTSP is a remote control for a video stream. A player or video recorder connects to a camera on port 554 and sends text commands: DESCRIBE to learn what the stream is, SETUP to choose how it is delivered, PLAY to start and TEARDOWN to stop. The messages look a lot like HTTP.

The video itself does not travel inside those commands. It flows as RTP packets, usually over UDP, or tucked into the same TCP connection when a firewall blocks UDP. Almost every IP security camera and network video recorder speaks RTSP, which is why rtsp:// links are the usual way to watch a camera.

Think of it like this. RTSP is the TV remote and RTP is the picture. Pressing play on the remote does not carry the film to the screen; it asks the box to start sending it. The remote and the picture travel on different paths.

Step by step

Normal

6 steps

A player on a laptop opens an IP camera's live view, with a password, then closes it.

  1. 1

    Connect and ask

    TCP 554 and OPTIONS

    The player connects to the camera on TCP port 554. OPTIONS asks which commands are supported. RTSP looks a lot like HTTP, with a CSeq counter on every message.

  2. 2

    Describe

    401, then SDP

    DESCRIBE asks for a description of the stream. The camera first demands a password with a digest challenge, then answers with SDP listing the tracks and codecs.

  3. 3

    Setup

    Choose ports, get a session

    SETUP tells the camera which UDP ports the laptop will listen on. The camera answers with its own ports and a session ID.

  4. 4

    Play

    Video starts flowing

    PLAY starts the stream. The video itself arrives as RTP packets over UDP, not inside RTSP. RTSP is only the remote control.

  5. 5

    Keep alive

    GET_PARAMETER

    The player sends a small request now and then so the session does not time out.

  6. 6

    Teardown

    Stop and free the session

    TEARDOWN ends the session. The camera stops sending RTP and frees its resources.

Wrong password

2 steps

The player has the wrong camera password, so DESCRIBE is refused and no video flows.

  1. 1

    Connect and ask

    OPTIONS works without a password

    Most cameras answer OPTIONS to anyone, so this step succeeds.

  2. 2

    Refused

    401 again

    The digest answer is built from the wrong password, so the camera answers 401 Unauthorized a second time. The player gives up and shows an error. Many cameras lock the account for a while after several failures.

Over TCP

3 steps

A firewall blocks UDP, so the video is tucked inside the same TCP connection as the commands.

  1. 1

    UDP is blocked

    Only TCP 554 is open

    The firewall between the office and the camera network allows only TCP port 554. RTP over UDP would never arrive.

  2. 2

    Ask for TCP

    interleaved=0-1

    In SETUP the player asks for RTP/AVP/TCP. Channel 0 will carry RTP video and channel 1 will carry RTCP, both inside the RTSP connection.

  3. 3

    Framed video

    $, channel, length

    Each RTP packet is sent with a 4 byte prefix: a dollar sign, the channel number and the length. It works through strict firewalls, but a slow link now delays the video instead of dropping frames.

Myths and mix-ups

  • RTSP does not carry the video itself; RTP does, and RTSP only controls it.
  • rtsp:// links are not private by default; plain RTSP and RTP are readable by anyone on the path.
  • Putting a camera's port 554 on the internet is not a safe way to watch it remotely; use a VPN instead.
  • RTSP 2.0 is not backward compatible with 1.0, and most cameras still use 1.0.

Try it yourself

Run these on your own computer to see RTSP at work.

  • Check a camera stream

    ffprobe -rtsp_transport tcp rtsp://admin:password@192.168.1.64:554/stream1

    Use your camera's address, login and stream path. Prints the codec, size and frame rate.

  • Watch it

    ffplay -rtsp_transport tcp rtsp://admin:password@192.168.1.64:554/stream1

    Drop -rtsp_transport tcp to try UDP. The stream path differs by camera maker.

  • See the commands

    sudo tcpdump -n -A -i any tcp port 554

    Run it while a player connects. You will read OPTIONS, DESCRIBE, SETUP and PLAY as text.

RTSP at a glance

Layer
Application (7)
Default port
554 (TCP), 322 for RTSP over TLS
Transport
TCP for commands, RTP over UDP or TCP for media
Format
Text, HTTP-like, with an SDP description
Main methods
OPTIONS, DESCRIBE, SETUP, PLAY, PAUSE, TEARDOWN
Versions
1.0 (RFC 2326, 1998) and 2.0 (RFC 7826, 2016)
Common in
IP cameras, video recorders, video walls

Defined inRFC 2326 (RTSP 1.0)RFC 7826 (RTSP 2.0)RFC 8866 (SDP)RFC 3550 (RTP)

Header fields

What RTSP puts in its messages, with example values from the stories above.

RTSP/1.0

Start line
OPTIONS rtsp://192.168.1.64:554/stream1 RTSP/1.0
CSeq
1A counter that pairs each answer with its request.
Public
OPTIONS, DESCRIBE, SETUP, PLAY, PAUSE, TEARDOWN, GET_PARAMETER
Accept
application/sdpThe player wants the description in SDP format.
WWW-Authenticate
Digest realm="IP Camera", nonce="4f2a9c1e7b3d5a60"Digest means the password is hashed with the nonce, so it is never sent as is.
Authorization
Digest username="admin", response="c2b1e7d0a94f36e8b5a1f07d2c9e4b63"The player repeats this header on every later request too.
Transport
RTP/AVP;unicast;client_port=50000-50001Plain RTP over UDP, one copy just for me. Video to my port 50000, RTCP to 50001.
Session
66334873;timeout=60Every later request carries this ID. Without a request or RTCP for 60 seconds, the camera ends the session.
Range
npt=0.000-Normal play time from now, with no end: a live stream.
RTP-Info
url=rtsp://192.168.1.64:554/stream1/trackID=1;seq=12312;rtptime=3450012000

SDP

Media
video 0 RTP/AVP 96A video track. Port 0 here, because ports are agreed later in SETUP.
Codec
96 H264/90000Payload type 96 means H.264 for this session. Video RTP clocks tick 90,000 times a second.
Control
trackID=1The name to use when setting up this track.

Test yourself

Question 1 of 5Score 0

Which RTSP command tells the camera to start sending video?

Questions people ask

What port does RTSP use?

Port 554 over TCP for the commands. The video itself uses RTP on UDP ports agreed in SETUP, or travels inside the TCP connection.

How do I find the RTSP CAM_URL of my IP camera?

It is usually rtsp://user:password@camera-ip:554/ followed by a path that depends on the maker, such as /stream1 or /live. The camera's manual or settings page lists it.

What is the difference between RTSP and RTMP?

RTSP is used to pull video from cameras and controls an RTP stream. RTMP is mainly used to push a live stream from an encoder up to a server.

Is RTSP secure?

Plain RTSP is not encrypted, and many cameras use weak passwords. RTSP over TLS exists but few cameras support it, so keep cameras on a private network and use a VPN to view them from outside.

Why does my RTSP stream work on TCP but not UDP?

A firewall or NAT router is probably blocking the UDP ports for RTP. Asking for TCP interleaved mode sends the video over the already open port 554.

Donate