问题描述
当我尝试使用 GPU 时使用如下命令在 opencv 上运行 FFMPEG:
When I try to use GPUFFMPEG on opencv by using a command like:
VideoCapture cap("rtsp link");
for(;;)
{
mat frame;
cap>>frame;
}
尽管编译了 FFMPEG 的 GPU 版本,但我在 nvidia-smi 上没有看到任何输出.
I don't see any output on nvidia-smi despite compiling the GPU version of FFMPEG.
我试图让 FFMPEG 使用 GPU 来提高我的程序速度.我通过克隆 this 获得了 FFMPEG 并按照步骤 此处 使其正常工作.
I am trying to get FFMPEG to use GPU to improve the speed of my program. I got FFMPEG from cloning this and followed the steps here to get it working.
我已经使用 nvidia-smi dmon -i 0
验证了结果,并且看到当我运行命令 ffmpeg -c:v 时
.dec%
增加h264_cuvid -i test_video.mp4 test_output.mkv
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
.
然后我编译 Opencv 以使用支持 GPU 的 FFMPEG,我通过从 opencv 运行 getBuildInformation 来检查:
I then compiled Opencv to use the GPU enabled FFMPEG, I check this by running getBuildInformation from opencv:
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
我交叉验证我使用的是相同的 ffmpeg(通过检查版本号):
I cross-verify that I'm using the same ffmpeg (by checking the version numbers):
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
请告诉我应该如何编译 OpenCV 以使用 FFMPEG 的 GPU 版本.谢谢!
Please advise me on how I should compile OpenCV to use the GPU version of FFMPEG. Thank you!
推荐答案
与 FFmpeg 不严格相关,但建议您能够通过 OpenCV API 使用高性能的 GPU 功能.
Not strictly FFmpeg related, but as an advise for you to be able to use hugely performant GPU capabilities through OpenCV API.
假设您使用 OpenCV 3.x.x - 您应该使用特殊的 OpenCV GPU Api 进行视频解码.从官方文档中查看此示例:
Assuming that you use OpenCV 3.x.x - you should use special OpenCV GPU Api for video decoding. Take a look on this example from official documentation:
此外,预见到使用现代 OpenCV 3.4.1 和 >=CUDA 9.0 编译和运行代码的问题,请阅读我对 OpenCV 问题跟踪器的评论以克服这些问题:
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:
而且是的 - 它将为您提供视频解码/阅读的巨大加速.绝对值得一试.
And also yes - it will give you huge speed-up on video decoding/reading. Absolutely worth trying.
这篇关于将GPU版本的FFMPEG编译成OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!