GstRtspSink - Basic usage
The rtspsink element from GstRtspSink works by attaching encoded streams to its pads and assigning each stream a mapping. The result is one or more RTSP URLs that clients can open. This page covers the minimum concepts you need to build working server pipelines.
Core concepts
The three concepts you need first are:
- service: the RTSP TCP port, such as 5000.
- mapping: the RTSP path, such as /stream1.
- request pads: each independent stream is linked to a rtspsink pad depending on the media to be streamed.
Consider the basic pipeline below using rtspsink to stream encoded audio:
gst-launch-1.0 audiotestsrc ! avenc_aac ! "audio/mpeg, mapping=/mystream" ! rtspsink service=3000
The resulting URL that a client can open is:
rtsp://<DEVICE_IP>:3000/mystream
In this example, the RTSP stream is served using the port 3000, under the mapping "/mystream". The rtspsink element will create an audio/mpeg pad to be able to link itself to the encoded audio stream.
Service
By default, rtspsink will listen in the port 554 to clients who want to connect to a stream. This port number can be changed using the service property. Ports below 1024 often require elevated privileges, so using a port such as 3000 or 5000 is usually simpler during development.
Mapping
All the media streams published by a pipeline with rtspsink will share the same ip address and service port. However, clients can use different mappings to access each individual stream independently.
To assign a mapping to a stream simply set the desired value in the caps, using the mapping= value. The only rule is that the mapping must always start with a leading slash "/". If no mapping is explicitly provided, it will default to /test.
Each mapping will be treated as an individual stream. This means that if you want to combine audio and a video branch within a single A/V stream, it is as simple as using the same mapping name. The following pipeline will produce 3 independent streams: a video mapped to "/video", audio mapped to "/audio" and an audio+video mapped to "/audiovideo".
gst-launch-1.0 rtspsink name=sink \ <branch 1> ! capsfilter caps="video/x-h264, mapping=/video" ! sink. \ <branch 2> ! capsfilter caps="audio/mpeg, mapping=/audio" ! sink. \ <branch 3v> ! capsfilter caps="video/x-h264, mapping=/audiovideo" ! sink. \ <branch 3a> ! capsfilter caps="audio/mpeg, mapping=/audiovideo" ! sink.
This will combine branches 3v and 3a as a single stream under the name of "/audiovideo".

Request Pads
The rtspsink sink pads are available on request, depending on the media that the user wants to stream. This becomes important when moving from gst-launch-1.0 prototype pipelines to an application. The rtspsink element pads are requested using the GStreamer API. Consider the following example, where we want to send three streams:
gst-launch-1.0 rtspsink name=sink \ <branch 1> ! sink. \ <branch 2> ! sink. \ <branch 3> ! sink.
When using gst-launch-1.0 the process of requesting and linking the pads is handled for us. In a C application, the pads need to be requested as follows:
rtspsinkpad1 = gst_element_get_request_pad(rtspsink, "sink_%d"); gst_pad_link (branch1pad, rtspsinkpad1); rtspsinkpad2 = gst_element_get_request_pad(rtspsink, "sink_%d"); gst_pad_link (branch2pad, rtspsinkpad2); rtspsinkpad3 = gst_element_get_request_pad(rtspsink, "sink_%d"); gst_pad_link (branch3pad, rtspsinkpad3);
The pipeline would look like the image below:

Since we didn't specify the mapping, all three pipelines would be mapped to /test.
Supported formats
The following table summarizes the supported encoding formats and their respective mimetypes of the sink pads available on request:
| Format | Mimetype |
|---|---|
| H264 video | video/x-h264 |
| H265 video | video/x-h265 |
| VP8 video | video/x-vp8 |
| VP9 video | video/x-vp9 |
| MPEG4 video | video/mpeg video/x-jpeg |
| MPEG TS | video/mpegts |
| MJPEG video | image/jpeg |
| AAC audio | audio/mpeg |
| AC3 audio | audio/x-ac3 audio/ac3 |
| PCMU audio | audio/x-mulaw |
| PCMA audio | audio/x-alaw |
| OPUS audio | audio/x-opus |
| KLV metadata | meta/x-klv |
Related pages
FAQ
- What is the mapping in rtspsink?
- The mapping is the RTSP path segment that appears at the end of the stream URL.
- Can I expose multiple RTSP URLs from one pipeline?
- Yes. Use multiple sink branches and assign a different mapping to each branch.