Converting color format with zero copy using hardware

I am using sample 07_video_convert as my reference. I would like to convert from yuv to rgb. I successfully converted a yuv file to rgb. Now I would like to convert camera frames from yuv to rgb. I have noticed from the code that there are two operations that need to be done. A read and a write operation and each one of them requires copying data from/to pointers returned by NvBufferMemMap. This means that data is copied twice. Is there a way to avoid those two copy operations?

Hi,
Is your camera a Bayer sensor, YUV snesor or USB camera? If the frame data is captured into NvBuffer directly you can call NvBufferTransform() to convert YUV420 to RGBA.

Its a gmsl camera and we are using V4L2_MEMORY_MMAP to get the data from the camera. The camera does not support V4L2_MEMORY_USRPTR, but I think it could support V4L2_MEMORY_DMABUF

Hi,
Please execute the command and share the information for reference:

$ v4l2-ctl -d /dev/videoX --list-formats-ext

Would like to know what formats are supported.

v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'UYVY'
	Name        : UYVY 4:2:2
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'NV16'
	Name        : Y/CbCr 4:2:2
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)

	Index       : 2
	Type        : Video Capture
	Pixel Format: 'UYVY'
	Name        : UYVY 4:2:2
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)

We are using UYVY format 4:2:2

Hi,
Please try to run this sample with your camera:

/usr/src/jetson_multimedia_api/samples/12_camera_v4l2_cuda/

If you can run it successfully, please modify this line:

-    input_params.colorFormat = get_nvbuff_color_fmt(V4L2_PIX_FMT_YUV420M);
+    input_params.colorFormat = NvBufferColorFormat_ABGR32;
    input_params.nvbuf_tag = NvBufferTag_NONE;
    /* Create Render buffer */
    if (-1 == NvBufferCreateEx(&ctx->render_dmabuf_fd, &input_params))

By default the YUV422(YUYV or UYVY) frame data is converted to YUV420 for rendering. You can change to RGBA and try.

Yes it does work, thank you.

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