NvBufferTransform causes Segmentation fault

I want to convert an image from RGBA to YUV420 on the Orin. According to various threads on this forum this should be possible using the NvBufferTransform method. Somehow I cannot get this to work, I get a Segmentation fault no matter what.
I put together a minimal example. In this example I don’t try to do color conversion but just any transformation at all but it still fails with a Segmentation fault:

int dmaFd1;
int dmaFd2;
unsigned long out_buf_size;
unsigned char *out_buf;
int width = 100;
int height = 100;

NvBufferCreateParams paramsCreate1 = {.width = width,
                                   .height = height,
                                   .payloadType = NvBufferPayload_SurfArray,
                                   .layout = NvBufferLayout_BlockLinear,
                                   .colorFormat = NvBufferColorFormat_GRAY8,
                                   .nvbuf_tag = NvBufferTag_NONE};

NvBufferCreateParams paramsCreate2 = {.width = width,
                                  .height = height,
                                  .payloadType = NvBufferPayload_SurfArray,
                                  .layout = NvBufferLayout_BlockLinear,
                                  .colorFormat = NvBufferColorFormat_GRAY8,
                                  .nvbuf_tag = NvBufferTag_NONE};

NvBufferCreateEx(&dmaFd1, &paramsCreate1);
NvBufferCreateEx(&dmaFd2, &paramsCreate2);

unsigned char *dummy_data = new unsigned char[width * height];
for (int i = 0; i < width * height; i++){
    dummy_data[i] = 42;
}

Raw2NvBuffer(dummy_data, 0, width, height, dmaFd1);

NvBufferTransformParams paramsTransform;
paramsTransform.transform_flag = NVBUFFER_TRANSFORM_FLIP;
paramsTransform.transform_flip = NvBufferTransform_None;
int retNv = NvBufferTransform(dmaFd1, dmaFd2, &paramsTransform);

Any ideas what’s wrong here?

Hi,
NvBuffer APIs are deprecated on Jetpack 5 releases. Please call NvBufSurfTransform(). NvBufSurface APIs are defined in

/usr/src/jetson_multimedia_api/include/nvbufsurftransform.h
/usr/src/jetson_multimedia_api/include/nvbufsurface.h

Hey, thanks for the quick reply!
I tried NvBufSurfTransform() and it seems to work. The problem is that after the transformation I have to perform a JPEG encoding. From what I read there is no straight-forward way to use the hardware JPEG encoder with a NvBufSurface right? It can only be used with an NvBuffer as shown in /usr/src/jetson_multimedia_api/samples/05_jpeg_encode.

What is the recommanded way here? Use NvBufferTransform even though it is deprecated so that I get an NvBuffer object? Or is there a way to encode a NvBufSurface that I overlooked?

Hi,
Do you install the samples through SDKManager? All Jetpack 5 samples should be based on NvBufSurface APIs.

I am not really sure, got the Orin provided by my company. Can you point me to any resources regarding JPEG encoding?

Even on the NVidia page (https://docs.nvidia.com/jetson/l4t-multimedia/l4t_mm_05_jpeg_encode.html) it says that the JPEG encoder takes an NvBuffer. Or is this outdated?

Hi,
The content may not be well updated. Please directly refer to the sample:

/usr/src/jetson_multimedia_api/samples/05_jpeg_encode/

I did take a look at this sample, but it still uses NvBuffer. So, there is currently no way to encode a NvBufSurface ?

Nvm, I figured it out. I just looked at encodeFromBuffer and not encodeFromFd. The latter works with the new API.

Hi,
Please check if you use Jetpack 5.1.1 or 5.1.2 and install the samples through SDKManager. You shall see NvBufSurface APIs are called, such as NvBufSurf::NvAllocate(), NvBufSurf::NvTransform()

Yeah, I did so, works now, thanks

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