Creating an RTSP Stream with GStreamer

with No Comments

Creating an RTSP Stream with GStreamer

Recently, we have been using an IP camera as a baby monitor to watch our 18 month old in his crib. It ran for several months without issue but then, without warning, the WIFI just stopped working. The camera provided an RTSP stream that we had become accustomed to logging into via our Android phones.

Armed with an old PC, a webcam, and a few open source software packages I decided to piece together a quick fix. We have since replaced the IP camera, due to the less than desirable form factor and power consumption of a full blown PC. However, theres no reason the PC could not have been replaced with a BeagleBoard, BeagleBone, Raspberry Pi, etc..

What is RTSP?

Multiparty Multimedia Session Control Working Group (MMUSIC WG) of the Internet Engineering Task Force (IETF)
developed Real Time Streaming Protocol (RTSP) as a means to control streaming servers.
The RTSP protocol is similar to HTTP, but is tailored to better suit multimedia streams.
Read the deets on RTSP @

GStreamer, a multimedia swiss army knife, enables you to easily do various processing on a video or audio stream. In GStreamer this processing is structured as a ‘pipeline’ of elements. Elements can be sources which provide an output, sinks that consume a stream, or both source and sink. You can easily test these pipelines on the command line before wrapping the working pipeline into your own application. This is the library I used for our interim baby monitor. The GStreamer library can be used with many languages. I chose to work in C just because of familiarity.

Before we start coding, we’ll have to install a couple packages. You’ll need to install libgstreamer & gstrtspserver. I’m using Ubuntu so I installed them with the following command at the terminal prompt.

Next I created a makefile to tell GCC which libraries I will be linking to.
Create a Makefile and paste in the contents below.

Now we just need to write the code. In this example it is pretty straight forward. Create a rtsptest.c file and fill it up with the code below.



This will create an RTSP stream of a video test pattern. Not all that useful, but its helpful when debugging pipelines. This could be replaced with a file, or a live camera source. To use a webcam as a live video source, simply replace ‘videotestsrc’ with ‘v4l2src’ on line 17.

When you’ve got the code like you want; just build, run and test. From the command line run the following commands.


You should see VLC pop up in a new window and display whatever video source you requested in the code above.


Earlier I mentioned streaming RTSP in Android. If you are interested in seeing just how easy it is to write an RTSP client in Android, drop a request in the comments.

Edit: Turns out there was some interest in an Android RTSP Client