运行时错误:无法在Matplotlib动画中使用MovieWriters。

10
我遇到的问题类似于这个例子中的代码: https://matplotlib.org/examples/animation/basic_example_writer.html 错误信息如下:
在上述示例中,Writer = animation.writers ['ffmpeg'] 时出现“RuntimeError:无可用的MovieWriters”
我正在使用mac,已经使用brew安装了ffmpeg,甚至使用conda安装了它,尽管我没有在此特定代码中使用anaconda。
我确定它已经安装成功-我已经在终端中使用它来更改文件,但它在程序内部无法工作。
谢谢!
3个回答

6
尝试手动指定 ffmpeg 程序的路径,例如:
import matplotlib.pyplot as plt
plt.rcParams['animation.ffmpeg_path'] = '/usr/local/bin/ffmpeg'

您需要在脚本开头放置这些代码行,然后使用动画Writer


你所指的指定程序路径是指我应该指定ffmpeg文件夹的路径还是Unix可执行文件的路径?我都尝试过,但都没有成功。 - user8715977
Bin指的是可执行文件。 - Serenity
哦,非常感谢!!现在行了,问题是我需要把plt.rcParams直接放在import matplotlib.pyplot下面 - 虽然我不知道为什么,你介意解释一下吗? - user8715977
RcParams是设置;在使用matplotlib之前,您必须指定选项。 - Serenity

3

我不确定为什么,但在我的情况下以下方法有效(我的情况是在Windows上)。

初始化一个写入器:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
Writer = animation.FFMpegWriter(fps=30, codec='libx264') # Or 
Writer = animation.FFMpegWriter(fps=20, metadata=dict(artist='Me'), bitrate=1800) ==> This is WORKED FINE ^_^

Writer = animation.writers ['ffmpeg'] ==> 出错,显示“RuntimeError:请求的MovieWriter(ffmpeg)不可用”


0

我发现在我的电脑上 '/usr/local/bin/ffmpeg' 不存在,所以我尝试了这个:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
Writer = animation.writers['pillow']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

对我来说它有效


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