FFmpeg Timelapse from Dynamic Image Filenames

Creating a time-lapse video from an image sequence with dynamic, timestamped, or non-sequential filenames requires bypassing FFmpeg's standard sequential numbering format. This guide covers how to handle arbitrarily named images directly using FFmpeg's glob pattern matching or the concat demuxer, allowing you to compile smooth, high-quality videos without having to manually rename your files.


Method 1: Using the Glob Pattern (Linux and macOS)

If you are using Linux or macOS, the most efficient way to handle dynamic filenames (such as capture_2023-10-12_08-30-00.jpg) is the -pattern_type glob option. This allows FFmpeg to read all files matching a specific wildcard pattern sorted in alphabetical order.

Run the following command in the directory containing your images:

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

Parameter Breakdown:

  • -framerate 30: Sets the input frame rate to 30 frames per second. Adjust this number to speed up or slow down the time-lapse.
  • -pattern_type glob: Tells FFmpeg to use wildcard expansions.
  • -i '*.jpg': Selects all JPEG files matching the pattern. Ensure the dynamic names sort chronologically (e.g., standard ISO dates YYYY-MM-DD).
  • -c:v libx264: Encodes the video using the H.264 codec.
  • -pix_fmt yuv420p: Ensures broad compatibility with standard media players and browsers.

Method 2: Using the Concat Demuxer (Windows, macOS, and Linux)

Windows builds of FFmpeg do not natively support the glob pattern. The universal cross-platform solution is to generate a text file containing the list of images and feed it into FFmpeg using the concat demuxer.

Step 1: Generate the File List

On Windows (PowerShell):
Get-ChildItem -Filter *.jpg | Sort-Object Name | ForEach-Object { "file '$_'" } | Out-File -Encoding utf8 images.txt
On Linux / macOS (Bash):
ls -1v *.jpg | sed "s/\(.*\)/file '\1'/" > images.txt

(The -1v flag ensures natural version-based sorting).

Step 2: Render with FFmpeg

Once images.txt is generated, compile the video:

ffmpeg -r 30 -f concat -safe 0 -i images.txt -c:v libx264 -pix_fmt yuv420p timelapse.mp4

Parameter Breakdown:

  • -r 30: Sets the output frame rate.
  • -f concat: Uses the concat demuxer to read file paths sequentially from the text file.
  • -safe 0: Allows FFmpeg to process relative or non-standard file paths listed inside the text file.

Troubleshooting Common Issues

Uneven Dimensions Error

H.264 requires dimensions that are divisible by 2. If your images have odd-numbered widths or heights, add a scale filter to automatically adjust them:

-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"

Memory/Performance Optimization

If your images are from high-resolution digital cameras (e.g., 24MP or 4K+), downscale them during encoding to reduce processing time and file size:

-vf "scale=1920:-2"

(The -2 automatically calculates the height while preserving the aspect ratio and ensuring divisibility by 2).