Skip to content

RTSP Server, SDP

Martin Pulec edited this page Aug 8, 2024 · 21 revisions

When using network protocol SDP or RTSP, UltraGrid uses RTP as normally but 2 things act differently:

  1. codecs are packed according to the RFCs (that however limits available codecs that can be used - H.264 for video and OPUS or PCMU for audio)
  2. descriptive SDP file is produced - depending on the protocol used it is provided either as a file (or with a HTTP server) or utilized within a RTSP session

Note 1: Current implementation is able to handle only one receiver at the same time. To process multiple receivers, check Use Cases.
Note 2: This setup doesn't provide neither NAT traversal nor firewall passthrough. Traffic from sender must pass to receiver UDP ports 5004 and 5006.
Note 3: Not to be confused with NAT traversal server mode.

Table of Contents

RTSP

RTSP server can be run with following commands:

uv -t <vcap> -c libavcodec:encoder=libx264 -x rtsp
# or with audio:
uv -t <vcap> -c libavcodec:encoder=libx264 -x rtsp -s <acap> -A u-law
# codec can be omitted for RTSP, in which case H.264 and Opus is used:
uv -t <vcap> -s <acap> -x rtsp

If you omit audio/video compression, some suitable will be chosen.

Client than can play the stream with either of:

ffplay rtsp://<ip>:8554/ultragrid
mpv --rtsp-transport=udp rtsp://<ip>:8554/ultragrid

The current list of supported codecs can be obtained by -x rtsp:help.

SDP

uv -t <vcap> -s <acap> -x sdp <receiver>

In this case, default compression will be chosen (can be changed similarly to RTSP, eg. also A-law or OPUS for audio). SDP file ug.sdp will be created which can then be played by the receiver given on command-line. Alternatively, the receiver can use (play) the URL provided by sender on terminal, eg.:

mpv http://93.184.216.34:8554/ug.sdp

Multicast

UltraGrid can also use a multicast address as a receiver. In that case all receivers that are able to receive multicast can join the multicast group:

sender$ uv -t <video_capture> -s <audio_capture> --protocol sdp 224.0.0.20 # send IPv4
# or
sender$ uv -t <video_capture> -s <audio_capture> --protocol sdp ff02::20 # send IPv6

receiver$ mpv http://93.184.216.34:8554/ug.sdp # receivers IPv4

The current list of supported codecs can be obtained by -x sdp:help.

Autorun

There is also an autorun option without receiver IP address, which is obtained automatically automatically, eg.:

sender$ uv -4 -t <video_capture> -s <audio_capture> --protocol sdp:autorun
receiver$ mpv http://93.184.216.34:8554/ug.sdp

It works as a very simple session management - UltraGrid will send data to the client that requests the SDP file over HTTP.

Note: Avoid sending the URL over services (eg. Facebook) that deliberately open the sent links.

Supported formats

Audio

working:

  • 1 channel PCMA/PCMU 8000 Hz (G.711) - --audio-codec u-law:sample-rate=8000
  • any other PCMA/PCMU (arbitrary number of channels or sampling frequency), the packet type will be specified in SDP
  • 1 channel MP3 or Opus (arbitrary codec-supported sampling frequency - Opus allows only 8, 12, 16, 24 and 48 kHz but the others may be resampled to the supported value)

not working:

  • MP3 or Opus with 2 or more channels

Video

H.264 and JPEG are currently supported for video. H.264 is set automatically if no compression is explicitly given.

For best compatibility it is recommended to turn of Intra Frame Refresh and possibly reduce the bitrate for H.264:

-c libavcodec:encoder=libx265:subsampling=420:disable_intra_refresh:bpp=0.15

JPEG encapsulation is quite rigid according to RFC 2435. Only interleaved, YUV 4:2:2 and 4:2:0 with default Huffman tables is supported. Therefore recommended settings for GPUJPEG and libavcodec are:

-c GPUJPEG:interleaved
# or
-c libavcodec:encoder=mjpeg:subsampling=420   # libavcodec uses RFC-incompatible component order for 422, thus only 420 can be used

Latency considerations

Clone this wiki locally