SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Kyle D. <kyl...@gm...> - 2016年02月24日 20:34:51
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 framedef init(): line.set_data([], []) return
line,# animation function. This is called sequentiallydef 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 animatoranim =
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
<module> anim.save('basic_animation.mp4', writer = myWriter) File
"/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py",
line 810, in save
writer.grab_frame(**savefig_kwargs) File
"/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/animation.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/backends/backend_qt5agg.py",
line 196, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs) File
"/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py",
line 2232, in print_figure
**kwargs) File
"/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backends/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.
From: Ryan M. <rm...@gm...> - 2016年02月24日 21:56:08
Try running with '--verbose-debug' as in:
python basic_example_writer.py --verbose-debug
That should give you standard out and standard error from running ffmpeg,
which might be illustrative.
x264 is probably the most universally supported codec for html5 video.
Another option would be to use imagemagick with the ImagemagickWriter and
make an animated gif.
Ryan
On Wed, Feb 24, 2016 at 1:34 PM, Kyle Douglass <kyl...@gm...>
wrote:
> 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 framedef init(): line.set_data([], []) return
> line,# animation function. This is called sequentiallydef 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 animatoranim =
> 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
> <module> anim.save('basic_animation.mp4', writer = myWriter) File
> "/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py",
> line 810, in save
> writer.grab_frame(**savefig_kwargs) File
> "/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/animation.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/backends/backend_qt5agg.py",
> line 196, in print_figure
> FigureCanvasAgg.print_figure(self, *args, **kwargs) File
> "/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py",
> line 2232, in print_figure
> **kwargs) File
> "/home/kmdouglass/anaconda3/lib/python3.5/site-packages/matplotlib/backends/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.
>
>
>
> ------------------------------------------------------------------------------
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just 35ドル/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
-- 
Ryan May
From: Kyle D. <kyl...@gm...> - 2016年02月25日 07:25:12
>
> Try running with '--verbose-debug' as in:
>
> python basic_example_writer.py --verbose-debug
>
Thanks for the suggestion, Ryan. By doing so I discovered that the error
was caused by ffmpeg not finding the libx264 library; the error was not at
all connected with matplotlib.
As it turns out, I neglected to use the *--enable-libx264 --enable-gpl
--enable-nonfree* flags when running the configuration script for ffmpeg
just before compiling. I recompiled ffmpeg and now everything is working
properly.
Thanks again,
Kyle
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /