【问题标题】:visualise html video with matplotlib animation使用 matplotlib 动画可视化 html 视频
【发布时间】:2020-09-14 02:55:08
【问题描述】:

在我的笔记本中,我从 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 ffmpegffmpeg-python==0.2.0)

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

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

【问题讨论】:

    标签: html html5-video watson-studio matplotlib-animation


    【解决方案1】:

    我们目前没有在 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
    

    【讨论】:

    • 感谢您回答@Roland。鉴于我还在本地升级了一些 Python 包(发布!pip install --user --upgrade pandas),是否可以一劳永逸地完成它,而不是在每次执行笔记本时执行它?我打算分享这个笔记本的 URL 并设置工作。谢谢
    • 你不能这样做一次。但是,如果您创建一个自定义来运行您的笔记本,则在您启动 runtime 时会自动安装这些包。您可以让多个笔记本共享同一个运行时,并且重新启动内核将继续使用同一个运行时。所以安装频率可以降低到一天一次左右。
    猜你喜欢
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 2021-11-18
    • 2015-09-23
    相关资源
    最近更新 更多