This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux: GStreamer BIN errors

Tool/software: Linux

Why i'm Getting this Type of Errors


    Pipeline Initialized Successfully...

    All the Elements were Created.....

    Tee was Enabled...

(stream_record:5644): GLib-GObject-WARNING **: value "((GstQueueLeaky) 134518788)" of type `GstQueueLeaky' is invalid or out of range for property `leaky' of type `GstQueueLeaky'

    Text Was Added...

    Filesink was Linked...

     RTMP Sink Was Linked...

(stream_record:5644): GStreamer-WARNING **: Name 'queue1' is not unique in bin 'pipeline0', not adding

(stream_record:5644): GStreamer-WARNING **: Name 'videoconvert0' is not unique in bin 'pipeline0', not adding

(stream_record:5644): GStreamer-WARNING **: Name 'queue0' is not unique in bin 'pipeline0', not adding

(stream_record:5644): GStreamer-WARNING **: Name 'x264enc0' is not unique in bin 'pipeline0', not adding

    Checking...

** (stream_record:5644): ERROR **:
    Failed to link elements

Trace/breakpoint trap (core dumped)

For this Code :-

/******************************************************************************
* Header File
******************************************************************************/

#include <string.h>
#include <gst/gst.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>    

/**********************************************************************
*   Macro Substitutions
***********************************************************************/

/**********************************************************************
*   Global variable declerations
***********************************************************************/

static GMainLoop *loop;
static GstElement *pipeline, *v4src, *filter, *tee, *queue, *queue1, *timelay, *textlay, *convert, *filemux, *filesink, *encoder, *muxer, *sink, *new_element;
static GstCaps *filtercaps = NULL;
static GstBus *bus;

/***********************************************************************
*   Function Prototypes
************************************************************************/

int sigintHandler(int unused);
static gboolean message_cb (GstBus * bus, GstMessage * message, gpointer user_data);

/**********************************************************************

*   Function    : main function
*
*   Description : handle the Plugins and record the video
*
*   Parameters  : void
*
*   Return value: it will send the Interrupt to Signal handler.

***********************************************************************/

int main(int argc, char* argv)
{

    signal(SIGINT,sigintHandler);

    gst_init ( NULL, NULL);

        printf("\n\n\tPipeline Initialized Successfully...\n");

    pipeline   = gst_pipeline_new(NULL);
    v4src      = gst_element_factory_make("videotestsrc",  NULL);
        filter     = gst_element_factory_make("capsfilter",    NULL);
        tee        = gst_element_factory_make("tee",           NULL);
        convert    = gst_element_factory_make("videoconvert",  NULL);
        queue      = gst_element_factory_make("queue",         NULL);
        queue1     = gst_element_factory_make("queue",         NULL);
        timelay    = gst_element_factory_make("timeoverlay",   NULL);
        textlay    = gst_element_factory_make("textoverlay",   NULL);
    encoder    = gst_element_factory_make("x264enc",       NULL);
        filemux    = gst_element_factory_make("mp4mux",        NULL);
    muxer      = gst_element_factory_make("flvmux",        NULL);
        filesink   = gst_element_factory_make("filesink",      NULL);
    sink       = gst_element_factory_make("rtmpsink",      NULL);

/**********************************************************************************************************************************************

 gst-launch-1.0 -e videotestsrc pattern=ball is-live=true ! timeoverlay ! textoverlay text="@Fossilshale" ! 'video/x-raw,width=1280,height=720,framerate=30/1' ! tee name=liveTee ! queue leaky=downstream ! videoconvert! queue ! x264enc ! avimux ! filesink location=output02.mp4 liveTee. ! queue leaky=downstream ! videoconvert ! queue ! x264enc ! flvmux ! queue ! rtmpsink location='rtmp://52.39.19.115:1935/live/camera1000'

**********************************************************************************************************************************************/

    if (pipeline == NULL || v4src == NULL || filter == NULL || tee == NULL || convert == NULL || encoder == NULL || queue == NULL || timelay == NULL || textlay == NULL || queue1 == NULL || filemux == NULL || filesink == NULL || muxer == NULL || sink == NULL)
        {
        g_error("\n\tFailed to create elements\n");
        return -1;
    }

        filtercaps = gst_caps_new_simple ("video/x-raw",
                                         "framerate",GST_TYPE_FRACTION,25,1,
                                         "width", G_TYPE_INT,1280,
                                         "height", G_TYPE_INT,720,
                                          NULL );
        g_object_set (G_OBJECT (filter), "caps", filtercaps, NULL);

        gst_caps_unref (filtercaps ) ;

        printf("\n\tAll the Elements were Created.....\n");

    /*g_object_set(v4src, "device", "/dev/video0", NULL);

        printf("\n\tSource Was Linked...\n");*/
        
    g_object_set(tee, "name", "liveTee", NULL);

        printf("\n\tTee was Enabled... \n");

        g_object_set(queue1, "leaky", "downstream", NULL);
        
        g_object_set(textlay, "text", "@Fossilshale", NULL);

        printf("\n\tText Was Added...\n");
    
        g_object_set(filesink, "location", "test00.mp4", NULL);

        printf("\n\tFilesink was Linked...\n");

    g_object_set(sink, "location", "rtmp://64.62.151.174:1935/live/camera1000", NULL);

        printf("\n\t RTMP Sink Was Linked...\n");

/**********************************************************************************************************************************************

 gst-launch-1.0 -e videotestsrc pattern=ball is-live=true ! timeoverlay ! textoverlay text="@Fossilshale" ! 'video/x-raw,width=1280,height=720,framerate=30/1' ! tee name=liveTee ! queue leaky=downstream ! videoconvert! queue ! x264enc ! avimux ! filesink location=output02.mp4 liveTee. ! queue leaky=downstream ! videoconvert ! queue ! x264enc ! flvmux ! queue ! rtmpsink location='rtmp://52.39.19.115:1935/live/camera1000'

**********************************************************************************************************************************************/

    gst_bin_add_many(GST_BIN(pipeline), v4src, timelay, textlay, filter, tee,queue1, convert,  queue, encoder, filemux, filesink, queue1, convert, queue, encoder, muxer, sink, NULL);

        printf("\n\tChecking...\n");

        if (!gst_element_link_many(v4src, timelay, textlay, filter, tee, NULL) || !gst_element_link_many(tee, queue1, convert, encoder, filemux, filesink, NULL) || !gst_element_link_many(tee, convert, queue, encoder, muxer, queue, sink, NULL))
        {
                g_error("\n\tFailed to link elements\n");
                return -2;
        }

    loop = g_main_loop_new(NULL, FALSE);

    bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
    gst_bus_add_signal_watch(bus);
    g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(message_cb), NULL);
    gst_object_unref(GST_OBJECT(bus));

    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    g_print("\n\tStarting loop...\n");
    g_main_loop_run(loop);

    return 0;
}

/**********************************************************************

*   Function    : Signal Handler Function
*
*   Description : It will get the Interrup signal and Send EOS to the Gstreamer.
*
*   Parameters  : unused signals
*
*   Return value: it will send Eos only

***********************************************************************/

int sigintHandler(int unused)
{
        g_print("\n\tSending EoS\n");
        gst_element_send_event(pipeline, gst_event_new_eos());
        return 0;
}

/**********************************************************************

*   Function    : Message Callback finction
*
*   Description : It will handle all the messages from the bus
*
*   Parameters  : bus, message and the user data
*
*   Return value: it will determine the End of encode.

***********************************************************************/
static gboolean message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
{
    switch (GST_MESSAGE_TYPE (message))
    {
      case GST_MESSAGE_ERROR:
      {
          GError *err = NULL;
          gchar *name, *debug = NULL;

          name = gst_object_get_path_string (message->src);
          gst_message_parse_error (message, &err, &debug);

          g_printerr ("ERROR: from element %s: %s\n", name, err->message);
          if (debug != NULL)
              g_printerr ("Additional debug info:\n%s\n", debug);

          g_error_free (err);
          g_free (debug);
          g_free (name);

          g_main_loop_quit (loop);
          break;
      }
      case GST_MESSAGE_WARNING:
      {
        GError *err = NULL;
        gchar *name, *debug = NULL;

        name = gst_object_get_path_string (message->src);
        gst_message_parse_warning (message, &err, &debug);

        g_printerr ("ERROR: from element %s: %s\n", name, err->message);
        if (debug != NULL)
                 g_printerr ("Additional debug info:\n%s\n", debug);

        g_error_free (err);
    
                g_free (debug);
        g_free (name);
        break;
      }
      case GST_MESSAGE_EOS:
      {
        g_print ("\n\tGot EOS\n");
        g_main_loop_quit (loop);
        gst_element_set_state (pipeline, GST_STATE_NULL);
        g_main_loop_unref (loop);
        gst_object_unref (pipeline);
        g_print("\n\tStream terminatted Succesfully\n\n");
        exit(0);
        break;
      }
      default:
        break;
   }

   return TRUE;
}

  • Hello,

    I see you are doing streaming. I guess it is from PC to the board. Could you let me know the hardware platform that you are using?

    Regarding the errors that you are seeing:
    1. This line is wrong:
    gst_bin_add_many(GST_BIN(pipeline), v4src, timelay, textlay, filter, tee,queue1, convert, queue, encoder, filemux, filesink, queue1, convert, queue, encoder, muxer, sink, NULL);

    I  see 2 queue1, 2 encoders and 2 convert elements in it but in      encoder    = gst_element_factory_make("x264enc",       NULL); I see only one created. Same for queue 1 and videoconvert.

    2. "Failed to link elements" error comes from the line below:

    if (!gst_element_link_many(v4src, timelay, textlay, filter, tee, NULL) || !gst_element_link_many(tee, queue1, convert, encoder, filemux, filesink, NULL) || !gst_element_link_many(tee, convert, queue, encoder, muxer, queue, sink, NULL))


    -I would recommend you to link the elements manually;
    Here is example:

    link_source_element_with_filter (video_source, queue_src);
    gst_element_link_pads (queue_src, "src", tee1, "sink");
    gst_element_link_pads (tee1, "src", video_queue0, "sink");
    gst_element_link_pads (video_queue0, "src", video_sink0, "sink");
    gst_element_link_pads (tee1, "src", video_queue1, "sink");
    gst_element_link_pads (video_queue1, "src",video_scale, "sink");
    link_scale_element_with_filter ( video_scale, video_sink1 );

    -This is not the right way to link the tee element;


    tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee1), "src_%u");
    tee_audio_pad = gst_element_request_pad (tee1, tee_src_pad_template, NULL, NULL);
    g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad));
    queue_audio_pad = gst_element_get_static_pad (video_queue0, "sink");
    tee_video_pad = gst_element_request_pad (tee1, tee_src_pad_template, NULL, NULL);
    g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad));
    queue_video_pad = gst_element_get_static_pad (video_queue1, "sink");
    if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK ||
    gst_pad_link (tee_video_pad, queue_video_pad) != GST_PAD_LINK_OK) {
    g_printerr ("Tee could not be linked1.\n");
    gst_object_unref (pipeline);
    return -1;
    }
    gst_object_unref (queue_audio_pad);
    gst_object_unref (queue_video_pad);



    and this must be after EOS is received:


    /* Wait until error or EOS */
    bus = gst_element_get_bus (pipeline);
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    /* Release the request pads from the Tee, and unref them */
    gst_element_release_request_pad (tee1, tee_audio_pad);
    gst_element_release_request_pad (tee1, tee_video_pad);
    gst_object_unref (tee_audio_pad);
    gst_object_unref (tee_video_pad);


    ....


    Please refer the gstreamer tutorials here:
    gstreamer.freedesktop.org/.../concepts.html



    You could try gst_parse_launch() function also:
    Here is the code that you could compile and test. It is using this pipeline :
    videotestsrc pattern=ball is-live=true ! timeoverlay ! textoverlay text=@Fossilshale ! video/x-raw,width=1280,height=720,framerate=30/1 ! tee name=liveTee ! queue leaky=downstream ! videoconvert! queue ! x264enc ! avimux ! filesink location=output02.mp4 liveTee. ! queue leaky=downstream ! videoconvert ! queue ! x264enc ! flvmux ! queue ! rtmpsink location=rtmp://52.39.19.115:1935/live/camera1000



    #include <gst/gst.h>

    #include <stdio.h>

    int main(int argc, char *argv[])

    {

    GstElement *pipeline;

    GstBus *bus;

    GstMessage *msg;

    const gchar *nano_str;

    guint major, minor, micro, nano;

    /* Initialize GStreamer */

    gst_init (&argc, &argv);

    gst_version (&major, &minor, &micro, &nano);

    printf ("GStreamer Version: %d.%d.%d\n",major, minor, micro);

    /* Build the pipeline */

    pipeline = gst_parse_launch("videotestsrc pattern=ball is-live=true ! timeoverlay ! textoverlay text=@Fossilshale ! video/x-raw,width=1280,height=720,framerate=30/1 ! tee name=liveTee ! queue leaky=downstream ! videoconvert! queue ! x264enc ! avimux ! filesink location=output02.mp4 liveTee. ! queue leaky=downstream ! videoconvert ! queue ! x264enc ! flvmux ! queue ! rtmpsink location=rtmp://52.39.19.115:1935/live/camera1000
    ", NULL);

    /* Start playing */

    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    /* Wait until error or EOS */

    bus = gst_element_get_bus (pipeline);

    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

    /* Free resources */

    if (msg != NULL)

    gst_message_unref (msg);

    gst_object_unref (bus);

    gst_element_set_state (pipeline, GST_STATE_NULL);

    gst_object_unref (pipeline);

    return 0;

    }


    Please if you are not using any TI devices, redirect your questions to gstreamer community.
    In this forum we are supporting TI devices and TI software releases only!

    Hope this helps.

    BR
    Margarita

  • This is the tutorial when tee is used in the gst application:
    gstreamer.freedesktop.org/.../multithreading-and-pad-availability.html


    BR
    Margarita

  • Hello,

    I am sorry but in your code I do not see the muxer code also.
    You could check the capabilities of the muxer which you are using with gst-inspect command and change the code.
    Here is example :

    void
    link_to_multiplexer(
    GstElement *tolink_element,
    GstElement *mux)
    {
    GstCaps *pad_caps =NULL;
    GstPad *pad;
    GstPad *tolink_pad;
    GstPadLinkReturn ret;

    tolink_pad = gst_element_get_static_pad(tolink_element, "src");
    pad_caps = gst_pad_query_caps(tolink_pad, NULL);
    pad = gst_element_get_compatible_pad(mux, tolink_pad, pad_caps);
    gst_caps_unref(pad_caps);

    ret = gst_pad_link(tolink_pad, pad);
    gst_object_unref(GST_OBJECT(pad));
    g_print("A new pad %s was created and linked to %s\n", gst_pad_get_name(tolink_pad), gst_pad_get_name(pad));
    }


    Here is how you could link this:
    ...
    link_to_multiplexer (q3, mux);
    gst_element_link_pads (mux, "src", sink, "sink");
    ...

    Hope this helps.

    BR
    Margarita
  • Hello,

    Please if this answers your question click the "This resolved my issue" button.
    Thank you!

    BR
    Margarita