简体   繁体   English

将FFMPEG的GPU版本编译为OpenCV

[英]Compile the GPU version of FFMPEG to OpenCV

When I try to use GPU FFMPEG on opencv by using a command like: 当我尝试通过以下命令在opencv上使用GPU FFMPEG时:

VideoCapture cap("rtsp link");

for(;;)
{
mat frame;
cap>>frame;
}

I don't see any output on nvidia-smi despite compiling the GPU version of FFMPEG. 尽管编译了FFMPEG的GPU版本,我在nvidia-smi上看不到任何输出。

I am trying to get FFMPEG to use GPU to improve the speed of my program. 我正在尝试让FFMPEG使用GPU来提高程序速度。 I got FFMPEG from cloning this and followed the steps here to get it working. 我从克隆得到FFMPEG 和遵循的步骤在这里得到它的工作。

I have validated the results using nvidia-smi dmon -i 0 and have seen that dec% increases when I run the command ffmpeg -c:v h264_cuvid -i test_video.mp4 test_output.mkv . 我已经使用nvidia-smi dmon -i 0验证了结果,并且看到当我运行命令ffmpeg -c:v h264_cuvid -i test_video.mp4 test_output.mkv时, dec%增加。

I then compiled Opencv to use the GPU enabled FFMPEG, I check this by running getBuildInformation from opencv: 然后,我编译Opencv以使用启用了GPU的FFMPEG,我通过从opencv运行getBuildInformation进行检查:

Video I/O: 
DC1394 1.x: NO 
DC1394 2.x: YES (ver 2.2.4) 
FFMPEG: YES 
codec: YES (ver 58.20.103) 
format: YES (ver 58.17.100) 
util: YES (ver 56.18.102) 
swscale: YES (ver 5.2.100) 
resample: NO 
gentoo-style: YES 
GStreamer: NO 
OpenNI: NO 
OpenNI PrimeSensor Modules: NO 
OpenNI2: NO 
PvAPI: NO 
GigEVisionSDK: NO 
UniCap: NO 
UniCap ucil: NO 
V4L/V4L2: NO/YES 
XIMEA: NO 
Xine: NO 
gPhoto2: NO

I cross-verify that I'm using the same ffmpeg (by checking the version numbers): 我通过使用相同的ffmpeg交叉验证(通过检查版本号):

ffmpeg version N-91273-g67747c8 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 20.101 / 58. 20.101
  libavformat    58. 17.100 / 58. 17.100
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 25.100 /  7. 25.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100

Please advise me on how I should compile OpenCV to use the GPU version of FFMPEG. 请告诉我如何编译OpenCV以使用FFMPEG的GPU版本。 Thank you! 谢谢!

Not strictly FFmpeg related, but as an advise for you to be able to use hugely performant GPU capabilities through OpenCV API. 与FFmpeg无关,但建议您通过OpenCV API使用性能卓越的GPU功能。

Assuming that you use OpenCV 3.xx - you should use special OpenCV GPU Api for video decoding. 假设您使用的是OpenCV 3.xx,则应使用特殊的OpenCV GPU Api进行视频解码。 Take a look on this example from official documentation: 从官方文档中查看以下示例:

Also, foreseeing the problems with compilation and running the code with modern OpenCV 3.4.1 and >=CUDA 9.0, read through my comment on OpenCV's issue tracker to overcome those: 另外,预见到使用现代OpenCV 3.4.1和> = CUDA 9.0进行编译和运行代码的问题,请阅读我对OpenCV的问题跟踪器的评论以克服这些问题:

And also yes - it will give you huge speed-up on video decoding/reading. 而且是的-它可以为您提供极大的视频解码/读取速度。 Absolutely worth trying. 绝对值得尝试。

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

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