1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| def makeVideo( inPattern, outFile, outCodec ):
# Get video stream dimensions from the image size
pygame.init()
i= 1
# Opening mpeg file for output
e= None
i= 1
fw= __builtin__.open( outFile, 'wb' )
while i:
if os.path.isfile( inPattern % i ):
s= pygame.image.load( inPattern % i )
if not e:
print "proutpourtprout"
if outCodec== 'mpeg1video':
bitrate= 2700000
else:
bitrate= 9800000
params= { \
'type': 0,
'gop_size': 12,
'frame_rate_base': 125,
'max_b_frames': 0,
'height': s.get_height(),
'width': s.get_width(),
'frame_rate': 2997,
'deinterlace': 0,
'bitrate': bitrate,
'id': vcodec.getCodecID( outCodec )
}
print 'Setting codec to ', params
e= vcodec.Encoder( params )
t= time.time()
# Create VFrame
ss= pygame.image.tostring(s, "RGB")
bmpFrame= vcodec.VFrame( vcodec.formats.PIX_FMT_RGB24, s.get_size(), (ss,None,None))
yuvFrame= bmpFrame.convert( vcodec.formats.PIX_FMT_YUV420P )
d= e.encode( yuvFrame )
fw.write( d )
i+= 1
else:
print '%d frames written in %.2f secs( %.2f fps )' % ( i, time.time()- t, float( i )/ ( time.time()- t ) )
i= 0
fw.close()
pygame.quit() |
Partager