Back to posts.

Compiling GStreamer from source on Windows

Recently I had to compile GStreamer form source on Windows and Linux. In this article I'll explain how you can compile GStreamer from sources in a local development directory. This allows you to have several GStreamer versions next to each other and change the source of GStreamer itself which can be helpfull during development.

GStreamer provides several solutions to get everything you need to start developing on Windows. They provide an installer that you can use for a system wide installation. Note that each installer comes with a unique ID and you can only install one version at a time; for binary release distributions this is fine, but this is not flexible when you want to install GStreamer in your own source tree.

GStreamer has an article that describes how you can compile from source using their cerbero build scripts. I ran into too many issues while using this solution and I was advised to use their new gst-build repository which uses the meson build tool.

GStreamer has many dependencies and the GStreamer team did an amazing job of writing the necessary scripts that compile these dependencies on Linux/Mac and Window.

Prerequisites:

Make sure that you've installed the following tools:

Compiling GStreamer from source on Windows

Follow these steps to compile GStreamer on Windows. I've disabled a couple of plugins because currently the build system throws an error while trying to compile those.

  • Open a x64 Native Tools Command Prompt for VS 2019
  • Get the gst-build repository:

    mkdir gst-build
    cd gst-build
    git clone https://gitlab.freedesktop.org/gstreamer/gst-build.git .
    
  • Configure:

    meson --prefix=%cd%/installed ^
          -Ddevtools=disabled ^
          -Dbad=enabled ^
          -Dugly=enabled ^
          -Dlibav=enabled ^
          -Dgst-plugins-ugly:x264=disabled ^
          -Dgst-plugins-bad:tests=disabled ^
          -Dgst-plugins-good:soup=disabled build
    
  • Compile and install:

    ninja -C build
    meson install -C build
    

Using the GStreamer libraries in your project

As you can see from the above meson command, I've used the installed directory as the install prefix. Below this directory you'll find the headers and libraries you need to link with.

  • Add these include paths to your project:

    installed/include/
    installed/include/gstreamer-1.0/
    installed/lib/gstreamer-1.0/include
    installed/lib/glib-2.0/include
    
  • Link with the gstreamer and glib libraries:

    installed/lib/gstreamer-1.0.lib
    installed/lib/gobject-2.0.lib
    installed/lib/glib-2.0.lib
    
  • Link with any other plugin library that you use:

    installed/lib/gstgl-1.0.lib
    installed/lib/gstapp-1.0.lib
    
  • Note that your application needs to be able to find the DLLs that GStreamer created. Of course this is the gstreamer-1.0.dll but there are several other dependencies. Because of these dependencies it's the easiest to copy the DLLs into the right directory. Let's assume that you have app.exe in myapp/bin/app.exe, then make sure to copy the files like this:

    installed/bin/*.dll               > myapp/bin/
    installed/lib/gstreamer-1.0/*.dll > myapp/lib/
    

Troubleshooting

GStreamer cannot find certain DLLs

Make sure that the *.dll from the installed/bin directory are next to your application.exe and also make sure that the plugin DLLs can be found; this means all the DLLs. These need to be in a directory relative to the gstreamer-1.0.dll. As gstreamer-1.0.dll must be in the same directory as your application.exe you should use: application.exe/../lib/ for the plugin DLLs. Also note that GStreamer may try to find libraries from a couple of other standard locations which are described at this page, see the At runtime, GStreamer will look for its plugins in the following folders: section.

Enable verbose debug output

You can set the following environment variable to get a very detailed log that tells you exactly what GStreamer is doing. When you see that certain plugins can't be loaded don't be fooled by the error message and make sure to use a tool like Depenencies to inspect the DLL. To enable verbose output you can run your application after setting the environment variable:

set GST_DEBUG=*REGISTRY*:7 && application.exe