simplest way to produce a video of a sequence of plots with python?

361 views Asked by At

I would like to start with a sequence of arrays of 1s and 0s (each array representing a 2 dimensional pattern of on off pixels) and create a simple black and white video of this sequence. controling pixel size and image size and length of time per frame would be good too.

basically it would be a video of a program to execute a cellular automaton.

is there a way to do this without first creating 100 or so image files and then constructing the video from them? (say with avconv?)

if not, what is the simplest way to create each image file?

i would like to use the simplest tools possible without a 1000 bells and whistles. (i'd like to avoid having to wade through matplotlib or pygame or pil etc..i have trouble wading through the documentation)

adding text and audio would be a later step. i just want the bare bones first thanks.

2

There are 2 answers

0
MattDMo On

Unfortunately, matplotlib and Pillow (the replacement for PIL) are two of the best modules that come to mind for creating images and animating them. Combine them with a NumPy array of your pixels, and you have a very straightforward way of proceeding. Assuming you already know how to program in Python, the learning curve isn't too steep, once you grasp how everything is laid out.

I haven't delved as deeply into Pillow yet, but I know from personal experience that the matplotlib documentation actually isn't too bad, and there are a ton of examples on their website. It has interfaces for ffmpeg, avconv, and other converters, so if you're already familiar with them you're halfway there. And remember, if you have specific questions along the way, StackOverflow is always here :)

Good luck!

0
Jesuisme On

The easiest way is probably to create an animated gif.

  1. Write each sequence to a jpeg.
  2. Use the ImageMagick convert function as mentioned in this post:

how to create gif animation from a stack of jpgs

When you write the image, let 1 = white (r=255, g=255, b=255) and 0 = black (r=0, g=0, b=0).

You'll have to go through a little documentation, but it's not as bad as you think. Besides, if it was easy, we wouldn't be asking questions on S.O. ;-)