gstreamer插件制作(插件内使用c++和opencv)

gstreamer插件制作(插件内使用c++和opencv)

gstreamer插件默认是使用c语言编写的,不过我们经常在插件中使用opencv来处理图像,而opencv对c语言的接口并不多,于是我们便要在gstreamer插件中使用c++和opencv,本篇就记录一个使用了c++和opencv的插件制作。这种插件和普通使用c语言插件创建的不同主要在于makefile内配置的不同。

1.获取创建插件的模板gst-template

方法一: CVS(我使用此方法连接不上cvs,用的第二个方法成功)
$cvs -d:pserver:[email protected]/cvs/gstreamer login
password: [root的密码]
$cvs -z3 -d:pserver:[email protected]:/cvs/gstreamer co gst-template

方法二: GIT
如果没有安装git,则首先安装git:
$sudo apt-get install git-core
再获取模板:         
$git clone git://anongit.freedesktop.org/gstreamer/gst-template.git

2.产生插件模板文件

进入目录gst-template/gst-plugin/src
$cd gst-template/gst-plugin/src
$../tools/make_element ExampleFilter	//可修改元件名称
此时会产生成gstexamplefilter.c gstexamplefilter.h两个文件

3.修改创建的两个文件

.c文件:进行元件属性以及功能的添加,在chain函数中完成对图像处理功能的添加。
.h文件:进行头文件的添加,结构体的定义。

4.修改Makefile.am文件 (注意:是src目录下的Makefile.am)

$sudo gedit Makefile.am
在文件上方plugin_LTLIBRARIES中添加参数:libgstexamplefilter.la

在文件下方添加如下几行:
libgstexamplefilter_la_SOURCES = gstexamplefilter.c gstexamplefilter.h
libgstexamplefilter_la_CFLAGS = $(GST_CFLAGS)
libgstexamplefilter_la_LIBADD = $(GST_LIBS)
libgstexamplefilter_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstexamplefilter_la_LIBTOOLFLAGS = --tag=disable-static

5.产生Makefile文件

运行命令:
$./autogen.sh

6.修改插件的makefile文件配置

(1)修改malefile文件,编译器修改为c++的编译器,添加引入opencv包。注:非系统自带的gstreamer路径为/usr/local/include/gstreamer-1.0
 c++编译器修改:
    CC = g++
    CPP = g++ -E
opencv2.14修改内容:
    GST_CFLAGS = -pthread -I/usr/include/gstreamer-1.0 -I/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/cairo -I/usr/include/x86_64-linux-gnu/c++/4.8/bits -I/usr/include/c++ -Wall
    GST_LIBS = -L/usr/local/lib -lgstcontroller-1.0 -lgstaudio-1.0 -lgstbase-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -L/usr/local/lib -lgstcontroller-1.0 -lgstaudio-1.0 -lgstbase-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -L/usr/lib/x86_64-linux-gnu -lGL -lGLU -ltbb -lrt -lpthread -lm -ldl
opencv3.4修改内容:
    GST_CFLAGS = -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/cairo -I /usr/include/x86_64-linux-gnu/c++/5/bits -I /usr/include/c++ -I /usr/local/cuda/include -Wall
    GST_LIBS = -L/usr/local/lib -lgstcontroller-1.0 -lgstaudio-1.0 -lgstbase-1.0 -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_shape -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_calib3d -lopencv_features2d -lopencv_objdetect -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_cudawarping -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_video -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_cudaarithm -lopencv_core -lopencv_cudev -lcairo -lopencv_dnn

(2)$make
(3)$sudo make install
运行完会发现/gst-plugins/src下产生了许多.la/.lo文件。/usr/local/lib/gstreamer-1.0下产生了.so/.la文件。

7.测试插件

$gst-inspect examplefilter
若显示插件属性表示插件制作成功。

8.gst-inspect找不到新插件错误

插件制作完成.la/.so文件都成功生成但gst-inspect找不到新插件:

产生原因:若使用的gstreamer是ubuntu自带的,则gstreamer的插件查询路径为/usr/lib/x86_64-linux-gnu/gstreamer-1.0而插件的默认安装路径为/usr/local/lib/gstreamer-1.0。

解决方法:将/usr/local/lib/gstreamer-1.0下的.so/.la文件拷贝到/usr/lib/x86_64-linux-gnu/gstreamer-1.0路径下。

进入/usr/local/lib/gstreamer-1.0路径下然后进行拷贝:
$sudo cp libgstexamplefilter.la /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstexamplefilter.la
$sudo cp libgstexamplefilter.so /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstexamplefilter.so
或者在/usr/local/lib/gstreamer-1.0路径下使用:
sudo cp * /usr/lib/x86_64-linux-gnu/gstreamer-1.0

你可能感兴趣的:(Gstreamer)