Create per-folder timelapse of photos in multiple folders

May 18, 2022 unzip python [code]

Given many directories where each directory contains multiple photos, go into each directory and create a timelapse.

 
#!/usr/bin/python3
import os

#Get a list of directories
dirnames = os.listdir('.')

#Go into each directory
for dirname in dirnames:

    #Skip if it is not a directory
    if not os.path.isdir(dirname):
        continue
    
    #cd into directory
    os.chdir(dirname)
    print("Dir: " + os.path.abspath(os.path.curdir))
    #FFMPEG command to generate a timelapse of 4s/image using two threads.
    cmd = 'ffmpeg -y -threads 2 -framerate 0.25 -i %04d.jpg -c:v libx264 -movflags +faststart -crf 0 ' + dirname + '.mp4'
    os.system(cmd)
    
    #Return to top dir
    os.chdir('..')
    print("Dir: " + os.path.abspath(os.path.curdir))