Convert image sequence to video using ffmpeg and list of files

14,109

Solution 1

Use the concat demuxer with a list of files. The list format is:

file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

Basic ffmpeg usage:

`ffmpeg -f concat -i mylist.txt ... <output>`

Concatenate [FFmpeg wiki]

Solution 2

use pattern_type glob for this

ffmpeg -f image2 -r 25 -pattern_type glob -i '*.jpg' -an -c:v libx264 -r 25 timelapse.mp4

Solution 3

ffmpeg probably uses the same file name globbing facility as the shell, so all valid file name globbing patterns should work. Specifically in your case, a pattern of images/201?-??-??/??/201?-??-??-????-?? will expand to all files in question e.g.

ls -l images/201?-??-??/??/201?-??-??-????-??
ffmpeg ... 'images/201?-??-??/??/201?-??-??-????-??' ...

Note the quotes around the pattern in the ffmpeg invocation: you want to pass the pattern verbatim to ffmpeg to expand the pattern into file names, not have the shell do the expansion.

Share:
14,109
jimjamslam
Author by

jimjamslam

Updated on July 27, 2022

Comments

  • jimjamslam
    jimjamslam almost 2 years

    I have a camera taking time-lapse shots every 2–3 seconds, and I keep a rolling record of a few days' worth. Because that's a lot of files, I keep them in subdirectories by day and hour:

    images/
        2015-05-02/
            00/
                2015-05-02-0000-02
                2015-05-02-0000-05
                2015-05-02-0000-07
            01/
                (etc.)
        2015-05-03/
    

    I'm writing a script to automatically upload a timelapse of the sunrise to YouTube each day. I can get the sunrise time from the web in advance, then go back after the sunrise and get a list of the files that were taken in that period using find:

    touch -d "$SUNRISE_START" sunrise-start.txt
    touch -d "$SUNRISE_END" sunrise-end.txt
    find images/"$TODAY" -type f -anewer sunrise-start.txt ! -anewer sunrise-end.txt
    

    Now I want to convert those files to a video with ffmpeg. Ideally I'd like to do this without making a copy of all the files (because we're talking ~3.5 GB per hour of images), and I'd prefer not to rename them to something like image000n.jpg because other users may want to access the images. Copying the images is my fallback.

    But I'm getting stuck sending the results of find to ffmpeg. I understand that ffmpeg can expand wildcards internally, but I'm not sure that this is going to work where the files aren't all in one directory. I also see a few people using find's --exec option with ffmpeg to do batch conversions, but I'm not sure if this is going to work with image sequence input (as opposed to, say, converting 1000 images into 1000 single-frame videos).

    Any ideas on how I can connect the two—or, failing that, a better way to get files in a date range across several subdirectories into ffmpeg as an image sequence?