1

I keep getting this error when trying to save my animations in matplotlib:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

plt.rcParams['animation.ffmpeg_path'] = 'C:\FFmpeg\bin'

fig, ax = plt.subplots()
ax.set_xlim(-0.1 ,2*np.pi + 0.1)
ax.set_ylim(-1.1 ,1.1)
ln, = plt.plot([], [], '-')

x = np.linspace(0,2*np.pi,1000)

def update(frame):

    y = frame*np.sin(x)
    ln.set_data(x,y)
    return ln,

ani = FuncAnimation(fig,
                    update,
                    frames=np.linspace(1,-1,1000),
                    interval=1000/144)

ani.save('lol.gif')

MovieWriter ffmpeg unavailable. Trying to use pillow instead.

This is a repetition of an unanswered question: UserWarning: MovieWriter ffmpeg unavailable

I tried running a sample code from here, but it still says ffmpeg isn't available, even though I installed and activated it according to wikihow. So even setting the path to the binary doesn't seem to work.

I can't set the fps or the dpi, or anything since the save function just defaults. What can I do so that python finally starts using ffmpeg?

J.Doe
  • 224
  • 1
  • 4
  • 19
  • Did you see [How do I properly enable ffmpeg for matplotlib.animation?](https://stackoverflow.com/questions/42634997/how-do-i-properly-enable-ffmpeg-for-matplotlib-animation). Once you are sure your `'animation.ffmpeg_path'` rc parameter points to *the executable* (not the folder) you can follow [this example](https://matplotlib.org/3.1.1/gallery/animation/simple_anim.html). – ImportanceOfBeingErnest Aug 20 '19 at 19:03
  • Ok I just tried this: https://stackoverflow.com/questions/23856990/cant-save-matplotlib-animation and now I get a PermissionError. Does this mean I didn't set the environment variables correctly while activating ffmpeg? – J.Doe Aug 20 '19 at 19:18
  • PermissionError would usually mean that you cannot write to a file. Maybe it's still in use, or you cannot write to that folder? Make sure to terminate all processes that could access that file and/or try a different filename or folder. – ImportanceOfBeingErnest Aug 20 '19 at 19:21
  • Ok thanks for the tip with the binary...Why did I think just need the bin folder?! Anyways that worked so far. However I get this message now: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. % get_backend()) I don't really know what to make of this. I just want to save the mp4 so I don't really need to worry about it I guess? – J.Doe Aug 20 '19 at 19:24
  • Correct. However, you should usually only get that warning if you call `plt.show()` – ImportanceOfBeingErnest Aug 20 '19 at 19:26
  • Oh since I'm rendering the animation in a non-native program to mpl, plt.show() won't know how to display it? – J.Doe Aug 20 '19 at 19:38
  • What program is that? – ImportanceOfBeingErnest Aug 20 '19 at 21:17
  • Isn't ffmpeg not native to mpl? Sorry, I try to guess at things a lot. I thought the plt.show() didn't work anymore because it's not some part of mpl creating the animation but some other program (ffmpeg) to which I have to set the path explicitly. – J.Doe Aug 20 '19 at 23:18
  • 1
    ffmpeg is responsible for creating an mp4 (or some other) file from the animation. This is totally independent on whether or not you want to show the animation on screen. The UserWarning is unrelated to saving an animation. But this warning should really only occur if you call `plt.show()` or `plt.draw()`, but maybe you are running this code inside some special environment?! – ImportanceOfBeingErnest Aug 20 '19 at 23:30
  • Oh I didn't mention it? Yes of course I'm calling plt.show(). Sorry for the confusion. I'm using my root env in spyder3 on win10. – J.Doe Aug 20 '19 at 23:34
  • 1
    Ok, so in that case the reason for the warning is that you either have set the backend explicitely to `agg`, or your root environment does not have tkinter or pyqt or any other toolkit installed that would allow to show a GUI. – ImportanceOfBeingErnest Aug 20 '19 at 23:43
  • Aren't those just GUI modules for python though? I think anaconda3 installs those packages by default in the root env. If not, I guess I'll have to find out how to fix that. Thank you very much for your help ^^ – J.Doe Aug 21 '19 at 00:28

0 Answers0