Create a Time-Lapse Video Using FFmpeg on Linux

This guide provides a straightforward, step-by-step walkthrough for converting a directory of sequential images into a high-quality time-lapse video using FFmpeg on Linux. You will learn how to prepare your image files, run the core command, adjust frame rates, and optimize the output video format.

Step 1: Prepare Your Image Directory

Before running FFmpeg, your images need to be organized in a single directory and follow a consistent, sequential naming pattern. FFmpeg uses these patterns to read the files in the correct chronological order.

If your files are randomly named, you can quickly batch-rename them in a Linux terminal using a simple loop:

i=1; for f in *.jpg; do mv "$f" "$(printf "img_%04d.jpg" $i)"; i=$((i+1)); done

Step 2: The Core FFmpeg Command

Once your images are organized, navigate to your directory in the terminal and execute the following command to generate your time-lapse:

ffmpeg -framerate 24 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p output.mp4

Breakdown of the Command Options

Step 3: Advanced Adjustments (Optional)

You can customize your time-lapse further by tweaking the quality, resolution, or handling strict numerical sequences.

Alternative Input Method (Strict Sequence)

If you prefer not to use the glob pattern, you can tell FFmpeg to look for a specific number of digits using a placeholder:

ffmpeg -framerate 30 -i img_%04d.jpg -c:v libx264 -pix_fmt yuv420p output.mp4

In this scenario, %04d tells FFmpeg to look for a four-digit, zero-padded integer sequence.

Adjusting Video Quality

To change the quality of the output video, use the Constant Rate Factor (-crf) flag. The scale ranges from 0 (lossless) to 51 (worst quality). A value between 18 and 23 offers a great balance between visual quality and file size.

ffmpeg -framerate 24 -pattern_type glob -i '*.jpg' -c:v libx264 -crf 20 -pix_fmt yuv420p high_quality.mp4

Handling Odd-Dimension Images

H.264 requires the video width and height to be divisible by 2. If your images have odd dimensions, FFmpeg will throw an error. You can fix this on the fly by adding a scale filter that forces divisible dimensions:

ffmpeg -framerate 24 -pattern_type glob -i '*.jpg' -c:v libx264 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pix_fmt yuv420p output.mp4