Hi all,
I would like to use matplotlib’s animation API to create a movie that can be embedded into an html5 video tag. To do this, I am following a couple 2012 blog posts from Jake VanderPlas: http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/ and http://jakevdp.github.io/blog/2013/05/12/embedding-matplotlib-animations/
My understanding is that I need to use the x264 codec to do this. Unfortunately, I get a Broken Pipe Error when running the basic example below. I get the same error when calling the animation.to_html5_video() method.
Does anyone have an idea about why I’m getting the Broken Pipe error? Do I really need the x264 codec to embed matplotlib animations into html? Thanks!
Kyle
Example code:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animate
__fig = plt.figure()
ax = plt.axes(xlim = (0, 2), ylim = (-2, 2))
line, = ax.plot([], [], linewidth = 2)
initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
animation function. This is called sequentially
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,
call the animator
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
myWriter = animation.FFMpegWriter(fps = 30, extra_args=[’-vcodec’, ‘libx264’])
anim.save(‘basic_animation.mp4’, writer = myWriter)__
plt.show()
Traceback:
_Traceback (most recent call last):
File “test.py”, line 26, in
anim.save(‘basic_animation.mp4’, writer = myWriter)
File “/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/animat
ion.py”, line 810, in save
writer.grab_frame(**savefig_kwargs)
File “/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/animat
ion.py”, line 230, in grab_frame
dpi=self.dpi, **savefig_kwargs)
File “/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/figure
.py”, line 1565, in savefig
self.canvas.print_figure(*args, **kwargs)
File “/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backen
ds/backend_qt5agg.py”, line 196, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs)
File “/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backen
d_bases.py”, line 2232, in print_figure
**kwargs)
File “/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backen
ds/backend_agg.py”, line 519, in print_raw
fileobj.write(renderer.renderer.buffer_rgba())
BrokenPipeError: [Errno 32] Broken pipe
I’m using Anaconda/Python 3.5 with matplotlib 1.5.1. I installed FFmpeg 3.0 in Debian Jessie by compiling FFmpeg from source into a dpkg according to these instructions: http://superuser.com/questions/286675/how-to-install-ffmpeg-on-debian I also have Debian packages x264 and libx264-142 installed.