如何解决无法链接Gstreamer Elements
我是GStreamer的新手,我遵循Basic tutorial 2 on GStreamer website并尝试使其与本地mp4文件一起使用。 我的问题是我无法链接“ uridecodebin”和“ autovideosink”,这是我的相关代码:
GstElement *pipeline,*source,*sink;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
/* Initialize GStreamer */
gst_init (&argc,&argv);
/* Create the elements */
source = gst_element_factory_make ("uridecodebin","source");
sink = gst_element_factory_make ("autovideosink","sink");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("pipeline");
if (!pipeline || !source || !sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline),source,sink,NULL);
if (gst_element_link (source,sink) != TRUE) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
使用gst_element_link (source,sink)
总是返回false,但是如果我只使用gst-launch-1.0 uridecodebin uri=file://MyPathToVideo/test.mp4 ! autovideosink
命令,它会很好地工作,我在做什么错了?
非常感谢。
解决方法
尝试使用gst_parse_launch()
并为其提供管道。这样更短。而且我相信它可以解决您的一些特殊情况。
您的方法不起作用的主要问题是uridecodebin
不暴露任何填充物,因为在那个时候它不了解有关MP4文件的任何信息。因此它既可以包含音频,视频,也可以包含两者。正确的方法是实施延迟链接。
因此,不是直接链接它,而是在pad-added
上实现uridecodebin
信号:
https://gstreamer.freedesktop.org/documentation/gstreamer/gstelement.html?gi-language=c#GstElement::pad-added
然后在断开元素的情况下启动管道。
pad-added
扫描了您的媒体文件并暴露了可链接的打击垫时,将触发此uridecodebin
信号。如果这是您的视频板,则可以将其连接到autovideosink
。
gst_parse_launch()
,如果我没记错的话,它会自动为您处理(至少gst-lauch-1.0
所做的就是-不知道特定功能是否也移到了该API)。 / p>
P.S。你跳了枪。教程2不使用uridecodebin
,而是使用更多基本元素。教程3将介绍动态管道。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。