Scripts for creating timelapse videos on a Raspberry Pi.
Basic setup steps:
sudo apt install -y mencoder
git clone https://github.com/NanoDano/Pi-Timelapser /home/pi/Pi-Timelapser
/usr/bin/python3 -m venv /home/pi/Pi-Timelapser/venv
/home/pi/Pi-Timelapser/venv/bin/python -m pip install -r /home/pi/Pi-Timelapser/requirements.txt
cp /home/pi/Pi-Timelapser/app/app/app{.example,}.env
vim /home/pi/Pi-Timelapser/app/app/app.env
/home/pi/Pi-Timelapser/venv/bin/python /home/pi/Pi-Timelapser/app/manage.py migrate
/home/pi/Pi-Timelapser/venv/bin/python /home/pi/Pi-Timelapser/app/manage.py collectstatic
There are two cron jobs to setup:
- Taking a picture ever X minutes
- Nightly "build" which creates the timelapse video and uploads over FTP
Run:
crontab -e
And add the lines:
*/5 * * * * /home/pi/Pi-Timelapser/venv/bin/python /home/pi/Pi-Timelapser/app/manage.py take_picture
0 0 * * * /home/pi/Pi-Timelapser/venv/bin/python /home/pi/Pi-Timelapser/app/manage.py nightly_build
The merge_videos
script is not on a cron timer, but
is a utility script provided to assist with stitching multiple
videos together to create a longer video.
If you want the media dir with all images to be browsable via nginx, update the nginx config with the location alias:
# http ...
# server ...
location /timelapser-images {
autoindex on;
alias /home/pi/Pi-Timelapser/app/media/;
}
- Create a systemd service file for the gunicorn/django app.
# /etc/systemd/system/Timelapser.service
[Unit]
Description=Pi Timelapser
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=/var/www/Pi-Timelapser/app
ExecStart=/usr/local/bin/gunicorn app.wsgi -b 127.0.0.1:8001
Restart=always
[Install]
WantedBy=multi-user.target
- Enable and start the service
sudo systemctl enable Timelapser
sudo systemctl start Timelapser
- Generate SSL cert and key
# TODO put this ssl cert in the timelapser dir instead?
sudo openssl \
req \
-newkey rsa:2048 -nodes \
-keyout /etc/ssl/private/pi-timelapster.key \
-x509 -days 36500 -out /etc/ssl/private/pi-timelapser.cert \
-subj "/C=US/ST=NRW/L=Earth/O=CompanyName/OU=IT/CN=www.example.com/emailAddress=email@example.com"
- Create a config file for nginx in
/etc/nginx/sites-available/
.
# /etc/nginx/sites-available/pi-timelapser.conf
server {
listen 0.0.0.0:443 ssl;
server_name cammy.attlocal.net;
ssl_certificate /etc/ssl/private/pi-timelapser.cert;
ssl_certificate_key /etc/ssl/private/pi-timelapster.key;
ssl_ciphers HIGH:!aNULL:!MD5;
location /static/ {
alias /var/www/Pi-Timelapser/app/static/;
}
location /media/ {
alias /var/www/Pi-Timelapser/app/media/;
}
location / {
include proxy_params;
proxy_pass http://127.0.0.1:8001;
}
}
- Symlink config from sites-available to sites-enabled.
sudo ln -s \
/etc/nginx/sites-available/Pi-Timelapser.conf \
/etc/nginx/sites-enabled/Pi-Timelapser.conf
- Enable and start the service
sudo systemctl enable nginx
sudo systemctl start nginx
Pi Cam v1 - 2592x1944 Pi Cam v2 - 3280x2464