On Dec 13, 2007 8:26 AM, Lionel Barret De Nazaris <[EMAIL PROTECTED]> wrote: > Hi all, > > I am trying to join BMPs into one nice mpg and pygame do the parachute > thing to me.
Does it give a name of an Exception / line number when it crashes? > It's quite puzzling because the first image is processed, but it crashes > just after that... If time.time() returns time in seconds you might get a division by zero. You can use pygame's: pygame.time.get_ticks() to get the time in milliseconds. ( http://www.pygame.org/docs/ref/time.html ) Try adding error checking to your image loading code. An example: #!/usr/bin/python # code from: http://www.learningpython.com/2006/03/12/creating-a-game-in-python-using-pygame-part-one/ import os, sys import pygame from pygame.locals import * def load_image(name, colorkey=None): """Load an image, with error checking. Loads whole image to surface. Images are in the path: /data/images/'name' if colorkey is -1, then uses pixel at (0,0) for transparency. """ fullname = os.path.join('data', 'images') fullname = os.path.join(fullname, name) try: image = pygame.image.load(fullname) except pygame.error, message: print 'Cannot load image:', fullname print "\terror: ", pygame.get_error() raise SystemExit, message image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0,0)) image.set_colorkey(colorkey, RLEACCEL) return image, image.get_rect() > > 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() > -- Jake
