From RidgeRun Developer Connection
Jump to: navigation, search


RTSP Sink is a GStreamer element which permits high performance streaming to multiple computers using the RTSP / RTP protocols. The rtspsink element leverages previous logic from RidgeRun's RTSP server with extensions to create a GStreamer sink element providing benefits like greater flexibility to application integrate and easy gst-launch based testing.

With RTSP Sink you have the flexibility to stream different content to the same client, such as streaming audio and video to a client. You also can send different streams to different clients. This means that within a single GStreamer pipeline you can stream multiple videos, multiple audios and multiple lip-sync audio+video streams, each one to a different client using a different RTSP mapping. In the examples section different streaming possibilities are shown.


The rtspsink GStreamer element supports the following features:

  • Available for GStreamer-1.0 and Gstreamer-0.10 versions
  • Configurable mappings for each stream. The mapping is the text used at the end of the RTSP URL: rtsp://$SERVER_IP/$MAPPING
  • Configurable TCP port number.
  • Automatic payloader detection according to the negotiated pipeline capabilities.
  • Multiple independent video-only streams.
  • Multiple independent audio-only streams.
  • Multiple independent audio+video streams.
  • Support for:
    • H264 video encoding
    • MPEG4 video encoding
    • MJPEG video encoding
    • AAC audio encoding
    • TRANSPORT STREAM A/V encoding

Getting the code

RTSP Sink is an add-on to RidgeRun's professional SDK. You can purchase RTSP Sink, with full source code, from the RidgeRun Store.

Testing evaluation RTSP Sink

To help you test RTSP Sink, RidgeRun can provide an evaluation version of the plug-in. This evaluation version will be provided as a binary. The following table summarizes the features available in both the professional and evaluation version of the element.

Feature Professional Evaluation
Video Streaming Y Y
Audio Streaming Y Y
A/V Streaming Y Y
Multiple Parallel Streams Y Y
Multiple Encoding Formats Y Y
Unlimited Streaming Time Y N
Source Code Y N

The evaluation version will limit the streaming time of each pad to 5 minutes (at 30fps).

To use the binary provided by RidgeRun, append the following environment variable:

GST_PLUGIN_PATH=<path to the binary directory> gst-inspect-1.0 rtspsink
GST_PLUGIN_PATH=<path to the binary directory> gst-launch-1.0 ...

Additionally, you may just copy the binary into the standard GStreamer plug-in search path. Refer to the examples section for possible combinations and use cases.

Building the code

Although rtspsink source code is delivered ready to be built along with RidgeRun's SDK, the code is platform independent and can be built on a host PC or other build environment that is configured to build GStreamer plug-ins.

Building rtspsink using RidgeRun SDK

The source code for RTSP sink can be found on


The element will be built along with the SDK if selected on the configuration menu.

make config
 '-> Proprietary software
       '-> [*] RidgeRun RTSP GStreamer sink element
             '-> [] Enable Multicast support

The RTSP Sink can be built manually by:

cd $DEVDIR/proprietary/gst-rtsp-sink
make install


  • Building the gst-rtsp-sink as a standalone may fail if the package dependencies are not first built properly.
  • Enable the Enable Multicast support option to build the element with multicast support

Building for a host PC

  • Build the code
cd $DEVDIR/proprietary/rr_rtsp_sink/src # Note the src subdirectory
./configure --libdir=/usr/lib/x86_64-linux-gnu/     # Gstreamer will look for its plug-ins in this standard location
  • Install the plugin
sudo make install                       # You will need root privileges to install the plugin

Note: Running RTSP Sink on a host PC may require root privileges to open the appropriate sockets (port numbers less than 1024). If the debug reveals a permission problem run the pipeline using sudo. You should be able to run GStreamer pipelines with RTSPsink if the specified port number is 1024 or greater.

Basic usage

RTSP Sink is a GStreamer element which supports consuming the stream from multiple pipeline branches, each one describing a different media to stream.

Requesting pads

The RTSP Sink pads are requested using regular GStreamer notation. For example, using GStreamer textual pipeline notation, attaching three different h.2164 encoded video branches to the sink the pipeline looks like the following:

gst-launch rtspsink name=sink \
< branch 1 > ! sink. \
< branch 2 > ! sink. \
< branch 3 > ! sink. 

Programatically, the pads would be requested as the following:

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);

Graphically, the pipeline would look something like:

Rtspsink wiki1.png

Since we didn't specifying the mapping, which is described below, all three pipelines would be mapped to /test.

Combining and naming streams

Each stream needs to be mapped to a different URL so the different clients can access them independently. This is called the mapping of the stream. The RTSP Sink element will try to read the mapping from the caps it negotiates with the upstream element. This means that assigning a mapping to a stream is as simple as setting it 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 the it will default to /test

Each mapping will be treated as an individual stream. This means that if you want to combine an 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", an audio mapped to "/audio" and an audio+video mapped to "/audiovideo".

gst-launch rtspsink name=sink \
< branch 1  > ! video/x-h264, mapping=/video ! sink. \
< branch 2  > ! audio/mpeg, mapping=/audio ! sink. \
< branch 3v > ! video/x-h264, mapping=/audiovideo ! sink. \
< branch 3a > ! audio/mpeg, mapping=/audiovideo ! sink.

This will combine branches 3v and 3a as a single streaming under the name of "/audiovideo". This can be shown graphically on figure 2.

Rtspsink wiki2.png

Supported formats

The following table conveniently resumes the supported encoding formats and their respective mimetypes for you to build as

gst-launch ... ! mimetype, mapping="/test" ! rtspsink
Supported formats and their mimetypes
Format Mimetype
H264 video video/x-h264
MPEG4 video video/mpeg
MJPEG video image/jpeg
MPEG TS video/mpegts
AAC audio audio/mpeg

Service configuration

Besides the actual streaming data, RTSP is high level protocol that negotiates streaming internals with every client that intends to connect to a mapping. In order to request a stream, the client must connect to the server at a specific port where the RTSP server is up and waiting for connections. The port at which the server is listening to, and the clients must talk to is called the service and it is typically set to 554. RTSP Sink allows to configure the service by means of a GStreamer property like the following:

~# gst-launch audiotestsrc ! ffenc_aac ! audio/mpeg, mapping=/mystream ! rtspsink service="3000"

If no service is specified then it default to 554. Since all ports below 1024 require root priority to use, port 554 could cause the pipeline to fail. Specify a port number 1024 or above, i.e. 5000, to run the pipeline at normal user priority. There are other methods that are possible to avoid the need to have root privileges.


The following section provides a series of examples of possible use cases of RTSP Sink. For all of them, the different streams can be viewed on a host PC using VLC as the following:



where $SERVER_IP is the IP address of the RTSP server, $MAPPING is the name of the mapping that the client wants to connect to, and $PORT is the service at which the server is listening to.

Note: When running on a host PC root privileges may be needed to access the respective sockets.

Single MPEG4 video streaming

gst-launch v4l2src ! ffenc_mpeg4 ! video/mpeg, mapping=/stream ! rtspsink

Single AAC audio streaming

gst-launch alsasrc ! ffenc_aac ! audio/mpeg, mapping=/stream ! rtspsink

Dual H264 video streaming

gst-launch rtspsink name=sink \
v4l2src ! x264enc ! video/x-h264, mapping=/stream1 ! sink.
videotestsrc ! x264enc ! video/xh264, mapping=/stream2 ! sink.

Audio+Video Streaming

gst-launch rtspsink name=sink \
v4l2src ! x264enc ! video/x-h264, mapping=/stream ! sink.
alsasrc ! ffenc_aac ! audio/mpeg, mapping=/stream ! sink.

Audio+Video streaming plus H264 single streaming

gst-launch rtspsink name=sink \
v4l2src ! x264enc ! video/x-h264, mapping=/stream1 ! sink.
alsasrc ! ffenc_aac ! audio/mpeg, mapping=/stream1 ! sink.
videotestsrc ! x264enc ! video/x-h264, mapping=stream2 ! sink.

Transport Stream payloader

Often RTSP is used with the RTP payloader encoding. It is also possible to use RTSP with the Transport Stream (TS) payloader. This pipeline was tested on a Leopardboard 368 with an Aptina mt9p031 sensor.

Pipeline to run on target hardware

gst-launch v4l2src input-src=camera always-copy=false ! 'video/x-raw-yuv, width=1920, height=1088, framerate=(fraction)30/1' ! \
           dmaiaccel ! dmaiperf ! /
           dmaienc_h264 encodingpreset=2 ratecontrol=2 targetbitrate=2000000 intraframeinterval=30 idrinterval=90 bytestream=true ! \
           queue ! mpegtsmux ! capsfilter caps="video/mpegts,mapping=/stream" ! rtspsink

Pipeline to run on host PC

TARGET_IP_ADDRESS= # replace with the IP address of your target hardware

gst-launch rtspsrc location="rtsp://$TARGET_IP_ADDRESS/stream" ! rtpmp2tdepay ! mpegtsdemux ! queue ! \
           ffdec_h264 ! xvimagesink sync=false

Using VLC or mplayer to view streaming video

TARGET_IP_ADDRESS= # replace with the IP address of your target hardware

vlc rtsp://$TARGET_IP_ADDRESS/stream

mplayer rtsp://$TARGET_IP_ADDRESS/stream

Additional documentation

Access the full plugin documentation by making a gst-inspect of the rtspsink

gst-inspect rtspsink

Legacy RTSP Sink

The old version of RTSP Sink maintains the same idea of integrating an RTSP server into a gstreamer pipeline but its developed to support a single video stream. The main difference is that the service is specified by means of a property rather than on the caps.

On target board

gst-launch videotestsrc ! dmaienc_h264 idrinterval=30 targetbitrate=2500000 single-nalu=false ! rtspsink mapping="/mystream" service=554

On host PC

On the host PC you might need to use root privileges to access the respective sockets.

sudo gst-launch videotestsrc ! x264enc ! rtspsink mapping="/mystream" service=554


As an RTSP client vlc may be used as the following:

vlc rtsp://<target.or.host.pc.ip.address>:554/mystream

See also