Day-based videos for a large timelapse project

A few weeks ago, I started my security camera timelapse project which resulted in a lot of files being captured (my camera takes a photo every minute). I moved the files to the directories based on the file creation date. This way I separated days, but now I want to create a timelapse for each day.

Since I wanted to do this in Python, I installed the ffmpeg-python wrapper library:

pip3 install ffmpeg-python

I selected this one because it has all I needed for the successful timelapse creation. Some other libraries are not able to handle the parameters I’m using.

Since my files are already plaed in the directories based on the date, my script is looping through these directories. If you prefer to have your files all in one directory, you can simply adjust the loop to skip the directory, but select files with proper names.

import os
import ffmpeg
from datetime import timedelta, date

start_date = date(2020, 11, 26)
end_date = date(2020, 12, 10)
path = os.getcwd()
subdir_name = '/capture/'

def daterange(start_date, end_date):
    for n in range(int((end_date - start_date).days)):
        yield start_date + timedelta(n)

for single_date in daterange(start_date, end_date):
    print(single_date.strftime("%Y-%m-%d"))

    this_date = single_date.strftime("%Y%m%d")
    this_path = path + subdir_name + this_date

    ffmpeg.input(this_path + '/*.jpg', pattern_type='glob',
                 framerate=25).output(this_date + '.mp4').run()

Since this is a simple wrapper around ffmpeg, the script is telling ffmpeg to get all the JPG files from the selected day directory and convert them to a movie. You can select a different directory to store the result of this conversion, but I decided to store them simply in the capture directory.

Leave a Reply

Your email address will not be published. Required fields are marked *