Monday, 27 July 2015

Timelapse from a Raspberry Pi webcam

Just a few notes on taking very large numbers of photos with a view to making timelapse videos.

I've done a few timelapse videos using my DSLR, then processing them through Lightroom and LRTimeLapse. This work well, but is quite hard work, ties up my dslr and of course uses up a lot of shutter time (since I can't do electronic shutter with the dslr).

So I thought I'd have a go at making it happen with a webcam and a raspberry pi (I already had the webcam from other PC things I'd been doing, or else I might have used a picam).

I'm using a Logitech C920 webcam and planning to take full HD sized photos.

  1. Kit in use & setup
  2. Taking the photos - fswebcam
  3. And the answer is python and v4l2?
  4. First tests to check performance.

Kit in use

Did a standard install of raspbian (not noobs, just raspbian to save a little on space), then just added a few bits and bobs (I run the pi headless so I add ssh in raspi-config and I've installed nfs so I can copy stuff on and off easily)
sudo apt-get install v4l-utils nfs-kernel-server fswebcam
I started with a Pi 2 B as I suspect the extra oomph will help - if not I'll just save on power consumption anyway...

Taking the photos


I tried using streamer, but even on my Pi 2 (in fact even sometimes on my laptop) it had a nasty habit of repeating frames (it just scribbles over the last used buffer if it fails to get a fresh one). I also tried various webcam things like webcam and motion, but all had messy problems.

fswebcam is by far the cleanest and most reliable thing so far, used like this:
fswebcam --no-timestamp --no-banner -r 1920x1080 -S 4 --jpeg 85 --save a%Y-%m-%d_%H:%M:%S.jpg -q -l 2
 I get nice clean sequence of files with just a small amount of compression to keep the filesize under control.

I am looking at this python stuff though to see if it would help. I also need to use manual focus as on featureless sky (for example) the focus tends to get lost.

And the answer is python and v4l2

Looks like  this may be the way to go. For now, just getting started on setup:
sudo apt-get install python-pip
sudo pip install v4l2
sudo apt-get install libjpeg-dev libfreetype6-dev zlib1g-dev libpng12-dev
sudo apt-get install python-dev python-imaging libtiff4 tcl-dev tk-dev
sudo pip install pillow

I had a quick go with pylapse, but the install just falls in a heap on the floor, and a quick attempt at cpr got nowhere.

Got stuck into python streaming and image stuff, and now have a quick python script that can interrogate the usb camera and select various settings including the frame rate - although this camera offers a rather restricted set of rates (and they depend on the size and mode that is requested.

First tests to check performance

I've got my test script running with multiple threads and buffers using memory mapped I/O to the webcam. I can control (in a clunky manner) various parameters, and I can grab pics up to the max resolution of the camera (2304/1536).
At low resolution the slowest the camera will go is 5 frames per second (although I can obviously choose to chuck some away).
resolutionframe ratebuffers / workersactual ratecapture %age
160 x 1201/305 - 528.96100%
640 x 3601/305 - 328.0194.3%
864 x 4801/245 - 322.9767.1%
864 x 4801/105 - 39.66100%
1280 x 7201/105 - 39.6464.5%
1280 x 7201/55 - 34.79100%
1920 x 10801/55 - 34.8454.1%
1920 x 10801/58 - 34.8458.8%
2304 x 15361/28 - 31.6395.2%


No comments:

Post a Comment