Deepstream NvBufSurface memory type not changing (dGPU)


I’m creating a deepstream pipeline on my dGPU, and I’m trying to access the input frames and modify them (without opencv, I’m directly chaning the pixel values), this is part of the pipeline:

nvinfer → nvvideoconvert (nvbuf-memory-type = 3)

To access and edit the frames, I installed a probe at the source pad of the nvvideoconvert plugin:

GstPadProbeReturn srcProbe(GstPad *pad, GstPadProbeInfo *info) {
  GstBuffer *inbuf;
  GstMapInfo in_map_info;

  NvBufSurface *surface = NULL;
  NvDsBatchMeta *batch_meta = NULL;
  NvDsFrameMeta *frame_meta = NULL;
  NvDsMetaList * l_frame = NULL;
  guint i = 0;

  /*CHECK_CUDA_STATUS (cudaSetDevice (0), // gpu_id
      "Unable to set cuda device");*/

  memset (&in_map_info, 0, sizeof (in_map_info));

  // All this following code is preparing the frame buffer to CPU space
  inbuf = GST_PAD_PROBE_INFO_BUFFER(info);
  inbuf = gst_buffer_make_writable(inbuf);

  if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_WRITE)) {
    g_print ("Error: Failed to map gst buffer\n");
    return GST_PAD_PROBE_OK;

  gst_buffer_unmap(inbuf, &in_map_info);

  surface = (NvBufSurface *);

  NvBufSurfaceMap(surface, -1, -1, NVBUF_MAP_WRITE);

  // Modify the frame

  NvBufSurfaceUnMap (surface, 0, 0);

  return GST_PAD_PROBE_OK;

Even though the nvvideoconvert plugin is set to memory type 3, when I try to access the surface I get this error:

nvbufsurface: mapping of memory type (2) not supported

Any help would be greatly appreciated, thank you!

• Hardware Platform: GPU
• DeepStream 6.2

please refer to this sample for how to access nvBufSurface.

I’ve looked at the sample, and mapping the surface in read mode like the sample code actually works:

NvBufSurfaceMap(surface, -1, -1, NVBUF_MAP_READ);

But I need to map it in NVBUF_MAP_WRITE mode, which causes the memory type error I specified earlier.

Should I map the surface in Read, then create a new nvbufsurface infer_buf and map it in read-write mode, modify it, then copy its content into the original with NvBufSurfTransform (inter_buf, surface, &transform_params); ?

from the error, NvBufSurfaceMap failed because memory type (2) not supported on dgpu.
please refer NvBufSurfaceMap sample opt\nvidia\deepstream\deepstream-6.2\sources\gst-plugins\gst-dsexample\gstdsexample_optimized.cpp, NVBUF_MEM_CUDA_UNIFIED is supported on dgpu.

Found the issue, it looks like I need to change the memory type or resolution of the nvvideoconvert plugin for the memory-type change to work, this needs to be fixed.

Sorry for the late reply, Is this still an DeepStream issue to support? Thanks

No problem, yes it is an issue with the deepstream plugin Gst-nvvideoconvert whereby if the input format/resolution of the plugin is the same as that of the output the memory-type conversion won’t take place.

Currently, a workaround for this changing either the resolution or the format of the output. You can mark this issue as resolved but this still needs to be fixed in Deepstream.

1 Like

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