How can I use the nvdsosd plugin to add a watermark to video without using nvinfer plugin?

I want to add a watermark to my video.However, if the pipeline does not use the nvinfer plug-in, the nvdsosd callback function may run incorrectly(Segmentation fault)
The osd callback function I use is deepstream test1 app.c(deepstream-6.0\sources\apps\sample_apps\deepstream-test1\deepstream test1 app.c):
static GstPadProbeReturn
osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)
{
GstBuffer *buf = (GstBuffer *) info->data;
guint num_rects = 0;
NvDsObjectMeta *obj_meta = NULL;
guint vehicle_count = 0;
guint person_count = 0;
NvDsMetaList * l_frame = NULL;
NvDsMetaList * l_obj = NULL;
NvDsDisplayMeta *display_meta = NULL;

NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);

for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
  l_frame = l_frame->next) {
    NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
    int offset = 0;
    for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
            l_obj = l_obj->next) {
        obj_meta = (NvDsObjectMeta *) (l_obj->data);
        if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) {
            vehicle_count++;
            num_rects++;
        }
        if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
            person_count++;
            num_rects++;
        }
    }
    display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
    NvOSD_TextParams *txt_params  = &display_meta->text_params[0];
    display_meta->num_labels = 1;
    txt_params->display_text = g_malloc0 (MAX_DISPLAY_LEN);
    offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, "Person = %d ", person_count);
    offset = snprintf(txt_params->display_text + offset , MAX_DISPLAY_LEN, "Vehicle = %d ", vehicle_count);
    /* Now set the offsets where the string should appear */
    txt_params->x_offset = 10;
    txt_params->y_offset = 12;
    /* Font , font-color and font-size */
    txt_params->font_params.font_name = "Serif";
    txt_params->font_params.font_size = 10;
    txt_params->font_params.font_color.red = 1.0;
    txt_params->font_params.font_color.green = 1.0;
    txt_params->font_params.font_color.blue = 1.0;
    txt_params->font_params.font_color.alpha = 1.0;
    /* Text background color */
    txt_params->set_bg_clr = 1;
    txt_params->text_bg_clr.red = 0.0;
    txt_params->text_bg_clr.green = 0.0;
    txt_params->text_bg_clr.blue = 0.0;
    txt_params->text_bg_clr.alpha = 1.0;

    nvds_add_display_meta_to_frame(frame_meta, display_meta);
}

g_print ("Frame Number = %d Number of objects = %d "
        "Vehicle Count = %d Person Count = %d\n",
        frame_number, num_rects, vehicle_count, person_count);
frame_number++;
return GST_PAD_PROBE_OK;

}


The value of “batch meta->frame meta list” seems to be NULL.How can I use the nvdsosd plugin to add a watermark to video without using nvinfer plugin?In some pipelines I only want to add watermarks without nvinfer plugin to save device resources.

Can the deepstream-test1 app work in your device? Have you read the DeepStream document MetaData in the DeepStream SDK — DeepStream 6.1.1 Release documentation and understand the mechanism of NvDsBatchMeta?

It worked using nvinfer, but I only wanted to add a watermark to the video, not with inference.

All DeepStream plugins are working for Inferencing. If you don’t need inferencing, DeepStream may not be suitable for you.

What is your platform? Jetson or dGPU?

Jetson(JetPack4.6 deepstream6.0).
There are some pipelines inside my app that need infer and some that don’t, but all video pipes want to be watermarked.

There is no other OSD plugin with Nvidia acceleration here. If you want to use nvdsosd plugin to draw text on video, you must use the other DeepStream plugins to construct the pipeline. E.G. uridecodebin->nvstreammux->nvvideoconvert->nvmultistreamtiler->nvdsosd->… Please read the document and understand NvDsBatchMeta before you construct a DeepStream pipeline.

This is my current pipeline:
nvarguscamerasrc->nvvideoconvert->nvdsosd->nvvideoconvert->nvv4l2h265enc->appsink
Compare the pipeline which with the nvinfer plugin,my pipeline could not receive NvDsBatchMeta within the nvdsosd callback
,Is there a way to fill watermark NvDsBatchMeta before nvdsosd,then nvdsosd receives the message to automatically draw

You must add nvstreammux before nvdsosd

https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_plugin_gst-nvstreammux.html#gst-nvstreammux

1 Like

Thanks to your guidance, I solved the problem by adding the nvstreamuxer plugin

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