0

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

andrea
  • 525
  • 1
  • 5
  • 21

1 Answers1

0

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
Roland Weber
  • 1,865
  • 2
  • 17
  • 27
  • Thank you for answering @Roland. Given that I'm also upgrading locally some Python packages (issuing `!pip install --user --upgrade pandas`) is it possible to do it once for all, instead of during it at each execution of the notebook? I am planning to share the URL of this notebook and set a job. Thank you – andrea May 27 '20 at 09:03
  • You cannot do it once. But if you create a customization to run your notebook with, the packages will automatically be installed when you start the _runtime_. You can have multiple notebooks sharing the same runtime, and restarting a kernel will keep using the same runtime. So the installation frequency can be reduced to once a day or so. – Roland Weber May 27 '20 at 13:48