Quantcast
Channel: Philipp Klaus's Computing Blog » timelapse
Viewing all articles
Browse latest Browse all 2

Setting up a Raspberry Pi with Auto-Timelapse Recording

$
0
0

This blog post is still in the makes, you can, however, already take advantage of the pretty content available so far.

  1. Install Arch Linux ARM on SD Card (get the image from here)
  2. Plug SD card into RPi, connect the Camera Module (see this) and power up the RPi
  3. SSH into the RPi with user/pw root/root (find the IP of your Raspi with sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}').
  4. Change the root password with passwd
  5. Bring system up-to-date and install some important tools with pacman -Syyu vim htop screen
  6. Change the hostname to lapsepi using hostnamectl set-hostname lapsepi
  7. Get the time at startup via NTP using systemd-timesyncd:
    Edit /etc/systemd/timesyncd.conf and uncomment the Servers then
    pacman -R openntpd || pacman -R ntp
    systemctl start systemd-timesyncd.service
    systemctl enable systemd-timesyncd.service
  8. Fix the timezone with timedatectl set-timezone Europe/Berlin
  9. Add these lines to your /boot/config.txt:
    start_file=start_x.elf
    fixup_file=fixup_x.dat
    #disable_camera_led=1
    Also adjust the gpu_mem_xxx values in the /boot/config.txt file:
    gpu_mem_512=128
    gpu_mem_256=128
  10. Install the Raspberry Pi firmware: pacman -S raspberrypi-firmware
  11. Improve bash experience with
    cat << "EOF" >> ~/.bashrc
    export PATH=$PATH:/opt/vc/bin
    export HISTSIZE=2000000
    export HISTFILESIZE=50000000
    EOF
    and
    echo 'if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' > .bash_profile
    Then log back in via SSH
  12. If you are using a new B+ model, you may need to blacklist i2c_bcm2708 if they didn’t fix this yet.
  13. Reboot and check that the camera module works via raspistill -o image.jpg

Now you’re ready to use your Pi as a Time Lapse Recorder.

More preparations

Own FAT Partition for images on a USB thumb drive

Find the USB thumb drive drive:

ls /dev/sd?
lsblk

Create Partition

DEV=/dev/sda
parted -s $DEV mklabel msdos
parted -s $DEV mkpart primary 1 -1
#parted -s $DEV set 1 boot on
#parted -s $DEV set 1 lba on
parted -s $DEV print

Format

pacman -S dosfstools
mkfs.vfat -F 32 /dev/sda1

Simple use of raspistill, raspivid…

# start a *screen* session (will continue to run even when disconnecting ssh):
screen
# capture an image every 30 seconds for 6 hours:
raspistill -o a%04d.jpg -t 21600000 -tl 30000
# capture 6 hours of video
raspivid -w 1280 -h 720 -o video.h264 -t 21600000

Post-processing

Get ffmpeg using pacman -S ffmpeg. Then you can embed a recorded movie in an mp4 container like this:

MOVIE=video.h264
ffmpeg -r 30 -i $MOVIE -vcodec copy $(basename -s .h264 $MOVIE).mp4

Python Script

  1. Install Python using pacman -S python python-pip
  2. Install the Python bindings for the camera module: pip install picamera

Continue with http://picamera.readthedocs.org/

http://picamera.readthedocs.org/en/latest/recipes1.html#capturing-timelapse-sequences

Use snap.py to capture pictures every x seconds.

Get some ideas from raspiLapseCam.py?

Add to autostart

Add a cron entry with crontab -e:

@reboot python /root/timelapse/cont.py &

Afterwards shutdown -h now and unplug the battery/plug it back in.

Alternative: Write a systemd service file.

Putting it together in a watertight box

Check this post where they use an illy coffee tin.

Adding a shutdown button

Python script shutdown.py to monitor GPIO #17:

import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)
while True:
    print GPIO.input(17)
    if(GPIO.input(17) == False):
        os.system("sudo shutdown -h now")
        break
    time.sleep(1)

Add python /root/shutdown.py to autostart via crontab:

@reboot python /root/shutdown.py

Then short GPIO Pins 9 and 11 to shut down.

Alternative: http://danielpecos.com/2013/09/raspberrypi-custom-command-button/

Or maybe completely via Shell script?

#!/bin/bash
# monitor GPIO pin 17 (wiringPi pin 1) for shutdown signal
# export GPIO pin 17 and set to input with pull-up
echo "17" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio17/direction
echo "high" > /sys/class/gpio/gpio17/direction
# wait for pin to go low
while [ true ]
do
  if [ "$(cat /sys/class/gpio/gpio17/value)" == '0' ]
  then
    echo "Raspberry Pi Shutting Down!"
    #halt &
    shutdown -h now &
    exit 0
  fi
  sleep 1
done

Add bash /root/shutdown.sh to autostart via crontab:

@reboot bash /root/shutdown.sh

The script should also stop the image capture script first.

Converting the pictures to a movie

Using avconv

http://www.raspberrypi-spy.co.uk/2013/05/creating-timelapse-videos-with-the-raspberry-pi-camera/

avconv -r 10 -i timelapse_%04d.jpg
   -r 10 -vcodec libx264 -crf 20 -g 15
   -vf crop=2592:1458,scale=1280:720
   timelapse.mp4

Using mencoder

https://wiki.archlinux.org/index.php/MEncoder

pacman -S mencoder

Then combine the images to the mpeg4 file timelapse.avi:

cd ~/pictures
ls *.jpg > stills.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o timelapse.avi -mf type=jpeg:fps=30 mf://@stills.txt

Converting a real-time movie file to a timelapse movie file

Changing the Framerate / FPS of an x264 .mp4 movie file without re-encoding

Finally some ideas for your timelapse movies

  • Flowers blooming,
  • cleaning your room,
  • traffic moving at night,
  • people walking on the street,
  • sunsets/Sunrises,
  • lights turning on in buildings,
  • driving through town,
  • the front window on a train/subway,
  • snow piling up,
  • day-to-night/Night-to-day,
  • daily selfies,
  • seasons changing,
  • making a drawing,
  • boats on a harbor,
  • hyperlapse – walking around a building,
  • tourself working out.

Also check out 10 things you should not do in Time-lapse.

Resources


Viewing all articles
Browse latest Browse all 2

Trending Articles