htmlhtml5-videowatson-studiomatplotlib-animation

visualise html video with matplotlib animation


In my notebook I get some data from URL, perform some analysis and do some plotting.
I want also create a html animation using FuncAnimation of matplotlib.animation. So in the preamble I do

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

(something else... def init()..., def animate(i)...) then

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

To visualise, I then call

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

link = anima.to_html5_video()

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

because I want the clip to show up as a neat html video in the notebook

Whereas this works well on my machine, on Watson-Studio I get the following error:

RuntimeError: Requested MovieWriter (ffmpeg) not available

I've checked that ffmpeg is available in the form of a Python package
(!pip freeze --isolated | grep ffmpeg gives ffmpeg-python==0.2.0)

The question is: how can I tell matplotlib.animation.writers to use the codec in ffmpeg-python?

Many thanks to all responders and supporters


Solution

  • We currently don't have ffmpeg pre-installed in Watson Studio on Cloud. The package ffmpeg-python that you mention is just a Python wrapper, but it won't work without the actual ffmpeg.

    You can install ffmpeg from conda:

    !conda install ffmpeg
    

    Once you have the full list of additional packages that your notebook needs, I recommend to create a custom environment. Then you don't have to put install commands into the actual notebook.

    The customization might look like this:

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