Dump YUV buffer with libargus

I have wrote a sample to capture yuv image accroding to the sample of oneShot.
Here is the main code:

EGLStream::Image *image = iFrame->getImage();
EXIT_IF_NULL(image, “Failed to get Image from iFrame->getImage()”);
EGLStream::IImageHeaderlessFile *iHeaderlessFile = Argus::interface_castEGLStream::IImageHeaderlessFile(image);
if (!iHeaderlessFile)
EXIT_IF_NULL(iHeaderlessFile,“Devil : --------------------------- Failed to get IImageHeaderlessFile interface.\n”);
status = iHeaderlessFile->writeHeaderlessFile(FILE_PREFIX “devil_yuv.yuv”);
EXIT_IF_NOT_OK(status,“Devil : ---------------------------- faileed to write yuv \n”)
printf("Devil : --------- " FILE_PREFIX “devil_yuv.yuv\n”);

Also,I wanted to dump the yuv buffer as below:

char buf[128];
printf("\n buffer count : %d \n buffer size : %d",iImage->getBufferCount(),iImage->getBufferSize());
int devil_fd = open(buf,O_RDWR|O_CREAT,0777);
int length = write(devil_fd,iImage->mapBuffer(5),12807203/2);
printf(“Devil : fd is null”);

But the buffer I dumped can’t be recognized as a yuv image.Is there any error with my code or process?

Have reference to argus_camera to capture the headless(nv12) files.

I have capture the headless file successfully, but I want to get the yuv buffer not only capture a image.I use the mapbuffer function to get the buffer,but it occurs some question.The buffer I saved to a file couldn’t be recognized as a yuv image.

Have a check the yuvJpeg sample code.

        // Print out some capture metadata from the frame.
        IArgusCaptureMetadata *iArgusCaptureMetadata = interface_cast<IArgusCaptureMetadata>(frame);
        if (!iArgusCaptureMetadata)
            ORIGINATE_ERROR("Failed to get IArgusCaptureMetadata interface.");
        CaptureMetadata *metadata = iArgusCaptureMetadata->getMetadata();
        ICaptureMetadata *iMetadata = interface_cast<ICaptureMetadata>(metadata);
        if (!iMetadata)
            ORIGINATE_ERROR("Failed to get ICaptureMetadata interface.");
        CONSUMER_PRINT("\tSensor Timestamp: %llu, LUX: %f\n",
                       static_cast<unsigned long long>(iMetadata->getSensorTimestamp()),

        // Print out image details, and map the buffers to read out some data.
        Image *image = iFrame->getImage();
        IImage *iImage = interface_cast<IImage>(image);
        IImage2D *iImage2D = interface_cast<IImage2D>(image);
        for (uint32_t i = 0; i < iImage->getBufferCount(); i++)
            const uint8_t *d = static_cast<const uint8_t*>(iImage->mapBuffer(i));
            if (!d)
                ORIGINATE_ERROR("\tFailed to map buffer\n");

            Size2D<uint32_t> size = iImage2D->getSize(i);
            CONSUMER_PRINT("\tIImage(2D): "
                           "buffer %u (%ux%u, %u stride), "
                           "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
                           i, size.width(), size.height(), iImage2D->getStride(i),
                           d[0], d[1], d[2], d[3], d[4], d[5],
                           d[6], d[7], d[8], d[9], d[10], d[11]);

I have print the info as below:
Capturing from device 0 using sensor mode 4 (1280x720)
count : 2
Devil :
count : 0
height : 720
width : 1280
stride : 1280
Devil :
count : 1
height : 360
width : 640
stride : 1280

buffer count : 2

And I saved buffer with iImage->mapbuffer(1) as a yuv file, but I can’t preview normal picture in this file.

Could you please share the source code of WriteHeadlessFile() or tell me how to save yuv image from the buffer?

Please check the sample and do modification:


The default code is

        if (m_dmabuf == -1)
            m_dmabuf = iNativeBuffer->createNvBuffer(iStream->getResolution(),
            if (m_dmabuf == -1)
                CONSUMER_PRINT("\tFailed to create NvBuffer\n");
        else if (iNativeBuffer->copyToNvBuffer(m_dmabuf) != STATUS_OK)
            ORIGINATE_ERROR("Failed to copy frame to NvBuffer.");

Please modify NvBufferLayout_BlockLinear to NvBufferLayout_Pitch and then you can dump the frames with following code:

        char filename[256];

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

        delete outputFile;

I have dumped the buffer successfully.
Thanks a lot.

What does the plane of “1”,“2”,“3” mean?
Is the plane 1 corresponding Y buffer,2 corresponding U buffer and 3 corresponding V buffer?

I use the NvBufferParams to get the num_planes is 3,but I still would like to know what does each plane mean.


Yes, this is correct. For NvBufferColorFormat_YUV420, there are 3 planes, in Y, U, and V planes.

OK,thank u very much.

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