Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert image sequence to video using ffmpeg and list of files

Tags:

bash

ffmpeg

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?

like image 940
jimjamslam Avatar asked May 12 '15 10:05

jimjamslam


People also ask

How to create a video from a sequence of images with ffmpeg?

To create a video from a sequence of images with FFmpeg, you need to specify the input images and output file. There are several ways you can specify the input images and we'll look at examples of some of these.

How do I make a video from a sequence of images?

Create a Video from Sequential Images using FFmpeg The most basic form of the command to create a video from images using FFmpeg is as follows: ffmpeg -framerate 10 -i filename-%03d.jpg output.mp4 If the -framerate parameter is not provided, FFmpeg selects the default rate of 25 fps.

How do I know what file format FFmpeg should use?

FFmpeg format specifiers If you have a series of images that are sequentially named, e.g. happy1.jpg, happy2.jpg, happy3.jpg, happy4.jpg, etc. you can use ffmpeg format specifiers to indicate the images that FFmpeg should use: $ ffmpeg -framerate 1 -i happy%d.jpg -c:v libx264 -r 30 output.mp4

How do I pipe images from cat to FFmpeg?

You can also use cat to pipe to ffmpeg: You can use the concat demuxer to concatenate images listed in a file. Below, we create a file labelled input.txt and add a list of images for the slideshow.


1 Answers

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]

like image 168
aergistal Avatar answered Sep 23 '22 01:09

aergistal