Programmatically generate video or animated GIF in Python?
Question: I have a series of images that I want to create a video from. Ideally I could
specify a frame duration for each frame but a fixed frame rate would be fine
too. I'm doing this in wxPython, so I can render to a wxDC or I can save the
images to files, like PNG. Is there a Python library that will allow me to
create either a video (AVI, MPG, etc) or an animated GIF from these frames?

Edit: I've already tried PIL and it doesn't seem to work. Can someone correct
me with this conclusion or suggest another toolkit? This link seems to backup
my conclusion regarding PIL:
<http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-
pil-and-animated-gifs/>


Answer: As of June 2009 the originally cited blog post has a method to create animated
GIFs [in the
comments](http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-
library-pil-and-animated-gifs/#comment-197921). Download the script
[images2gif.py](https://pypi.python.org/pypi/images2gif) (formerly
[images2gif.py](http://sites.google.com/site/almarklein/files-1/images2gif.py),
update courtesy of @geographika).

Then, to reverse the frames in a gif, for instance:

    
    
    #!/usr/bin/env python
    
    from PIL import Image, ImageSequence
    import sys, os
    filename = sys.argv[1]
    im = Image.open(filename)
    original_duration = im.info['duration']
    frames = [frame.copy() for frame in ImageSequence.Iterator(im)]    
    frames.reverse()
    
    from images2gif import writeGif
    writeGif("reverse_" + os.path.basename(filename), frames, duration=original_duration/1000.0, dither=0)
    

