在macOS上安装ffmpeg以便用于MoviePy失败,出现SSL错误。

7

我正在尝试编写一个Python程序,在Mac OS 10.11.16上使用MoviePy将MP4文件转换为GIF。我使用以下命令:

import moviepy.editor as mp

我遇到了一个错误,提示我需要调用imageio.plugins.ffmpeg.download()来下载FFmpeg。我的代码如下:

import imageio
imageio.plugins.ffmpeg.download()

这导致了以下错误:

Imageio: 'ffmpeg.osx' was not found on your computer; downloading it now.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>.
Error while fetching file: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>.
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    imageio.plugins.ffmpeg.download()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/imageio/plugins/ffmpeg.py", line 55, in download
    get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/imageio/core/fetching.py", line 121, in get_remote_file
    _fetch_file(url, filename)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/imageio/core/fetching.py", line 177, in _fetch_file
    os.path.basename(file_name))
OSError: Unable to download 'ffmpeg.osx'. Perhaps there is a no internet connection? If there is, please report this problem.

我肯定有互联网连接。我找到了这个链接,并尝试使用Homebrew和静态构建进行安装,但都没有成功。似乎自己编译对我来说有点太高级了(我只是简单地研究了一下)。我在IDLE上使用了imageio.plugins.ffmpeg.download()。我读到过使用PyCharm运行MoviePy代码的方法,但我得到了相同的初始错误。ffmpeg目前位于我的/usr/local/bin文件夹中。欢迎任何建议。感谢您的帮助。
编辑:我正在使用Python 3.6.1

尝试在imageio的GitHub问题跟踪器上报告它? - Tom Burrows
1
如果我的解决方案能够帮助到您,我会很高兴如果您能接受该解决方案作为答案。 - whiletrue
3个回答

12

我通过调试提取脚本,找到了macOS的解决方法:

  1. 手动下载构建文件(这是出现SSL错误的地方): https://github.com/imageio/imageio-binaries/raw/master/ffmpeg/ffmpeg-osx-v3.2.4

  2. 将文件粘贴到路径:/Users/yourusername/Library/Application\ Support/imageio/ffmpeg/

  3. 重新运行您的代码

未解决我的问题的方法:

  • 使用pip升级moviepy,然后通过导入movie.editor来提示下载ffmpeg
  • 明确导入imageio并执行imageio.plugins.ffmpeg.download()
  • brew install ffmpeg

第二步,如何将文件粘贴到路径中? - user7345804
1
抱歉回复晚了。很遗憾这对我不起作用。我得到的错误与我的原始帖子中相同。但是,我真的很感谢你抽出时间尝试这个。 - shmible
@MPath,在终端中使用命令“mv源目标”(在聚光灯中键入“终端”以打开终端) - whiletrue

3
我能够使用类似于Bill Bell的解决方案来解决这个问题。首先,请确保您的系统上实际安装了ffmpeg,方法是运行brew install ffmpeg。然后,运行which ffmpeg应该返回像/usr/local/bin/ffmpeg这样的内容。
正如Bill所建议的那样,在执行Python代码之前添加FFMPEG_BINARY = "/usr/local/bin/ffmpeg"或者可以选择添加:
import os    
os.environ["FFMPEG_BINARY"] = "/usr/local/bin/ffmpeg"

在你的代码中,这些在我的机器上都可以正常工作。


1
我提醒你,我对Mac OS一无所知。但是这里有一个可能性。
在moviepy文件夹下的config_defaults.py文件中查找(在Linux和Windows上),可以设置某些可执行文件的位置。
添加以下行:
FFMPEG_BINARY = "/usr/local/bin/ffmpeg.osx"

将光标移至文件底部,我假设ffmpeg.osx是您的FFMPEG可执行文件的名称。


很遗憾,我无法使用你的方法使其工作。不过,我感谢你的建议。 - shmible

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接