Skip to content

rtspout

RTSP Server

Register name used to load filter: rtspout
This filter may be automatically loaded during graph resolution.

The RTSP server partially implements RTSP 1.0, with support for OPTIONS, DESCRIBE, SETUP, PLAY, PAUSE and TEARDOWN.
Multiple PLAY ranges are not supported, PLAY range end is not supported, PAUSE range is not supported.
Only aggregated control is supported for PLAY and PAUSE, PAUSE/PLAY on single stream is not supported.
The server only runs on TCP, and handles request in sequence: it will not probe for commands until previous response is sent.
The server supports both RTP over UDP delivery and RTP interleaved over RTSP delivery.

The scheduling algorithm and RTP options are the same as the RTP output filter, see gpac -h rtpout
The server will disconnect UDP streaming sessions if no RTCP traffic has been received for timeout seconds.

The server can run over TLS by specifying cert and pkey, in which case the default port is 322.

Sink mode

The filter can work as a simple output filter by specifying the dst option:
Example

gpac -i source -o rtsp://myip/sessionname  
gpac -i source -o rtsp://myip/sessionname
In this mode, only one session is possible. It is possible to loop the input source(s).

Server mode

The filter can work as a regular RTSP server by specifying the mounts option to indicate paths of media file to be served:
Example

gpac rtspout:mounts=mydir1,mydir2
In this case, content RES from any of the specified directory is exposed as rtsp://SERVER/RES

The mounts option can also specify access rule file(s), see gpac -h creds. When rules are used:
- if a directory has a name rule, it will be used in the URL
- otherwise, the directory is directly available under server root /
- only read access and multicast rights are checked
Example

[foodir]  
name=bar
Content RES of this directory is exposed as rtsp://SERVER/bar/RES.

In this mode, it is possible to load any source supported by gpac by setting the option dynurl.
The expected syntax of the dynamic RTSP URLs is rtsp://servername/?URL1[&URLN] or rtsp://servername/@URL1[@URLN]
Each URL can be absolute or local, in which case it is resolved against the mount point(s).
Example

gpac -i rtsp://localhost/?pipe://mynamepipe&myfile.mp4 [dst filters]
The server will resolve this URL in a new session containing streams from myfile.mp4 and streams from pipe mynamepipe.
When setting runfor in server mode, the server will exit at the end of the last session being closed.

The parameter name=VAL is reserved to assign a session name in case multicast mirroring is used.
Example

gpac -i rtsp://localhost/?name=live?pipe://mynamepipe&myfile.mp4 [dst filters]

Usage of dynamic URLs can also be configured using the specific directory $dynurl in an access rule file.
EX[$dynurl]
ru=foo
This will allow dynamic URLs only for foo user.

Note: If the dynurl is set, it is enabled for all users, without authentication.

Multicasting

In both modes, clients can setup multicast if the mcast option is on or mirror.
When mcast is set to mirror mode, any DESCRIBE command on a resource already delivered through a multicast session will use that multicast.
Consequently, only DESCRIBE methods are processed for such sessions, other methods will return Unauthorized.

In server mode, multicast can be enabled per read directory using the mcast access rule of the directory configuration - see gpac -h creds.

HTTP Tunnel

The server mode supports handling RTSP over HTTP tunnel by default. This can be disabled using htun.
The tunnel conforms to QT specification, and only HTTP 1.0 and 1.1 tunnels are supported.

Options

dst (cstr): location of destination resource
port (uint, default: 554): server port
firstport (uint, default: 6000): port for first stream in session
mtu (uint, default: 1460): size of RTP MTU in bytes
ttl (uint, default: 0): time-to-live for multicast packets (a value of 0 uses client requested TTL, or 1)
ifce (str): default network interface to use
payt (uint, default: 96, minmax: 96-127): payload type to use for dynamic decoder configurations
mpeg4 (bool, default: false): send all streams using MPEG-4 generic payload format if possible
delay (sint, default: 0): send delay for packet (negative means send earlier)
tt (uint, default: 1000): time tolerance in microsecond (whenever schedule time minus realtime is below this value, the packet is sent right away)
runfor (sint, default: -1): run the session for the given time in ms. A negative value means run for ever if loop or source duration, value 0 only outputs the sdp
tso (sint, default: -1): set timestamp offset in microseconds (negative value means random initial timestamp)
xps (bool, default: false): force parameter set injection at each SAP. If not set, only inject if different from SDP ones
latm (bool, default: false): use latm for AAC payload format
mounts (strl): list of directories to expose in server mode
block_size (uint, default: 10000): block size used to read TCP socket
maxc (uint, default: 100): maximum number of connections
timeout (uint, default: 20): timeout in seconds for inactive sessions (0 disable timeout)
user_agent (str, default: $GUA): user agent string, by default solved from GPAC preferences
close (bool, default: false): close RTSP connection after each request, except when RTP over RTSP is used
loop (bool, default: true): loop all streams in session (not always possible depending on source type)
dynurl (bool, default: false): allow dynamic service assembly
mcast (enum, default: off): control multicast setup of a session
off: clients are never allowed to create a multicast
on: clients can create multicast sessions
* mirror: clients can create a multicast session. Any later request to the same URL will use that multicast session

quit (bool, default: false): exit server once first session is over (for test purposes)
htun (bool, default: true): enable RTSP over HTTP tunnel
trp (enum, default: both): transport mode
both: allow TCP or UDP traffic
udp: only allow UDP traffic
* tcp: only allow TCP traffic

cert (str): certificate file in PEM format to use for TLS mode
pkey (str): private key file in PEM format to use for TLS mode