Sorry for the delay. I have found a work around by simply saving lots of individual images and then calling ffmpeg to chain them together. This isn't ideal but gets the job done. (part of larger class)
def easyway(self, frames):
##INSERT CODE TO GET xdata and ydata!
for i in range(0, frames):
fileName = "videoName"+"%04d.png" % i
matplotlib.pyplot.scatter(xdata,ydata,c=coldata, marker='*',
s=15.0, edgecolor='none')
matplotlib.pyplot.savefig(self.workingDirectory+'temp/'+fileName, dpi=dpi)
matplotlib.pyplot.close()
##INSERT CODE TO UPDATE xdata and ydata!
self.createVideoFile(fps)#calls FFMpeg to chain together all the pictures
if cleanUp:#removes all the picture files created in the process
print "temporary picture files being removed..."
self.clearDirectory()
print "FINISHED"
def clearDirectory(self,directoryName='temp'):
files = glob.glob(self.workingDirectory+directoryName+"/*")
for f in files:
os.remove(f)
def createVideoFile(self,fps=3):
command="ffmpeg -f image2 -r %s -i %s%s" % (str(fps), self.workingDirectory+'temp/', self.universe.description)
command+="%04d.png"
command+=" -c:v libx264 -r 30 %s.mp4" % (self.workingDirectory+'videos/'+self.universe.description)
print "Running command:"
print command
p = subprocess.Popen(command, shell=True, stdout = subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()[0]
print "output\n"+"*"*10+"\n"
print output
print "*"*10
print "Video file has been written"