77

Under Linux, I've been checking out matplotlib's animation class, and it seems to work except that I cant initialise the movie writer to write out the movie.

Using either of the examples:

results in the error "RuntimeError: No MovieWriters available!"

Im using matplotlib version 1.3.x and have installed (hopefully) all the codecs.

Can someone please suggest as to why I get this error? If its a codecs issue, which codecs (+versions) should I install? If its something else that's broken, is there an alternative for creating animations in python?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Paradise
  • 1,408
  • 1
  • 14
  • 25

10 Answers10

118

For fellow googlers using Anaconda, install the ffmpeg package:

conda install -c conda-forge ffmpeg

This works on Windows too.

(Original answer used menpo package owner but as mentioned by @harsh their version is a little behind at time of writing)

fiat
  • 15,501
  • 9
  • 81
  • 103
  • worked for me too. Installed it from within Pycharm and was then able to use Writer = animation.writers['ffmpeg'] without any further action. – Johan Jan 21 '20 at 11:00
  • 1
    I installed this but matplotlib was unable to find it. Am I missing something? – steven Jul 10 '20 at 22:46
  • Is there a pip install option? – CromeX Sep 15 '20 at 11:08
  • 2
    This is gold! If not working pls try `plt.rcParams['animation.ffmpeg_path'] = 'yourhomepath/anaconda2/envs/yourenv/bin/ffmpeg' `! – ABCMOONMAN999 Jan 04 '21 at 04:50
  • This works great with Anaconda. @steven, just make sure its installed in the same environment if you have one. – Hummer Sep 11 '21 at 23:23
54

Had the same problem....managed to get it to work after a little while.

Thing to do is follow instructions on installing FFmpeg - which is (at least on windows) a bundle of executables you need to set a path to in your environment variables

http://www.wikihow.com/Install-FFmpeg-on-Windows

Download from ffmpeg.org

Hope this helps someone - even after a while after the question - good luck

greybeard
  • 2,249
  • 8
  • 30
  • 66
JPH
  • 1,224
  • 2
  • 14
  • 21
  • I'm running Linux. I formatted and forgot all about this question. However, to close the question, I re-installed FFmpeg and it works now (tested on Ubuntu 10.04, 10.10 and 12.04). So I would assume there was something that didn't get installed the first time around – Paradise Jan 29 '13 at 07:57
  • 1
    Also make sure you have an up-to-date install of matplotlib. I resolved this after I updated from an older version (I was running 1.2.1). – kjgregory Dec 21 '14 at 04:59
  • 2
    ImageMagick installer for windows will provide ffmpeg, and it's easier to install. – RubenLaguna Feb 06 '16 at 07:44
  • 1
    FFmpeg got a new home for libraries. [https://www.ffmpeg.org/](https://www.ffmpeg.org/) – Tirtha R Feb 28 '18 at 06:06
  • ``choco install ffmpeg`` works for me on windows. God bless package managers! – A.King Dec 28 '21 at 21:24
30

I know this question is about Linux, but in case someone stumbles on this problem on Mac like I did here is the solution for that. I had the exact same problem on Mac because ffmpeg is not installed by default apparently, and so I could solve it using:

brew install yasm
brew install ffmpeg
patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
  • 1
    i tried this and made sure ffmpeg was installed. Still get the same error. – Kai Feb 24 '17 at 16:24
  • @Kai is ffmpeg installed using `brew`? – patapouf_ai Mar 22 '17 at 09:44
  • 1
    I am using Anaconda and conda, so I used conda install -c menpo ffmpeg=3.1.3 and I also had to: sudo ln -s /opt/local/bin/ffmpeg /usr/bin/ffmpeg and this actually worked on my macbook (10.11.2). – Kai Mar 23 '17 at 16:37
  • 1
    @patapouf_ai: yes, brew didn't work for me since I am using anaconda/conda. condo install as my comment above worked. – Kai Mar 23 '17 at 19:41
  • This works for Mac OS X using python virtual environments. – Kyle Swanson Oct 05 '18 at 14:46
14

Had the same problem under Linux. By default the animate.save method is using ffmpeg but it seems to be deprecated. https://askubuntu.com/questions/432542/is-ffmpeg-missing-from-the-official-repositories-in-14-04

Solution: Install some coder, like avconv or mencoder. Provide the alternative coder in the call:

ani.save('the_movie.mp4', writer = 'mencoder', fps=15)
Community
  • 1
  • 1
Tapio
  • 141
  • 1
  • 2
7

If you are using Ubuntu 14.04 ffmpeg is not available. You can install it by using the instructions directly from https://www.ffmpeg.org/download.html.

In short you will have to:

sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install ffmpeg gstreamer0.10-ffmpeg

If this does not work maybe try using sudo apt-get dist-upgrade but this may broke things in your system.

Heberto Mayorquin
  • 10,605
  • 8
  • 42
  • 46
6

I had the following error while running the cell. enter image description here

This may be due to not having ffmpeg in your system. Try the following command in your terminal.

sudo apt install ffmpeg

This works for me. I hope it will work out for you too.

Nisan Chhetri
  • 339
  • 3
  • 3
2

I'm running Ubuntu 20 and I had a similar problem

Installed ffmpeg

pip install ffmpeg

then

sudo apt install ffmpeg

Fush
  • 2,469
  • 21
  • 19
0

(be sure to follow JPH feedback above about the proper ffmpeg download) Not sure why, but in my case here is the one that worked (in my case was on windows).

Initialize a writer:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
Writer = animation.FFMpegWriter(fps=30, codec='libx264')  #or 
Writer = animation.FFMpegWriter(fps=20, metadata=dict(artist='Me'), bitrate=1800) ==> This is WORKED FINE ^_^

Writer = animation.writers['ffmpeg'] ==> GIVES ERROR ""RuntimeError: Requested MovieWriter (ffmpeg) not available""

HassanSh__3571619
  • 1,859
  • 1
  • 19
  • 18
0

If error "MovieWriter imagemagick unavailable; using Pillow instead." pops up, try to import PillowWriter explicitly to save as mp4-File by:

from matplotlib.animation import FuncAnimation, PillowWriter
0

Use this command pip install ffmpeg