Generate Mandelbrot Fractal Video Using FFmpeg

This article provides a step-by-step guide on how to generate a high-definition video of the Mandelbrot fractal using FFmpeg’s built-in mandelbrot video source filter. You will learn the exact command-line syntax required to render the fractal, customize its resolution, frame rate, and duration, and encode the final output into a widely compatible MP4 video file.

The Basic Command

FFmpeg includes a virtual input device called lavfi (Libavfilter input-device) which can generate a Mandelbrot fractal sequence directly without requiring external images.

To generate a basic 10-second Mandelbrot fractal video at 1080p resolution and 30 frames per second, run the following command in your terminal:

ffmpeg -f lavfi -i mandelbrot=size=1920x1080:rate=30 -t 10 -c:v libx264 -pix_fmt yuv420p mandelbrot.mp4

Command Breakdown


Customizing the Fractal Parameters

The mandelbrot filter accepts several parameters that allow you to adjust the visual quality, position, and zoom behavior of the render.

1. Adjusting Detail (Iterations)

The max_iter parameter determines the rendering depth. Higher values reveal more intricate details at deeper zoom levels but increase rendering time.

ffmpeg -f lavfi -i mandelbrot=size=1920x1080:rate=30:max_iter=1000 -t 10 -c:v libx264 -pix_fmt yuv420p detailed_fractal.mp4

2. Changing the Initial Coordinates and Zoom

By default, the filter zooms into the center of the fractal. You can change the starting position and scale using start_x, start_y, and start_scale.

ffmpeg -f lavfi -i mandelbrot=size=1920x1080:rate=30:start_scale=1.5:start_x=-0.5:start_y=0 -t 10 -c:v libx264 -pix_fmt yuv420p custom_start.mp4

3. Modifying the Zoom Speed

The bailout parameter determines the threshold limit for the iteration loop. Adjusting this, along with the camera options, affects how quickly the camera transitions through the fractal structure.

To achieve a slower, more hypnotic zoom, you can increase the frame rate while keeping the overall duration short, or utilize FFmpeg’s video filters to post-process the speed of the output.