Gstreamer get the buf content from (memory:NVMM) form jetson

I’m using gstreamer to get the raw frame in the GPU(nvmemory).But I don’t know how to get the frame data using the gpupointer in the recallfunction.

static GstPadProbeReturn
pic_fetch (GstPad *pad,
GstPadProbeInfo *info,
VideoStream *ptr)
{
gint x, y;
GstMapInfo map;
GstBuffer *buffer;
GstMemory *mem;

buffer = GST_PAD_PROBE_INFO_BUFFER (info);
if (buffer == NULL)
return GST_PAD_PROBE_OK;

buffer = gst_buffer_make_writable (buffer);
GstBuffer * app_buffer = gst_buffer_copy(buffer);
return GST_PAD_PROBE_OK;
}

It’s different from the cpu buffer, info.data is a constant size of 1008 bytesize pointing the gpu.
So,how could I parse and using it to download buffer to CPU correctly.

Hi 2791914419,

May I know which Jetson platform you’re using?
Which JetPack version?

I’m using Jetson Xavier NX jetpack 4.6 now ,
and really having problem in fetch picture of rgb in nvmemory.
Buffer in the cpu can be get easily , in the gstpad probe.just map the info data.
But the type of nvbuf can’t fetch directly.
I found a useful reference which tell me use function of cudaEGL.h.

static GstPadProbeReturn
conv_src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)
{
GstBuffer *buffer = (GstBuffer *) info->data;
GstMapInfo map = {0};
int dmabuf_fd = 0;
gst_buffer_map (buffer, &map, GST_MAP_READ);
ExtractFdFromNvBuffer((void *)map.data, &dmabuf_fd);
//CUDA postprocess
{
EGLImageKHR egl_image;
egl_image = NvEGLImageFromFd(egl_display, dmabuf_fd);
CUresult status;
CUeglFrame eglFrame;
CUgraphicsResource pResource = NULL;
cudaFree(0);
status = cuGraphicsEGLRegisterImage(&pResource,
egl_image,
CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (status != CUDA_SUCCESS)
{
printf(“cuGraphicsEGLRegisterImage failed: %d \n”,status);
}
status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0);
status = cuCtxSynchronize();
if (create_filter) {
filter = cv::cuda::createSobelFilter(CV_8UC4, CV_8UC4, 1, 0, 3, 1, cv::BORDER_DEFAULT);
//filter = cv::cuda::createGaussianFilter(CV_8UC4, CV_8UC4, cv::Size(31,31), 0, 0, cv::BORDER_DEFAULT);
create_filter = false;
}
cv::cuda::GpuMat d_mat(h, w, CV_8UC4, eglFrame.frame.pPitch[0]);
filter->apply (d_mat, d_mat);

    status = cuCtxSynchronize();
    status = cuGraphicsUnregisterResource(pResource);
    NvDestroyEGLImage(egl_display, egl_image);
}
gst_buffer_unmap(buffer, &map);

return GST_PAD_PROBE_OK;

}

but it’s handeling the RGBA format.
I need to convert NV12(memory:NVMM) to RGB then save the pic.
So,shall we have a more easy way or introduction to solve the problem ?

Moving to Jetson NX forum for better support.

Hi,
Hardware converter in Jetson platforms does not support RGB/BGR, so you would need to convert to RGBA, create cuda buffer in RGB/BGR and re-sample RGBA to RGB/BGR. This is the optimal solution to get RGB/BGR buffer.

ok,thanks.

fine,thanks.

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