我必须开发一个应用程序,通过udp将视频从网络摄像头传输到远程PC。 我写了一小段代码但它运行了一秒然后抛出错误。
我得到的错误是
*Running...
Error: Internal data flow error.
Returned, stopping playback
Deleting pipeline*
有人可以指出我的错误 以下是我的代码
GstElement *pipeline, *source, *sink, *muxer, *videoenc, *payloader, *udpsink;
GstBus *bus;
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");
muxer = gst_element_factory_make ("qtdemux", "mux");
// videoenc = gst_element_factory_make("ffdec_mpeg4", "videoenc"); //why this failed
videoenc = gst_element_factory_make("ffmpegcolorspace", "videoenc");// but this passed but in both cases app failed to run
payloader = gst_element_factory_make("rtpmp4vpay", "rtpmp4vpay");
udpsink = gst_element_factory_make("udpsink", "udpsink");
// Create the empty pipeline
pipeline = gst_pipeline_new ("test-pipeline");
if (!pipeline || !source )
{
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
if( !muxer )
{
g_printerr ("failed to create muxer Exiting.\n");
return -1;
}
if( !videoenc)
{
g_printerr ("failedto create videoenc. Exiting.\n");
return -1;
}
if( !payloader || !udpsink)
{
{
g_printerr ("One element could not be created out of payloader or udpsink. Exiting.\n");
return -1;
}
}
g_object_set(G_OBJECT(payloader),
"config-interval", 0,
NULL);
g_object_set(G_OBJECT(udpsink),
"host", "127.0.0.1",
"port", 5000,
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);
//set der source
g_object_set (G_OBJECT ( source ), "device", "/dev/video0", NULL);
gst_bin_add_many (GST_BIN (pipeline), source, videoenc, payloader, udpsink, NULL);
gst_element_link_many (source, videoenc, payloader, udpsink, NULL);
// g_print("Linked all the Elements together\n");
gst_element_set_state (pipeline, GST_STATE_PLAYING);
// 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));
}
答案 0 :(得分:0)
评论太长了,我会发表回答,我们会看到我们得到的结果。
你肯定要使用0.10吗?已经有版本1.6.1 ..在Ubuntu 15.10中有内置1.6 ..无论如何..
我猜你错过了capfilter:
GstElement *capsfilter = gst_element_factory_make("capsfilter", "camera_caps");
GstCaps *caps = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)YUY2,width=1280,height=720,framerate=25/1");
g_object_set (capsfilter, "caps", caps, NULL);
你应该把它放在v4l2src元素之后..
如果这不起作用,您可以使用GST_DEBUG=default:4
调试运行应用程序,如果存在链接问题,应该打印该应用程序。
您还可以生成dot graph管道并检查是否所有内容都已正确链接。
您可以通过在gst-launch shell命令中重写代码来加快调试速度:
GST_DEBUG=3 gst-launch-0.10 v4l2src device=/dev/video0 ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=1280,height=720,framerate=25/1 ! ffmpegcolorspace ! rtpmp4vpay ! queue ! udpsink port=5000 host=127.0.0.1