Tethered shooting with a DSLR (shooting directly to a connected computer via a USB cable) on Linux is very, very easy, assuming you have gphoto installed.
And start shooting away! However, I wanted to be a bit cleverer and improve my workflow slighty to overcome a few shortcomings. I wanted to:
- Shoot raw
- Display the last shot full-screen.
- Not clobber existing files if I re-ran the tether.
it turns out that this is all easy to do with a small bash script and gphoto’s “hook” capabilities. I knocked up the following based upon the sample distributed with gphoto and called it hook.sh.
#!/bin/bash self=`basename $0` case "$ACTION" in init) echo "$self: INIT" # exit 1 # non-null exit to make gphoto2 call fail ;; start) echo "$self: START" ;; download) echo "$self: DOWNLOAD to $ARGUMENT" TYPE=`file --mime-type -b "$ARGUMENT"` if [ "$TYPE" = 'image/x-canon-cr2' ]; then ufraw-batch --rotate=camera \ --compression=95 --out-type=jpg \ --embedded-image --output=thumb.jpg \ --overwrite "$ARGUMENT" mv -f thumb.jpg preview.jpg eog -f -w preview.jpg & ufraw-batch --rotate=no \ --compression=95 --out-type=jpg \ "$ARGUMENT" & else eog -f -w "$ARGUMENT" & fi ;; stop) echo "$self: STOP" rm preview.jpg ;; *) echo "$self: Unknown action: $ACTION" ;; esac exit 0
In simple terms, once gphoto has received an image from the tethered camera, the ‘download’ case of the hook script is called. If the image is a jpeg, Eye of Gnome is employed to display it full-screen. If it is a raw file (I have a Canon hence the CR2 mime type), the embedded jpeg is first extracted and displayed full-screen, then the most excellect ufraw is used to create a full size jpg copy.
Why are two jpgs created from the raw file? On my fairly slow laptop the conversion of a file to jpeg can take up to 30 seconds which I found frustratingly slow when shooting; the embedded jpeg has a higher resolution than my monitor and is quick to extract and display; the high-quality conversion can then take place in the background.
During my testing I discovered that Eye of Gnome sometimes reads the image before ufraw had finished writing it which resulted in some nasty displays. The quick and simple hack of creating the preview with a different name and replacing the displayed image is one of those things that ‘just works’.
All that is left is to tie it all up, and get gphoto to give the images timestamped names rather than sequential numbers. If you use the default filename you must remember to change folders before running the scripts again or you will clobber the existing files!
gphoto2 --capture-tethered --hook-script=hook.sh --filename TET_%H%M%S.%C