How can I get gpu memory from deepstream buffer in gstreamer plugin in python?

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
GPU (T4)
• DeepStream Version
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs)
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

I want to get gpu memory using python deepstream api in python gstreamer plugin.

There are pyds.get_nvds_buf_surface method in API, but it return cpu numpy array.

I can get gpu memory by using c gstreamer plugin and c++ deepstream api in deepstream 4.
But I want to change from C to python by using python gstreamer plugin and python deepstream api in deepstream 6.

I used NvBufSurface in c++, and there pyds.NvBufSurface in API.
But, there are no sample for using pyds.NvBufSurface.
I tried like using in c++, but it failed.

I think image is already in gpu nvmm memory. How can I get gpu memory from deepstream buffer in gstreamer plugin?

My Gstreamer pipeline

    uridecodebin uri=file:///sample_video/1.mp4 !
    nvvideoconvert nvbuf-memory-type=0 !
    "video/x-raw(memory:NVMM),format=RGBA" !
    m.sink_0 nvstreammux name=m nvbuf-memory-type=0 width=1920 height=1080 batch-size=1 !
    gsttestplugin !
    fakesink sync=1

My Python Gstreamer plugin (gsttestplugin)

import gi
gi.require_version("Gst", "1.0")
gi.require_version("GstBase", "1.0")
from gi.repository import GObject, Gst, GstBase

import pyds

class GstTestPlugin(GstBase.BaseTransform):
    GST_PLUGIN_NAME = "gsttestplugin"

    __gstmetadata__ = (
        "Test Plugin",

    __gsttemplates__ = (

    def __init__(self):
        super(GstTestPlugin, self).__init__()

    def do_transform_ip(self, buffer: Gst.Buffer) -> Gst.FlowReturn:
        res, map_info =
        if not res:
            return Gst.FlowReturn.ERROR

        surf = pyds.NvBufSurface.cast(hash(
        print(surf.gpuId, surf.batchSize)


        return Gst.FlowReturn.OK

__gstelementfactory__ = (


Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Traceback (most recent call last):
  File "/opt/nvidia/deepstream/deepstream/lib/gst-plugins/python/", line 41, in do_transform_ip
    surf = pyds.NvBufSurface.cast(hash(
TypeError: cast(): incompatible function arguments. The following argument types are supported:
    1. (self: capsule) -> pyds.NvBufSurface
    2. (self: int) -> pyds.NvBufSurface

Invoked with: -6714784618403796263
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
exec gdb failed: No such file or directory
Spinning.  Please run 'gdb gst-launch-1.0 835' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:01.272463991
Setting pipeline to PAUSED ...
Setting pipeline to READY ...

My Using Code in C api in deepstream 4.0

GstMapInfo in_map_info;
NvBufSurface* in_surf = nullptr;
memset(&in_map_info, 0, sizeof(in_map_info));

if (!gst_buffer_map(inbuf, &in_map_info, GST_MAP_READ))
    return GST_FLOW_ERROR;

in_surf = reinterpret_cast<NvBufSurface*>(;

gst_buffer_unmap(inbuf, &in_map_info);

We have not released DS 6.0.1, how can you use such version?

Oh, DS version is 6.0.

Please use get-nvds-buf-surface API: get_segmentation_masks — Deepstream Deepstream Version: 6.0 GA documentation

There is sample code in deepstream_python_apps/ at master · NVIDIA-AI-IOT/deepstream_python_apps (

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