我已经按照说明下载了ffmpeg并根据以下条件添加路径Matplotlib-Animation "No MovieWriters Available"虽然我可以在命令提示符和 Windows 控制台上的 Bash 中键入版本,但心爱的 PyCharm 警告我:
Requested MovieWriter (ffmpeg) not available
当我尝试保存动画时:
ani = anim.FuncAnimation(fig, animate, frames = 14, init_func = init, interval = 500, repeat = False)
plt.show()
ani.save("Inno.mp4", writer=writer)
我必须添加其他路径吗?请帮助我,我真的厌倦了这个错误。
您可以直接指定 ffmpeg 路径,如下所示:
plt.rcParams['animation.ffmpeg_path'] = 'ffmpeg path on your machine' (e.g.: "C:FFmpegbinffmpeg.exe")
或者尝试在 cmd 上调用 FFMPEG,以确保 在 env 变量中正确定义了其路径。
要在确保正确定义路径后获取路径,请在 cmd 中写入:
where ffmpeg
Windows 10:1(打开:蟒蛇提示2(火:康达安装-C康达锻造FFMPEG3( 重新启动环境
为我工作。
我建议以下内容来显示时间 t(例如这里的 3000 毫秒(的模拟,然后在关闭动画之前保存动画,因为代码中的问题是在创建保存之前关闭动画,因此 tk 后端无法在其中找到要绘制的图形。我建议如下:
def close():
animation.save("Inno.mp4", writer='ffmpeg')
plt.close()
timer = fig.canvas.new_timer(interval = 1000)
timer.add_callback(close)
plt.show(block=False)
timer.start()
plt.show()