# Gstreamer NVMM memory buffer to torch tensor with zero copy

**URL:** <https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501>\
**Category:** DeepStream SDK\
**Created:** [June 6, 2024, 9:42pm UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501 "2024-06-06T21:42:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vermillionblu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vermillionblu](https://forums.developer.nvidia.com/u/vermillionblu)\
**Post date:** [June 6, 2024, 9:42pm UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501/1 "2024-06-06T21:42:36Z")

</div>

Hi, I’m trying to convert Gstreamer buffer to torch tensor without going through numpy array. For several reasons, I don’t want to use Deepstream elements (I don’t need inference or visualisation, just torch tensor frame buffer from decoded video to reduce latency introduced by buffer copies).

How can I achieve this using simple buffer probe?

```auto
pipeline = Gst.parse_launch(f'''
    filesrc location=video.mp4 num-buffers=200 !
    decodebin !
    nvvideoconvert !
    video/x-raw(memory:NVMM),format=RGBA !
    fakesink name=s
''')

```

```auto
def on_frame_probe(pad, info):
    buf = info.get_buffer()
    caps_structure = caps.get_structure(0)
    height, width = caps_structure.get_value('height'), caps_structure.get_value('width')

    is_mapped, map_info = buf.map(Gst.MapFlags.READ)
    if is_mapped:
        try:
            # Add code for conversion here.
            return Gst.PadProbeReturn.OK

```

Please guide me on how can I solve this? I’m not much familiar with C/C++. I’m using deepstream docker image 6.4-triton-multiarch.  
Architecture: x86-64 with Nvidia DGPU

Thanks

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [June 7, 2024, 2:22am UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501/3 "2024-06-07T02:22:40Z")

</div>

Yes. You can try to add a probe to the src\_pad of nvvideoconvert and use [deepstream\_imagedata-multistream.py](https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/blob/master/apps/deepstream-imagedata-multistream/deepstream_imagedata-multistream.py#L121) to get the buffer.

---

<div class="post-metadata">

**Author:** ![vermillionblu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@vermillionblu](https://forums.developer.nvidia.com/u/vermillionblu)\
**Post date:** [June 7, 2024, 3:00pm UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501/4 "2024-06-07T15:00:47Z")

</div>

Thank you I was successfully able to cast it to torch tensor from cupy.  
Is it possible to do so without using pyds library bindings?

---

<div class="post-metadata">

**Author:** ![yuweiw](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yuweiw/32/101255_2.png) [@yuweiw](https://forums.developer.nvidia.com/u/yuweiw)\
**Post date:** [June 10, 2024, 7:10am UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501/5 "2024-06-10T07:10:37Z")

</div>

> [@vermillionblu](#):
>
> Is it possible to do so without using pyds library bindings?

NO. You have to use pyds if you use the method in the deepstream\_imagedata-multistream.py.

---

<div class="post-metadata">

**Author:** ![yingliu](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/yingliu/32/136703_2.png) [@yingliu](https://forums.developer.nvidia.com/u/yingliu)\
**Post date:** [July 2, 2024, 2:38am UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501/6 "2024-07-02T02:38:37Z")

</div>

**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**

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [July 16, 2024, 2:39am UTC](https://forums.developer.nvidia.com/t/gstreamer-nvmm-memory-buffer-to-torch-tensor-with-zero-copy/295501/7 "2024-07-16T02:39:25Z")

</div>

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