Extracting GPU pointer from gstreamer output file (multifilesink)

Hi,
I am trying to get the gpu pointer from the output file generated by gstreamer (1008 bytes struct).
This is what I’m doing:

  1. I run the following command to generate the files:
gst-launch-1.0 filesrc location=file.mp4 ! decodebin ! videorate max-rate=4 ! multifilesink location="/tmp/frame%d.buffer"
  1. I read the buffer (1008 bytes) from file and extract the file descriptor:
FILE* fp = fopen("/tmp/frame0.buffer", "rb");
void* buff = malloc(1008);
fread(buff, 1008, 1, fp);
ExtractFdFromNvBuffer(buff, &dmabuf_fd);
  1. I extracted the parameters and printed the values:
NvBufferParams par;
NvBufferGetParams(dmabuf_fd, &par);

I can see that the par.width, par.height matches the source video resolution (file.mp4).

  1. I tried to get EGLImage from FD but it fails:
EGLImageKHR egl_image = NvEGLImageFromFd(NULL, dmabuf_fd);

But I get the following error:

NvEGLImageFromFd: Failed to create EGLImage from dma-buf fd (1066)

(dmabuf_fd = 1066 in this example)

I also tried this, but I got the same error:

static EGLDisplay egl_display = EGL_NO_DISPLAY;
if (egl_display == EGL_NO_DISPLAY)
{
    egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (egl_display == EGL_NO_DISPLAY)
    {
        exit(-1);
    }
}
EGLImageKHR egl_image = NvEGLImageFromFd(egl_display, dmabuf_fd);

What am I doing wrong?

Hi,
It is information to the buffer, not real YUV data. You would need to call ExtractFdFromNvBuffer() when running the application. For saving to a file, you would need to save the real YUV data.

Hi DaneLL, thank you!
I called ExtractFdFromNvBuffer() in step 2, and I was able to retrieve the file descriptor, but it fails to create the EGLImage from the retrieved descriptor.
If I understand correctly, what I saved only contains information to the buffer, and there is no way to extract a GPU pointer from it since it holds no real data?!

Hi,
We generally access NvBuffer in appsink. Please refer to
Gstreamer pipeline using nvv4l2h264enc to write from shared memory - #6 by DaneLLL

For dumping YUV data to a file, please try to link the pipeline like

… ! nvv4l2decoder ! nvvidconv ! video/x-raw ! multifilesink

1 Like

Thank you, actually I was using the decoder.cpp, modified it so that I get the NvBuffer from file, but as you said it only holds information about the buffer with no real data.

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