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:

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

*Solution

#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 😉

5 Comments

Add a Comment

Your email address will not be published. Required fields are marked *