Use FFmpeg Life Filter for Conway’s Game of Life
This article provides a practical guide on how to use FFmpeg’s
built-in life video source filter to generate videos based
on Conway’s Game of Life. You will learn the basic command syntax, how
to customize the grid dimensions, colors, and rules, and how to scale up
the resulting pixel-art video so it is clearly visible on modern
displays.
Basic Syntax
The life filter in FFmpeg is a virtual input device
(part of the lavfi library filter wrappers). It generates
video frames based on the cellular automaton rules of Conway’s Game of
Life.
The simplest command to generate a 10-second video with a random initial state is:
ffmpeg -f lavfi -i life=size=320x240:rate=25 -t 10 output.mp4Here is a breakdown of the parameters: * -f lavfi:
Specifies the Libavfilter input virtual device. *
-i life=...: Invokes the Game of Life source filter. *
size=320x240 (or s=320x240): Sets the grid
resolution to 320 columns by 240 rows. Each cell is represented by one
pixel. * rate=25 (or r=25): Sets the frame
rate to 25 frames per second, which also controls how fast generations
evolve. * -t 10: Sets the duration of the output video to
10 seconds.
Customizing Colors and Rules
You can customize the appearance and simulation rules using parameters within the filter string, separated by colons.
ffmpeg -f lavfi -i life=s=200x200:r=15:life_color=white:death_color=black:mold_color=darkgray -t 15 output.mp4Key configuration options include: * life_color: The
color of live cells (default is white). * death_color: The
color of dead cells (default is black). * mold_color: The
color of cells that have recently died, creating a “trail” effect. *
ratio: The random fill ratio for the initial seed (default
is 0.61). * rule: The survival and birth
rules. The default is B3/S23 (Birth on 3 neighbors, Survive
on 2 or 3). You can change this to explore other automata rules, such as
HighLife (B36/S23):
ffmpeg -f lavfi -i life=s=200x200:rule=B36/S23 -t 10 highlife.mp4Scaling Up the Output
Because each cell in the simulation is exactly one pixel, a raw Game
of Life video will be very small on standard screens. To make the video
watchable without blurriness, use FFmpeg’s scale video
filter with the neighbor flag to perform nearest-neighbor
interpolation:
ffmpeg -f lavfi -i life=s=160x120:r=10 -vf "scale=1280:960:flags=neighbor" -t 10 output_large.mp4This command takes a small 160x120 grid and upscale it to 1280x960, preserving the sharp, blocky pixel-art aesthetic of the simulation.
Using a Custom Seed File
Instead of starting with a random distribution, you can define an
initial state using a text file. Create a file named
seed.txt containing 0 for dead cells and
1 for live cells, or use space and #
characters:
00000000
00100000
00010000
01110000
00000000
Load this seed file into the filter using the filename
(or f) parameter:
ffmpeg -f lavfi -i life=s=100x100:f=seed.txt:r=5 -vf "scale=800:800:flags=neighbor" -t 10 custom_seed.mp4Ensure the grid size is large enough to contain your
seed file text. The seed will be positioned at the top-left corner of
the grid by default.