Skip to content

Building latest GStreamer from source on distributions with older GStreamer (e.g. Raspberry Pi OS ).

fduncanh edited this page Nov 17, 2024 · 133 revisions

If you want to build a GStreamer that is newer than the one provided by your distribution, it is possible, but the only case where it is recommended to do this is if you wish to use UxPlay on the unsupported "Legacy" (Debian-10 "Buster" based) version of Raspberry Pi OS "Lite" on a Pi model 4B, where the firmware breaks Legacy GStreamer omx support.

The reason for doing this would usually be that you wish to run UxPlay along with some applications that are not supported on (Debian-11 "Bullseye" -based) Raspberry Pi OS Lite.

  • Only the "Lite" version qualifies for the upgrade because the distribution-supplied GStreamer (GStreamer-1.14.4 in Debian 10) must be completely removed ("sudo apt remove gstreamer1.0") before the upgrade, and this will usually break a "Desktop" system where many things depend on the system GStreamer. Because of the way GStreamer uses a cache, two different installations of GStreamer cannot both be active on the same system.

The recommended update for the Legacy system is a conservative one: install GStreamer-1.18.6, the last of the 1.18.x series, on which the Video4Linux2 gstreamer plugin needed to access the Broadcom GPU for hardware-accelerated video decoding can be patched to work correctly on the Pi model 4B. (There is no patch available for GStreamer-1.14.4.) This recommended update is tested, and works.

1. Create the meson/ninja build system:

First get the lastest meson and ninja (and maybe update cmake)

These provide the build system used by GStreamer.

Any system-installed version of meson is likely to be too old to build the new version: if it is installed, uninstall it: sudo apt remove meson; also sudo apt remove ninja and sudo apt remove gstreamer1.0 if applicable.

Install a new build system for gstreamer (meson + ninja)

sudo apt install bison flex cmake git pkg-config libssl-dev python3-pip

Now install meson, which is a python3 application:

sudo pip3 install meson

Also install the latest ninja, which has replaced "make" in the meson build system:

git clone https://github.com/ninja-build/ninja
cd ninja
cmake .
make
sudo make install 
cd ..

Cmake issues:

GStreamer uses meson to setup its own build, but when meson builds some of Gstreamer's external dependencies it may use cmake; meson currently issues a warning that cmake < 3.17 is "deprecated" and will eventually no longer be supported by meson. Raspberry Pi OS (Legacy, Buster) only provides cmake-3.16, which is fine for building the GStreamer-1.18.6 recommended for it, but if a later meson release refuses to build GStreamer using cmake-3.16 you can easily upgrade to a later cmake version.

  • To upgrade cmake, download the newer cmake source from https://github.com/kitware/CMake/releases/ . Choose a release, and download the "tar.gz" source code. Untar it, cd to the unpacked directory, then "cmake . ; make ; sudo make install ". Then uninstall the old cmake ("sudo apt remove cmake"). (If an old cmake is not installed, instead run "./boostrap ; make ; sudo make install", which takes longer.) Check that the new cmake (now installed in /usr/local/bin, rather than /usr/bin) is seen, with cmake --version.

2. Next download GStreamer :

To build a 1.18.x or older version (for example, for Raspberry Pi OS Legacy (Buster) recommended version is 1.18.6):

git clone https://gitlab.freedesktop.org/gstreamer/gst-build
cd gst-build
git checkout 1.18.6

To build a 1.20.x or newer version, replace "gst-build" by "gstreamer" in the above lines, and change the version in "git checkout".

You may wish to now install some optional dependencies: this is an incomplete list, and not all may be useful for you. In principle, GStreamer is complete in that it will attempt to download and build for itself any dependencies that your system does not provide, but it is better to use the versions your system provides, if available (this reduces the chance of build failures when building the external dependencies). If a dependency cannot be satisfied, the corresponding plugin is not built.

sudo apt install libglib2.0-dev libjson-glib-dev libffi-dev libdrm-dev libsoup2.4-dev libxml2-dev 

sudo apt install libdw-dev libunwind-dev libgmp-dev libgsl-dev libbz2-dev libgcrypt-dev 

sudo apt install libmicrodns-dev libmount-dev                

If you are building on Bullseye, omit the third line.

Next install support for various audio/video codecs (list is probably incomplete)


sudo apt install libx264-dev libx265-dev libopus-dev libtheora-dev libvorbis-dev libogg-dev libasound-dev 

sudo apt install libdv4-dev libmpeg2-4-dev libsndio-dev  libflac-dev libvpx-dev libgsm1-dev liba52-0.7.4-dev

sudo apt install libpulse-dev libmp3lame-dev libtwolame-dev libwavpack-dev libmpg123-dev libjack-jackd2-dev

This list is sufficient for running UxPlay with GPU support on Debian-10-based Raspberry Pi OS Lite Legacy (Buster) with pulseaudio installed for sound, using the framebuffer video (Linux kernel mode setting (KMS) videosink "-vs kmssink") without X11.

3.Build and Install GStreamer

To complete the installation, which by default will be in /usr/local:

meson setup build

To save the output from "meson setup", replace the above with "meson setup build > meson.out", and examine meson.out for other missing dependencies you might wish to add, such as those needed for openGL support, if you want to add support for video on X11 rather than just framebuffer video.

  • "meson.out" will show which plugins will be built, and which external dependencies will be built. From meson's tests which return the answer "NO", you should be able to work out which additional lib*-dev packages to install so missing plugins are built, or so that external dependencies are supplied by system-supplied libraries, rather than by private copies built along with GStreamer.

If you need to apply the v4l2 patch (for GStreamer older than 1.22.0, but not older than 1.18.4), get it for the version of GStreamer that you are building from https://github.com/FDH2/UxPlay/wiki/Gstreamer-Video4Linux2-plugin-patches . For 1.18.6, get it with wget https://github.com/FDH2/UxPlay/files/9196647/v4l2_1_18_6_diff3.txt

cd subprojects/gst-plugins-good
patch -p1 < (path to patch)/v4l2_1_18_6_diff3.txt
cd ../..

Finally, build and install GStreamer:

cd build
ninja

when ninja has successfully finished,

sudo ninja install
  • Since the installation is in /usr/local/lib, on Debian-based systems you may need to use sudo to add a line "/usr/local/lib", to /etc/ld.so.conf, if that has not yet been done. Then make the new GStreamer libraries installed in /usr/local/lib available with
sudo ldconfig
  • If GStreamer was previously installed, it is also recommended to clear its cache in the users' home directories: "rm -rf ~/.cache/gstreamer-1.0/".

Adding more plugins after installation

If you find you need some additional plugins which were not built by the above procedure, just install the appropriate lib*-dev packages needed to build them, and return to the build directory in which you ran ninja. Some examples are

sudo apt install libxv-dev libopengl-dev libpng-dev libavfilter-dev libfreetype-dev libxrender-devc

Then proceed with

ninja reconfigure
ninja
sudo ninja install
sudo ldconfig

Troubleshooting:

  • It is possible this error only occurs on 64-bit Raspberry Pi OS Bullseye systems.

If the build fails with error messages mentioning "DISPMANX" (should not occur for GStreamer later than 1.20.4), this is because meson has decided that you are building with support for OpenGL (probably because some OpenGL Libraries are installed). This error was seen on Raspberry Pi OS (64-bit Bullseye) where some remnants of an obsolete 32-bit-only windowing system ("DispmanX", used only on older R Pi systems to access the GPU) were left behind when it was released.

The fix is to disable compilation of "DISPMANX", and try the build again.

cd .. 
meson build -Dgst-plugins-base:gl_winsys=
cd build
ninja

If you actually do want an OpenGL windowing System, the option gl_winsys take values that are 'A comma separated list of opengl window systems to enable building against'. Supported values are chosen from the list

x11, wayland, win32, winrt, cocoa, dispmanx, egl, viv-fb, gbm, android.

The alternative choice is the default value auto, which causes a search of your system for appropriate values.

Unfortunately, the default choice "auto" may incorrectly attempt to include "dispmanx" on a Raspberry Pi OS system. This is a deprecated 32-bit windowing system that should no longer be present on the Pi, but enough pieces of it to be detected, but not to build, are left behind in the 64 bit Raspberry Pi OS: this will prevent GStreamer-1.20.4 or earlier from building (the detection error was fixed in GStreamer-1.20.5). Choices x11, wayland, egl, gbm are possible on Raspberry Pi OS (Bullseye 64-bit). The appropriate libraries must be available for the choices you explicitly make.