Question about NVBUF_COLOR_FORMAT_NV12

I am trying to get a buffer pointer from EGLStream. I am trying the NVBUF_COLOR_FORMAT_NV12 format. But I got following information from the NV buffer parameters:

    plane: 0
        width: 5544
        height: 3710
        pitch: 5632
        offset: 0
        psize: 20971520
        bytesPerPix: 1
    plane: 1
        width: 2772
        height: 1855
        pitch: 5632
        offset: 20971520
        psize: 10485760
        bytesPerPix: 2

But to me, the size doesn’t make sense because 5632 X 3710 = 20894720 but not 20971520. I also tried to just write the Y plane with the size of 20894720 and the image seems okay.

My end goal is to get a CPU accessible pointer to the continuous buffer with a frame in YUV420 format. But it seems the method mentioned in this post: How to get YUV Buffer pointer? - #5 by JerryChang is not valid anymore.

hello suchao,

may I know what’s the real use-case,
or… what’s the pipeline you’re running with.

please refer to Topic-165300, comment#12.
the basic flow are…

  1. Get NvBuffer in RGBA, pitch-linear
  2. Map to CPU
  3. Map the CPU pointer to cv::Mat

Does that mean there is no way to get YUV420 format frame data in continuous memory location?

The use case is that we have some algorithm which takes YUV420 frame data. But the algorithm needs continuous memory not different channels in separated memory locations.

hello suchao,

you may still check MMAPI samples,
please refer to NvBufSurfTransform for the input/output DMA buffer, both exported as fd.
for instance,
/usr/src/jetson_multimedia_api/samples/unittest_samples/transform_unit_sample

I checked the sample code. But I couldn’t find all those NvBufSurfTransform related definitions. It seems the sample code includes “transform_unit_sample.hpp” header file. But I couldn’t find that file anywhere.

Also, even I find the definitions, are all output planes in continuous memory? From the sample code, I couldn’t tell if that is the case. It still writes the data plane by plane.

Hi,
NvBufSurface is hardware DMA buffer and needs to consider data alignment. For multiple-plane resolutions, pitch and width and not identical. Would suggest use single-plane format such as RGBA for mapping to cv::Mat or cv::gpu::gpuMat

Please note for certain resolutions, it is still possible to see pitch and width are different in single-plane formats.

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