Printing out a NvBuffer

What is the easiest way to print image data to file from a dmabuf_fd?

I tried getting the CUeglFrame (with NvEGLImageFromFd, register, map, etc) and using ofstream::write with frame.pPitch[0], but my file is always zero bytes.

DEBUG_INFO("writing raw buffer to '%s'", ctx->m_write_path);
std::ofstream file(ctx->m_write_path);
char *data = (char *)egl_frame_in.frame.pPitch[0];

DEBUG_VERBOSE("height: %d pixels", egl_frame_in.height);
DEBUG_VERBOSE("width: %d pixels (%d bytes)", egl_frame_in.width, egl_frame_in.width * sizeof(uchar4));
DEBUG_VERBOSE("pitch: %d bytes", egl_frame_in.pitch);

for(size_t i = 0; i < egl_frame_in.height; ++i) {
    file.write(data, egl_frame_in.width * sizeof(uchar4));
    data += egl_frame_in.pitch;

I’m assuming its some sort of device/cpu memory issue.

Please refer to dump_dmabuf() in 00_video_decode

static int
dump_dmabuf(int dmabuf_fd,
                unsigned int plane,
                std::ofstream * stream);