c++ - 将GPU版本的FFMPEG编译为OpenCV

标签 c++ opencv tensorflow video ffmpeg

当我尝试使用 GPU 时
FFMPEG 在 opencv 上使用如下命令:

VideoCapture cap("rtsp link");

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

尽管编译了 FFMPEG 的 GPU 版本,但我在 nvidia-smi 上没有看到任何输出。

我试图让 FFMPEG 使用 GPU 来提高我的程序的速度。我从克隆得到 FFMPEG this并按照步骤here让它工作。

我已经使用 nvidia-smi dmon -i 0 验证了结果并且已经看到 dec%当我运行命令 ffmpeg -c:v h264_cuvid -i test_video.mp4 test_output.mkv 时增加.

然后我编译 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

我交叉验证我使用的是相同的 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

请告诉我应该如何编译 OpenCV 以使用 GPU 版本的 FFMPEG。谢谢!

最佳答案

不严格与 FFmpeg 相关,但建议您能够通过 OpenCV API 使用高性能的 GPU 功能。

假设您使用 OpenCV 3.x.x - 您应该使用特殊的 OpenCV GPU Api 进行视频解码。看看官方文档中的这个例子:

  • https://github.com/opencv/opencv/blob/master/samples/gpu/video_reader.cpp

  • 此外,预见到使用现代 OpenCV 3.4.1 和 >=CUDA 9.0 编译和运行代码的问题,请通读我对 OpenCV 问题跟踪器的评论以克服这些问题:
  • https://github.com/opencv/opencv/issues/10201#issuecomment-402453361

  • 而且是的 - 它会给你视频解码/阅读带来巨大的加速。绝对值得一试。

    关于c++ - 将GPU版本的FFMPEG编译为OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50984383/

    相关文章:

    opencv - 如何删除文档图像中的文本区域?

    google-app-engine - 我可以在 Google App Engine 模块中使用 TensorFlow 吗?

    python - 无法安装库以在Anaconda中打开音频文件

    c++ - 将 int64_t 转换为 int 时,如何让 g++ 发出警告?

    c++ - constexpr std::array with static_assert

    c# - Cv2.CountNonZero返回意外结果

    python - opencv - 将像素从 bgr 转换为 hsv

    python - 尝试导入 Tensorflow 时出现 ModuleNotFoundError

    c++ - 将 const char** 与模板特化结合使用

    c++ - MinGW 下 windows 中的 Protobuf