pygame: output to file?

Temia Eszteri lamialily at cleverpun.com
Mon Apr 16 14:39:55 EDT 2012


On Mon, 16 Apr 2012 12:48:37 -0400, you wrote:

>On 4/16/2012 8:37 AM, superpollo wrote:
>> alex23 ha scritto:
>>> On Apr 16, 7:34 pm, superpollo <superpo... at tznvy.pbz> wrote:
>>>> is there a way to convert the graphical output of a pygame application
>>>> to a mpeg file or better an animated gif? i mean, not using an external
>>>> capture program...
>>>
>>> There is, but it's probably not going to be as performant as using
>>> something external:
>>>
>>> http://stackoverflow.com/questions/6087484/how-to-capture-pygame-screen
>>
>> but where in the code should i put the line:
>>
>> pygame.image.save(window, "screenshot.jpeg")
>>
>> ?
>
>Somewhere in the loop that draws frames, perhaps just before or after 
>flipping to the screen. Of course, number the frames.
>
>framenum = 0 # somewhere, just once
># in loop
>pygame.image.save(window, 'frame%05d' % framenum)
>framenum += 1
>
>5 digits for frames is just an example.
> >>> 'frame%05d.jpg' % 21
>'frame00021.jpg'
> >>> 'frame{:0>5d}.jpg'.format(21)
>'frame00021.jpg'
>
>You might consider saving .bmp bitmaps, as mpeg compresses across frames 
>as well as within frames. If you have sprites moving over a static 
>background, only the changes need to be encoded.
>
>-- 
>Terry Jan Reedy

If there's a image-handling library out there for Python that can make
animated GIFs, I might be able to come up with a faster and more
internalized solution using surface.convert() to paletted modes and
image.tostring() functions or similarmeans to pass the frames to said
library.

Problem is that I can't seem to find a library that does handle
animated GIFs. My google-fu has always been weak, alas. Does anyone
feel up to confirming whether one exists or not?

~Temia
--
When on earth, do as the earthlings do.



More information about the Python-list mailing list