Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode video in Cuda using a socket / memory instead of a file

Tags:

c++

sockets

cuda

I am currently trying to decode video using cuda. I have the cuda sample called cudaDecodeD3D9. This sample uses a method called cuvidCreateVideoSource which takes a file pointer to the source video. Is there any way to get Cuda to load video from memory / socket / stream?

like image 209
default Avatar asked Nov 16 '15 20:11

default


1 Answers

Turns out I can't use cuvidCreateVideoSource method at all, but instead I can feed each frame of data directly to the cuda video parser by calling cuvidParseVideoData.

Here's an example of reading one frame from a file and feeding it to the cuda parser. The file was created by me by writing the size of each frame to the file, followed by the frame data. The file can easily be replaced with reading from a socket:

unsigned int size = 0u;
fread( &size, sizeof( unsigned char ), sizeof( unsigned int ), _file );

unsigned char *buf = new unsigned char[size];
fread( buf, sizeof( unsigned char ), size, _file );

CUVIDSOURCEDATAPACKET packet = {};
packet.payload_size = size;
packet.payload = buf;
cuvidParseVideoData( pCudaParser, &packet );

delete [] buf;
like image 103
default Avatar answered Oct 15 '22 23:10

default