Folkert van Heusden
Folkert van Heusden

Reputation: 534

feeding video to gstreamer from c++; how to get timing to work

I'm trying to add a gstreamer pipeline to my program. My program produces a video-stream that I would like to be processed by gstreamer. This basically works only timing is way off: there are huge delays between each frame showed. Also after a couple of seconds, it completely stalls.

Here's the code to start the stream:

    GstCaps *video_caps = gst_caps_new_simple("video/x-raw",
             "format", G_TYPE_STRING, "RGB",
             "width", G_TYPE_INT, w,
             "height", G_TYPE_INT, h,
             "block", G_TYPE_BOOLEAN, TRUE,
             "do-timestamp", G_TYPE_BOOLEAN, TRUE,
             "framerate", GST_TYPE_FRACTION, fps, 1, nullptr);

    gst_app_src_set_caps(GST_APP_SRC(appsrc), video_caps);

    gst_app_src_set_max_bytes((GstAppSrc *)appsrc, 1 * w * h * 3);

    gst_element_set_state(gpipeline, GST_STATE_PLAYING);

and then for each frame I do:

    GstBuffer *buffer = gst_buffer_new_and_alloc(w * h * 3); 
    gst_buffer_fill(buffer, 0, my_frame, w * h * 3); 

    if (gst_app_src_push_buffer(GST_APP_SRC(appsrc), buffer) != GST_FLOW_OK)
            log(LL_WARNING, "Problem queing frame");

Complete source: complete source

Upvotes: 3

Views: 1145

Answers (1)

Florian Echtler
Florian Echtler

Reputation: 2513

I think you need to also set some of the appsrc properties directly, not just the caps. E.g. block and do-timestamp are not caps and will not have any effect there. See https://github.com/floe/surface-streams/blob/master/common.cpp#L189-L207 for reference:

  /* setup */
  g_object_set (G_OBJECT (appsrc), "caps",
    gst_caps_new_simple ("video/x-raw",
      "format", G_TYPE_STRING, type,
      "width",  G_TYPE_INT, tw,
      "height", G_TYPE_INT, th,
      "framerate", GST_TYPE_FRACTION, 0, 1,
    NULL), NULL);
  gst_bin_add_many (GST_BIN (gpipeline), appsrc, videosink, NULL);
  gst_element_link_many (appsrc, videosink, NULL);

  /* setup appsrc */
  g_object_set (G_OBJECT (appsrc),
    "stream-type", 0, // GST_APP_STREAM_TYPE_STREAM
    "format", GST_FORMAT_TIME,
    "is-live", TRUE,
    "block", TRUE,
    "do-timestamp", TRUE,
    NULL);

Upvotes: 3

Related Questions