Tethering from your Nikon to your Linux PC

If you're using Windows, you can buy some software from Nikon to have Photo Tethering (I guess it's called Tethering). I.e. you take a picture with your camera and it pops up on your computer screen. It's used in studio photography and very useful. I missed it very much during the last three days of product photography.

I wanted to have that on Linux as well. There is an excellent library called gphoto2, that can do half of the trick (i.e. it can download a picture right after the shot), but it can't display it. So I played around a little bit and wrote that script:

#!/bin/bash

case "$ACTION" in
    download)
        pkill qiv
        qiv -l -f -m "$ARGUMENT" &
        ;;
    "")
        me=$(cd ${0%/*} && echo $PWD/${0##*/})
        gphoto2 --capture-tethered --hook-script=$me
        ;;
esac

To "install" it, place it somewhere on your path.

To use it, connect your Nikon camera to your computer via USB. Go to an empty folder in a shell and just start it:

rian@thunder:~Pictures/example$ tether

Then take pictures. They will be displayed on your screen and stored in your current folder.

For this to work, you need the image-viewer qiv (or use any other viewer and adjust the script) in its most recent version (older versions don't support the -l switch which autorotates the image), if you're using ubuntu jaunty, you need to install qiv from karmic.

And you have to install gphoto2 to access the camera as well.

Kommentare

That's the awesome thing about Linux and Unix: you can create little utilities like this so fast and easy. The catch is you need to know a little bit about what you're doing, and too few people want to bother with figuring this stuff out (including myself sometimes).

Excellent script and solution!

That's what I really love about Linux, and other Unix-ish operating systems. There are small tools that can't do much, but the thing they do, they do perfectly. And they're designed to play nice with other small tools. And you have the right clue to easily paste them together the way you want. I just love it!

But you're right, you need to read a lot in the beginning to understand how the basics really work. And then you still need to read much whenever you're hitting a new problem. But the good thing is, documentation is always on-board. ;-)

And I'm a little bit proud of that small script, because it serves two purposes. It launches the tethering using gphoto2, and at the same time it's the hook-script that gets executed after the image has been transferred.

Very cleaver. Thanks!
A few potential gotchas:

1) My version of qiv doesn't have a -l option. I don't know wht it does on your system, but removing it didn't have bad effect.

2) The camera USB menu item has to be in MTP/PTP mode. gphoto2 can't talk to it if it is in USB mass storage (my usual setting)

3) You might have permission issue depending on how your system automatically mounts devices. I installed vbox (the virtual machine from Sun) which totally changed my default permissions so I had to go into /dev/bus/usb/xx and change the file mode to writable.

Your script is awesome. It is a nice way to abuse my old camera.

To be able to use the script with a D80 I needed to change the camera settings:
- File no.sequence must be on
- USB must be set to MTP/PTP

The script itself also needed to be adapted. When using RAW+jpeg qiv hangs while trying to display a .NEF-file. It is probably related to the sequence the files are downloaded which can differ between different models. I primarily shoot RAW,but use the JPG as a kind of preview since the difference between what you see at the camera-screen and the RAW differ very much with newer models like the D300, the D90 and the D5000.

Then there is the issue of wanting to dump all the files at a predefined folder (to prevent JPG's and NEF's being place al over the drive).

I rewrote the script a little:
#!/bin/bash

TETHER_FOLDER=~/nikon/tether
cd $TETHER_FOLDER

case "$ACTION" in
download)
pkill qiv
PICTUREFILE=`echo "$ARGUMENT" | sed -e "s/DSC\(.*\)\.\(.*\)/DSC\1.JPG/"`
#qiv -f -m "$ARGUMENT" &
qiv -f -m "$PICTUREFILE" &
;;
"")
me=$(cd ${0%/*} && echo $PWD/${0##*/})
echo $me
gphoto2 --folder="$TETHER_FOLDER" --capture-tethered --hook-script=$me
;;
esac

Still not perfect, since it fails when I call the script without absolute path, but it does the job for me.
Also it currently loads the pictures twice, but that should hardly be a real problem.

I liked what you did with this script, but wasn't fond of the startup and shutdown with each new image, flashing the background in between... Particularly bothersome for public presentations.

So I modified it a bit to use QIV's watch feature to simply substitute the image being shown. QIV only gets started when it's not already running, as soon as you snap your first pic and then cleans up after itself if needed.

Thanks...

#!/bin/bash

QIVWATCHFILE='DISPLAYIMAGE.JPG'
QIVCOMMANDLINE="qiv --fullscreen --watch $QIVWATCHFILE"

case "$ACTION" in
download)
cp "$ARGUMENT" $QIVWATCHFILE
if ! ps ax | grep -v grep | grep "$QIVCOMMANDLINE" > /dev/null
then
$QIVCOMMANDLINE &
fi
;;
stop)
echo "$self: STOP"
pkill "$QIVCOMMANDLINE"
rm $QIVWATCHFILE
;;
"")
me=$(cd ${0%/*} && echo $PWD/${0##*/})
gphoto2 --capture-tethered --hook-script=$me
;;
esac