import numpy as np import subprocess class VideoSink(object) : def __init__( self, size, filename="output", rate=10, byteorder="bgra") : self.size = size cmdstring = ('mencoder', '/dev/stdin', '-demuxer', 'rawvideo', '-rawvideo', 'w=%i:h=%i'%size[::-1]+":fps=%i:format=%s"%(rate,byteorder), '-o', filename+'.avi', '-ovc', 'lavc', ) self.p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE, shell=False) def run(self, image) : #assert image.shape[0:2] == self.size self.p.stdin.write(image.tostring()) def close(self) : self.p.stdin.close()