问题描述
在MacBook下pyCharm的Terminal使用
pip install moviepy
后,运行一段测试代码:
# coding: utf-8
from moviepy.editor import *
video = VideoFileClip("0.mp4")
result = CompositeVideoClip([video])
result.write_videofile("new.mp4")
发现提示错误:
Imageio: 'ffmpeg-osx-v3.2.4' was not found on your computer; downloading it now.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>.
Traceback (most recent call last):
File "test_ffmpeg.py", line 3, in <module>
from moviepy.editor import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/moviepy/editor.py", line 30, in <module>
imageio.plugins.ffmpeg.download()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/imageio/plugins/ffmpeg.py", line 79, in download
get_remote_file(fname=fname, directory=directory, force_download=force_download)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/imageio/core/fetching.py", line 130, in get_remote_file
_fetch_file(url, filename)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/imageio/core/fetching.py", line 189, in _fetch_file
% os.path.basename(file_name)
IOError: Unable to download 'ffmpeg-osx-v3.2.4'. Perhaps there is a no internet connection? If there is, please report this problem.
根据提示逐个文件进行回溯,发现是因为imageio需要实时下载ffmpeg,但是该链接时常断掉,所以程序认为现在没网。
问题解决
事情变得明朗,我们只需要找到ffmpeg-osx-v3.2.4
是从哪里下载到哪里的,然后手动操作一次即可。
找到ffmpeg的资源:ffmpeg in github
在目录下找到需要的文件:ffmpeg-osx-v3.2.4
,下载到本地。
现在我们需要知道Macbook下应该把这个文件放到哪里,才能使得imageio
找到它并进行下一步操作。
根据错误提示,逐个回溯文件,到达fetching.py,发现
def _fetch_file(url, file_name, print_destination=True):
print(
"Imageio: %r was not found on your computer; "
"downloading it now." % os.path.basename(file_name)
)
这里会输出文件错误的信息,可见file_name
即为我们所需要的下载到本地的文件路径。修改代码:
def _fetch_file(url, file_name, print_destination=True):
print(
"Imageio: %r was not found on your computer; "
"downloading it now.\n %r"
% (os.path.basename(file_name), file_name)
)
再次运行测试代码(见上文),获取到本地的文件路径,把我们下载的ffmpeg-osx-v3.2.4
复制到对应目录:
cp -R /Users/_your_account_/Downloads/ffmpeg-osx-v3.2.4 /Users/_your_account_/Library/Application\ Support/imageio/ffmpeg/
再次运行测试代码,可以看到成功了。