Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 56 lines (47 sloc) 1.435 kb
import subprocess
import numpy as np
class VideoSink(object) :
def __init__( self, size, filename="output", rate=1, byteorder="bgra" ) :
self.size = size
cmdstring = ('mencoder',
'-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 == self.size
# image.swapaxes(0,1).tofile(self.p.stdin) # should be faster but it is indeed slower
def close(self) :
if __name__ == "__main__" :
import sys
W,H = 480,360
rate = 40
video = VideoSink((H,W), "test", rate=rate, byteorder="bgra")
image = np.ones((H,W), np.uint32)
for color in (
0x00ff0000, # red
0x0000ff00, # green
0x000000ff, # blue
0xffff0000, # red with alpha (should be ignored)
) :
image[:] = color
for i in xrange(rate) :
# Turn green from left to right
for col in xrange(0,W,2) :
image[:,col] = 0x0000ff00
# Turn blue from up to down
for row in xrange(0,H,2) :
image[row,:] = 0x000000ff
for r in xrange(400) : g,b : np.uint32(b)+0x100*g+0x10000*r, shape=(H,W), dtype=np.uint32))
print ".",
Jump to Line
Something went wrong with that request. Please try again.