Tag Archives: udev

Automatic photo capturing

Steps:
1) detect camera is attached
2) capture images
3) copy image to movie dir and add name to image manifest
4) trigger upload
5) move image to backup folder
6) add cron job to make movie

Detecting camera is attached

USB hotplug events are handled by udev.

Here’s how you monitor udev events to write a rule:
udevadm monitor

Get USB bus info with:
lsusb

You can list udev attributes for a device with:
udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/001/003)

Example rule:
SUBSYSTEMS==”usb”, ATTRS{product}==”Some FooDev”, RUN+=”/pathto/script”

https://unix.stackexchange.com/questions/28548/how-to-run-custom-scripts-upon-usb-device-plug-in
http://weininger.net/how-to-write-udev-rules-for-usb-devices.html

Capture images

gphoto2 can capture images from a USB connected camera and trigger an event when download. The easiest mode seems to be –capture-image-and-download. There’s an interval setting (-I) as well that will allow continuous downloads every x seconds. The –hook-script allows you to execute a script when the image is downloaded. The –filename option can set a filename pattern, but it doesn’t allow %s.

Resources:
http://www.gphoto.org/doc/manual/ref-gphoto2-cli.html
http://www.gphoto.org/doc/manual/using-gphoto2.html
http://www.gphoto.org/doc/manual/
http://photolifetoys.blogspot.com/2012/08/control-your-camera-with-gphoto2-via.html

Upload images to tumblr

This is fairly straightforward with the tumblr.js node library:

client = tumblr.createClient({api keys});

client.photo(blogname, { 'state': 'published', 'tags': tags, 'data': fullpath }, function(err) {
if (err) {
console.log(err);
process.exit(1);
}
});

The only tricky thing is that if you upload too quickly then tumblr will block you. Once every 10 minutes seems good. Maybe a cron job is the best way to do the rate limiting?

Creating movies

Before uploading to tumblr, copy files to movie directory and if the time is in the 14h window, add filename to the image list for ffmpeg.

You can do something like this in ffmpeg to read in a list of image filenames and create a film:
cat $(cat manifest) | ffmpeg -framerate $in_fr -i – -r $out_fr -preset ultrafast $out_file