How to build Gstreamer from sources on Ubuntu?
When developing real-time streaming applications using Gstreamer I prefer to build library from sources, than install from official Ubuntu repositories via apt-get. Also building Gstreamer from sources gives you more flexibility and there are a lot of bug fixes, features in latest versions.
Ordered list of packages to build:
For Gstreamer installation from sources I created simple script BUILD-GSTREAMER.SH. Launch in terminal:
./build-gstreamer.sh
Also next links could be useful for advanced cases:
- How to checkout Gstreamer repositories? (official documentation)
- Build Gstreamer from sources on Ubuntu 16.04 (RidgeRun Docs)
- All possible requirements (packages) for Gstreamer installation (RidgeRun Docs)
- How to install Gstreamer on Ubuntu (install some of required dependencies)
- Readme for each gst-* repository
Steps
#1. Install gstreamer
git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer cd gstreamer git checkout $BRANCH ./autogen.sh --disable-gtk-doc make sudo make install cd ..
Dependencies
sudo apt-get install cmake git autoconf autopoint sudo apt-get install gtk-doc-tools glib-2.0 sudo apt-get install bison flex libglib2.0-dev sudo apt-get install libunwind-dev libdw-dev libgtk-3-dev sudo apt-get install libx11-dev xorg-dev libglu1-mesa-devfreeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev
#2. Install gst-plugins-base
git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-base cd gst-plugins-base git checkout $BRANCH ./autogen.sh --disable-gtk-doc make sudo make install cd ..
Dependencies
# theora sudo apt-get install libtheora-bin libtheora-dev libtheora-doc # vorbis sudo apt-get install libvorbis-dev # cdparanoia sudo apt-get install libcdparanoia-dev sudo apt-get install alsa-base alsa-tools sudo apt-get install libasound2-dev sudo apt-get install libopus-dev libvisual-0.4-dev libpango1.0-dev
#3. Install gst-plugins-good
git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-good cd gst-plugins-good git checkout $BRANCH ./autogen.sh --disable-gtk-doc make sudo make install cd ..
Dependencies
sudo apt-get install libwavpack-dev libspeex-dev qt libjack-sdk libjpeg-dev libdv-dev libsoup2.4-dev qtdeclarative5-dev sudo apt-get install libcairo-dev
#4. Install gst-libav
git clone git://anongit.freedesktop.org/git/gstreamer/gst-libav cd gst-libav git checkout $BRANCH ./autogen.sh --disable-gtk-doc --enable-orc make sudo make install cd ..
Dependencies
sudo apt-get install yasm nasm libbz2-dev liblzma-dev
#5. Install gst-plugins-bad
git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-bad cd gst-plugins-bad git checkout $BRANCH ./autogen.sh --disable-gtk-doc --enable-orc make sudo make install cd ..
Dependencies
sudo apt-get install x265 x264
#6. Install gst-plugins-ugly
git clone git://anongit.freedesktop.org/git/gstreamer/gst-plugins-ugly cd gst-plugins-ugly git checkout $BRANCH ./autogen.sh --disable-gtk-doc --enable-orc make sudo make install cd ..
Dependencies
sudo apt-get install libx264-dev
#7. Install gst-python
git clone git://anongit.freedesktop.org/git/gstreamer/gst-python export PYTHON=/usr/bin/python3 (Specify required python version) cd gst-python git checkout $BRANCH ./autogen.sh --disable-gtk-doc --noconfigure # --with-libpython-dir = location of libpython*.so ./configure --with-libpython-dir="/usr/lib/x86_64-linux-gnu" make sudo make install cd ..
Dependencies
# PyGobject not found sudo apt-get install python-gi-dev
# Python headers
sudo apt-get install python3-dev
# 'DynamicImporter' object has no attribute 'find_spec'
sudo apt-get install gir1.2-gst-plugins-base-1.0
Test gst-python
wget https://gist.githubusercontent.com/jackersson/7baaff902d9f6c722460303f13cba289/raw/486758baeb71695291e3a49a98dc7395d064bfd3/gstreamer_empty_plugin_test_case.py python3 gstreamer_empty_plugin_test_case.py
If no error messages, than gst-python working correctly, otherwise read next “Usage Tips”
Usage Tips
How to use Gstreamer-Python in virtual environment?
# Create symbolic link to gi folder ln -s /usr/lib/python*/dist-packages/gi ~/virtualenvs/cv/lib/python*/site-packages
How to fix “Plugin not registered”?
ImportError: Plugin “_________” not registered
GStreamer-WARNING **: Element factory metadata for ” __________” has no valid long-name field
Locate GI_PATH:
import gi
import gi.repository
print(gi.repository.__file__)
For example:
GI_PATH=/usr/lib/python3/dist-packages/gi
Locate GST_PYTHON_PATH:
- Find path to gst-python (from which you’ve built gstreamer for python).
- Check GST_PYTHON_PATH/gi/overrides has next files (Gst.py, GstPbutils.py, _gi_gst.la, _gi_gst.cpython-*m-*-linux-gnu.so)
Copy files from GST_PYTHON_PATH/gi/overrides to GI_PATH/overrides. For example:
sudo cp $GST_PYTHON_PATH/gi/overrides/Gst.py $GI_PATH/overrides
sudo cp $GST_PYTHON_PATH/gi/overrides/GstPbutils.py $GI_PATH/overrides
sudo cp $GST_PYTHON_PATH/gi/overrides/_gi_gst.la $GI_PATH/overrides
sudo cp $GST_PYTHON_PATH/gi/overrides/_gi_gst.cpython-*m-*-linux-gnu.so $GI_PATH/overrides
Installation Tips
#1. Enable Orc
Orc accelerates code and makes more efficient data processing (read more). Most of gstreamer plugins (gst-plugins-bad, gst-plugins-ugly, gst-libav) use Orc under the hood. To build Orc from sources use
git clone https://github.com/GStreamer/orc ./autogen.sh make sudo make install
Check also this official doc for Orc installation
Or install with sudo
sudo apt-get install liborc-0.4-0 liborc-0.4-dev
#2. Failed to load plugin
GStreamer-WARNING **: Failed to load plugin '/usr/local/lib/gstreamer-1.0/libgstcoreelements.so' ldd /usr/local/lib/gstreamer-1.0/libgstcoreelements.so | grep libgstreamer-1.0 sudo ldconfig
#3. Enable/disable Gtk-docs
./autogen.sh --disable-gtk-docs # build without Gtk-Docs or sudo apt-get install gtk-doc-tools # install Gtk-Docs with sudo
#6. Check available flags for lib configuration
./configure --help
Hope everything works fine. Leave questions, problems in comments, I’ll try to find solutions and update this post 😉
Hi Taras.
After finishing all step. I run ./gst-launch-1.0 v4l2src ! autovideosink in folder gstreamer/tool and got this error:
Setting pipeline to PAUSED …
Pipeline is live and does not need PREROLL …
Setting pipeline to PLAYING …
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
Execution ended after 0:00:00.000219587
Setting pipeline to PAUSED …
Setting pipeline to READY …
Setting pipeline to NULL …
Freeing pipeline …
I checked with ./gst-launch-1.0 videotestsrc ! autovideosink . It worked fine. Could you help me?
I fixed this by adding videoconvert before autovideosink. Thank you!
Glad to hear 😉
Thank you so much for replying me.
I’m trying to send mp4 file over TCP or RTSP. I’m using this command:
gst-launch-1.0 filesrc location=hncloud.mp4 ! decodebin ! x264enc !
mpegtsmux ! queue ! tcpserversink host=xxx.xxx.x.xxx port=5000
recover-policy=keyframe sync-method=latest-keyframe sync=false
And VLC (tcp://xxx.xxx.x.xx:5000) in role receiver. It works fine.
But, when I change x264enc to x265enc. It’s not working.
Can you show me how to encode mp4 file by h265 and send to over TCP or RTSP?
Hi, David)
Till now the best solution I have is the next:
Server:
gst-launch-1.0 videotestsrc ! x265enc tune=zerolatency ! rtph265pay config-interval=10 pt=96 ! udpsink port=5000
Client
gst-launch-1.0 udpsrc port=5000 ! ‘application/x-rtp, encoding-name=H265’ ! rtph265depay ! h265parse ! avdec_h265 ! videoconvert ! gtksink -v
This is not ideal, but I’ll try to find better solution 😉