【问题标题】:Gstreamer-0.10 code failed to stream webcam video over udpGstreamer-0.10 代码无法通过 udp 流式传输网络摄像头视频
【发布时间】:2015-12-04 00:43:34
【问题描述】:

操作系统: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));

}  

【问题讨论】:

    标签: c streaming video-streaming gstreamer multimedia


    【解决方案1】:

    评论太长了,我会发布答案,我们会看到我们得到什么。

    你一定要使用 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

    【讨论】:

    • 优秀的伙伴。实际上,添加大写字母后我仍然遇到错误。因此,正如您建议的那样,我进行了调试,发现 ffmpegcolorspace 和 rtpmp4vpay 无法链接在一起。当我输入“gst-launch-0.10 v4l2src!video/x-raw-yuv,format=(fourcc)YUY2,width=320,height=240,framerate=20/1!jpegenc!rtpjpegpay!udpsink host= 127.0.0.1 port=5200”和接收器“gst-launch-0.10 udpsrc port=5200!application/x-rtp,encoding-name=JPEG,payload=26!rtpjpegdepay!jpegdec!autovideosink”它可以工作。
    • 所以我调查并将 ffmpegcolorspace 更改为“jpegenc”,并在有效载荷中将其更改为“rtpjpegpay”并且它可以工作。实际上我需要使用 mpeg-4 进行编码,所以它对我有用
    • 对于您之前的评论,我的项目中的主要要求是只使用 gstreamer-0.10,这就是为什么我的手有点束缚
    • 总而言之,您提供的解决方案并没有直接帮助我,但您对调试的解释确实帮助了我。再次感谢
    • 只是匆匆忙忙,我添加了您提到的几行代码。但是我如何将 caps 链接到 v4l2src 元素。
    猜你喜欢
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    相关资源
    最近更新 更多