How to free all meta from buffer?

I would like to free meta, from primary detector and dsexample, from a buffer. I tried to use nvds_free_frame_meta function but I got segmentation fault.

// the primary detector
    GstMeta *gst_meta;
    NvDsMeta *dsmeta = NULL;
    // NOTE: Initializing state to NULL is essential
    gpointer state = NULL;
    NvDsFrameMeta *bbparams;
    // Standard way of iterating through buffer metadata
    while ((gst_meta = gst_buffer_iterate_meta (inbuf, &state)) != NULL) 
      //Check if this metadata is of NvDsMeta type
      if (!gst_meta_api_type_has_tag (gst_meta->info->api, _dsmeta_quark))

      dsmeta = (NvDsMeta *) gst_meta;
      // Check if the metadata of NvDsMeta contains object bounding boxes
      if (dsmeta->meta_type != NVDS_META_FRAME_INFO)

      bbparams = (NvDsFrameMeta *) dsmeta->meta_data;
      // Check if these parameters have been set by the primary detector /
      // tracker
      if (bbparams->gie_type != 3 || bbparams->gie_type != 1) {

What is the right way to solve this problem? I only see an nvds_free_frame_meta function from gstnvdsmeta.h for freeing meta.

I think you can do like this

gst_buffer_remove_meta(inbuf, gst_meta)

Please let me know if it can work. Thanks.

I ended up creating my own meta and attach to the buffer.

Thank Chris.

you do not need call the free function here manually

// Attach the NvDsFrameMeta structure as NvDsMeta to the buffer. Pass the
  // function to be called when freeing the meta_data
  dsmeta = gst_buffer_add_nvds_meta (inbuf, bbparams, free_ds_meta);

the callback will be called when free the meta_data


I want to create my own meta and attach to buffer in a plugin, called Filtering-plugin. Then, in the next plugin, I will get the filtered frame_meta again and add on text, called Text-plugin. However, I can only extract the unfiltered frame_meta from the Text-plugin. May I know how to overcome this problem.

NvDsMeta *gst_frame_meta = NULL;
    NvDsFrameMeta *frame_meta;
    frame_meta = (NvDsFrameMeta *)dsmeta->meta_data;
    frame_meta->num_rects = 1;
    NvOSD_RectParams *rect_params = (NvOSD_RectParams *)&frame_meta->obj_params[0].rect_params;
    rect_params.left = 100;
    gst_frame_meta = gst_buffer_add_nvds_meta(outbuf, frame_meta, free_frame_meta);
    if (gst_frame_meta)
      gst_frame_meta->meta_type = NVDS_META_FRAME_INFO;
      g_print("Error in attaching frame meta to buffer\n");
static void free_frame_meta(gpointer meta_data)
  NvDsFrameMeta *params = (NvDsFrameMeta *)meta_data;
  for (guint i = 0; i < params->num_rects; i++)