Martin McBride, 2020-07-27
Tags movie video
Categories generativepy generative art

The movie module contains utility functions of dealing with lazy sequences of frames.

By storing images in memory, we can set up an efficient processing pipeline to process the frames. We can then process the entire video by treating it as a lazy iterable that returns frames. The frames pass through the pipeline, one by one.

The final stage of this pipeline, saving the frames as a file sequence, can be done by the save_frames function below.


This function has been removed. Use make_image_frames from the generativepy.drawing module instead.


This function has been removed. Use make_image_frame from the generativepy.drawing module instead.


save_frames(outfile, frames)
Parameter Type Description
outfile String The path and base filename for the output PNG files. See below.
frames iterable An iterbale that returns frames.

Iterates through the sequence of frame NumPy arrays returned by the frames iterable, and save each one as a PNG file.

The outfile parameter should be a base filepath. For example:


In this case the files will be created in the folder C:/temp, and their names will be based on the base name "image":


Once the images have been created, you can use an external program to convert them into an animated GIF or movie.


save_frame(outfile, frame)
Parameter Type Description
outfile String The path and filename for the output PNG file. It should end in '.png'.
frame NumPy array An image array in memory.

Saves the frame as a PNG file.


duplicate_frame(frame, count)
Parameter Type Description
frame NumPy array An image array in memory.
count int Number of repeats.

Returns an iterable that consists of the frame, repeated count times.

This can be used for static frames, for example a title frame that is displayed unchanged for several seconds.

If you found this article useful, you might be interested in the book Computer Graphics in Python or other books by the same author.


Popular tags

2d arrays abstract data type alignment and animation arc array arrays bezier curve built-in function callable object circle classes close closure cmyk colour comparison operator comprehension context context manager conversion creational pattern data types design pattern device space dictionary drawing duck typing efficiency else encryption enumerate fill filter font font style for loop function function composition function plot functools game development generativepy tutorial generator geometry gif gradient greyscale higher order function hsl html image image processing imagesurface immutable object index inner function input installing iter iterable iterator itertools l system lambda function len line linspace list list comprehension logical operator lru_cache magic method mandelbrot mandelbrot set map monad mutability named parameter numeric python numpy object open operator optional parameter or partial application path polygon positional parameter print pure function pycairo radial gradient range recipes rectangle recursion reduce rgb rotation scaling sector segment sequence singleton slice slicing sound spirograph sprite square str stream string stroke subpath symmetric encryption template text text metrics tinkerbell fractal transform translation transparency tuple turtle unpacking user space vectorisation webserver website while loop zip