how to render the nvbuffer use NvEglRenderer?

Hi

I tried the code below in samples/06_jpeg_decode/main.cpp. the Segmentation fault(core dumped) occurred.

NvBuffer *buffer;
        ret = ctx.jpegdec->decodeToBuffer(&buffer, ctx.in_buffer,
            ctx.in_file_size, &pixfmt, &width, &height);
        TEST_ERROR(ret < 0, "Could not decode image", cleanup);
        cout << "Image Resolution - " << width << " x " << height << endl;
                ExtractFdFromNvBuffer(buffer, &m_dmabuf);
        printf("m_dmabuf: %d\n", m_dmabuf);
        while(1) {
          g_renderer->render(m_dmabuf);
        }

Hi,
You should call decodeToFd() instead of decodeToBuffer().

Hi DaneLLL

Thank you for your answer.
I want to use nvbuffer for easy to convert from opencv Mat.
How to convert nvbuffer to Fd?
Or can I convert opencv mat to Fd?

Hi,

We have suggestion for you in this post

You may also refer to this to map NVBuffer to cv::Mat.

Hi DaneLLL

Thank you for replay me again.
I need find the way nvbuffer to Fd or mat to Fd.
But your suggestion is NVBuffer to cv::Mat.

So is there no solution for nvbuffer to Fd / mat to Fd?

I search a lot time and found way cv::mat to nvbuffer below.I still cannot render mat uing NvEglRenderer.

Hi,

No, we don’t have solution for this. It is not possible to achieve zero memcpy() in this case. cv::Mat is mainly in BGR format, which is not supported in hardware DMA buffer NvBuffer.

Hi DaneLLL

Thank you for your answer.
I wish I could understand a little more about Nvbuffer.
The output of decodeToBuffer is the Nvbuffer software buffer.
The output of decodeToFd is hardware DMA buffer NvBuffer.
Is that possible to convert between Nvbuffer software buffer and hardware DMA buffer NvBuffer?

Hi,

No. It requires memcpy.

You may create a NvBuffer, call decodeToFd, and call NvBufferTransform() to copy decoded YUV to the created NvBuffer. In calling NvBufferTransform(), it utilizes hardware VIC engine to copy the buffers.