Gstreamer-0.10 代码无法通过 udp 传输网络摄像头视频

Gstreamer-0.10 code failed to stream webcam video over udp

OS : Ubuntu
Gstreamer 版本 0.10

我必须开发一个应用程序来通过 udp 将视频从网络摄像头传输到远程电脑。 我写了一小段代码,但它运行了一秒钟然后抛出错误。

我得到的错误是

*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));

}  

评论时间太长,我会post回答,我们会看到结果。

你一定要用0.10吗?已经有版本 1.6.1.. 在 Ubuntu 15.10 中内置了 1.6.. 无论如何..

我猜你缺少 capsfilter:

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