Pi Camera Essentials

Raspberry Pi Logo

Pi Camera Essentials

Assumptions

The camera is enabled

RaspiStill for Photos

Take a full resolution picture

raspistill -o picture.jpg

Specify the dimentions

raspistill -o picture.jpg -w 1920 -h 1080

RaspiVid for Videos

Take a full resolution 1 second video

raspivid -o video.h264

Take a 1080×720, 7 second video at 25 frames per second.

raspivid -o video.h264 -t 7000 -w 1880 -h 720 -fps 25

TimeLapse

Capture Via Command Line

Take a picture ever 1 second for 60 seconds

mkdir TimeLapse
cd TimeLapse
raspistill -t 60000 -tl 1000 -o %07dimg.jpg

The above is OK for smaller timelapse sessions. It can take pictures very frequently, multiple times per minute.

Howeve if anything goes wrong e.g. power outage.
Hours even months could be wasted.

Another option is to have cron schedule a picture. However cron is limited to once every 1 minute. Also each picture taken is in isolation so the %07 cannot be used.

Some aditional post processing will be required.

Capture Via Cron & Script

touch timelapse.sh
chmod +x timelapse.sh
nano timelapse.sh

#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
raspistill -w 1920 -h 1080 -o /home/pi/timelapse/$DATE.jpeg

sudo mv timelapse.sh /usr/bin

crontab -e

* * * * * sh /usr/bin/timelapse.sh 2>&1

Post Processing Cron Captured Images

ls -1v | awk 'BEGIN{ a=0 }{ printf "mv \"%s\" %07d.jpg\n", $0, a++ }' | bash
ls -1
0000000.jpeg
0000001.jpeg
...
9999998.jpeg
9999999.jpeg

Create Video from Images Captured Above

sudo apt install ffmpeg
ffmpeg -r 30 -i %07d.jpg -r 30 -vcodec libx264 -vf scale=1080:720 timelapse.mp4
  • -i In File
  • -r rate set frame rate (Hz value, fraction or abbreviation)
    Assume 30 frames per second in input and output files

Scanario & Samples

Input of 7000 Captured JPG Pictures

ffmpeg -r 30 -i %07d.jpg -r 120 -vcodec libx264 -vf scale=1080:720 timelapse.mp4

Results in a 48.9MB, 120FPS, 3 Minute and 52 Second Video File

ffmpeg -r 120 -i %07d.jpg -r 30 -vcodec libx264 -vf scale=1080:720 timelapse.mp4

Results in a 13.1MB, 30FPS, 0 Minute and 58 Second Video File

ffmpeg -r 30 -i %07d.jpg -r 30 -vcodec libx264 -vf scale=1080:720 timelapse.mp4

Results in a 37.4MB, 30FPS, 3 Minute and 52 Second Video File

ffmpeg -r 120 -i %07d.jpg -r 120 -vcodec libx264 -vf scale=1080:720 timelapse.mp4

Results in a 19.7MB, 120FPS, 0 Minute and 58 Second Video File

GUI for the Camera

git clone https://github.com/Billwilliams1952/PiCameraApp.git
cd PiCameraApp/Source/
python3 PiCameraApp.py

https://www.raspberrypi.org/documentation/usage/camera/raspicam/timelapse.md

,