How to acquire frames out of EGLStreamKHR and map to NvBuffer for use in NvVideoEncoder

Hi,

I have a CUDA-based EGLStream producer that needs to connect to a consumer based on NvVideoEncoder. The CUDA producer connects to a EGLStreamKHR that will be provided to the encoder consumer for it to also connect to, but I cannot figure out how to acquire frames out of the EGLStreamKHR stream, and map them to an NvBuffer.

The only examples showing consumers using a EGLStreamKHR are based on GL textures, which seems to have specific calls for mapping EGL frames from the stream to GL and acquiring them, e.g. eglStreamConsumerGLTextureExternalKHR() and eglStreamConsumerAcquireKHR().

The “EGL_KHR_stream - Khronos Group” spec mentions acquiring frames via eglStreamConsumerAcquireAttribKHR(), but is not clear on how to get the actual pointer to the frame. The 10_camera_recording example is helpful, but only covers how to map between Argus::Buffer and NvBuffer, while I am looking for a more generic solution that deals with EGLStreamKHR directly.

Please note that I realize that I can use Gstreamer via nveglstreamsrc to consume the frames, however I would prefer to use NvVideoEncoder directly. Can anyone please explain how to acquire a frame out of an EGLStreamKHR stream and map it to an NvBuffer, so it can be encoded by NvVideoEncoder?

Hi,
It is impossible to map the buffer directly. Need one memcpy through CUDA.
You need to create NvBuffer and get CUDA pointer of destination by calling:

NvEGLImageFromFd();
cuGraphicsEGLRegisterImage();
cuGraphicsResourceGetMappedEglFrame();

,use CUDA consumer APIs to get CUDA pointer of source:

cuEGLStreamConsumerAcquireFrame();
cuGraphicsResourceGetMappedEglFrame();

, and copy source(CUDA consumer) to destination(NvBuffer).