GStreamer自定义插件多Sink Pad连接:指定关联filesrc方法
GStreamer多Sink Pad自定义插件管道构建方案
问题场景
开发了带有两个Sink Pad(sink_1、sink_2)的自定义GStreamer插件,需求如下:
- 将
filesrc1连接到sink_1 - 将
filesrc2连接到sink_2 sink_2会将缓冲区推送到插件的Src Pad
尝试执行以下gst-launch-1.0命令构建管道时触发语法错误:
gst-launch-1.0 filesrc location=left.avi ! decodebin ! videoconvert ! video/x-raw,format=BGR,width=1920,height=1080 ! custom_plugin.sink_1 ! filesrc location=right.avi ! decodebin ! videoconvert ! video/x-raw,format=BGR,width=1920,height=1080 ! custom_plugin.sink_2 ! fakesink
报错信息:
WARNING: erroneous pipeline: syntax error
错误原因
原命令采用线性串联的写法,GStreamer无法识别两条独立流如何分支到自定义插件的不同Sink Pad,必须明确指定插件实例并分别连接每条流。
正确实现方式
通过给自定义插件指定实例名称,分别将两条流连接到对应的Sink Pad,最终将插件的Src Pad接入输出元素。完整命令如下:
gst-launch-1.0 \ filesrc location=left.avi ! decodebin ! videoconvert ! video/x-raw,format=BGR,width=1920,height=1080 ! my_plugin.sink_1 \ filesrc location=right.avi ! decodebin ! videoconvert ! video/x-raw,format=BGR,width=1920,height=1080 ! my_plugin.sink_2 \ custom_plugin name=my_plugin ! fakesink
关键说明
- 使用
custom_plugin name=my_plugin给插件实例命名,后续通过my_plugin.sink_1、my_plugin.sink_2精准指定要连接的Sink Pad - 两条流为独立并行链路,分别指向自定义插件的不同输入
- 最后将自定义插件的Src Pad(默认自动匹配)连接到
fakesink作为输出
如果decodebin出现链路阻塞,可在decodebin后添加queue元素缓解:
gst-launch-1.0 \ filesrc location=left.avi ! decodebin ! queue ! videoconvert ! video/x-raw,format=BGR,width=1920,height=1080 ! my_plugin.sink_1 \ filesrc location=right.avi ! decodebin ! queue ! videoconvert ! video/x-raw,format=BGR,width=1920,height=1080 ! my_plugin.sink_2 \ custom_plugin name=my_plugin ! fakesink
内容的提问来源于stack exchange,提问作者Karthik
相关产品推荐
相关产品推荐

