Setup gstreamer production environment after built from sources on Ubuntu

Hi.

Say I’ve clone gst repo into /opt/gstreamer, followed these instructions.

Is there any bash script which setups environment needed for prodution?

I’m aware of gst-env.py, but is it ok to use in production, because it is used to setup development environment, plus it creates new shell?

I would like to have small sh script with configures gst environment given it’s path (or taken by default /opt/gstreamer) and running my app.

What is the best practics to use gst in production environment?

Thanks in advance.

what are your program language and GUI packages(like Qt) in your product?
is your product launched at start-up of the target computer?
Do you use any gstreamer command in your code?

Thank you for reply, again!

It is service, written on dotnet core. It uses gstreamer and it’plugins – good, bad, ugly and so on. Nothing fancy (I’ve already posted my pipeline here). I need to properly setup env. so my service could use gstreamer. gst-env.py seems ok, but it is explicitly stated that it is for development and it doing redundant things like create new session. I want something simple and robust. Some simple shell script which configure gst environment for production use and laucnh my service app.

I set envs for lib, bin and plugins paths inside the code(main.cpp in C++)

1 Like

The larger GStreamer build system, cerbero, does provide a gst-env script for non standard prefix installation. Though we don’t have that as part of our low level build system meson. Meson offser an uninstalled way to run GStreamer with meso devenv, but this is a developer tools, not really for production.

The GStreamer core library locates GStreamer plugins by default already based on the prefix it was configured for, so as long as you pull in the right GStreamer (+ glib + any other deps) that should work fine out of the box already. If you have to force it (which you shouldn’t have to in the installed case) there’s GST_PLUGIN_SYSTEM_PATH, see Running GStreamer Applications for this and other environment variables.

Others are more general system environment variables that are not GStreamer specific, e.g. LD_LIBRARY_PATH to make the run-time linker look in specific prefixes (that are not in the global config file), or PKG_CONFIG_PATH to make pkg-config pick up the right .pc files for development purposes (if you want to develop/build against that non-standard-prefix installation).

1 Like

Hi!

What exact envs did you specify?
Below is contents of of folders /opt/gstreamer, /opt/gstreamer/builddir, /opt/gstreamer/builddir/subprojects.

What should I add to envs?

I guess what you did is not right. Do not build any package or app under root. Instead, install it under /opt/

And you are showing build dir. You have not installed gstreamer.

git clone the source code somewhere under Videos dir or your working dir.
Build it there and install the build under /opt/. Do not build it under root.

Hi!

I didn’t buld src under root. It is installed (cloned) under /opt (see img above). Am I right that I need to init LD_LIBRARY_PATH with each folder with *.so
in /opt/gstreamer/builddir/subprojects/ ? Can you share main ideas of your init code? In my case it looks like:

LD_LIBRARY_PATH=/opt/gstreamer/builddir/subprojects/gobject-introspection-1.74.0/girepository:/opt/gstreamer/builddir/subprojects/gst-editing-services/ges:/opt/gstreamer/builddir/subprojects/gst-devtools/validate/plugins/ssim:/opt/gstreamer/builddir/subprojects/gst-devtools/validate/plugins/gapplication:/opt/gstreamer/builddir/subprojects/gst-devtools/validate/plugins/fault_injection:/opt/gstreamer/builddir/subprojects/gst-devtools/validate/gst/overrides:/opt/gstreamer/builddir/subprojects/gst-devtools/validate/gst/validate:/opt/gstreamer/builddir/subprojects/gst-rtsp-server/gst/rtsp-server:/opt/gstreamer/builddir/subprojects/FFmpeg:/opt/gstreamer/builddir/subprojects/libsrtp-2.5.0:/opt/gstreamer/builddir/subprojects/libmicrodns/src:/opt/gstreamer/builddir/subprojects/fdk-aac-2.0.2:/opt/gstreamer/builddir/subprojects/json-glib-1.6.6/json-glib:/opt/gstreamer/builddir/subprojects/libavtp:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/webrtc:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/va:/opt/gstreamer/builddir/subprojects/libva/va:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/transcoder:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/sctp:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/player:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/play:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/mpegts:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/isoff:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/interfaces:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/insertbin:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/cuda:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/codecs:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/codecparsers:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/basecamerabinsrc:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/audio:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/adaptivedemux:/opt/gstreamer/builddir/subprojects/gst-plugins-bad/gst-libs/gst/uridownloader:/opt/gstreamer/builddir/subprojects/libsoup-2.74.3/libsoup:/opt/gstreamer/builddir/subprojects/libpsl-0.21.2/src:/opt/gstreamer/builddir/subprojects/sqlite-amalgamation-3400000:/opt/gstreamer/builddir/subprojects/dv/libdv:/opt/gstreamer/builddir/subprojects/lame-3.100/libmp3lame:/opt/gstreamer/builddir/subprojects/libxml2-2.10.3:/opt/gstreamer/builddir/subprojects/libvorbis-1.3.7/lib:/opt/gstreamer/builddir/subprojects/pango-1.50.14/pango:/opt/gstreamer/builddir/subprojects/cairo-1.17.8/util/cairo-trace:/opt/gstreamer/builddir/subprojects/cairo-1.17.8/util/cairo-script:/opt/gstreamer/builddir/subprojects/cairo-1.17.8/util/cairo-gobject:/opt/gstreamer/builddir/subprojects/cairo-1.17.8/src:/opt/gstreamer/builddir/subprojects/pixman-0.42.2/pixman:/opt/gstreamer/builddir/subprojects/fontconfig-2.14.2/src:/opt/gstreamer/builddir/subprojects/harfbuzz-8.0.0/src:/opt/gstreamer/builddir/subprojects/freetype-2.12.1:/opt/gstreamer/builddir/subprojects/fribidi-1.0.13/lib:/opt/gstreamer/builddir/subprojects/opus/src:/opt/gstreamer/builddir/subprojects/libogg-1.3.5/src:/opt/gstreamer/builddir/subprojects/graphene-1.10.8/src:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/gl:/opt/gstreamer/builddir/subprojects/libgudev-237/gudev:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/allocators:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/app:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/riff:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/rtsp:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/sdp:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/pbutils:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/rtp:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/audio:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/video:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/fft:/opt/gstreamer/builddir/subprojects/gst-plugins-base/gst-libs/gst/tag:/opt/gstreamer/builddir/subprojects/gstreamer/libs/gst/check:/opt/gstreamer/builddir/subprojects/gstreamer/libs/gst/net:/opt/gstreamer/builddir/subprojects/gstreamer/libs/gst/controller:/opt/gstreamer/builddir/subprojects/gstreamer/libs/gst/base:/opt/gstreamer/builddir/subprojects/gstreamer/gst:/opt/gstreamer/builddir/subprojects/glib-2.76.4/gio:/opt/gstreamer/builddir/subprojects/glib-2.76.4/gmodule:/opt/gstreamer/builddir/subprojects/glib-2.76.4/gthread:/opt/gstreamer/builddir/subprojects/glib-2.76.4/gobject:/opt/gstreamer/builddir/subprojects/glib-2.76.4/glib:/opt/gstreamer/builddir/subprojects/orc/orc-test:/opt/gstreamer/builddir/subprojects/orc/orc:/home/gstreamer/prefix/lib64:/home/gstreamer/prefix/lib```

The installed dirs are
bin
include
lib
libexec
share

I’ve built gst from sources, I have no such folders.

what you showed is build dir, not installation dir.

Build and install steps:

  1. cd gstreamer
  2. meson setup --pkgconfig.relocatable --prefix=/opt/gstreamer -Dlibdir=lib builddir
  3. ninja -C builddir
  4. sudo ninja install -C builddir
1 Like

Thank you so much again, will try. For now I have problem with setting env variables on Linux, Ubunta. In code (dotnet core project) I setup LD_LIBRARY_PATH and GST_PLUGIN_PATH – doesn’t work, can’t find libgstreamer. Env. variables are set, because I can print them.
If I setup them in shell and run my app – everything is fine. I think that gst is looking in a parent proc (shell) environment for needed variable or somehow ignores them. So, it seems to be more fundamental problem.

Is your app under Linux and use C++/C ? You just setup env variables and call gst_init?

Yes. If you can not install gstreamer properly, you can not set gstreamer ENVs correctly.

Here is what my program prints for env:

23:29:41.395 [129487:1 ] [DBG] [myapp] XDG_SESSION_TYPE=tty
23:29:41.397 [129487:1 ] [DBG] [myapp] PWD=/home/sharov_am/myapp/net6.0
23:29:41.397 [129487:1 ] [DBG] [myapp] LD_LIBRARY_PATH=/opt/gstreamer/lib
23:29:41.397 [129487:1 ] [DBG] [myapp] TERM=xterm
23:29:41.397 [129487:1 ] [DBG] [myapp] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/gstreamer/bin

Namely, I add /opt/gstreamer/bin to PATH and create LD_LIBRARY_PATH in code. Doesn’t work. If I set (export) before my app, everything works.
What I’m doing wrong? I don’t think that it relates somehow to installation. With ninja it is more elegant but I did basically the same, just added much more folders (copy-paste from gst-env.py). I don’t understand what I’m missing…

your gstreamer bin path is the last one and will be selected only when no other gstreamer bin path is available. I guess you have one in your system. Put it to the first to override system path. Also try to set the plugin path as well.

export PATH=/opt/gstreamer/bin:$PATH
export LD_LIBRARY_PATH=/opt/gstreamer/lib:$LD_LIBRARY_PATH

In this way, your gstreamer will be applied. Otherwise, the installed one with distribution will be used.

The point is to setup env variables by application itself. I setup it in code. Part of env variables of my process you can see above, the problem is that gst doesn’t see them. It seems to be problem of parent-child environment difference. Probably gst looks env vars in parent (process) environment or smth similiar. If I setup env vars in code – it doesn’t work, if in shell (parent process), it works.

Moreover, following approach works great:
export LD_LIBRARY_PATH=/opt/gstreamer/lib && dotnet app.dll
but in this case I have to create intermediate shell script file which is not great.

So, setting env vars externally to app – works, setting very same env vars in app – doesn’t work. And I have no clue why.

do the following in linux:
env LD_LIBRARY_PATH=/opt/gstreamer/lib dotnet6 app.dll

dll in Linux?

Hi.

Yes, it is ok, it is dotnet. Dotnet now (almost 5-6 years actually) works on Linux, so one can build cross-platform application. Hence dll. It works, it is not a problem.