how to get mipi YCbCr_420_888 frame data ?

I’m using the argus sample yuvJpeg and samples/09_camera_jpeg_capture/main.cpp,I can use iImage->mapBuffer get the jpeg frame buffer,but how can get the YCbCr_420_888 original frame buffer data ?

Hi,
Please call

m_dmabuf = iNativeBuffer->createNvBuffer(iStream->getResolution(),
                                                     NvBufferColorFormat_YUV420,
                                                     NvBufferLayout_Pitch);

And refer to dump_dmabuf() in 00_video_decode

I use this way to save yuv data,the resolution is 640X480,but the data size is 457600 bytes,Less than 640x480x1.5 bytes,use opencv Parse prompt format error,Why is this happening?

my code:

NV::IImageNativeBuffer *iNativeBuffer =
        Argus::interface_cast<NV::IImageNativeBuffer>(iFrame->getImage());
    if (!iNativeBuffer)
        printf("IImageNativeBuffer not supported by Image.");

    int m_dmabuf = -1;

    m_dmabuf = iNativeBuffer->createNvBuffer(iStream->getResolution(),NvBufferColorFormat_YUV420,NvBufferLayout_Pitch);
    printf("dmabuf=%d,number=%d\n",m_dmabuf,iFrame->getNumber());

    //m_dmabuf, iFrame->getNumber();


    char filename[256] = "output.yuv";

    std::ofstream *outputFile = new std::ofstream(filename);

    dump_dmabuf(m_dmabuf,0,outputFile);
    dump_dmabuf(m_dmabuf,1,outputFile);
    dump_dmabuf(m_dmabuf,2,outputFile);

Hi,
We suggest you print out some parameters in dump_dmabuf() for debugging.

parm.pixel_format
parm.pitch[plane]
parm.width[plane]
parm.height[plane]

this is my debugging,but why the 640x480 data only have 299520 bytes? the normal yuv data I think is 640x480x1.5 bytes.

############ parm.pixel_format=0,pitch=768,width=640,height=480
############ parm.pixel_format=0,pitch=512,width=320,height=240
############ parm.pixel_format=0,pitch=512,width=320,height=240

Hi,
640x480 + 320x240 + 320x240 = 1.5x640x480

Not sure but maybe you should add ‘delete outputFile;’ to get a complete file.

my dump_dmabuf code

static int
dump_dmabuf(int dmabuf_fd,
                unsigned int plane,
                std::ofstream * stream)
{
    if (dmabuf_fd <= 0)
        return -1;

    int ret = -1;
    NvBufferParams parm;
    ret = NvBufferGetParams(dmabuf_fd, &parm);

    if (ret != 0)
        return -1;


    printf("############ parm.pixel_format=%d,pitch=%d,width=%d,height=%d\n",parm.pixel_format,parm.pitch[plane],parm.width[plane],parm.height[plane]);


    void *psrc_data;

    ret = NvBufferMemMap(dmabuf_fd, plane, NvBufferMem_Read_Write, &psrc_data);
    if (ret == 0)
    {
        unsigned int i = 0;
        NvBufferMemSyncForCpu(dmabuf_fd, plane, &psrc_data);
        for (i = 0; i < parm.height[plane]; ++i)
        {
            if(parm.pixel_format == NvBufferColorFormat_NV12 &&
                    plane == 1)
            {
                stream->write((char *)psrc_data + i * parm.pitch[plane],
                                parm.width[plane] * 2);
                if (!stream->good())
                    return -1;
            }
            else
            {
                stream->write((char *)psrc_data + i * parm.pitch[plane],
                                parm.width[plane]);
                if (!stream->good())
                    return -1;
            }
        }
        NvBufferMemUnMap(dmabuf_fd, plane, &psrc_data);
    }

    return 0;
}

hi,now I can use dump_dmabuf save the data in stream file,but how can I save the data in buffer ? are you have a function ?

Hi,
For copying to another NvBuffer, you can call

/**
 * This method is used to transform one DMA buffer to another DMA buffer.
 * It can support transforms for copying, scaling, fliping, rotation and cropping.
 * @param[in] src_dmabuf_fd DMABUF FD of source buffer
 * @param[in] dst_dmabuf_fd DMABUF FD of destination buffer
 * @param[in] transform_params transform parameters
 *
 * @return 0 for sucess, -1 for failure.
 */
int NvBufferTransform (int src_dmabuf_fd, int dst_dmabuf_fd, NvBufferTransformParams *transform_params);

Is it resolved? I also want to get the original data.

Hi @qodlsrud20712
You can try NvBuffer APIs. Please check

/usr/src/jetson_multimedia_api/include/nvbuf_utils.h

If you hit issues in is using the APIs, please create new topics.