How to set "config-file" path property of nvdsanalytics plugin dynamically every-time I add a new source?

Hi,
I want to set “config-file” path property dynamically for the nvdsanalytics plugin whenever add a new source to the pipeline. Pipeline should be running always.

• Hardware Platform (Jetson / GPU) Desktop GPU
• DeepStream Version 6.4
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only) 535.171.04
• Issue Type( questions, new requirements, bugs) Question

I tried to set the “config-file” path property inside the add_sources function below but it only works for the first source. For the subsequent sources, it does not work and I suspect the plugin itself do not work for the subsequent sources.

static gboolean on_file_changed(GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) {
    if (event_type == G_FILE_MONITOR_EVENT_CREATED) {
        gchar *uri = g_file_get_uri(file);
        char *arg1 = (char *) user_data;
        g_print("New file created: %s\n", uri);
        add_sources(uri,arg1);
        g_free(uri);
    }
    return TRUE;
}

static gboolean add_sources(gchar *uri, char *argv) {
    GstElement *source_bin;
    GstStateChangeReturn state_return;
    std::string file_path_in_string(uri);

    g_print("Calling Start %d \n", source_id);

    source_bin = create_uridecode_bin(source_id, uri);
    source_id++;
    if (!source_bin) {
        g_printerr("Failed to create source bin. Exiting.\n");
        return -1;
    }

    if(sink){
      // get the input video file name
      std::filesystem::path file_path_obj(file_path_in_string);
      std::string processed_video_path = std::string(PROCESSED_VIDEO_PATH) + argv + "/" + file_path_obj.stem().string();
      gst_element_set_state(sink, GST_STATE_NULL);
      gst_object_unref (GST_OBJECT (sink));
      g_print("path of the processed video saved : %s \n", processed_video_path.c_str());
      g_object_set(G_OBJECT(sink), "container", 2, "output-file", g_strdup_printf("%s.mkv", processed_video_path.c_str()), NULL);
    }

    g_object_set (G_OBJECT (nvdsanalytics), "config-file", nvanalytics_config_file, NULL);
    
    g_source_bin_list[source_id] = source_bin;
    gst_bin_add(GST_BIN(pipeline), source_bin);

    state_return = gst_element_set_state(g_source_bin_list[source_id], GST_STATE_PLAYING);
    switch (state_return) {
        case GST_STATE_CHANGE_SUCCESS:
            g_print("STATE CHANGE SUCCESS\n\n");
            source_id++;
            g_num_sources++;
            break;
        case GST_STATE_CHANGE_FAILURE:
            g_print("STATE CHANGE FAILURE\n\n");
            // Handle failure as needed
            break;
        case GST_STATE_CHANGE_ASYNC:
            g_print("STATE CHANGE ASYNC\n\n");
            break;
        case GST_STATE_CHANGE_NO_PREROLL:
            g_print("STATE CHANGE NO PREROLL\n\n");
            // Handle no preroll state change as needed
            break;
        default:
            break;
    }

    return TRUE; 
}

For context, on_file_changed function will be called every time there is a new source video file on the folder.
My pipeline file is also attached.

pipeline.zip (9.0 KB)

please refer to this topic.

1 Like

Setting the config file path parameter dynamically as above also works. The issue was when I’m modifying the config file for each new source I did not update the stream ID so the analytics rules only applied for the 1st stream.
Tested out this suggested method as well. I works too. Thanks for the support!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.