Nvds_obj_enc_process SIGSEGV

Please provide complete information as applicable to your setup.

• Hardware Platform: Jetson AGX Orin)
• DeepStream Version: 6.1
• JetPack Version: 5.0.2.
• TensorRT Version: 8.4.1
• Issue Type: Question

I am trying to run the deepstream-image-meta-test sample found here: /opt/nvidia/deepstream/deepstream-6.1/sources/apps/sample_apps/deepstream-image-meta-test/

This sample app out-of-the-box gives a segmentation fault in nvds_obj_enc_process while trying to save images. I modified the pgie_src_pad_buffer_probe to save full frames instead:

static GstPadProbeReturn
pgie_src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer ctx)
{
  GstBuffer *buf = (GstBuffer *) info->data;
  GstMapInfo inmap = GST_MAP_INFO_INIT;
  if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
    GST_ERROR ("input buffer mapinfo failed");
    return GST_FLOW_ERROR;
  }
  NvBufSurface *ip_surf = (NvBufSurface *) inmap.data;
  gst_buffer_unmap (buf, &inmap);

  NvDsObjectMeta *obj_meta = NULL;
  guint vehicle_count = 0;
  guint person_count = 0;
  NvDsMetaList *l_frame = NULL;
  NvDsMetaList *l_obj = 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);

    // Create a new NvDsObjectMeta for the entire frame
    NvDsObjectMeta full_frame_meta = {0};
    full_frame_meta.rect_params.left = 0;
    full_frame_meta.rect_params.top = 0;
    full_frame_meta.rect_params.width = frame_meta->source_frame_width;
    full_frame_meta.rect_params.height = frame_meta->source_frame_height;
    full_frame_meta.class_id = PGIE_CLASS_ID_VEHICLE; // or any other class ID

    NvDsObjEncUsrArgs userData = { 0 };
    /* To be set by user */
    userData.saveImg = save_img;
    userData.attachUsrMeta = attach_user_meta;
    /* Set if Image scaling Required */
    userData.scaleImg = FALSE;
    userData.scaledWidth = 0;
    userData.scaledHeight = 0;
    /* Preset */
    userData.objNum = 1;
    /* Quality */
    userData.quality = 80;
    /*Main Function Call */
    nvds_obj_enc_process (ctx, &userData, ip_surf, &full_frame_meta, frame_meta);
  }
  nvds_obj_enc_finish (ctx);
  return GST_PAD_PROBE_OK;
}

Now, the first full frame is saved, but the segmentation fault still occurs in the call to nvds_obj_enc_finish. Analyzing the stack trace, the issue is with nvds_acquire_user_meta_from_pool which is internally called by the API.

Here is another forum post detailing my exact issue: Calling nvds_obj_enc_finish SIGSEGV - #8 by doug4350

Is there any working demo or correct resource usage for encoding the entire image? Is saving the entire frame even supported?

Hi

You need to allocate an object meta using nvds_acquire_obj_meta_from_pool when creating full_frame_meta instead of manually instantiating it.

Regards,
Allan Navarro

Embedded SW Engineer at RidgeRun

Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/
Website: www.ridgerun.com

Hi, thank you for responding so soon. I’ve modified the code to do that and still receive a seg fault in the same place:

static GstPadProbeReturn
pgie_src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer ctx)
{
  GstBuffer *buf = (GstBuffer *) info->data;
  GstMapInfo inmap = GST_MAP_INFO_INIT;
  if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
    GST_ERROR ("input buffer mapinfo failed");
    return GST_FLOW_ERROR;
  }
  NvBufSurface *ip_surf = (NvBufSurface *) inmap.data;
  gst_buffer_unmap (buf, &inmap);

  NvDsObjectMeta *obj_meta = NULL;
  guint vehicle_count = 0;
  guint person_count = 0;
  NvDsMetaList *l_frame = NULL;
  NvDsMetaList *l_obj = 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);

    // Allocate a new NvDsObjectMeta for the entire frame
    NvDsObjectMeta *full_frame_meta = nvds_acquire_obj_meta_from_pool(batch_meta);
    if (!full_frame_meta) {
      GST_ERROR ("Failed to acquire object meta from pool");
      return GST_FLOW_ERROR;
    }
    full_frame_meta->rect_params.left = 0;
    full_frame_meta->rect_params.top = 0;
    full_frame_meta->rect_params.width = frame_meta->source_frame_width;
    full_frame_meta->rect_params.height = frame_meta->source_frame_height;
    full_frame_meta->class_id = PGIE_CLASS_ID_VEHICLE; // or any other class ID

    NvDsObjEncUsrArgs userData = { 0 };
    /* To be set by user */
    userData.saveImg = save_img;
    userData.attachUsrMeta = attach_user_meta;
    /* Set if Image scaling Required */
    userData.scaleImg = FALSE;
    userData.scaledWidth = 0;
    userData.scaledHeight = 0;
    /* Preset */
    userData.objNum = 1;
    /* Quality */
    userData.quality = 80;
    /*Main Function Call */
    nvds_obj_enc_process (ctx, &userData, ip_surf, full_frame_meta, frame_meta);
  }
  nvds_obj_enc_finish (ctx);
  return GST_PAD_PROBE_OK;
}

I think using nvds_obj_enc_process might not be the best idea to save the full frame, maybe using the GstBuffer might be better, let me check if I have some sample for that.

Regards,
Allan Navarro

Embedded SW Engineer at RidgeRun

Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/
Website: www.ridgerun.com

@shaunramj , could you upgrade your DeepStream to our latest version? You can just set the userData.isFrame=1 without changing any other code to save the full frame.

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

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