|
#!/usr/bin/python2 |
|
|
|
# |
|
# Timelapse maker by Raresh Nistor (@thegreatrazz) |
|
# |
|
# A program that takes a photo every amount of time set |
|
# in order to make a timelapse |
|
# |
|
|
|
# |
|
# Keep in mind that I am rather crap at writing in Python |
|
# and this video may make a bunch of more professional devs |
|
# cringe. Viewer disretion advised. |
|
# |
|
# It also uses ffmpeg to stich the images into a video |
|
# |
|
|
|
# Import dem libz |
|
import os, sys, random, time |
|
|
|
# Check a few things |
|
|
|
if os.path.isdir("captures"): |
|
print "You need to delete the captures folder before you can do anything else" |
|
sys.exit(1) |
|
|
|
os.mkdir("captures") |
|
|
|
if os.path.exists("timelapse.mp4"): |
|
print "There already is a video. Please move it somewhere else first." |
|
sys.exit(2) |
|
|
|
# Ask for parameters |
|
|
|
captureInterval = 0 # How many seconds between captures |
|
captureNumber = 0 # How many captures before stopping |
|
outputFps = 0 # How many frames per second in the video |
|
|
|
try: |
|
captureInterval = float(raw_input("How many seconds between captures? ")) |
|
captureNumber = int(raw_input("How many captures before stopping? ")) |
|
outputFps = float(raw_input("How many frames per second in the video? ")) |
|
except: |
|
print "You need to input numbers, not text" |
|
os.exit(3) |
|
|
|
print "" |
|
print "The recording will take more than {} seconds long".format(captureInterval * captureNumber) |
|
print "Your video will be {} seconds long".format(captureNumber / outputFps) |
|
print "" |
|
print "" # A buffer for the ASCII escape lower down |
|
|
|
# Import SimpleCV (cuz its stupid simple... cv) |
|
import SimpleCV |
|
|
|
# Create a camera object |
|
cam = SimpleCV.Camera() |
|
|
|
# Photo-taking loop |
|
for i in range(0, captureNumber): |
|
print "\033[F{} :: {}s left".format(i + 1, captureInterval * (captureNumber - i)) |
|
img = cam.getImage() |
|
img.save("captures/img-{}.png".format(i)) |
|
time.sleep(captureInterval) |
|
|
|
# FFMPEG bit |
|
print "\033[FCapturing complete!" |
|
print "" |
|
|
|
print "Making video..." |
|
print "Use 'ffmpeg -framerate {} -i captures/img-%d.png timelapse.mp4' if it fails".format(outputFps) |
|
|
|
os.system("ffmpeg -framerate {} -i captures/img-%d.png timelapse.mp4".format(outputFps)) |
|
|
|
print "Done" |