Log in

View Full Version : How to use GPU decoding 264 stream, any open source code?


l35633
7th May 2015, 10:17
hello,every dear friend!

I want to use GPU to decode 264 stream encoded by x264 library, I wonder if there is any open source code for GPU decoding 264 stream?

Any idea?

Thank you very much!
Best regards

captainadamo
7th May 2015, 18:51
LAVFilters.

LoRd_MuldeR
7th May 2015, 19:31
The so-called "GPU decoding" almost always does not actually run on the GPU, but uses a dedicated hardware H.264 decoder (i.e. a separate piece of silicon) that just happens to be integrated with the GPU. This has the important consequence that you do not need to write your own GPU shader/kernel code for H.264 decoding (e.g. via CUDA or OpenCL), since the "programmable" part of the GPU is not even used. Instead, you just use the "hardwired" H.264 decoding routines that already are burnt into the silicon. And you can use the hardware H.264 decoder via standard programming interfaces, such as DXVA, CUVID or VDPAU. So it's the DXVA, CUVID or VDPAU SDK that you need to look into for code samples, I suppose...

l35633
24th May 2015, 10:46
The so-called "GPU decoding" almost always does not actually run on the GPU, but uses a dedicated hardware H.264 decoder (i.e. a separate piece of silicon) that just happens to be integrated with the GPU. This has the important consequence that you do not need to write your own GPU shader/kernel code for H.264 decoding (e.g. via CUDA or OpenCL), since the "programmable" part of the GPU is not even used. Instead, you just use the "hardwired" H.264 decoding routines that already are burnt into the silicon. And you can use the hardware H.264 decoder via standard programming interfaces, such as DXVA, CUVID or VDPAU. So it's the DXVA, CUVID or VDPAU SDK that you need to look into for code samples, I suppose...

Thank you very much!
Now I wonder if I can decode 8bit/10bit 264 encoded data by "NVIDIA VIDEO CODEC SDK" as shown below link, would you please give me some great advices? Thank you very much!
https://developer.nvidia.com/nvidia-video-codec-sdk

:)

nevcairiel
24th May 2015, 11:37
Thank you very much!
Now I wonder if I can decode 8bit/10bit 264 encoded data by "NVIDIA VIDEO CODEC SDK" as shown below link, would you please give me some great advices? Thank you very much!
https://developer.nvidia.com/nvidia-video-codec-sdk

:)

You cannot, that SDK is for encoding video.
Decoding is done through NVCUVID, which is part of the CUDA Toolkit (https://developer.nvidia.com/cuda-toolkit)

l35633
26th May 2015, 08:20
You cannot, that SDK is for encoding video.
Decoding is done through NVCUVID, which is part of the CUDA Toolkit (https://developer.nvidia.com/cuda-toolkit)

Did you mean that if I use NVCUVID as you referred, I can decode 264 8bit/10bit data directly by API from GPU?

Thank you very much!

nevcairiel
26th May 2015, 08:50
Only 8-bit, 10-bit decoding for H264 is not supported by hardware.

l35633
27th May 2015, 07:48
Only 8-bit, 10-bit decoding for H264 is not supported by hardware.

Thank you very much!

Another question is which one is better between LAV Filters and NVCUVID through CUDA Toolkit.
Would you please give more advices?
Thank you very much!

Asmodian
27th May 2015, 22:27
LAV Filters is a finished implementation of NVCUVID through CUDA Toolkit, it is well tested so if all you need is a direct show filter to implement CUVID, LAV is already available.

LAV also has DXVA2 support, so it works on AMD or Intel GPUs as well. It also has software decoding to fall back to if the format is not compatible with hardware decoding.

Better depends on what you want it to do and how you are implementing it. If you want CUVID decoding integrated into your own application and don't care about DXVA2 or software decoding using the CUDA Toolkit will give you more control but would be more work.

stax76
27th May 2015, 22:44
Maybe he wants to build a AviSynth or VapourSynth plugin. :)

l35633
28th May 2015, 08:06
LAV Filters is a finished implementation of NVCUVID through CUDA Toolkit, it is well tested so if all you need is a direct show filter to implement CUVID, LAV is already available.

LAV also has DXVA2 support, so it works on AMD or Intel GPUs as well. It also has software decoding to fall back to if the format is not compatible with hardware decoding.

Better depends on what you want it to do and how you are implementing it. If you want CUVID decoding integrated into your own application and don't care about DXVA2 or software decoding using the CUDA Toolkit will give you more control but would be more work.

Thank you very much! What I only wan to do is to decode the 264 stream with GPU in my own programm, so as what you said, CUDA Toolkit is a better option?
Thank you!

Asmodian
28th May 2015, 12:26
Thank you very much! What I only wan to do is to decode the 264 stream with GPU in my own programm, so as what you said, CUDA Toolkit is a better option?
Thank you!

Yes, but remember CUDA is Nvidia only.

l35633
2nd June 2015, 11:19
hi, now I want to use the GTX980 to decode 264, then there is a decoding sample named cudaDecodeGL in CUDA samples, there is no error when making.
When I ran cudaDecodeGL, the error showed below, why is it, would you please give me some advices? Thank you very much!

> Device 0: < GeForce GTX 980 >, Compute SM 5.2 detected
>> initGL() creating window [1280 x 720]
MapSMtoCores for SM 5.2 is undefined. Default to use 128 Cores/SM
> Using CUDA/GL Device [0]: GeForce GTX 980
> Using GPU Device: GeForce GTX 980 has SM 5.2 compute capability
Total amount of global memory: 4095.3125 MB
>> modInitCTX<NV12ToARGB_drvapi64.ptx > initialized OK
>> modGetCudaFunction< CUDA file: NV12ToARGB_drvapi64.ptx >
CUDA Kernel Function (0x027f5940) = < NV12ToARGB_drvapi >
>> modGetCudaFunction< CUDA file: NV12ToARGB_drvapi64.ptx >
CUDA Kernel Function (0x027f3050) = < Passthru_drvapi >
cuvidCtxLockCreate failed: 100
cudaDecodeGL: videoDecodeGL.cpp:1039: void initCudaVideo(): Assertion `0' failed.
Aborted (core dumped)


// and the function source code is below
void
initCudaVideo()
{
// bind the context lock to the CUDA context
CUresult result = cuvidCtxLockCreate(&g_CtxLock, g_oContext);

if (result != CUDA_SUCCESS)
{
printf("cuvidCtxLockCreate failed: %d\n", result);
assert(0);
}

size_t totalGlobalMem;
size_t freeMem;

cuMemGetInfo(&freeMem,&totalGlobalMem);
printf(" Free memory: %4.4f MB\n", (float)freeMem/(1024*1024));

std::auto_ptr<VideoDecoder> apVideoDecoder(new VideoDecoder(g_pVideoSource->format(), g_oContext, g_eVideoCreateFlags, g_CtxLock));
std::auto_ptr<VideoParser> apVideoParser(new VideoParser(apVideoDecoder.get(), g_pFrameQueue, &g_oContext));
g_pVideoSource->setParser(*apVideoParser.get());

g_pVideoParser = apVideoParser.release();
g_pVideoDecoder = apVideoDecoder.release();

// Create a Stream ID for handling Readback
if (g_bReadback)
{
checkCudaErrors(cuStreamCreate(&g_ReadbackSID, 0));
checkCudaErrors(cuStreamCreate(&g_KernelSID, 0));
printf(">> initCudaVideo()\n");
printf(" CUDA Streams (%s) <g_ReadbackSID = %p>\n", ((g_ReadbackSID == 0) ? "Disabled" : "Enabled"), g_ReadbackSID);
printf(" CUDA Streams (%s) <g_KernelSID = %p>\n", ((g_KernelSID == 0) ? "Disabled" : "Enabled"), g_KernelSID);
}
}

videoh
2nd June 2015, 14:05
The error is telling you that no CUDA device is detected. Give your platform details, driver version, and CUDA toolkit version.

Is your main display running off the card? Are you using remote access to the machine?

l35633
3rd June 2015, 10:10
The error is telling you that no CUDA device is detected. Give your platform details, driver version, and CUDA toolkit version.

Is your main display running off the card? Are you using remote access to the machine?

The version info is below:
Ubuntu 14.04.2 LTS

CUDA 6.5
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2011 NVIDIA Corporation
Built on Thu_Jan_12_14:41:45_PST_2012
Cuda compilation tools, release 4.1, V0.2.1221

NVIDIA Driver Version:346.35

And I am running in the local machine not remote way.
Maybe CUDA version is too old for GeForce GTX 980 ?
Need your advices again!
Thank you very much!

videoh
3rd June 2015, 15:12
Toolkit 6.5 should be fine.

I don't do linux so can't help you directly, but I found this following link where a guy has the same problem and gets a working solution.

https://devtalk.nvidia.com/default/topic/807712/linux-gtx-980-cuda-6-5-gpu-undetected/

Surely worth a try.

l35633
4th June 2015, 10:11
Toolkit 6.5 should be fine.

I don't do linux so can't help you directly, but I found this following link where a guy has the same problem and gets a working solution.

https://devtalk.nvidia.com/default/topic/807712/linux-gtx-980-cuda-6-5-gpu-undetected/

Surely worth a try.

Thank you very much! It worked after I installed the newest CUDA_toolkit 7.0 version.