使用套接字/内存而不是文件解码Cuda中的视频 [英] Decode video in Cuda using a socket / memory instead of a file
问题描述
我目前正在尝试使用cuda解码视频。我有cuda示例调用 cudaDecodeD3D9
。此示例使用一个名为 cuvidCreateVideoSource
的方法,该方法接收源视频的文件指针。有没有办法让Cuda从内存/套接字/流加载视频?
结果我不能使用 cuvidCreateVideoSource
方法,而是我可以通过调用 cuvidParseVideoData
直接将每帧数据直接提供给cuda视频解析器。 / p>
这是一个从文件中读取一个帧并将其提供给cuda解析器的示例。该文件是由我通过将每帧的大小写入文件,然后是帧数据创建的。该文件可以很容易地替换为读取套接字:
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;
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?
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;
这篇关于使用套接字/内存而不是文件解码Cuda中的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!