Jetson Orin AGX NvJpeg hardware acceleration

Hello,
I currently am working on a Jetson Orin AGX on Jetpack 6.1 with VPI 3.2 and I’m using a VPIImage in the VPI_IMAGE_FORMAT_RGB8.
Since the hardware jpeg encoder needs a dmabuf file descriptor I need to convert this to YUV420 or NV12.
So I have created a NvBufSurface with memType NVBUF_MEM_SURFACE_ARRAY, layout NVBUF_LAYOUT_PITCH and colorFormat NVBUF_COLOR_FORMAT_YUV420. This image has been converted correctly and using dump_dmabuf I was able to fully extract all 3 planes. For the conversion I used libyuv::RGB24ToI420 which worked fine, but I would like to use a GPU accelerated conversion. Having tried the Nvidia Performance Primitive nppiRGBToNV12_8u_ColorTwist32f_C3P2R_Ctx I had successfully converted the image to NV12 but I was forced to use a memType that is neither NVBUF_MEM_SURFACE_ARRAY nor NVBUF_MEM_HANDLE. I tried to NvBufSurfaceTransform my NvBufSurface but had to find out that conversion between CUDA and the aforementioned mem types isn’t supported.

What would be the preferred way to transform or wrap a VPIImage in VPI_IMAGE_FORMAT_RGB8 so that I get a dmabuf fd for the Nvjpeg Encoder?

Having the CPU conversion works, but I’d rather use some other method.

*** Please note that this reply is generated by LLM automatically ***

To convert a VPIImage in VPIIMAGEFORMATRGB8 to a format that can be used with the hardware JPEG encoder on the Jetson AGX Orin, which requires a dmabuf file descriptor, you have a few options. Since you’ve already successfully converted the image using libyuv’s RGB24ToI420 function on the CPU, I’ll focus on exploring GPU-accelerated conversion methods that can provide a dmabuf file descriptor.

Option 1: Using NPP (NVIDIA Performance Primitives)

You’ve already tried using NPP’s nppiRGBToNV12_8u_C3P2R function, which successfully converted the image to NV12 format. However, you encountered issues with the memory type, as NPP requires a specific memory layout that isn’t compatible with NVBUFMEMSURFACEARRAY or NVBUFMEMHANDLE.

To overcome this limitation, you could consider using NPP’s nppiRGBToNV12_8u_C3P2R function with a CUDA memory allocation, and then use the cudaMalloc and cudaMemcpy functions to transfer the data to a NvBufSurface with the desired memory type. This approach would require additional memory copies, which might impact performance.

Option 2: Using VPI (Vision Programming Interface)

Since you’re already using VPI, you can explore the VPIImage conversion functions provided by the VPI library. Specifically, you can use the vpiImageConvert function to convert the VPIImage in VPIIMAGEFORMATRGB8 to a VPIImage in VPIIMAGEFORMATYUV420 or VPIIMAGEFORMATNV12.

VPI provides a VPIImage conversion function that can convert between different formats, including RGB8 to YUV420 or NV12. This function is optimized for the Jetson platform and can take advantage of the GPU acceleration.

To use this function, you’ll need to create a VPIImage object with the desired output format and then call the vpiImageConvert function to perform the conversion. The resulting VPIImage object will contain the converted image data in the desired format.

Option 3: Using NvBufSurfaceTransform

As you’ve already tried, NvBufSurfaceTransform can be used to convert between different formats, but it doesn’t support conversion between CUDA and NVBUFMEMSURFACEARRAY or NVBUFMEMHANDLE memory types.

However, you can use NvBufSurfaceTransform to convert the NvBufSurface with NVBUFMEMSURFACEARRAY memory type to a NvBufSurface with NVBUFMEMHANDLE memory type, and then use the NvBufSurfaceMap function to get a dmabuf file descriptor for the converted surface.

In summary, the preferred way to transform or wrap a VPIImage in VPIIMAGEFORMATRGB8 to get a dmabuf file descriptor for the Nvjpeg Encoder is to use the VPI library’s vpiImageConvert function, which provides a GPU-accelerated conversion to the desired format. If you prefer to use NPP, you’ll need to perform additional memory copies to transfer the data to a NvBufSurface with the desired memory type.

*** Please give the thumbs up if you get answers you like. Or provide feedback to help us improve the answer. ***

Hi,
Please try this patch:

Jetson/L4T/VPI Interoperability Example - eLinux.org

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