使用套接字/内存而不是文件解码Cuda中的视频 [英] Decode video in Cuda using a socket / memory instead of a file

查看:938
本文介绍了使用套接字/内存而不是文件解码Cuda中的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆