[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] pygame parachut/coredump on pygame image load.
Hi all,
I am trying to join BMPs into one nice mpg and pygame do the parachute
thing to me.
It's quite puzzling because the first image is processed, but it crashes
just after that...
Any idea ? The images are over 4000 but I don't see how that could
affect this code or cause this core dump...
Lionel
----
#! /bin/env python
import sys, os, time
import pygame
import pymedia.video.vcodec as vcodec
import glob
from pprint import pprint
def getEncoder(outCodec, height, width):
if outCodec== 'mpeg1video':
bitrate= 2700000
else :
bitrate= 9800000
#==
params= { \
'type': 0,
'gop_size': 12,
'frame_rate_base': 125,
'max_b_frames': 0,
'height': height,
'width': width,
'frame_rate': 2997,
'deinterlace': 0,
'bitrate': bitrate,
'id': vcodec.getCodecID( outCodec )
}
return vcodec.Encoder( params )
def fileList(patterns):
return glob.glob(patterns)
def add_one_frame(img, encoder, file_dest):
s = pygame.image.load(img)
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 = encoder.encode( yuvFrame )
file_dest.write( d.data )
def joinFrames(file_list, encoder, file_dest):
start_time= time.time()
for img in file_list:
add_one_frame(img, encoder, file_dest)
nb = len(file_list)
time_elapsed = time.time() - start_time
print '%d frames written in %.2f secs( %.2f fps )' % ( nb,
time_elapsed, float( nb )/ time_elapsed )
return file_dest
def get_size_info(img_path):
s = pygame.image.load( img_path )
return s.get_height(), s.get_width()
if __name__== '__main__':
pass
pygame.init()
fl = fileList("../../*.bmp")
assert fl, "filelist ok"
h, w = get_size_info(fl[0])
print "size ok"
e = getEncoder("mpeg2video", h, w)
print "encoder ok"
file = open("movie3.mpg", "wb")
joinFrames(fl, e, file)
file.close()
pygame.quit()