Argus to CUDA and H265 Encoding


I have written some code that goes from Argus into CUDA using an EGLStream, and then I also have code that goes from Argus into H265 encoding based on the “frontend” example from the tegra_multimedia_api. However, when I enable both output streams, the CUDA Acquire fails, so it seems that the encoding is blocking CUDA from access. I call for capture requests in Argus, and then in the loop, I call the CUDA consumer.

I have the encoding in a separate thread, so I was wondering if there is another way to do this so that I can put the image into CUDA and encode it. Specifically, the CUDA processing needs to be done at framerate, while the encoding can lag behind if needed. I know that you can something similar using GStreamer, so I was wondering how I can do something related without putting the CUDA processing in a separate thread. I specifically need to use Argus for other reasons, so I cannot use GStreamer.

You should get NvBuffer from Argus, and use below calls to access it via CUDA.

static bool
cuda_postprocess(context_t *ctx, int fd)
    if (ctx->enable_cuda)
        // Create EGLImage from dmabuf fd
        ctx->egl_image = NvEGLImageFromFd(ctx->egl_display, fd);
        if (ctx->egl_image == NULL)
            ERROR_RETURN("Failed to map dmabuf fd (0x%X) to EGLImage",

        // Running algo process with EGLImage via GPU multi cores

        // Destroy EGLImage
        NvDestroyEGLImage(ctx->egl_display, ctx->egl_image);
        ctx->egl_image = NULL;

    return true;

The reference code is in 12_camera_v4l2_cuda


The example you gave me is using V4L2, but not Argus. I need to send the images from Argus into VisionWorks using an EGLStreamKHR, which I already have working. The problem is that the encoding thread is blocking the stream from acquiring the image when running both simultaneously.

After looking at the “denoise” Argus example, I realized that I need an OutputStream for each process, so one for CUDA and one for encoding. It seems to be working at first glance, but if there’s any other way that’s preferable, feel free to post.

cuda_postprocess() is good for Argus also. You can get NvBuffer from Argus and get CUDA pointer for post-processing.