为了让 ffmpeg 使用 gpu 进行解码, 可以按以下步骤:
1 下载 nvidia 官网提供的 ffmpeg, 编译安装
https://developer.nvidia.com/ffmpeg
注意原来的选项上还需要添加上 --enable-shared
如果出现编译错误
ERROR: cuda requested, but not all dependencies are satisfied: ffnvcodec
参考: https://superuser.com/questions/1299064/error-cuvid-requested-but-not-all-dependencies-are-satisfied-cuda-ffnvcodec
- git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
- make
- sudo make install
2 编译 opencv
可以采用 2.4.13.6
注意会出现报错
error: 'CODEC_FLAG_GLOBAL_HEADER' was not declared in this scope
解决办法参考 https://stackoverflow.com/questions/46884682/error-in-building-opencv-with-ffmpeg
即把以下三行拷贝到 cap_ffmpeg_impl.hpp 开头
- #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
- #define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
- #define AVFMT_RAWPICTURE 0x0020
- ffmpeg+cuda+opencv
来源: http://www.bubuko.com/infodetail-2662324.html