How i can get the dma data(YUV420M),and tranlate to NvBuffer StructData?

I have read all the examples in the Tegra_multimedia_api.
I have a question ,How get the dma(YUV420DATA) data .

the sample 12:
STEP1: I got preprebuffer about dmabuffer in function “prepare_buffers”

STEP2: use the “start_capture” we can get YUV422 file.


        NvBufferMemSyncForDevice(ctx->g_buff[v4l2_buf.index].dmabuff_fd, 0,
                                 (void **) &ctx->g_buff[v4l2_buf.index].start);

        // Convert the camera buffer from YUV422 to YUV420P
        if (-1 == NvBufferTransform(ctx->g_buff[v4l2_buf.index].dmabuff_fd, ctx->render_dmabuf_fd,
            ERROR_RETURN("Failed to convert the buffer");

        cuda_postprocess(ctx, ctx->render_dmabuf_fd);


How can I get data in render_dmabuf_fd,ths video format is YUV420 and how can i translate
to NvBuffer struct ;

I want use the “NvVideoEncoder” to encode video that come form V4L2_DMA.
can you help me ?

    // TODO add multi-planar support
    // Currently it supports only YUV422 interlaced single-planar
    if (-1 == NvBufferMemMap(ctx->g_buff[index].dmabuff_fd, 0, NvBufferMem_Read_Write,
                             (void **) &ctx->g_buff[index].start))
        ERROR_RETURN("Failed to map buffer");

I tried this method, and by virtual mapping, I can get YUV422 data.But it really can’t get YUV420M data.

ctx->render_dmabuf_fd is YUV420M converted from ctx->g_buff[index].dmabuff_fd, so you should map/unmap render_dmabuf_fd.

Thank you ,dear DaneLL,I found a similar method in the sample, referring to sample_00;

    NvBufferParams params;

    NvBufferGetParams(ctx->render_dmabuf_fd, &params);
    // create new ifstream
     ofstream *streamOutput = new ofstream("appYuv420p.yuv");
//         streamOutput->good();

         printf("Error opeing input file\n");
     void *psrc_data;
//     unsigned int plane;
     for(int j=0;jrender_dmabuf_fd,j,NvBufferMem_Read_Write,&psrc_data);
         if(ret == 0)
//             unsigned int i = 0;

             for(int pos=0;poswrite((char*)psrc_data+pos*params.pitch[j],params.width[j]);
//                    streamOutput->
                    printf("stream write failed plane:%d\n",j);
             NvBufferMemUnMap(ctx->render_dmabuf_fd, j, &psrc_data);