# Best practice to Get gstreamer buffer to GPU memory? 

**URL:** <https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473>\
**Category:** Jetson TX1\
**Created:** [May 28, 2019, 6:49am UTC](https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473 "2019-05-28T06:49:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gil.gilad](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gil.gilad](https://forums.developer.nvidia.com/u/gil.gilad)\
**Post date:** [May 28, 2019, 6:49am UTC](https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473/1 "2019-05-28T06:49:48Z")

</div>

what is the best way to gain accsess to a buffer without using memcpy?

```auto
NvBufferMemMap (fd, 0, NvBufferMem_Read,
                        &mapped_ptr) != 0)

```

using NvBufferMemMap only allows cpu accsess

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [May 28, 2019, 8:15am UTC](https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473/2 "2019-05-28T08:15:09Z")

</div>

Hi,  
You may try nvivafilter:  
[url][https://devtalk.nvidia.com/default/topic/963123/jetson-tx1/video-mapping-on-jetson-tx1/post/4979740/#4979740[/url]](https://devtalk.nvidia.com/default/topic/963123/jetson-tx1/video-mapping-on-jetson-tx1/post/4979740/#4979740%5B/url%5D)  
[url][https://devtalk.nvidia.com/default/topic/978438/jetson-tx1/optimizing-access-to-image-data-acquired-with-nvcamerasrc/post/5026998/#5026998[/url]](https://devtalk.nvidia.com/default/topic/978438/jetson-tx1/optimizing-access-to-image-data-acquired-with-nvcamerasrc/post/5026998/#5026998%5B/url%5D)  
[url][https://devtalk.nvidia.com/default/topic/1046218/jetson-tx2/unable-to-overlay-text-when-using-udpsrc-/post/5310313/#5310313[/url]](https://devtalk.nvidia.com/default/topic/1046218/jetson-tx2/unable-to-overlay-text-when-using-udpsrc-/post/5310313/#5310313%5B/url%5D)  
[url][https://devtalk.nvidia.com/default/topic/1022543/jetson-tx2/gstreamer-nvmm-lt-gt-opencv-gpumat/post/5311027/#5311027[/url]](https://devtalk.nvidia.com/default/topic/1022543/jetson-tx2/gstreamer-nvmm-lt-gt-opencv-gpumat/post/5311027/#5311027%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![miguel.taylor](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/miguel.taylor/32/273049_2.png) [@miguel.taylor](https://forums.developer.nvidia.com/u/miguel.taylor)\
**Post date:** [May 28, 2019, 8:24pm UTC](https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473/3 "2019-05-28T20:24:31Z")

</div>

Hi,  
In our case, we get a **cudaEglFrame** from the file descriptor. This contains pointers that can be used on GPU and avoids memory copies if the buffer is on shared memory. The steps are:

1. Get an **EGLImage** with NvEGLImageFromFd
2. Get a **CUgraphicsResource** with cuGraphicsEGLRegisterImage
3. Get an **EglFrame** with cuGraphicsResourceGetMappedEglFrame

We provide an out of the box solution for CUDA algorithm integration into GStreamer pipelines called GstCUDA. Please check our wiki page if you are interested on GstCUDA:

> **[GstCUDA - GstCUDA](https://developer.ridgerun.com/wiki/index.php?title=GstCUDA)**
>
> GstCUDA is a RidgeRun developed GStreamer plug-in enabling easy CUDA algorithm integration into GStreamer pipelines.

---

<div class="post-metadata">

**Author:** ![gil.gilad](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gil.gilad](https://forums.developer.nvidia.com/u/gil.gilad)\
**Post date:** [June 5, 2019, 9:28am UTC](https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473/4 "2019-06-05T09:28:54Z")

</div>

Hi,

I have followed your advice and the linked you provided. with the example code

```auto
input_params.width = 1000; 
  input_params.height = 1000;
  input_params.layout = NvBufferLayout_Pitch;
  input_params.colorFormat = NvBufferColorFormat_ABGR32;
  input_params.payloadType = NvBufferPayload_SurfArray;
  input_params.nvbuf_tag = NvBufferTag_NONE;

 NvBufferCreateEx (&mobileplugin->conv_dmabuf_fd, &input_params) ;
 

  static EGLDisplay egl_display = EGL_NO_DISPLAY;
    EGLImageKHR egl_image;

    // Init egl_display if not initialized
    if (egl_display == EGL_NO_DISPLAY) {
     
      egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
      if (egl_display == EGL_NO_DISPLAY) {
        flow_ret = GST_FLOW_ERROR;
        goto done;
      }
    }

    // Create an EGLImage from the FD
    egl_image = NvEGLImageFromFd (egl_display, mobileplugin->conv_dmabuf_fd);
    
    if (!egl_image) {
    
      flow_ret = GST_FLOW_ERROR;
      goto done;
    }

```

but i am getting NvEGLImageFromFd: Failed to create EGLImage from dma-buf fd (1265) error

what am i missing ? what can cause this error?

---

<div class="post-metadata">

**Author:** ![DaneLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/danelll/32/14043_2.png) [@DaneLLL](https://forums.developer.nvidia.com/u/DaneLLL)\
**Post date:** [June 13, 2019, 9:38am UTC](https://forums.developer.nvidia.com/t/best-practice-to-get-gstreamer-buffer-to-gpu-memory/75473/5 "2019-06-13T09:38:21Z")

</div>

Hi,  
Can you please share a full code so that we can build and run to reproduce the error? Are you on r28.2/TX1?
