need to encode directly from OpenCV::cuda::GpuMat

I want to compress the contents of an OpenCV::cuda::GpuMat to H264. I don’t know much about OpenCV’s cuda::GpuMat class, but I know it allocates and uses cuda GPU memory buffers, and you can do all sorts of nifty cuda operations on them. I’d like to compress from one of these buffers to H264, but when I try to “map” or “register” the GpuMat to allow the encoder to use it directly, I get lost, and nothing seems to work. Calling NvEncRegisterResource( ), passing in NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR gives a return code of “device missing” or something like that. I don’t know what a “CudaDevicePtr” is, but I would guess it’s a pointer to cuda memory. But then, maybe not, the docs don’t specify.

One of the things that annoys me about OpenCV’s cuda::GpuMat is that it’s nothing more than a Gpu byte *, you can’t tell anything else about the class, as far as I can tell. I don’t know which video card it was allocated upon, or any other information about it at all.

Also, OpenCV allows one to “map” a DirectX texture to a “cudaGraphicsResource”, but I can’t figure out what a “cudaGraphicsResource” is useful for, or what it’s good for. My idea would be to try to find a way to allocate a DirectX texture, get a pointer to its Gpu bits on the NVidia card (by mapping/registering it with cuda?), then ALSO register this buffer with the encoder SDK. But, I have no idea how to create an OpenCV GpuMat on that buffer/texture so I can do the pre-encode buffer operations in OpenCV/Cuda! This is a mess.

can anybody offer some advice? I know this is poorly described.

LOVE the abundance of help on this one, the lengthy replies, the community effort… Thanks!

Hello,

I am looking for a technical resource that can assist you.
Thanks for your patience.

Best,
Tom

Hello,

The person that can best assist you is currently out of the office. He is aware of this forum topic and will get back to you as soon as he returns.

Best,
Tom

Hello,

I am facing same issue and I want to compress the contents of an OpenCV::cuda::GpuMat to H265.
Can you please provide API interface for the same?

Thanks
Kailash

OpenCV GpuMat implementation uses a CUdeviceptr for its storage. That class has an element data which is a CUdeviceptr, so this can be used directly for registering with NVENCAPI. Is it possible for you to share the problematic sample implementation with us?