Skip to content

elliotwaite/pycairo-animations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pycairo Animation Library

A library for generating animations using Pycairo (the Python version of Cairo) and ffmpeg. Pycairo is used to generate each frame of the animation and then an ffmpeg process is called to merge all those frames into a ProRes (.mov) video file.

Requirements

  • pycairo - conda install pycairo or pip install pycairo * Pillow - conda install pillow or pip install Pillow * ffmpeg - brew install ffmpeg * To use a different version of ffmpeg (A non-Homebrew version), just specify the ffmpeg_path argument when initializing an instance of VideoWriter (it should be the path to the ffmpeg bin file that you want to use).

Overview

The anim directory contains two classes, Frame and VideoWriter. The Frame class manages a Cairo surface (the image data) and a Cairo context (what Cairo uses to update the image data). The Frame class has methods for drawing lines, writing text, applying a blur, and clearing parts or all of the image. A Frame instance can be passed to a VideoWriter instance using video_writer.add_frame(frame) to write that frame to disk as a PNG image file in a temporary directory. Once all the frames have been written to disk, call video_writer.write_video('output_path.mov') to run the ffmpeg process that merges all those frames into a video file.

The examples directory contains two examples (hello_world.py and random_walks.py) which demonstrate how to use the library.

The video generated by hello_world.py (converted to a GIF, the actual video is smoother):

The video generated by random_walks.py (converted to a GIF):

⚠️ There are currently very few methods available on the Frame class. I've only added the methods that I've needed for my personal use cases. But you can easily extend the class to meet your needs. If you want to extend the class, but you're not familiar with Pycairo, here's a great tutorial that explains how Pycairo works: Cairo Tutorial for Python Programmers (Note: this link is to an archived version of the original since the original site is currently down).

Releases

No releases published

Packages

No packages published

Languages