2

I want to create a movie or an animation using lots of 2D plots. I have tried it in two different ways, one by using the matplotlib.animation:

[...]
for i in xrange(imagdat+start,lendata-imagdat, imagdat):
    [...]
    ims.append((plt.pcolormesh(X,Y, forup, vmin=vmin, vmax=vmax, cmap=col),))
    plt.axis('off')
    plt.tight_layout()
im_ani = animation.ArtistAnimation(fig2, ims)

im_ani.save(fileout+'.mp4', fps=fps)
#plt.show()
plt.close()

and one by using mencoder:

for i in xrange(imagdat+start,lendata-imagdat, imagdat):
    [...]   
    plt.pcolormesh(X,Y, forup, vmin=vmin, vmax=vmax, cmap=col)
    plt.axis('off')
    fname = '_tmp%03d.png'%i
    savefig(fname, bbox_inches='tight', pad_inches=0)
    files.append(fname)

os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps="+str(fps)+"    -ovc lavc -lavcopts vcodec=wmv2 -oac copy    -o " + fileout + ".mpg")

for fname in files: os.remove(fname)

In the first case the creation of the animation is quite fast, it takes a lot of time to save the animation (in one case for example, i need 4 seconds to create an animation, that I could see, but 108 seconds for creating and saving the animation) The second code is even slower. The problem is the same in both cases: the images are saved as an png file, before they are combinded to a movie. That takes a lot of time.

The question is now, how can I create a movie without saving png files on the disk.

Thanks in advance.

Nathan
  • 3,558
  • 1
  • 18
  • 38
  • What version of mpl are you using? There should be streaming writers. – tacaswell Apr 15 '14 at 14:32
  • possible duplicate of [Generating movie from python without saving individual frames to files](http://stackoverflow.com/questions/4092927/generating-movie-from-python-without-saving-individual-frames-to-files) – tacaswell Apr 15 '14 at 14:33

0 Answers0