学习OpenCV3:Cmake编译OpenCV时无法下载ffmpeg、xfeatures2d等文件


1. 错误描述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
  FFMPEG: Download failed: 6;"Couldn't resolve host name"

  For details please refer to the download log file:

  D:/opencv/bulid_mingw/CMakeDownloadLog.txt

Call Stack (most recent call first):
  3rdparty/ffmpeg/ffmpeg.cmake:20 (ocv_download)
  modules/videoio/cmake/detect_ffmpeg.cmake:14 (download_win_ffmpeg)
  modules/videoio/cmake/init.cmake:3 (include)
  modules/videoio/cmake/init.cmake:22 (add_backend)
  cmake/OpenCVModule.cmake:312 (include)
  cmake/OpenCVModule.cmake:375 (_add_modules_1)
  modules/CMakeLists.txt:7 (ocv_glob_modules)

无法下载opencv_videoio_ffmpeg.dll

2. 分析

??根据错误提示打开D:/opencv/bulid_mingw/CMakeDownloadLog.txt。从中可发现出错的文件夹是D:/opencv/sources/.cache。在D:/opencv/sources/.cache中,凡是文件大小是0KB,都是无法下载并报错的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#use_cache "D:/opencv/sources/.cache"
#match_hash_in_cmake_cache "OCV_DOWNLOAD_ADE_HASH_3rdparty_ade_v0_1_1f_zip"
#do_copy "opencv_videoio_ffmpeg.dll" "3b094c37d270a30f0b20a0bc8d3ecafb" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/opencv_videoio_ffmpeg.dll" "D:/opencv/bulid_mingw/3rdparty/ffmpeg"
#missing "D:/opencv/bulid_mingw/3rdparty/ffmpeg/opencv_videoio_ffmpeg.dll"
#check_md5 "D:/opencv/sources/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll"
#mismatch_md5 "D:/opencv/sources/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll" "d41d8cd98f00b204e9800998ecf8427e"
#delete "D:/opencv/sources/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll"
#cmake_download "D:/opencv/sources/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/opencv_videoio_ffmpeg.dll"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#

错误文件夹

无法下载的文件

3. 解决方法

  1. 打开https://github.com/opencv/opencv_3rdparty,找到正确版本的ffmpeg并下载。若网速太慢或不能下载可以参考学习OpenCV3:解决github下载速度慢的方法(码云)。

opencv_3rdparty

ffmpeg相关文件

  1. 将下载的ffmpeg相关文件拷贝到D:/opencv/sources/.cache中。打开cmd,输入编译命令获取各个文件的MD5。当MD5相同时,用已下载的dll替换对应大小为0KB的dll文件,注意修改文件名,其格式是:MD5-文件名。

拷贝下载的ffmpeg相关文件

1
2
cd /d D:\opencv\sources\.cache\ffmpeg
certutil -hashfile ffmpeg_version.cmake MD5

获取文件的MD5

替换后的ffmpeg相关文件

  1. 同样的,对D:/opencv/sources/.cache大小为0KB的文件进行如上类似操作,最后重新点击Configue,编译便不会报此类错误了。

正确编译结果