[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] pygame parachut/coredump on pygame image load.
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] pygame parachut/coredump on pygame image load.
- From: "Jake b" <ninmonkeys@xxxxxxxxx>
- Date: Thu, 13 Dec 2007 11:09:16 -0600
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 13 Dec 2007 12:09:25 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=NurASzmJlGUfbs1RSwu2c4Fh/w+7UkF6qM+886n4QbY=; b=fRSgt8dsVvupYDes3TUHtcmuL1+RsIxu2uExvTaHu49iTEFPYeJc+yumfOqdZQyvz2TMHXOn5cuo35BCkkjt4hmmC6LZAhdv3LoH8hXadSBeBdCWSex+CUVgN2xIJd5enkKnAaMz0b53WZCWtSkmlq4wIqXoJWZFdGKrxbxtXTc=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=AyjUMHJYdBdUwIDAx6E9/AxWGy4lsz7hsIe2DM0QoU6fGI9Vs07euvaMdt1iTtExjaseZ7qsINwtgTCVngVKzBrA2uwAZtlUHsZqBHmc2ONs9sTNKtuXiupomFlKvauUg3ECjTBPq2eZL1H/QHro7rwQwd97Y34YPAvjS4BAOEo=
- In-reply-to: <47614128.5090909@xxxxxxx>
- References: <47614128.5090909@xxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
On Dec 13, 2007 8:26 AM, Lionel Barret De Nazaris <lionel.bdn@xxxxxxx> 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