Creating Gstreamer Multimedia Pipeline With C++ Part 1
Gstreamer is a powerful and versatile framework for creating streaming media applications. Its gives an extensive power to building real time IVA (Intelligence Vision Analytics) applications.
NVIDIA DeepStream SDK is built based on Gstreamer framework. So learning the Gstreamer will give you the wide angle view to build an IVA applications. My primary language for developing IVA applications is C++.
This guide is intended to help you understand the GStreamer framework so you can develop applications based on it. The first part of this series will focus on development of a simple Gstreamer Hello world program. We are dealing with multimedia application,so we going to play a network video.
Gstreamer is available on Linux, Mac OS X, Windows,
Installation:
To install Gstreamer on Ubuntu 18.04.4 LTS
sudo apt-get updatesudo apt-get upgradesudo apt install g++ cmake pkg-configsudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
For Windows and Mac installation follow this link
https://gstreamer.freedesktop.org/documentation/installing/index.html?gi-language=c
File Structure
- CmakeLists.txt
- main.cpp
we are using cmake tool to build the cpp program. For more information on cmake follow this link https://cmake.org/cmake/help/v3.17/
CmakeLists.txt
main.cpp
Code walk through
gst_init(&arg, &argv);
- It initializes all internal structures
- Check what plugins are available
- Executes any command-line option intended for Gstreamer
If you always pass your command-line parameters argc and argv to gst_init() your application will automatically benefit from the GStreamer standard command-line options
pipeline = gst_parse_launch(
"playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",
nullptr);
This line is the core of this example. gst_parse_launch() and playbin.
Gstreamer is a framework designed to handled multimedia flows, media travels through source (the producers ) to sink ( the consumers ), passing series of intermediate elements to perform all tasks. The set of all interconnected elements are called pipeline.
In Gstreamer, you usually build the pipeline by manually assembling the individual elements. For this simple demo we are using gst_parse_launch(), this function takes a textual representation of a pipeline and turns into actual pipeline.
Playbin, is a special element which acts as a source and sink, and is a whole pipeline. Internally it will creates and connects all necessary elements to play your media.
gst_element_set_state(pipeline, GST_STATE_PLAYING);
Every gstreamer element has an associated state, in-order to play the media, we need to set the pipeline in PLAYING state.
bus = gst_element_get_bus(pipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
static_cast<GstMessageType>(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
This line will wait until any errors occurs or the end of the stream is found
before exiting the application, free the resources.
if (msg != nullptr)
gst_message_unref(msg);gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
Build & Execute :
git clone https://github.com/karthickai/gstreamer.git
cd gstreamer/gstreamer-01
mkdir build; cd build
cmake ../
make
./gstreamer-01
Output :
Thanks for reading.
If you have any suggestions/Questions kindly let us know in the comments section!