当前位置: 代码迷 >> 综合 >> 在 Jetson Nano 上编写 GStreamer 插件 ——实现自己的第一个作品
  详细解决方案

在 Jetson Nano 上编写 GStreamer 插件 ——实现自己的第一个作品

热度:79   发布时间:2023-12-12 15:36:14.0

1. 编译

这个 git 模块包含可能的 GStreamer 项目的模板代码。

  • gst-app
    用于编写基于GStreamer的应用程序的基本自动工具布局。
  • gst-plugin
    基本的自动工具布局和基本的过滤代码,用于编写
    GStreamer插件。

这段代码是在麻省理工学院的许可证1下提供的,这基本上意味着“按你的意愿处理它,但如果它不起作用,不要责怪我们”。您可以根据自己的意愿,在任何许可证下,将此代码用于任何项目。我们建议对应用程序和插件使用LGPL2许可证,因为多媒体现在是专利的雷区。详情请参见我们的网站3

按以下方式构建每个模块:

$ cd gst-plugin
$ ./autogen.sh
$ make

2. Jetson Nano 实际操作说明

我是从 GitHub 网站上下载的一份 2013 年提交的版本,内容配置完整,解压到 home 目录下,文件夹名称是 gst-template-master。因此,我的执行过程如下:

$ cd ~/gst-template-master/gst-plugin
$ sh autogen.sh
$ make

3. 配置 Makefile

修改 gst-plugin/src/Makefile.am 以添加或删除源文件以生成或添加其他依赖项或编译器标志,或更改要安装的插件文件的名称。如果更改在“make”上未自动生效,请运行./autoregen.sh

4. 安装插件

构建插件后,可以使用“sudo make install”安装它。默认情况下,它将安装在 /usr/local 前缀的目录中。在 Jetson Nano 上运行,安装位置是 /usr/local/lib/gstreamer-1.0/

5. 配置插件

GStreamer 不会自动到 /usr/local/lib/gstreamer-1.0/ 访问你新设计的插件。因此,需要将 GST_PLUGIN_PATH 环境变量设置为包含或指向 /usr/local/lib/gstreamer-1.0/,以便让 GStreamer 找到新设计的插件。

或者,您可以在 gst-plugins/src/.libs/ 中找到您的插件二进制文件 libgstplugin.so 或类似的(扩展名可能不同),因此您还可以将 GST_PLUGIN_PATH 环境变量设置为 gst-plugins/src/.libs/ 目录(最好指定一个绝对路径)。

您还可以使用以下工具检查它是否已正确构建:

gst-inspect-1.0 gst-plugins/src/.libs/libgstplugin.so

我的操作记录:

$ sudo make install
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /usr/local/lib/gstreamer-1.0
----------------------------------------------------------------------
Libraries have been installed in:/usr/local/lib/gstreamer-1.0If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:- add LIBDIR to the 'LD_LIBRARY_PATH' environment variableduring execution- add LIBDIR to the 'LD_RUN_PATH' environment variableduring linking- use the '-Wl,-rpath -Wl,LIBDIR' linker flag- have your system administrator add LIBDIR to '/etc/ld.so.conf'See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[1]: Leaving directory '/home/jetson/gst-template-master/gst-plugin/src'
$ gst-inspect-1.0 /usr/local/lib/gstreamer-1.0/libgstmyfilter.so
Plugin Details:Name                     myfilterDescription              Template myfilterFilename                 /usr/local/lib/gstreamer-1.0/libgstmyfilter.soVersion                  1.0.0License                  LGPLSource module            my-plugin-packageBinary package           GStreamerOrigin URL               http://gstreamer.net/myfilter: MyFilter1 features:+-- 1 elements

6. 在 Jetson Nano 上安装配置

我在 src 文件夹用 ..\tools\make_element YepingFilter 命令创建了自己的插件,然后修改 src 文件夹下的 Makefile.am 文件。修改后内容如下:

# Note: myfilterdir is set in configure##############################################################################
# TODO: change libgstmyfilter.la to something else, e.g. libmysomething.la #
##############################################################################
plugin_LTLIBRARIES = libgstyepingfilter.la##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
# e.g. libmysomething.la => libmysomething_la_SOURCES #
# libmysomething_la_CFLAGS #
# libmysomething_la_LIBADD #
# libmysomething_la_LDFLAGS #
############################################################################### sources used to compile this plug-in
libgstyepingfilter_la_SOURCES = gstyepingfilter.c gstyepingfilter.h# compiler and linker flags used to compile this myfilter, set in configure.ac
libgstyepingfilter_la_CFLAGS = $(GST_CFLAGS)
libgstyepingfilter_la_LIBADD = $(GST_LIBS)
libgstyepingfilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstyepingfilter_la_LIBTOOLFLAGS = --tag=disable-static# headers we need but don't want installed
noinst_HEADERS = gstyepingfilter.h

然后,在 gst-plugin 文件夹下执行 sh autogen.shmakesudo make install,完美实现编译安装。

最后看一下结果:

$ gst-inspect-1.0 /usr/local/lib/gstreamer-1.0/libgstyepingfilter.so
Plugin Details:Name                     yepingfilterDescription              Template yepingfilterFilename                 /usr/local/lib/gstreamer-1.0/libgstyepingfilter.soVersion                  1.0.0License                  LGPLSource module            my-plugin-packageBinary package           GStreamerOrigin URL               http://gstreamer.net/yepingfilter: YepingFilter1 features:+-- 1 elements

修改一下 etc/profile,定义环境变量 GST_PLUGIN_PATH,在最后加上下面这两行:

GST_PLUGIN_PATH=$GST_PLUGIN_PATH://usr/local/lib/gstreamer-1.0
export GST_PLUGIN_PATH

重启系统后,试一下命令 gst-inspect-1.0 yepingfilter,查看一下我们写的新元素 yepingfilter:

$ gst-inspect-1.0 yepingfilter
Factory Details:Rank                     none (0)Long-name                YepingFilterKlass                    FIXME:GenericDescription              FIXME:Generic Template ElementAuthor                   jetson <<user@hostname.org>>Plugin Details:Name                     yepingfilterDescription              Template yepingfilterFilename                 //usr/local/lib/gstreamer-1.0/libgstyepingfilter.soVersion                  1.0.0License                  LGPLSource module            my-plugin-packageBinary package           GStreamerOrigin URL               http://gstreamer.net/GObject+----GInitiallyUnowned+----GstObject+----GstElement+----GstYepingFilterPad Templates:SRC template: 'src'Availability: AlwaysCapabilities:ANYSINK template: 'sink'Availability: AlwaysCapabilities:ANYElement has no clocking capabilities.
Element has no URI handling capabilities.Pads:SINK: 'sink'Pad Template: 'sink'SRC: 'src'Pad Template: 'src'Element Properties:name                : The name of the objectflags: readable, writableString. Default: "yepingfilter0"parent              : The parent of the objectflags: readable, writableObject of type "GstObject"silent              : Produce verbose output ?flags: readable, writableBoolean. Default: false

再试验一下 gst-launch-1.0 命令:

$ gst-launch-1.0 faketsrc ! yepingfilter ! fakesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
I'm plugged, therefore I'm in.
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
I'm plugged, therefore I'm in.
... ... 

也是相当完美呀!我们可以开始真正地自己编写插件了!


  1. [1] http://www.opensource.org/licenses/mit-license.php 或复制.MIT ??

  2. [2] http://www.opensource.org/licenses/lgpl-license.php 或复制.LIB ??

  3. [3] http://gstreamer.freedesktop.org/documentat ??

  相关解决方案