Skip to content

Instantly share code, notes, and snippets.

@romanschejbal
Last active January 19, 2017 12:05
Show Gist options
  • Save romanschejbal/2fa1dc3fed94f53963fb8b63f02bb102 to your computer and use it in GitHub Desktop.
Save romanschejbal/2fa1dc3fed94f53963fb8b63f02bb102 to your computer and use it in GitHub Desktop.
from PIL import Image
import os, sys, cv2, numpy
path = sys.argv[1]
filename = sys.argv[2]
blendCount = int(sys.argv[3])
files = os.listdir(path)
files = sorted(files)
previousImage = Image.open(path + '/' + files[0])
height, width, layers = numpy.array(previousImage).shape
video = cv2.VideoWriter(filename, -1, 30, (width, height))
for imageFilename in files:
image = Image.open(path + '/' + imageFilename)
if files[0] != imageFilename:
for i in range(1, blendCount + 1):
print 'Blending ' + str(i / float(blendCount + 1))
blendedImage = Image.blend(previousImage, image, i / float(blendCount + 1))
video.write(cv2.cvtColor(numpy.array(blendedImage), cv2.COLOR_RGB2BGR))
print 'Adding ' + imageFilename
video.write(cv2.cvtColor(numpy.array(image), cv2.COLOR_RGB2BGR))
previousImage = image
video.release()
print width
print height
@romanschejbal
Copy link
Author

romanschejbal commented Jan 17, 2017

Usage: timelapse.py ~/Downloads/directory-with-photos-only destination-file.mp4 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment