



























Having battled through this in Matlab, doing it the Python way is extremely easy on any platform. One makes use of Mencoder, which we can just call using os.system. Here’s an idiom, culled mostly from the scipy wiki:
from pylab import *
import os
# set the interactive mode of pylab to ON
ion()
# opens a new figure to plot into
fig_hndl = figure()
# make an empty list into which we'll append
# the filenames of the PNGs that compose each
# frame.
files=[]
# filename for the name of the resulting movie
filename = 'animation'
number_of_frames = 100
for t in range(number_of_frames):
# draw the frame
imshow(rand(100,100))
# form a filename
fname = '_tmp%03d.png'%t
# save the frame
savefig(fname)
# append the filename to the list
files.append(fname)
# call mencoder
os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10
-ovc lavc -lavcopts vcodec=wmv2 -oac copy
-o " + filename + ".mpg")
# cleanup
for fname in files: os.remove(fname)
Depending on how complicated the plot is, this can take anywhere from a while to ages and ages. It’s good quality, though! You can muck about with the frame rate in the call to encoder where it says fps=10. Change that 10 to something else (30 seems popular!). Also there are probably better codecs than wmv2!
Having written this, it strikes me we could probably do all this in Matlab in the same way, rather than trying to make movies using Matlab’s builtins…
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。