Zed 2 Gstreamer Pipeline issues

@Myzhar I am writing a CPP pipeline for Zed Camera , having a close look at gst-inspect-1.0 zedsrc , I realized I cannot use Nvidia Gpu Hardware encoder as src doen not support Video/x-raw(NVMM) !!

Also are Gst Caps supported for zedsrc element ?

However further on writing a complete pipeline , my element zedsrc is not recognised in code , even when plugin is installed , where is the issue ?

#include <iostream>
#include <gst/gst.h>


static GMainLoop *loop;

struct ZedData {
    GstElement *pipeline;
    GstElement *source;
   
    GstElement *timeolay;

    GstElement *avc;
    GstElement *enc1;
    GstElement *enc2;
    GstElement *enc3;  // rtph264pay
    GstElement *rtspsink;

};


static gboolean my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
{
  // g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));

  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR:{
      GError *err;
      gchar *debug;

      gst_message_parse_error (message, &err, &debug);
      g_print ("Error: %s\n", err->message);
      g_error_free (err);
      g_free (debug);

      g_main_loop_quit (loop);
      break;
    }
    case GST_MESSAGE_EOS:
      /* end-of-stream */
      g_main_loop_quit (loop);
      break;
    default:
      /* unhandled message */
      break;
  }

    return TRUE; /* we want to be notified each time message is received on the bus */
}



int main(int argc, char **argv){

    ZedData data {} ;
    GstBus *bus;
    GstMessage *msg;
    guint bus_watch_id;
    GstStateChangeReturn ret;
   

    std::string ip;

    std::string cam = "/Zed";

    ip = argv[1] + cam ;

    GError *error = nullptr;

    gst_init_check(&argc,&argv,&error);

    data.source = gst_element_factory_make("zedsrc","source");

    // data.fil1 = gst_element_factory_make("capsfilter", "fil1");

    data.timeolay = gst_element_factory_make("clockoverlay","timeolay");

    data.avc  = gst_element_factory_make("autovideconvert","avc");

    data.enc1 = gst_element_factory_make("x264enc","enc1");

    data.enc2 = gst_element_factory_make("h264parse","enc2");

    data.enc3 = gst_element_factory_make("rtph264pay","enc3");

    data.rtspsink = gst_element_factory_make("rtspclientsink","rtspsink");

    data.pipeline = gst_pipeline_new("pipelineOne");

    if ( ! data.pipeline || ! data.source || !data.timeolay || !data.enc1 || !data.enc2 || !data.enc3 || ! data.avc || ! data.rtspsink) 
    {
        g_printerr("Not All Elements can be created\n");
    
    }

    /* Configure Gstreamer Element Properties */

    g_object_set(data.source,"camera-resolution",2,NULL);

    // caps = gst_caps_from_string("video/x-raw,width=(int)1280,height=(int)720,format=(string)BGRA,framerate=(fraction)30/1");

    // g_object_set(data.fil1,"caps",caps,NULL);

    g_object_set(data.timeolay, "time-format", "%D %H:%M:%S", NULL);

    // gst_caps_unref(caps);

    g_object_set(data.enc1,"byte-stream",true,"speed-preset",1,NULL);

    g_object_set(data.rtspsink,"location","ip",NULL);

    gst_bin_add_many(GST_BIN(data.pipeline),data.source,data.timeolay,data.avc,data.enc1,data.enc2,data.enc3,data.rtspsink,NULL);

    if(! gst_element_link_many(data.source,data.timeolay,data.avc,data.enc1,data.enc2,data.enc3,data.rtspsink,NULL))
    {
             g_printerr("Elements could not be linked");
             gst_object_unref(data.pipeline);
             return -1;
    }


    ret = gst_element_set_state(data.pipeline, GST_STATE_PLAYING);
    if (ret == GST_STATE_CHANGE_FAILURE) {
        g_printerr("unable to set the pipeline to playing state");
        gst_object_unref(data.pipeline);
        return -1;
    }



    bus = gst_pipeline_get_bus(GST_PIPELINE(data.pipeline));

    gst_bus_add_signal_watch(bus);

    g_signal_connect(G_OBJECT(bus),"message",G_CALLBACK(my_bus_callback),NULL);


    gst_object_unref(bus);

    loop = g_main_loop_new (NULL,FALSE);

    g_main_loop_run(loop);

     /* clean up */
    gst_element_set_state (data.pipeline, GST_STATE_NULL);
    gst_object_unref (data.pipeline);
    g_source_remove (bus_watch_id);
    g_main_loop_unref (loop);
   

    return 0;
 


}

Hi @IshanBhatnagar14
what is the error that you are getting?

@Myzhar I am getting an Error:- Not all elements can be created.

I have checked all elements using the below commands all elements are present

 factory = gst_element_factory_find ("zedsrc");

Also, I have One Doubt Zedsrc is capable of (video/x-raw) , I can use nvvidconv in AGX Xavier to convert it into video/x-raw(NVMM) , so that I can use hardware encoders on AGX Xavier ?

Have you ever treid this thing , because Hardware acceleration allows a lot many zed cameras to be used , right now I am using 2 Zed 2 Cameras on AGX Xavier .

The ZED GStreamer elements are not designed to be integrated into “source code” pipelines.
We should export the header files while installing the GStreamer elements.

Can you please open a “Feature Request” issue on Github asking for this modification?
In this way, we can keep track of it.

1 Like

Hi, @Myzhar . Could you elaborate by what you mean by “ZED GStreamer elements are not designed to be integrated into source code pipelines”?

I am curious since I have been using ZED-GStreamer elements in “source code” pipelines without a problem*. Currently, my pipeline only uses the ZedSrc element, but I have built test pipelines using ZedDemux and ZedDataCSVSink. (* Note: I have had issues with buffers being lost using ZedDemux and ZedDatamux before but that’s for a different issue/thread)

Usually, to use GStreament elements in a pipeline generated by code it is necessary to export the library files and the relative headers, but the current version of the package does this only for the metadata.
How could you create a pipeline with ZedDemux and ZedDataCSVSink?

I created the example pipeline from here for a pipeline with ZedDemux and ZedDataCSVSink:

gst-launch-1.0 zedsrc stream-type=4 ! \
 zeddemux stream-data=true name=demux \
 demux.src_left ! queue ! autovideoconvert ! fpsdisplaysink \
 demux.src_aux ! queue ! autovideoconvert ! fpsdisplaysink \
 demux.src_data ! queue ! zeddatacsvsink location="${HOME}/test_csv.csv" append=FALSE

We use a custom CMakeLists file with a cmake file for the GStreamer dependencies/libraries.

Have you tried to use this in a gst-launch pipeline?