Generate Mandelbrot Fractal Video with FFmpeg
FFmpeg includes a built-in mandelbrot video filter that
algorithmically generates animated renderings of the Mandelbrot set
without requiring external image assets. This guide explains how to call
the filter using FFmpeg's lavfi (Libavfilter) virtual
input, configure core parameters such as resolution, duration, and frame
rate, and adjust zoom, coordinates, and iteration depth to produce
smooth fractal animation videos.
Basic Command Syntax
To generate a simple Mandelbrot video, invoke the filter through the
lavfi input format and define a duration using the
-t flag:
ffmpeg -f lavfi -i mandelbrot -t 10 output.mp4This command generates a 10-second video with default settings (640x480 resolution, 25 frames per second, and default zoom parameters) encoded using standard settings.
Setting Dimensions, Frame Rate, and Quality
For modern displays, you should explicitly set the canvas size, frame rate, and pixel format for standard playback compatibility:
ffmpeg -f lavfi -i mandelbrot=size=1920x1080:rate=60 -c:v libx264 -pix_fmt yuv420p -t 10 mandelbrot_1080p.mp4size(ors): Defines the output video resolution (e.g.,1920x1080or1280x720).rate(orr): Specifies the frame rate (e.g.,30or60).-c:v libx264: Encodes the stream to H.264 video.-pix_fmt yuv420p: Converts the color space to YUV 4:2:0, ensuring broad compatibility across web browsers and media players.
Configuring Zoom, Coordinates, and Detail
The mandelbrot filter provides specific parameters to
customize how the camera navigates the fractal over the course of the
video:
start_scale/end_scale: Sets the initial and final zoom levels. Smaller numbers zoom further in.start_x/start_y: Sets the starting center coordinates on the complex plane.end_x/end_y: Sets the destination center coordinates on the complex plane.maxiter: Sets the maximum calculation iterations per pixel. Higher values yield significantly greater detail around edges at deep zoom levels, at the expense of rendering speed.
Example: Deep Zoom Animation
The following command zooms from an overview of the full set into the intricate Seahorse Valley feature over 20 seconds:
ffmpeg -f lavfi -i mandelbrot=size=1920x1080:rate=60:maxiter=1000:start_scale=3.0:end_scale=0.005:start_x=-0.75:start_y=0.0:end_x=-0.74364388703:end_y=0.1318259042 -c:v libx264 -pix_fmt yuv420p -t 20 seahorse_zoom.mp4Coloring and Visual Customization
You can control the algorithmic coloring applied to the interior and exterior regions of the set:
outer: Determines the coloring algorithm for points outside the set. Options includeiteration_count(default),normalized_iteration_count, andproportional_cycle.inner: Determines how points inside the set are colored. Options includeblack(default),period, andconvergence.bailout: Sets the bailout threshold (default is 10.0), altering edge detection geometry.
For example, to produce smooth color gradients on the exterior rather than standard banding:
ffmpeg -f lavfi -i mandelbrot=size=1920x1080:rate=60:maxiter=800:outer=normalized_iteration_count:inner=period -c:v libx264 -pix_fmt yuv420p -t 15 smooth_mandelbrot.mp4