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.mp4Command Breakdown:
-f image2: Forces the use of the image file demuxer.-pattern_type glob: Enables wildcard expansion for the input.-framerate 24: Sets the speed of the video. In this case, 24 images will be displayed per second. Adjust this number to speed up or slow down your video.-i '*.jpg': The input pattern. The single quotes are critical to prevent your terminal shell from expanding the wildcard before FFmpeg can process it. This matches all files ending in.jpg.-c:v libx264: Encodes the video using the H.264 codec, which is highly compatible with most media players and web browsers.-pix_fmt yuv420p: Sets the pixel format to YUV 4:2:0. This is necessary because many players cannot open H.264 videos that use pixel formats generated directly from RGB images.output.mp4: The name of the resulting video file.
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.mp4Controlling 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