Encode jpeg image with nvds_obj_enc_process Segmentation fault

**• Hardware Platform Jetson **
• DeepStream Version 6.1.1
• JetPack Version 5.0.2
• Issue Type( questions)

My pipeline is a peoplenet pgie with tracker, nvdsanalytics.

I have a probe as follow,it tend to encode jpeg image every 10 frame.
I want to show detection line and boundingbox so I put this probe after nvosd.

The pipeline after nvdsanalytics is [ queue → nvvideoconvert → nvosd → fake_sink ]

However this pipeline will crash with Segmentation fault in Jetson. But in dGPU it work fine.

Additionally, If I put this before nvvideoconvert process data, everything work fine.

I also notice when this program run on jetson will repeatedly report this warning. Again, dGPU did not get this warning.

26462 0xfffeec019b00 WARN   bufferpool gstbufferpool.c:1235:default_reset_buffer:<nvv4l2decoder0:pool:sink> Buffer 0xfffeec0357e0 without the memory tag has maxsize (0) that is smaller than the configured buffer pool size (4194304). The buffer will be not be reused. This is most likely a bug in this GstBufferPool subclass

Is this a software bug, or maybe hardware bug or broken hardware?
(This machine is running under around 78 Celsius degree GPU temperature for 7 days.)

static GstPadProbeReturn
snapshot_probe(GstPad * pad, GstPadProbeInfo * info,
    gpointer ctx){
    GstBuffer *buf = (GstBuffer *) info->data;
    NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
    GstMapInfo inmap = GST_MAP_INFO_INIT;
    if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
      GST_ERROR ("input buffer mapinfo failed");
      return GST_PAD_PROBE_DROP;
    }
    NvBufSurface *ip_surf = (NvBufSurface *) inmap.data;
    gst_buffer_unmap (buf, &inmap);
    guint vehicle_count = 0;
    guint person_count = 0;
    NvDsMetaList *l_frame = NULL;
    NvDsObjectMeta *obj_meta = nvds_acquire_obj_meta_from_pool (batch_meta);
    NvDsMetaList * l_obj = NULL;

    for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
            l_frame = l_frame->next) {
          NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
        if (frame_meta->frame_num % 10 != 0){
            return GST_PAD_PROBE_OK;
        }


        //obj_meta = (NvDsObjectMeta *) (l_obj->data);
        NvDsObjEncUsrArgs frameData = { 0 };
        /* To be set by user */
        frameData.saveImg = true;
        frameData.attachUsrMeta = true;
        /* Set if Image scaling Required */
        frameData.scaleImg = FALSE;
        frameData.scaledWidth = 0;
        frameData.scaledHeight = 0;
        /* Quality */
        frameData.quality = 80;
        /* Main Function Call */
        sprintf(frameData.fileNameImg, "snapshot/%s/source_%d.jpg", snapshot_folder, frame_meta->source_id);

        obj_meta->rect_params.width = 1920; 
        obj_meta->rect_params.height = 1080; 
        obj_meta->rect_params.top = 0.0f;
        obj_meta->rect_params.left = 0.0f;
        //g_print ("encode image %d\n", frame_meta->frame_num);
        nvds_obj_enc_process (ctx, &frameData, ip_surf, obj_meta, frame_meta);
        ///save image
        nvds_obj_enc_finish (ctx);
      }
    
    return GST_PAD_PROBE_OK;
}

We can first rule out whether it is a problem with your code. Could you add your probe function to our demo like: sources\apps\sample_apps\deepstream-test1\deepstream_test1_app.c? What is the specific brand of your Jetson, like Orin or Xavier?

I insert the probe to the deepstream-nvdsanalytics-test example. Again, dGPU work fine but Jetson will hang after running about 10 frame.

My plateform is this one. Jetson Xavier™ NX

diff --git a/Makefile b/Makefile
index 7314c85..a54367e 100644
--- a/Makefile
+++ b/Makefile
@@ -53,7 +53,7 @@ CFLAGS+= $(shell pkg-config --cflags $(PKGS))
 
 LIBS:= $(shell pkg-config --libs $(PKGS))
 
-LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lm \
+LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lnvbufsurface -lnvds_batch_jpegenc -lm \
        	-L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart \
 	   -lcuda -Wl,-rpath,$(LIB_INSTALL_DIR)
 
diff --git a/deepstream_nvdsanalytics_test.cpp b/deepstream_nvdsanalytics_test.cpp
index 4ccc4f2..8403ae4 100644
--- a/deepstream_nvdsanalytics_test.cpp
+++ b/deepstream_nvdsanalytics_test.cpp
@@ -37,6 +37,10 @@
 #include "gst-nvmessage.h"
 #endif
 
+//jped encode
+#include "nvbufsurface.h"
+#include "nvds_obj_encode.h"
+
 #define MAX_DISPLAY_LEN 64
 
 #define PGIE_CLASS_ID_VEHICLE 0
@@ -299,11 +303,67 @@ create_source_bin (guint index, gchar * uri)
   return bin;
 }
 
+
+static GstPadProbeReturn
+snapshot_probe(GstPad * pad, GstPadProbeInfo * info,
+    gpointer ctx){
+    NvDsObjEncCtxHandle ctx_convert = (NvDsObjEncCtxHandle) ctx;
+    GstBuffer *buf = (GstBuffer *) info->data;
+    NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
+    GstMapInfo inmap = GST_MAP_INFO_INIT;
+    if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
+      GST_ERROR ("input buffer mapinfo failed");
+      return GST_PAD_PROBE_DROP;
+    }
+    NvBufSurface *ip_surf = (NvBufSurface *) inmap.data;
+    gst_buffer_unmap (buf, &inmap);
+    guint vehicle_count = 0;
+    guint person_count = 0;
+    NvDsMetaList *l_frame = NULL;
+    NvDsObjectMeta *obj_meta = nvds_acquire_obj_meta_from_pool (batch_meta);
+    NvDsMetaList * l_obj = NULL;
+
+    for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
+            l_frame = l_frame->next) {
+          NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
+        if (frame_meta->frame_num % 150 != 0){
+            return GST_PAD_PROBE_OK;
+        }
+
+
+        //obj_meta = (NvDsObjectMeta *) (l_obj->data);
+        NvDsObjEncUsrArgs frameData = { 0 };
+        /* To be set by user */
+        frameData.saveImg = true;
+        frameData.attachUsrMeta = true;
+        /* Set if Image scaling Required */
+        frameData.scaleImg = FALSE;
+        frameData.scaledWidth = 0;
+        frameData.scaledHeight = 0;
+        /* Quality */
+        frameData.quality = 80;
+        /* Main Function Call */
+        sprintf(frameData.fileNameImg, "source_%d.jpg", frame_meta->source_id);
+        // 儲存整張照片暫時調整
+        obj_meta->rect_params.width = 1920; //寫死在streammux設定檔
+        obj_meta->rect_params.height = 1080; //寫死在streammux設定檔
+        obj_meta->rect_params.top = 0.0f;
+        obj_meta->rect_params.left = 0.0f;
+        //g_print ("encode image %d\n", frame_meta->frame_num);
+        nvds_obj_enc_process (ctx_convert, &frameData, ip_surf, obj_meta, frame_meta);
+        ///save image
+      }
+    nvds_obj_enc_finish (ctx_convert);
+    return GST_PAD_PROBE_OK;
+}
+
+
+
 int
 main (int argc, char *argv[])
 {
   GMainLoop *loop = NULL;
-  GstElement *pipeline = NULL, *streammux = NULL, *sink = NULL, *pgie = NULL,
+  GstElement *pipeline = NULL, *streammux = NULL, *sink = NULL, *pgie = NULL, *fake_sink = NULL,
              *nvtracker = NULL, *nvdsanalytics = NULL,
       *nvvidconv = NULL, *nvosd = NULL, *tiler = NULL,
       *queue1, *queue2, *queue3, *queue4, *queue5, *queue6, *queue7;
@@ -311,6 +371,7 @@ main (int argc, char *argv[])
   GstBus *bus = NULL;
   guint bus_watch_id;
   GstPad *nvdsanalytics_src_pad = NULL;
+  GstPad *fake_sink_sink_pad = NULL;
   guint i, num_sources;
   guint tiler_rows, tiler_columns;
   guint pgie_batch_size;
@@ -411,6 +472,7 @@ main (int argc, char *argv[])
     transform = gst_element_factory_make ("nvegltransform", "nvegl-transform");
   }
   sink = gst_element_factory_make ("nveglglessink", "nvvideo-renderer");
+  fake_sink = gst_element_factory_make ("fakesink", "nvvideo-renderer");
 
   if (!pgie || !nvtracker || !nvdsanalytics || !tiler || !nvvidconv ||
       !nvosd || !sink || !queue1 || !queue2 || !queue3 || !queue4 || !queue5 ||
@@ -472,7 +534,7 @@ main (int argc, char *argv[])
   if(prop.integrated) {
     gst_bin_add_many (GST_BIN (pipeline), queue1,  pgie, queue2, nvtracker, queue3,
             nvdsanalytics , queue4, tiler, queue5,
-            nvvidconv, queue6, nvosd, queue7, transform, sink,
+            nvvidconv, queue6, nvosd, queue7, transform, fake_sink,
         NULL);
 
     /* we link the elements together, with queues in between
@@ -481,7 +543,7 @@ main (int argc, char *argv[])
     */
     if (!gst_element_link_many (streammux,queue1, pgie , queue2, nvtracker,
           queue3, nvdsanalytics, queue4, tiler, queue5,
-          nvvidconv, queue6, nvosd, queue7, transform, sink, NULL)) {
+          nvvidconv, queue6, nvosd, queue7, transform, fake_sink, NULL)) {
       g_printerr ("Elements could not be linked. Exiting.\n");
       return -1;
     }
@@ -489,14 +551,14 @@ main (int argc, char *argv[])
   else {
     gst_bin_add_many (GST_BIN (pipeline), queue1, pgie, queue2,
                   nvtracker, queue3, nvdsanalytics, queue4, tiler, queue5,
-                  nvvidconv, queue6, nvosd, queue7, sink, NULL);
+                  nvvidconv, queue6, nvosd, queue7, fake_sink, NULL);
     /* we link the elements together
     * nvstreammux -> nvinfer -> nvtracker -> nvdsanalytics -> nvtiler ->
     * nvvideoconvert -> nvosd -> sink
     */
     if (!gst_element_link_many (streammux, queue1, pgie, queue2, nvtracker,
         queue3, nvdsanalytics, queue4, tiler, queue5, nvvidconv, queue6,
-        nvosd, queue7, sink, NULL)) {
+        nvosd, queue7, fake_sink, NULL)) {
       g_printerr ("Elements could not be linked. Exiting.\n");
       return -1;
     }
@@ -514,6 +576,18 @@ main (int argc, char *argv[])
         nvdsanalytics_src_pad_buffer_probe, NULL, NULL);
   gst_object_unref (nvdsanalytics_src_pad);
 
+  NvDsObjEncCtxHandle obj_ctx_handle = nvds_obj_enc_create_context ();
+  fake_sink_sink_pad = gst_element_get_static_pad (fake_sink, "sink");
+  if (!fake_sink_sink_pad)
+    g_print ("Unable to get fake_sink_sink_pad pad\n");
+  else {
+      gst_pad_add_probe (fake_sink_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
+          snapshot_probe, (gpointer) obj_ctx_handle, NULL);
+  }
+  gst_object_unref (fake_sink_sink_pad);
+
+
+
   /* Set the pipeline to "playing" state */
   g_print ("Now playing:");
   for (i = 0; i < num_sources; i++) {

Sorry for late response. I have added your patch to the deepstream-nvdsanalytics-test code. It works normally. But I use the latest DeepStream version: DeepStream 6.2. Could you update your version to 6.2 and try it? Thanks

Unfortunately the board vender did not follow the Jetpack release tightly. So I only have deepstream 6.1.1 on my board. Or it is OK to upgrade deepstream to 6.2 version in L4T 35.1.0?

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

There may be incompatible problems. But you can try with docker first: deepstream-l4t. If it doesn’t work, you can only upgrade the version. We will not provide patches separately on the old version to solve the problem.

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