How to use BufferOutputStream with NvBufferColorFormat_ABGR32

Hi i’m trying to make BufferOutputStream work with NvBufferColorFormat_ABGR32. I’m testing sample code under jetson_multimedia_api/argus/samples/eglimage.

Specifically, I replaced below

nativeBuffers[i] = NativeBuffer::create(Size2D<uint32_t>(options.windowRect().width(),
                                                                 options.windowRect().height()));

with

        nativeBuffers[i] = NvNativeBuffer::create(Size2D<uint32_t>(options.windowRect().width(),
                                                                 options.windowRect().height()),
                                                  NvBufferColorFormat_ABGR32,
//                                                  NvBufferColorFormat_NV12,
                                                  NvBufferLayout_Pitch
                                                  );

and the program hangs. If I uncomment the NV12 line, then it works again.

I want to get ABGR format because I followed this tutorial and successfully converted the eglframe to opencv mat. However, when I’m using NV12, the converted format is wrong. I’m not sure how I can convert the NV12 formated frame to a opencv mat.

Hi,
Please refer to this sample to call copyToNvBuffer():

/usr/src/jetson_multimedia_api/samples/09_camera_jpeg_capture

But 09 is not using BufferOutputStream. For EGLOutputStream it works fine. However, the EGLOutputStream is slower than the BufferOutputStream and sometimes it’s dropping frames.

Is there any updates on this? Thanks

Hi,
The code is in

/usr/src/jetson_multimedia_api/argus/samples/utils/NativeBuffer.cpp
/usr/src/jetson_multimedia_api/argus/samples/utils/nvmmapi/NvNativeBuffer.cpp

You may modify to RGBA for a try.

ok, let me have a try. Thanks!

Hi, i’m trying to locate the source code of this copyToNvBuffer but I can only find the header file ImageNativeBuffer.h I couldn’t find the implementation of this header file. Where I can get that? Thanks

Hi,
The code of copyToNvbuffer() is not public. It is in prebuilt libs.

I’m not sure if I understand your answer. Do you just want me to create a Buffer with the create method in NvNativeBuffer.cpp file? but just use ABGR color format? I have tried that. it didn’t work. If I directly change the color format from NV12 to ABGR, the BufferOutputStream will just be stuck at acquireBuffer method.
main.cpp (26.6 KB)
I’m sharing the code here.

If you look at line 547,

nativeBuffersPreview[i] = DmaBuffer::create(STREAM_SIZE,
                                            NvBufferColorFormat_NV12,
                                            NvBufferLayout_Pitch
                                            );

If I directly change NvBufferColorFormat_NV12 with NvBufferColorFormat_ABGR32, the acquireBuffer just halts there. I don’t know what else I need to do. Although currently, I made the code work with NV12, the NV12 data conversion is not something I preferred. I do prefer using ABGR for some other use cases.

Hi, any updates on this? thanks

Hi,
If changing the format in NvNativeBuffer doesn’t work, the format is not supported in this mode. You have to use the method demonstrated in 09 sample.

You mean to use EglOutputStream with FrameConsumer?

FrameConsumer way works. but i’m wondering is there a way to convert a NV12 formated NvNativeBuffer to ABGR32 formated buffer?

Hi,
The format is fixed to NV12 in NvNativeBuffer. You may try to create some NvBuffers in RGBA, and call NvBufferTranform() to convert NV12 to RGBA.

I actually looked at NvBufferTransform before but from the API reference all I can see is it’s mostly do warp type of transformations
image

Am I looking at the wrong place? This is the TransformParams

Hi,
Format conversion is supported. You can grep it in the samples and see some reference code. For example, in 12_camera_v4l2_cuda, frame data in YUV422(YUYV or UYVY) is converted to YUV420 for rendering.

Thanks, this is helpful!

I tested and this works. I think this can be closed

1 Like

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