gstreamer代码无法链接所有GST元素
gstreamer code failed to link all GST ELEMENTS
Ubuntu 14.04Gstreamer 0.10代码Sdk:Qt。
我是Gstreamer的新手。当我在我的终端上使用gst启动工具时,我可以成功地看到连接到我的工作站的相机捕获&流式传输视频。
为了继续,我在Qt中编写了c代码。它编译正确,当我运行它时,它会打开新的Xterm窗口并抛出错误"Elements could not be linked"
我做错了吗?或者我需要做其他事情来查看流式吗?"
以下是我的代码(深受他人代码的启发)
.Pro文件
QT += core
QT -= gui
QT += core gui
QT += network
QT +=core
QMAKE_CXXFLAGS+= -std=c++11
QMAKE_LFLAGS += -std=c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = justtest
PKGCONFIG +=glib-2.0
PKGCONFIG += gstreamer-0.10
CONFIG += link_pkgconfig
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += pkg-config --cflags glib-2.0
INCLUDEPATH += /usr/include/glib-2.0/glib/
INCLUDEPATH +=/usr/include/libxml2/
INCLUDEPATH += /usr/include/gstreamer-0.10/
SOURCES += main.cpp
main.cpp
#include <gst/gst.h>
#include <glib.h>
static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of streamn");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
g_printerr ("Error: %sn", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc, char *argv[])
{
//QApplication app(argc, argv);
GstElement *pipeline, *source, *sink, *convert, *videoenc;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
GMainLoop *loop;
// Initialize GStreamer /
gst_init (&argc, &argv);
loop = g_main_loop_new( NULL, FALSE );
// Create the elements
source = gst_element_factory_make ("v4l2src", "source");
sink = gst_element_factory_make ("autovideosink", "sink");
convert =gst_element_factory_make("ffmpegcolorspace","convert");
videoenc = gst_element_factory_make ("ffdec_mpeg4", "videoenc");
// Create the empty pipeline
pipeline = gst_pipeline_new ("test-pipeline");
if (!pipeline || !source || !sink || !convert)
{
g_printerr ("Not all elements could be created.n");
return -1;
}
//set der source
g_object_set (G_OBJECT ( source ), "device", "/dev/video0", NULL);
// we add a message handler
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
//Build the pipeline
gst_bin_add_many (GST_BIN (pipeline), source, convert,videoenc, sink, NULL);
if (gst_element_link (convert, sink) != TRUE)
{
g_printerr ("Elements could not be linked confert sink.n");
gst_object_unref (pipeline);
return -1;
}
// if (gst_element_link (source, convert) != TRUE) {
// g_printerr ("Elements could not be linked source -convert.n");
// gst_object_unref (pipeline);
// return -1;
// }
if( gst_element_link_many ( source, convert, videoenc, sink,
NULL) != TRUE )
{
g_printerr ("Elements could not be linked source -convert.n");
}
g_print("Linked all the Elements togethern");
// Iterate
g_print ("Running...n");
g_main_loop_run (loop);
// Out of the main loop, clean up nicely
g_print ("Returned, stopping playbackn");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipelinen");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}
输出:在新的X终端窗口上
"Elements could not be linked"
Press <Return> to close this window
您似乎试图链接同一个元素两次,这是不可能的。
你链接转换到水槽,然后下面几行你尝试链接转换!videoenc!下沉
只有当您知道您的相机提供mpeg4视频时,才可以使用解码器(您将其命名为videoenc),否则协商将失败。如果你的相机支持原始格式,只需从管道中删除解码器。
同样,0.10是多年未接触和过时的,请考虑移动到1.x.
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用strcpy将char数组的元素复制到另一个数组
- 使用不带参数的函数访问结构元素
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- C++如何通过用户输入删除列表元素
- lower_bound()返回最后一个元素
- 基于多个条件处理地图中的所有元素
- 调整大小后指向元素值的指针unordered_map有效?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 使用函数"remove"删除重复元素
- 具有最大子序列大小的序列,每个元素都相同
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 如何将元素添加到数组的线程安全函数?
- 有没有办法将谓词中的元素偏移量传递给 std 算法?
- 我想访问std::unique_ptr中的一个特定元素
- 如何通过 getter 函数删除矢量的元素?
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- GStreatermm:通过从Gst::element派生创建一个新的元素类型(在插件中)
- gstreamer代码无法链接所有GST元素