-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtimelapse.py
29 lines (23 loc) · 1.26 KB
/
timelapse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from picamera import PiCamera
from os import system
import datetime
from time import sleep
tlminutes = 10 #set this to the number of minutes you wish to run your timelapse camera
secondsinterval = 1 #number of seconds delay between each photo taken
fps = 30 #frames per second timelapse video
numphotos = int((tlminutes*60)/secondsinterval) #number of photos to take
print("number of photos to take = ", numphotos)
dateraw= datetime.datetime.now()
datetimeformat = dateraw.strftime("%Y-%m-%d_%H:%M")
print("RPi started taking photos for your timelapse at: " + datetimeformat)
camera = PiCamera()
camera.resolution = (1024, 768)
system('rm /home/pi/Pictures/*.jpg') #delete all photos in the Pictures folder before timelapse start
for i in range(numphotos):
camera.capture('/home/pi/Pictures/image{0:06d}.jpg'.format(i))
sleep(secondsinterval)
print("Done taking photos.")
print("Please standby as your timelapse video is created.")
system('ffmpeg -r {} -f image2 -s 1024x768 -nostats -loglevel 0 -pattern_type glob -i "/home/pi/Pictures/*.jpg" -vcodec libx264 -crf 25 -pix_fmt yuv420p /home/pi/Videos/{}.mp4'.format(fps, datetimeformat))
#system('rm /home/pi/Pictures/*.jpg')
print('Timelapse video is complete. Video saved as /home/pi/Videos/{}.mp4'.format(datetimeformat))