Showing posts with label how-to. Show all posts
Showing posts with label how-to. Show all posts

Sunday, March 13, 2011

How-to: A gphoto primer

A few years back, my time lapse video of the Portage Lake lift bridge at sunset turned out to be rather popular -- because of my brief tutorial on using gphoto2 for time-lapse video. So, I've written up a short (but more detailed) tutorial on setting up and using gphoto for time-lapse videos.

Warning! (October 2019): This post is quite out-of-date. I now use a camera with a built-in intervalometer and haven't had to wrangle gphoto2 in years. The instructions below might work -- or might not. They were last updated in March 2015.

Step 1: Install gphoto
The first step is getting gphoto installed on your computer. How exactly you do this depends on your operating system.

Mac OS X: While this isn't quite download-and-go, it is still fairly easy to install gphoto2 on Mac OS X. The first step is to install MacPorts, a package manager for Mac OS X. You can begin at the MacPorts installation page, skipping down to the "Mac OS X Package (.pkg) Installer" section. Click on the link in the first paragraph which corresponds to your system. Download, open, and run the installer. Once it is done, open a Terminal window and type:

sudo port -v selfupdate

This may take a while. Once MacPorts is done, type:

sudo port install gphoto2

this will take a while. Leave the computer alone, have some coffee, read a book. When the compiler is done, you'll have a working copy of gphoto2 and everything you need to make it work (on the computer side, at least)!

Good news for OS X programmers: In the comments, Andreas writes that he has put together a framework for Mac OS X programmers, which can be used directly in XCode. I haven't tried this myself -- and of course, always be careful with unknown code -- but if you're interested, you can find it here: https://github.com/lnxbil/GPhoto2.framework

Linux: If you are using Linux, you almost certainly know enough to install gphoto on your own -- your favorite package manager will work. Versions of gphoto2 are available for all major package managers. For example:

    sudo apt-get install gphoto2

Windows: Unfortunately for Windows users, there is no official version of gphoto for windows. In fact, the gphoto2 team has a few words to say on the matter. I have heard rumors of an unofficial version of gphoto for Windows, but finding and getting that set up is far beyond the scope of this tutorial.

Step 2: Set up and test your camera
Almost all digital cameras made in the last 10 years -- whether point-and-shoot or DSLR -- will almost certainly work with gphoto. To be sure, you can check out this complete list of supported cameras.

There are a few basic steps to getting your camera ready to work with gphoto:
  1. Set your camera to the correct connection mode. This isn't the exposure mode, but rather the mode which controls how your camera talks to your computer. To figure out which mode you need, look on the list of supported cameras. Find your camera in the list, and look for the text in parentheses at the end -- for example "(PTP mode)". You now need to change your camera into this mode. This is usually in a "setup" or "options" menu, and it's a rarely changed option. Every camera is different, and your best resource is the user's guide. Many cameras work in either their normal mode (requiring no special setup), or PTP mode, which is a standard allowing computers to control cameras.

    Here's an example for the Nikon D40x (my favorite camera) which works on most Nikon DSLRs. The mode you need is PTP mode. To set this, press the Menu button, then choose "Setup", then "USB", then "MTP/PTP" and hit OK.
  2. Connect your camera to a computer using a USB cable. This should be the normal USB cable which you use to connect your camera to your computer when downloading photos. If you normally use a card reader or some other method, you will need to locate a USB cable which lets you connect your camera directly to the computer -- typically cameras come pre-supplied with these. I recommend using a laptop, so that you can move the camera to your favorite shooting location.
  3. For Mac OS X users only: kill the PTP daemon. This isn't as evil as it sounds! Mac OS X automatically "grabs" the camera when you plug it in -- this is how iPhoto and other programs can automatically download your photos. But this also means that gphoto doesn't "own" the camera, and can't use it. To fix this, open Terminal and type:
    killall PTPCamera
    You will have to repeat this entire process every time you plug the camera in to your laptop, or if you turn the camera off and on again while attached to your computer. In fact, killing the PTP daemon is the answer to many weird gphoto errors on Mac OS X.
  4. Test that your camera is connected and working. To do so, execute this command in a terminal:
    gphoto2 --capture-image
    Your camera should (after a few seconds) take a photo, just as if you had pressed the shutter button. If it doesn't, the error message may be enlightening.

Step 3: Take photos!
You are now all ready to take photos! The most useful "advanced" feature of gphoto2 is the ability to take time-lapse photos. The basic command you need will look like this:
     gphoto2 --capture-image-and-download --interval=30 --frames=10
Here's a breakdown:
  • --capture-image: tells gphoto to take an image.
  • --interval=30 : tells gphoto to keep taking images, once every 30 seconds.
  • --frames=10 : tells gphoto to stop taking photos after 10 have been captured (leave this off to continue forever).

You can replace --capture-image-and-download with --capture-image if you want the images to be kept on the camera. (This completely fails to work on my Nikon D40x).  Remember, you don't want to touch the camera while it's taking shots!

Here are a handful of useful things to remember:
  • Your camera will take photos in the current exposure mode (Program, Aperture Priority, etc.). Be sure your camera is in the mode you want before you begin. This usually means going into full-manual mode, so that the exposure is consistent between frames. It is also possible to use gphoto2 to change your exposure mode on some cameras.
  • If using a camera with ISO-Auto, ADR, etc., turn it off. These features can change your intended exposure and make your frames look inconsistent, even if you're in fully manual exposure mode.
  • Focus your camera on the intended subject before you begin, and then turn your lens to manual focus. This will avoid the camera trying to refocus for each frame, especially if there are moving objects involved, or if lighting gets dim.
  • Don't touch your camera while taking time-lapse photos, unless you want different frames to have a different viewpoint. For time-lapse videos such as the one I mentioned at the top of this post, you want the camera to be untouched for the entire time.

Wrapup
Those are the basics! You can do a lot more than this with gphoto2 -- but that's for the future. If you're interested in seeing what you can do, there are many other tutorials available out on the web. You can also get a summary of gphoto's options by typing
   gphoto2 --help
in your terminal. For now, enjoy!


Appendix: Installing gphoto2 on Mac OS X, the hard way


For those interested in how we had to do things "back in the day", I'm keeping the information below: how to get the latest version of gphoto2 and libgphoto2 to install under Mac OS X. This is no longer necessary, because MacPorts currently has the newest version of gphoto. Read above for more information. And with that, here's the old data:

Here are more detailed instructions for installing the newest version of gphoto2 on Mac OS X. I recommend starting with the MacPorts version above -- even though it's old, installing it will also install and update many other programs which gphoto2 needs to operate. After doing that, you should get the newest version. To get the newest version, download both the gphoto and libgphoto packages from the gphoto homepage. The first step is to install libgphoto. Double-click the libgphoto package to uncompress it. In Terminal, type the following commands:
 cd (path to the libgphoto directory)
 sudo ./configure --prefix=/opt/local
A large amount of text should pass through the terminal, after which type
 sudo make
 sudo make install
This installs libgphoto. The next step is to install gphoto2 itself, which uses libgphoto to control your camera. Double-click the gphoto package to uncompress it. Again in Terminal, type the following commands:
 cd (path to the gphoto directory)
 sudo ./configure --prefix=/opt/local --without-cdk --without-aalib POPT_CFLAGS="-I${prefix}/include" POPT_LIBS="-L${prefix}/lib -lpopt"
 sudo make
 sudo make install
These should configure, compile, and install gphoto2 correctly. To double-check that it worked, type in Terminal:
 gphoto2 -v
The result should be a bit of information, including version numbers about gphoto2. If there are any errors, you'll need to reinstall gphoto2.

Friday, May 8, 2009

Lift Bridge Time-Lapse (Part 1: The Video)

The Portage Lake lift bridge at sunset -- in motion!
You can also view the video on my flickr page.

I've been experimenting with time-lapse photography lately. There are all kinds of cool things you can do, once you've figured out how! This is an example from my first try -- the Portage Lake lift bridge -- a true local monument -- over about an hour and a half, centered around sunset. I have more from this shoot, which I will feature soon.

For the technically minded, here's my process for how to make your own time-lapse photo -- you can modify this based on your equipment, but I warn you: it's not for the technologically faint of heart! The summary is short: get software that lets you control your camera from a laptop, set it up correctly, and then sit back and let your computer and camera take the photos. But the devil is in the details...
  1. Install gphoto2 on a laptop. It lets you control a camera remotely, using a normal USB cable (most camera makers have similar software which you can buy, but I prefer gphoto -- it's free and command-line controlled). There are packages for Mac OS X, Windows, and of course Linux.
  2. Write a shell script which uses gphoto to take a photo every 2-3 minutes (varies, this one was on a 2-minute timer) while slowing the shutter speed by one notch (about 1/3 stop, on my camera) for each photo. The changing shutter speed is important for sunrise or sunset photos! If you are taking a sunrise shot, you will need to change things around to make the shutter speed go faster, rather than slower. My script looked like this:
    #!/bin/bash
    for ((i=$1; i<=$2; i+=1))
    do
    gphoto2 --set-config /main/capturesettings/exptime=0$i;
    gphoto2 --capture-image-and-download;
    sleep $3;
    done
    A few technical notes: The first line sets the shutter speed, while the second takes a photo (and downloads it to your laptop, so that you can check it out right away -- no touching the camera, lest you move it and ruin the effect!). This script would be invoked (on OS X or Linux) with parameters: the first is an integer representing the starting shutter speed, the second is the ending shutter speed, and the third is the number of seconds to pause between shots. The numbers you use will depend on your camera: My Nikon D40X runs from 000 (1/4000 second) through 051 (30 seconds). For example, calling the script "gphoto.sh",
      ./gphoto.sh 016 030 180
    would cause my camera to take a photo every 3 minutes (180 seconds), starting at 1/100 second shutter speed (that's 016 in my camera's code) and ending at 1/2.5 second (030), for a total of 15 frames over 45 minutes.
  3. Get to your location at least half an hour early. Set up the camera, tripod, and laptop (connected to the camera) with plans to be ready by half an hour before sunset (when the sky is just starting to really darken). Set the camera to full-manual mode, at your desired aperture and ISO settings. Focus on your desired target, and put your lens into manual focus mode (to avoid the camera trying to autofocus when it starts to get dark). Start the script.
  4. [Optional] Call up a friend you haven't talked to for a long time and spend the next hour and a half chatting as your camera and laptop do the work for you!
  5. Batch process your photos however you like (rotate, crop, etc. -- as long as you do the same thing to each photo, so that they are the same size and the images have not been shifted with respct to each other). I used GraphicConverter for this step -- a Mac-only app which has some great batch-processing features. There are many other apps you could use.
  6. Combine the images into a movie. There are many ways to do this. I used GraphicConverter -- others use iMovie, Windows Media Player, etc. This movie is at about 6 frames per second -- I would prefer more, once I polish my script.

Some details:
  • If you don't need to change your shutter speed (for example, if you're shooting during the day), you can have gphoto automatically take photos at intervals without needing a script -- just use
    gphoto2 --capture-image --interval=180 --frames=20
    which would take a photo every 180 seconds, for a total of 20 frames (60 minutes).

  • Having your camera on fully manual setting is essential, so that the script has full control over the exposure -- don't let your camera do the thinking, it will almost certainly get the later evening exposure wrong!

  • It takes some experimentation to get the timing right. This video was made with images taken every 2 minutes, with the shutter speed changing by about 1/3 stop each time. That seems about right for sunset, but if you have finer control over shutter speed, or want a different effect, your timing should be different.

Finally... have fun! Feel free to drop me a line if you want more details or clarifications.