• Stars
    star
    278
  • Rank 148,454 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Time-lapse app for Raspberry Pi computers.

Raspberry Pi Time-Lapse App

Build Status

There are a ton of different Time-Lapse scripts and apps built for the Raspberry Pi, but I wanted to make a more customized setup for my own needs.

Here's an example time-lapse video I recorded of cirrus clouds in the sky outside my window (click to view on YouTube):

Cirrus clouds on a sunny day - Raspberry Pi Zero W time-lapse by Jeff Geerling

There are many other examples in my Timelapses playlist on YouTube.

Usage

For an in-depth overview, see my blog post Raspberry Pi Zero W as a headless time-lapse camera.

First, make sure the camera interface is enabled—if you don't, you'll see the message Camera is not enabled. Try running 'sudo raspi-config':

  1. Run sudo raspi-config
  2. Go to 'Interfacing Options'
  3. Select 'Camera'
  4. Select 'Yes' for enabling the camera
  5. Select 'Finish' in the main menu and then 'Yes' to reboot the Pi

Now, set up this timelapse app on your Raspberry Pi:

  1. Install dependencies: sudo apt-get install -y git python-picamera python-yaml
  2. Clone this repository to your Pi: git clone https://github.com/geerlingguy/pi-timelapse.git
  3. Copy example.config.yml to config.yml.
  4. Configure the timelapse by modifying values in config.yml.
  5. In the Terminal, cd into this project directory and run python timelapse.py.

After the capture is completed, the images will be stored in a directory named series-[current date].

Run on Raspberry Pi Startup and manage timelapses via Systemd

This project includes a Systemd unit file that allows the timelapse script to be managed like any other service on the system (e.g. start with systemctl start timelapse, stop with systemctl stop timelapse).

To use this feature, do the following:

  1. In your config.yml, set the total_images variable to a large number—as large as you want, within Python's limitations. This way you won't start a timelapse and it stops after very few images are taken.
  2. Copy the timelapse.service file into the Systemd unit file location: sudo cp timelapse.service /etc/systemd/system/timelapse.service.
  3. Reload the Systemd daemon (sudo systemctl daemon-reload) to load in the new unit file.
  4. Choose how you want to manage the timelapse service:
    1. To start a timelapse at system boot: sudo systemctl enable timelapse (disable to turn off, is-enabled to check current status)
    2. To start a timelapse at any time: sudo systemctl start timelapse (if one is not already running)
    3. To stop a timelapse in progress: sudo systemctl stop timelapse

Note: You should not try running a timelapse via the Python script directly and via Systemd at the same time. This could do weird things, and is not a typical mode of operation!

Creating animated gifs or videos

Animated gifs

Requirements: You should install ImageMagick (sudo apt-get -y install imagemagick)

If you have create_gif set to True in config.yml, the Pi will also generate an animated gif immediately following the conclusion of the capture.

Note: Animated gif generation can take a very long time on slower Pis, like the Pi Zero, A+, or original A or B.

Videos

Requirements: You should install FFmpeg (which is actually avconv on Raspbian — sudo apt-get -y install libav-tools)

If you have create_video set to True in config.yml, the Pi will also generate a video immediately following the conclusion of the capture.

Note: Video generation can take a very long time on slower Pis, like the Pi Zero, A+, or original A or B.

Manually Compiling Videos with ffmpeg

You can use ffmpeg on other platforms (or avconv on the Pi) to put together image sequences after the fact. For example, to take a sequence like image00001.jpg to image00248.jpg and generate an MP4 video:

ffmpeg -framerate 20 -i image%05d.jpg -vf format=yuv420p timelapse.mp4

And if you wanted to start the video in the middle of the sequence (e.g. instead of starting at image00001.jpg, start at image00024.jpg), you can pass the -start_number option:

ffmpeg -framerate 20 -start_number 634 -i image%05d.jpg -vf format=yuv420p timelapse.mp4

These commands assume you're inside the folder containing all the images, and output a file named timelapse.mp4 in the same directory.

Manual Settings

For a more pleasing timelapse, it's best to lock in manual settings for exposure and white balance (otherwise the video has a lot of inconsistency from frame to frame). This project allows almost complete control over manual exposure settings through variables in config.yml, and below are listed some rules of thumb for your own settings.

Read more about the Raspberry Pi's Camera hardware.

Resolution

The most common and useful Pi Camera resolutions (assuming a V2 camera module—V1 modules have different optimal resolutions) are listed below:

Size (width x height) Aspect Common name
3280 x 2464 4:3 (max resolution)
1920 x 1080 16:9 1080p
1280 x 720 16:9 720p (2x2 binning)
640 x 480 4:3 480p (2x2 binning)

Binning allows the Pi to sample a grid of four pixels and downsample the average values to one pixel. This makes for a slightly more color-accurate and sharp picture at a lower resolution than if the Pi were to skip pixels when generating the image.

ISO

ISO is basically an indication of 'light sensitivity'. Without getting too deep in the weeds, you should use lower ISO values (60 (V2 camera only), 100, 200) in bright situations, and higher ISO values (400, 800) in dark situations. There's a lot more to it than that, and as you find out creative ways to use shutter speed and ISO together, those rules go out the window, but for starters, you can choose the following manual values to lock in a particular ISO on the Pi Camera:

  • 60 (not available on V1 camera module)
  • 100
  • 200
  • 400
  • 800

Shutter Speed

Most photographers are familiar with the fractional values for common shutter speeds (1s, 1/10s, 1/30s, 1/60s, etc.), so here's a table to help convert some of the most common shutter speeds into microseconds (the value used in config.yml):

Fractional Shutter Speed µs
6 seconds (max) 6000000
1 second 1000000
1/8 125000
1/15 66666
1/30 33333
1/60 16666
1/125 8000
1/250 4000
1/500 2000
1/500 2000
1/1000 1000
1/2000 500

White Balance

White balance values on the Raspberry Pi camera are set by adjusting the red and blue gain values—the green value is constant. You need to amplify red and blue certain amounts to set a specific color temperature, and here are some of the settings that worked in specific situations for my camera. Note that you might need to adjust/eyeball things a little better for your own camera, as some unit-to-unit variance is to be expected on such an inexpensive little camera!

White Balance Setting Color Temperature (approx) red_gain blue_gain
Clear blue sky 8000K+ 1.5 1.5
Cloudy sky / overcast 6500K 1.5 1.2
Daylight 5500K 1.5 1.45
Fluorescent / 'cool' 4000K 1.3 1.75
Incandescent / 'warm' 2700K 1.25 1.9
Candle <2000K TODO TODO

Note: These values will be updated over time as I find more time to calibrate my Pi camera against a few DSLRs and other devices which are much more accurate! Please file an issue if you can help make these mappings better, or find a nicer way to adjust calibrations rather than a red_gain and blue_gain value.

Rotation

Depending on the placement of your camera, the picture taken could be upside down. To correct this, set rotation to a value of 0 (no rotation), or 90, 180 or 270 degrees to rotate the image.

License

MIT License.

Author

This project is maintained by Jeff Geerling, author of Ansible for DevOps.

More Repositories

1

ansible-for-devops

Ansible for DevOps examples.
Python
7,475
star
2

mac-dev-playbook

Mac setup and configuration via Ansible.
Shell
5,906
star
3

internet-pi

Raspberry Pi config for all things Internet.
Jinja
3,690
star
4

macos-virtualbox-vm

Instructions and script to help you create a VirtualBox VM running macOS.
Shell
2,519
star
5

ansible-vagrant-examples

Ansible examples using Vagrant to deploy to local VMs.
2,034
star
6

raspberry-pi-dramble

DEPRECATED - Raspberry Pi Kubernetes cluster that runs HA/HP Drupal 8
Shell
1,656
star
7

ansible-role-docker

Ansible Role - Docker
1,515
star
8

drupal-vm

A VM for Drupal development
Jinja
1,370
star
9

pi-webcam

Automation to configure a Raspberry Pi as a USB OTG webcam
1,322
star
10

internet-monitoring

Monitor your network and internet speed with Docker & Prometheus
1,237
star
11

raspberry-pi-pcie-devices

Raspberry Pi PCI Express device compatibility database
HTML
1,230
star
12

ansible-role-mysql

Ansible Role - MySQL
Jinja
988
star
13

ansible-role-jenkins

Ansible Role - Jenkins CI
Groovy
802
star
14

ansible-role-nginx

Ansible Role - Nginx
Jinja
774
star
15

ansible-role-security

Ansible Role - Security
Jinja
706
star
16

ansible-role-certbot

Ansible Role - Certbot (for Let's Encrypt)
Shell
698
star
17

ansible-role-gitlab

Ansible Role - GitLab
Jinja
653
star
18

packer-boxes

Jeff Geerling's Packer build configurations for Vagrant boxes.
Shell
635
star
19

ansible-for-kubernetes

Ansible and Kubernetes examples from Ansible for Kubernetes Book
Shell
612
star
20

my-backup-plan

How I back up all my data.
Shell
576
star
21

dotfiles

My configuration. Minimalist, but helps save a few thousand keystrokes a day.
Shell
540
star
22

ansible-role-firewall

Ansible Role - iptables Firewall configuration.
Shell
481
star
23

ansible-role-postgresql

Ansible Role - PostgreSQL
Jinja
478
star
24

kubernetes-101

Kubernetes 101 - by Jeff Geerling
HTML
477
star
25

ansible-role-php

Ansible Role - PHP
Jinja
468
star
26

ansible-role-kubernetes

Ansible Role - Kubernetes
Jinja
425
star
27

Ping

A PHP class to ping hosts.
PHP
415
star
28

ansible-role-apache

Ansible Role - Apache 2.x.
Jinja
392
star
29

ansible-role-nodejs

Ansible Role - Node.js
Jinja
386
star
30

turing-pi-cluster

DEPRECATED - Turing Pi cluster configuration for Raspberry Pi Compute Modules
Jinja
347
star
31

awx-container

Ansible Container project that manages the lifecycle of AWX on Docker.
297
star
32

ansible-role-java

Ansible Role - Java
Jinja
293
star
33

ansible-role-ntp

Ansible Role - NTP
Jinja
290
star
34

temperature-monitor

Raspberry Pi-based home temperature monitoring network.
JavaScript
256
star
35

pi-cluster

Raspberry Pi Cluster automation
Shell
231
star
36

ansible-role-awx

DEPRECATED Ansible Role - AWX
230
star
37

ansible-role-homebrew

Ansible Role - Homebrew (MOVED to geerlingguy.mac collection)
Shell
229
star
38

ansible-role-redis

Ansible Role - Redis
Jinja
228
star
39

packer-centos-7

This build has been moved - see README.md
223
star
40

ansible-collection-mac

Collection of macOS automation tools for Ansible.
Shell
220
star
41

ansible-role-dotfiles

Ansible Role - Easy and flexible dotfile installation.
214
star
42

ansible-role-nfs

Ansible Role - NFS
Jinja
207
star
43

ansible-role-haproxy

Ansible Role - HAProxy
Jinja
194
star
44

ansible-role-git

Ansible Role - Git
188
star
45

ansible-role-repo-epel

Ansible Role - EPEL Repository for RHEL/CentOS
175
star
46

ansible-role-composer

Ansible Role - Composer PHP Dependency Manager
Jinja
175
star
47

ansible-role-pip

Ansible Role - Pip (for Python)
174
star
48

turing-pi-2-cluster

DEPRECATED - Turing Pi 2 Cluster
Jinja
174
star
49

ansible-role-logstash

Ansible Role - Logstash
Jinja
168
star
50

ansible-role-elasticsearch

Ansible Role - Elasticsearch
Jinja
167
star
51

pico-w-garage-door-sensor

Wireless garage door sensor for Home Assistant powered by Raspberry Pi Pico W
Python
166
star
52

drupal-for-kubernetes

Drupal Example Site for Kubernetes
PHP
149
star
53

ansible-role-filebeat

Ansible Role - Filebeat for ELK stack
Jinja
137
star
54

ansible-role-backup

Ansible Role - Backup for simple servers
Shell
135
star
55

ansible-role-ansible

Ansible Role - Ansible
130
star
56

airgradient-prometheus

AirGradient Prometheus exporter.
C++
116
star
57

ansible-role-kibana

Ansible Role - Kibana
Jinja
115
star
58

ansible-role-swap

Ansible Role - Swap
107
star
59

obs-task-list-overlay

An HTML and Node.js-based task list overlay for OBS.
JavaScript
105
star
60

drupal-pi

Drupal on Docker on a Raspberry Pi. Pi Dramble's little brother.
Jinja
105
star
61

ansible-role-glusterfs

Ansible Role - GlusterFS
104
star
62

ansible-role-raspberry-pi

Configures a Raspberry Pi (running Raspbian).
102
star
63

docker-centos7-ansible

CentOS 7 Docker container for Ansible playbook and role testing.
Dockerfile
101
star
64

packer-ubuntu-1804

This build has been moved - see README.md
101
star
65

ansible-role-solr

Ansible Role - Apache Solr
Shell
97
star
66

ansible-mastodon

Mastodon installation on a single server using Ansible.
Jinja
95
star
67

sbc-reviews

Jeff Geerling's SBC review data - Raspberry Pi, Radxa, Orange Pi, etc.
93
star
68

ansible-role-supervisor

Ansible Role - Supervisor
Shell
92
star
69

ansible-role-docker_arm

Ansible Role - Docker for ARM and Pi
91
star
70

ansible-requirements-updater

Update your requirements.yml with this grisly Ansible playbook.
90
star
71

ansible-role-php-versions

Ansible Role - PHP Versions
88
star
72

ansible-role-ruby

Ansible Role - Ruby
Shell
86
star
73

ansible-role-mas

Ansible Role - Mac App Store CLI (MOVED to geerlingguy.mac collection)
85
star
74

JJG-Ansible-Windows

[DEPRECATED] Windows shell provisioning script to bootstrap Ansible from within a Vagrant VM.
Shell
85
star
75

ansible-role-drupal

Ansible Role - Drupal
84
star
76

pi4gpu

Raspberry Pi GPU Carrier Board
OpenSCAD
83
star
77

ansible-role-postfix

Ansible Role - Postfix
82
star
78

tower-operator

DEPRECATED: This project was moved and renamed to: https://github.com/ansible/awx-operator
Dockerfile
82
star
79

ansible-role-varnish

Ansible Role - Varnish HTTP accelerator
Jinja
82
star
80

packer-ubuntu-1404

DEPRECATED - Packer Example - Ubuntu 14.04 Vagrant Box using Ansible provisioner
Shell
82
star
81

pi-camera

A Raspberry Pi Camera
Python
79
star
82

packer-centos-6

This build has been moved - see README.md
79
star
83

pi-router

Raspberry Pi-based OpenWRT router config for 4G/5G Waveshare Dual Ethernet board.
Dockerfile
79
star
84

docker-ubuntu1804-ansible

Ubuntu 18.04 LTS (Bionic) Docker container for Ansible playbook and role testing.
Dockerfile
78
star
85

top500-benchmark

Automated Top500 benchmark for clusters or single nodes.
Jinja
76
star
86

deskpi-super6c-cluster

DEPRECATED - DeskPi Super6c 6-node Raspberry Pi CM4 Cluster
76
star
87

docker-examples

There are many like it, but this one is mine.
Python
75
star
88

youtube-10k-pods

10,000 Kubernetes Pods for 10,000 Subscribers
74
star
89

docker-ubuntu2004-ansible

Ubuntu 20.04 LTS (Focal Fossa) Docker container for Ansible playbook and role testing.
Dockerfile
74
star
90

pi-bell-slapper

The King of Ding. Internet-connected Raspberry Pi-based notification bell.
OpenSCAD
74
star
91

baby-safe-temp

Safe temperature monitor for baby's room. Made for Raspberry Pi Pico.
Python
74
star
92

ansible-role-memcached

Ansible Role - Memcached
Jinja
68
star
93

ansible-role-node_exporter

Ansible role - Node exporter
Jinja
66
star
94

ansible-role-mailhog

Ansible Role - MailHog for catching and viewing emails
Shell
62
star
95

molecule-playbook-testing

This is an example from the Ansible 101 livestream
62
star
96

ansible-role-ssh-chroot-jail

Ansible Role - SSH chroot jail config
Shell
60
star
97

pi-nvr

Raspberry Pi NVR for home CCTV recording.
Dockerfile
58
star
98

Imap

Simple wrapper class for PHP's IMAP-related email functions.
PHP
57
star
99

Request

A simple PHP HTTP request class.
PHP
56
star
100

ansible-role-samba

Ansible Role - Samba
55
star