使用 matplotlib 动画可视化 html 视频

visualise html video with matplotlib animation

在我的笔记本中,我从 URL 获取了一些数据,进行了一些分析并做了一些绘图。
我还想使用 matplotlib.animationFuncAnimation 创建一个 html 动画。 所以在序言中我做

import matplotlib.animation as manim
plt.rcParams["animation.html"] = "html5"
%matplotlib inline

(别的东西...def init()..., def animate(i)...) 然后

anima = manim.FuncAnimation(fig, 
                         animate, 
                         init_func=init, 
                         frames=len(ypos)-d0, 
                         interval=200, 
                         repeat=False,
                         blit=True)

为了形象化,我接着调用

FFMpegWriter = manim.writers['ffmpeg']
writer = FFMpegWriter(fps=15)

link = anima.to_html5_video()

from IPython.core.display import display, HTML
display(HTML(link))

因为我希望剪辑在笔记本中显示为整洁的 html 视频

虽然这在我的机器上运行良好,但在 Watson-Studio 上我收到以下错误:

RuntimeError: Requested MovieWriter (ffmpeg) not available

我检查过 ffmpeg 以 Python 包的形式提供
(!pip freeze --isolated | grep ffmpeg 给出 ffmpeg-python==0.2.0)

问题是:如何告诉 matplotlib.animation.writers 使用 ffmpeg-python 中的编解码器?

非常感谢所有响应者和支持者

我们目前没有在 Watson Studio on Cloud 中预安装 ffmpeg。您提到的包 ffmpeg-python 只是一个 Python 包装器,但如果没有实际的 ffmpeg,它就无法工作。

您可以从 conda 安装 ffmpeg:

!conda install ffmpeg

获得笔记本所需的附加包的完整列表后,我建议创建一个 custom environment。那么你就不必将安装命令放入实际的笔记本中了。

自定义可能如下所示:

dependencies:
- ffmpeg=4.2.2
- pip
- pip:
  - ffmpeg-python==0.2.0