Error saving Matplotlib animation

I tried to save the Matplotlib animation, but I get a strange error. Snippet (I believe) of the relevant code:

  def showMovie(self):
    frameFnc = self.getNoisyImage
    initFnc =  self.initImage

    movie = animation.FuncAnimation(self.movieFig, frameFnc,
                                frames = len(self.noiseArrays),
                                init_func = initFnc,
                                interval=1, blit=True,
                                repeat = True)


    movie.save("test.mp4", fps=10, extra_args=['-vcodec', 'libx264'])
    print "Saved movie"
    plt.ion()
    plt.show()



if __name__ == '__main__':
    z = noiseTester()
    z.makeStaticNoiseImages()
    z.readPredList()
    z.showMovie()

      

The error I'm getting looks like this:

Traceback (most recent call last):
  File "noiseTest6.py", line 134, in <module>
    z.showMovie()
  File "noiseTest6.py", line 123, in showMovie
    movie.save("test.mp4", fps=10, extra_args=['-vcodec', 'libx264'])
  File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 718, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 204, in grab_frame
    dpi=self.dpi, **savefig_kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1421, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2220, in print_figure
**kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 497, in print_raw
    renderer._renderer.write_rgba(filename_or_obj)
  RuntimeError: Error writing to file

      

When I check if filename_or_obj is ', the 'wb' mode is 0x7f3de99164b0> . This variable also has a name attribute with the value '' . The meaning of this string value, and not the name I was trying to assign to the file, is not clear to me.

I know my animation is fine because I've seen it work. It only has 500 frames, so I don't think it's too big. If anyone has any ideas on how I should be chasing this Runtime error, I would really appreciate it.

+3


source to share


1 answer


Well, using the info on libx264 from @hitzg I just got rid of the arguments indicating its use - ie

movie.save("test.mp4", fps=10, extra_args=['-vcodec', 'libx264'])

      

was replaced by



movie.save("test.mp4", fps=10)

      

Everything works now.

+2


source







All Articles