JPNotADragon
JPNotADragon

Reputation: 2230

Using video frame decoded by FFMPEG via CUDA as texture or image from OpenGL

Using the example provided here, I was able to get FFMPEG to decode an HEVC encoded video via CUDA (as evidenced by Task Manager showing me that my test program is using 75% of the GPU).

I would like to go one step further and display those frames directly from the GPU - it would be a pity having to download them to the CPU (as the above sample code does) just to re-upload them to the GPU as OpenGL textures, especially since the conversion from YUV to RGB is also more efficient on the GPU (and I already have a shader doing that).

EDIT: to clarify what I'm trying to do, here is the list of decoding devices reported by FFMPEG via avcodec_get_hw_config() and av_hwdevice_get_type_name:

Hardware configurations:
0: Device Type: dxva2
1: Device Type: (none)
2: Device Type: d3d11va
3: Device Type: cuda

As talonmies has pointed out in the comments, that last one is actually misnamed, the decoding is not done via CUDA computing but with dedicated hardware (SIP) on the GPU chip. There is no doubt however that that is the device I need to use, though it would be more properly designated as "NVDEC".

EDIT #2: looking through the FFMPEG source code file responsible for decoding via NVDEC, cuviddec.c, it appears that there is no optionthat would prevent the unnecessary copy from device (GPU) memory to host (CPU) memory. That means I will most probably have to program against the NVDEC API myself.

Upvotes: 3

Views: 1420

Answers (1)

kevinkiller
kevinkiller

Reputation: 11

Looking at the example cuda-samples/3_Imaging/cudaDecodeGL/ImageGL.cpp you'll see it using the CUDA API for mapping an OpenGL PBO as a CUDA buffer object (cuGLRegisterBufferObject or cuGraphicsGLRegisterBuffer) and then another CUDA API (cuGLMapBufferObject) to make the PBO memory available for CUDA processing.

Unfortunately searching the FFMPEG source code for any of these function returns no results.

Upvotes: 1

Related Questions