bewegung is a versatile video renderer, primarily targeting scientific visualizations of large quantities of data. Its core concepts are sequences and layers. Sequences describe a certain time span within a video and can overlap. Each sequence can hold multiple layers. Layers can be generated with
cairo (see pycairo documentation),
PIL (see Pillow documentation),
datashader (see datashader documentation),
matplotlib (see matplotlib documentation) and
bewegung’s internal drawing system
DrawingBoard (see chapter on drawing). Final compositing of every video frame and video effects are implemented via
Pillow. Video encoding is handled by
ffmpeg (see ffmpeg documentation).
bewegung also includes a simple vector algebra system and a “camera” for 3D to 2D projections.
bewegung is developed with ease of use, compute time and memory efficiency in mind.
Why another library for rendering / animating videos?
Many plotting & visualization libraries from the scientific Python ecosystem, such as
matplotlib for instance, have integrated animation functionality. Rendering individual frames as still images and streaming them to
ffmpeg for video encoding is also a rather common practice. However, as soon as more than one plotting or visualization library becomes relevant within a single animation and/or the video is supposed to become more structured and/or the video rendering process needs to scale (parallelization, in other words), things become pretty messy rather quickly. This library is based on the experiences made while writing a fair number of custom animated visualization pipelines. It collects and abstracts all common bits and pieces and offers clean structures for typical tasks. At the time of writing, it is the third iteration on the idea of having such a library. The first two iterations were never published, but the lessons learned from the mistakes made in their development went into designing this very library. Welcome to
Similar & Alternative Libraries
There are various libraries in the overall Python ecosystem which target tasks related to animations and videos. Compared to
bewegung, they all serve more or less different use-cases and applications. It can even make a lot of sense to combine them with
MoviePy: An advanced (non-linear) video editing library with support for audio tracks. In theory,
MoviePycan do a lot of what
bewegungcan do. However, in direct comparison,
MoviePy’s main focus is on editing. While it is extremely good at that, building complicated multi-layer animations similar to
bewegungbecomes a rather tedious and unmaintainable task above a level of complexity. Where
bewegunghas mechanisms to generalize the integration of 3rd-party drawing and plotting libraries,
MoviePyrequires the user to write a lot of boilerplate code himself.
MoviePyloads a lot of work off to
ffmpeg, but its own code can not (easily) be parallelized.
bewegungis based on a fully parallelized implementation.
matplotlib.animation: As sub-package of
matplotlib, it focuses entirely on
matplotlib. It can do both interactive animations and videos. It allows to encode videos with
ffmpegbut also integrates other encoders. In comparison to
bewegung, this framework is really primarily built around
matplotlib, its strengths and its quirks. While
bewegunghas a fully parallelized implementation, it is virtually impossible to parallelize
animatplot: Focuses on interactive animations virtually exclusively based on
celluloid: A simple, thin wrapper around
matplotlibfor rendering videos.
plotlylibrary has deeply integrated functionality for interactive animations and dashboards. Its undisputed strength is WebGL-based graphic acceleration.
plotlyis lacking any kind of functionality for rendering videos as well as rendering frames in parallel, while functionality of this kind could certainly be built around
manimpackage provides excellent functionality for generating explanatory math videos. It can handle LaTeX expressions and animate all sorts of mathematical expressions and transformations. Similar to
bewegung, it also integrates its own
cairo-based drawing system and encodes videos with
ffmpeg. In direct comparison to
manimserves a completely different but also very interesting use-case.
mayavilibrary has excellent integrated features for generating interactive, near-real-time 3D visualizations. It is fairly easy to use and provides graphics acceleration. It lacks built-in capabilities for generating videos.
vispypackage is the undisputed crown jewel of real-time visualization of large quantities of data with Python. Its great performance comes at a price, however: The user has to write OpenGL shaders in C++, which is anything but trivial.
vispydoes not have built-in features for video export.
glumpy: Very similar to
vispy, with even lower-level access to APIs and internal facilities.
glumpycan export videos via
ffmpegand borrows code from
MoviePyfor this task.
ffmpeg-pythonpackage is an object-oriented Python wrapper around the
ffmpegcommand line tool. It is an extremely powerful tool on its own, making the otherwise complicated and error-prone specification of
ffmpegoptions relatively easy.
bewegungoffers its own thin wrapper around
ffmpeg, which can be substituted by
PyAV: Python bindings to the libraries underneath
ffmpeg. In a nutshell even far more complicated to use than the
ffmpegcommand line version.
blender: A list of Python tools for animations would not be complete without
Blenderis a GUI application, it is fully programmable & controllable through Python.
Blender’s features far exceed those of
bewegung. It can be argued that
Blenderserves different use-cases, primarily 3D modeling, lighting and video editing, while it can certainly also do what
bewegungdoes - just different and slightly more complicated.