Thanks to a partnership between Collabora and Huawei is now possible to build Gstreamer with just the features required for a specific application, reducing the binary size for space-constrained embedded systems.
Gstreamer is a very popular open-source multimedia framework used in a wide variety of projects and products, and with an impressive number of features spread over 30 libraries and more than 1600 elements in 230 plugins. This is not a problem on desktop PC and most smartphones, but the size of the binary may be too large for some systems, and until recently it was no easy way to customize GStreamer build for a specific application. But Collabora changed the code to allow gst-build to generate a minimal GStreamer build.
The company built upon a new feature from GStreamer 1.18, released in September 2020, that makes it possible to build all of GStreamer into a single shared library named gstreamer-full with all libraries, as well as plugins and other dependencies such as a GLib. The company explains that gst-build already provides options to select the plugins to be built, but by using the gstreamer-full library it’s possible to select exactly which libraries are included in the final library with the -Dgst-full-libraries=
. The plugins are then automatically included according to the configuration and the dependencies available. Here’s an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$ meson build-gst-full \ --buildtype=release \ --strip \ --default-library=static \ --wrap-mode=forcefallback \ -Dauto_features=disabled \ -Dgst-full-libraries=app,video,player \ -Dbase=enabled \ -Dgood=enabled \ -Dbad=enabled \ -Dgst-plugins-base:typefind=enabled \ -Dgst-plugins-base:app=enabled \ -Dgst-plugins-base:playback=enabled \ -Dgst-plugins-base:volume=enabled \ -Dgst-plugins-base:videoconvert=enabled \ -Dgst-plugins-base:audioconvert=enabled \ -Dgst-plugins-good:audioparsers=enabled \ -Dgst-plugins-good:isomp4=enabled \ -Dgst-plugins-good:deinterlace=enabled \ -Dgst-plugins-good:audiofx=enabled \ -Dgst-plugins-bad:videoparsers=enabled |
The important part is the -Dauto_features=disabled
line that disables automatic features selection, and then allows us to select specific features within the selected plugin(s).
All of this is already included in Gstreamer 1.18. So what did Collabora do exactly? They added five new options to Gstreamer menu to provide better granularity namely:
- gst-full-plugins – Select the plugin you’d like to include. By default, all the plugins will be enabled by the build process, and at least one must be passed to avoid building all.
- gst-full-elements – Select the element(s) using the
plugin1:elt1,elt2;plugin2:elt1
format - gst-full-typefind-functions – Select the typefind(s) using the
plugin1:tf1,tf2;plugin2:tf1
format - gst-full-device-providers – Select the decide-provider(s) using the
plugin1:dp1,;dp2;plugin2:dp1
format - gst-full-dynamic-types – Select the dynamic-type(s) using the
plugin1:dt1,;dt2;plugin2:dt1
format
Element, typefind, device-provider, and dynamic type are all plugin features that are defined in Gstreamer documentation.
To showcase the solution, Collabora first built Gsteamer will all options resulting in a 49.2 MB gstreamer-full static library, following by a tailored build with just three elements namely filesrc,fakesink, andidentity:
1 2 |
$ meson build-gst-full --reconfigure -Dgst-full-plugins=coreelements '-Dgst-full-elements=coreelements:filesrc,fakesink,identity' '-Dgst-full-libraries=[]' $ ninja -C build-gst-full |
That ended up being just 3.2 MB in size, or a 93.5% reduction in size. Not too bad!
You’ll find more details about Collabora implementation in the announcement blog post.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
finnaly 🙂
Great job! I really like it when software developers take care of disabling features to shrink the final executable. First it’s a sign of respect for their users’ resources. Second it’s the best way to imrpove the software architecture by making parts optional and replaceable, and reducing the overall number of longterm bugs. I know such software tend to cause head scratching for distro maintainers who never know what to enable but it’s always better than having everything forcefully enabled!