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.
- Kit in use & setup
- Taking the photos - fswebcam
- And the answer is python and v4l2?
- First tests to check performance.
Kit in use
sudo apt-get install v4l-utils nfs-kernel-server fswebcamI 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 2I 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 v4l2Looks 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 performanceI'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).
|resolution||frame rate||buffers / workers||actual rate||capture %age|
|160 x 120||1/30||5 - 5||28.96||100%|
|640 x 360||1/30||5 - 3||28.01||94.3%|
|864 x 480||1/24||5 - 3||22.97||67.1%|
|864 x 480||1/10||5 - 3||9.66||100%|
|1280 x 720||1/10||5 - 3||9.64||64.5%|
|1280 x 720||1/5||5 - 3||4.79||100%|
|1920 x 1080||1/5||5 - 3||4.84||54.1%|
|1920 x 1080||1/5||8 - 3||4.84||58.8%|
|2304 x 1536||1/2||8 - 3||1.63||95.2%|