Create Video from Irregular Images with FFmpeg Glob

This article provides a step-by-step guide on how to compile a video from a folder of images with irregular or non-sequential filenames using FFmpeg and the glob pattern. You will learn the specific command-line syntax required to read various image formats, define frame rates, and export a high-quality video file without having to rename your source files.

The Challenge with Irregular Filenames

By default, FFmpeg expects image sequences to be sequentially numbered (e.g., image_001.jpg, image_002.jpg). If your folder contains files with irregular names like photo_9.jpg, holiday.jpg, or IMG_4821.jpg, the standard sequence demuxer will fail.

To bypass this, you can use the -pattern_type glob option. This tells FFmpeg to use wildcard matching (like *.jpg or *.png) to select all matching images in alphabetical order.

Note: The glob pattern is natively supported on Unix-like systems (macOS and Linux). If you are on Windows, you will need to run these commands inside the Windows Subsystem for Linux (WSL) or Git Bash.

The Basic Command

Navigate to the directory containing your images and run the following command in your terminal:

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

Command Breakdown:

Advanced Usage

Matching Multiple Formats

If your folder contains a mix of lowercase and uppercase extensions (like .jpg and .JPG), or different formats like PNG and JPG, you can use brackets in your glob pattern:

ffmpeg -f image2 -pattern_type glob -framerate 30 -i '*.[jJ][pP][gG]' -c:v libx264 -pix_fmt yuv420p output.mp4

Controlling Image Duration

If you want each irregular image to stay on screen for a specific number of seconds instead of playing as a high-speed video, lower the frame rate. For example, to show each image for 2 seconds, set the framerate to 0.5 (which is 1/2):

ffmpeg -f image2 -pattern_type glob -framerate 0.5 -i '*.png' -c:v libx264 -pix_fmt yuv420p output.mp4