Search code examples
cstreamingvideo-streaminggstreamermultimedia

Gstreamer-0.10 code failed to stream webcam video over udp


OS : Ubuntu
Gstreamer version 0.10

I have to develop an app to stream video from webcam to remote pc via udp. I have written a small piece of code but it runs for a second and then throws error.

Error I am getting is

*Running...
Error: Internal data flow error.
Returned, stopping playback
Deleting pipeline*

Can someone please pinpoint me about my mistake.
Below is my code

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

}  

Solution

  • Too long for comment, I will post answer and we will see what we get.

    Do you definitely has to use 0.10? there is already version 1.6.1.. in Ubuntu 15.10 there is built in 1.6.. anyway..

    I guess you are missing 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);
    

    You should place it right after v4l2src element..

    If this is not working, you can debug running your app with GST_DEBUG=default:4 which should print if there was linking problem. You can also generate dot graph of pipeline and check if everything is linked properly..

    You can speed up the debugging by rewriting the code in gst-launch shell command:

    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