Ubuntu 14.04 Gstreamer 0.10 代碼Sdk:Qt。gstreamer代碼未能鏈接所有GST元素
我對Gstreamer相當陌生。當我在我的終端上使用gst-launch工具時,我可以成功地看到連接到我的工作站的攝像機捕捉到流視頻。
要繼續前進,我已經在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 stream\n");
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: %s\n", 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 together\n");
// Iterate
g_print ("Running...\n");
g_main_loop_run (loop);
// Out of the main loop, clean up nicely
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}
OUTPUT:ON新的X詞窗口
"Elements could not be linked"
Press <Return> to close this window
你在gst-launch上做了什麼?你的申請是否與你想要做的一樣?您似乎試圖將編碼器鏈接到視頻輸出(通常需要原始視頻)。這不應該起作用,即使在gst-launch中也是如此。此外,0.10已經死了3年以上,請移至1.0。 – thiagoss
感謝reposne。你能提出我缺少的東西嗎? – samprat
對不起,您的代碼被誤讀了,因爲您的變量被命名爲編碼器。 – thiagoss