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.mp4Command Breakdown
-f lavfi: Tells FFmpeg to use the Libre-AV filtergraph as the input format.-i mandelbrot=size=1920x1080:rate=30: Specifies themandelbrotsource filter with a resolution of 1920x1080 pixels and a frame rate of 30 fps.-t 10: Sets the duration of the output video to 10 seconds.-c:v libx264: Encodes the video using the H.264 video codec for high compatibility.-pix_fmt yuv420p: Sets the pixel format to YUV 4:2:0, which is necessary for the video to play on standard media players and web browsers.mandelbrot.mp4: The name of the output video file.
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.mp42. 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.
start_x: Sets the initial X-coordinate (default is-0.743643887037158704752191506114774).start_y: Sets the initial Y-coordinate (default is0.131825904205311970493132056385139).start_scale: Sets the initial zoom scale (default is3.0).
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.mp43. 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.