简体   繁体   English

使用套接字/内存而不是文件在Cuda中解码视频

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

I am currently trying to decode video using cuda. 我目前正在尝试使用cuda解码视频。 I have the cuda sample called cudaDecodeD3D9 . 我有一个名为cudaDecodeD3D9的cuda样本。 This sample uses a method called cuvidCreateVideoSource which takes a file pointer to the source video. 此示例使用名为cuvidCreateVideoSource的方法,该方法获取指向源视频的文件指针。 Is there any way to get Cuda to load video from memory / socket / stream? 有没有办法让Cuda从内存/套接字/流加载视频?

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 . 事实证明我根本不能使用cuvidCreateVideoSource方法,但我可以通过调用cuvidParseVideoData将每帧数据直接提供给cuda视频解析器。

Here's an example of reading one frame from a file and feeding it to the cuda parser. 这是一个从文件中读取一帧并将其提供给cuda解析器的示例。 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM