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.