Timelapse video with Raspberry

Hi,
this is a simple guide to use Raspberry Camera Module and make timelapse video.

First of all you need to connect camera module on Raspberry...................................................................................................................................................

install ffmpeg

sudo apt-get install ffmpeg

then open your Raspberry Terminal and write this:

sudo raspi-config

you'll see this window


then select "Enable Camera" and Enable it:




then use the following code:

import time
import picamera

VIDEO_DAYS = 1
FRAMES_PER_HOUR = 60
FRAMES = FRAMES_PER_HOUR * 24 * VIDEO_DAYS

def capture_frame(frame):
    with picamera.PiCamera() as cam:
        time.sleep(2)
        cam.capture('/home/pi/captured_image/frame%03d.jpg' % frame)

# Catturo i vari frames

for frame in range(FRAMES):
    start = time.time()
    capture_frame(frame)
    # Resto in attesa del prossimo frame
    time.sleep(int(60*60/FRAMES_PER_HOUR) - (time.time() - start))



VIDEO_DAYS means how many days you want to recorder
FRAMES_PER_HOUR means how many pictures you need to take for every hour


/home/pi/captured_image/frame%03d.jpg

is the name pattern for every frame



ok, now you can turn your photos into a video:

ffmpeg -y -f image2 -i /home/pi/captured_image/frame%03d.jpg -r 24 -vcodec libx264 -profile high -preset slow /home/pi/captured_image/timelapse.mp4


well done!

check source code of this and other projects on
https://github.com/colino/RaspberryProjects/

Commenti