Showing posts with label time-lapse. Show all posts
Showing posts with label time-lapse. 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.

Wednesday, October 21, 2009

Quincy Stars - Take #2

Circular star trails with the Quincy Number 2 shaft house in the center.
Another shot at star trails at the Quincy Mine.

After my first try at star trails over the Quincy Mine, I learned many things about taking long nighttime exposures of the sky. Last Saturday, I headed back up to Quincy to put those lessons into action. In this post, I'll analyze the results, figure out what worked, what didn't, and list some more lessons learned.

Technical Details: This photo was made by "stacking" 144 separate exposures, each taken with these parameters:
  • Focal length: 10mm, on my shiny new Nikon 10-24mm
  • Shutter speed: 30 seconds
  • Aperture: f/3.5 (which was the maximum aperture available)
  • ISO: 400
I took the photos using gphoto2 (installation and details), a PTP camera controller program, installed on my MacBook Pro. The laptop controlled the camera via a USB connection. I used the gphoto2 command:
    gphoto2 --capture-image-and-download -I 34
This instructs the camera to take a photo every 34 seconds. Why 34 seconds? Interestingly, this is actually the ideal spot for my computer and camera combination to take photos at the correct rate. There is a bit of a delay when the computer instructs the camera to take the first photo. After that, gphoto2 keeps track of how far behind schedule it is -- and tries to catch up. The result is that the computer instructs the camera to take a photo after about a 1 second delay, just enough to let the sensor cool down.

Improvements and Problems: The purpose of trying this same photo shoot again was to learn from my mistakes last time. Here's a rundown of what I like and dislike about this photo.
  • Batteries and time:In many ways, this photo shoot (and the resulting star trails photo) came out much better than the last try. The major change is that my batteries -- both camera and laptop -- were fully charged. This allowed me to get much more than the mere 20 minutes of exposures which I had last time. This time, I got around 72 minutes, leading to much longer star trails.
  • gphoto Timing: Also, as mentioned above, I significantly improved the timing of the image-taking. In my previous attempt, the camera eventually got out of control (perhaps because of a "backlog" of "take a photo now!" commands), and kept taking photos without the computer being able to download them. The result was "stutters" in the star trails, as I had to reset the camera.
  • Composition and star trails: The main thing I don't like in this photo is the angle. While the shaft-rockhouse is quite dramatic, the stars are moving in circles -- much less interesting than the big ovals in the original photo. In addition, the wider angle of the star trails in the original emphasized the movement of the stars and made them appear longer.
  • Inability to take more than 30 second exposures: I still haven't found a way to both control my camera via my laptop, and take photos longer than 30 seconds. No camera control software -- whether gphoto2, Nikon Camera Control Pro, or any others -- will let me operate the camera in "bulb" mode, which allows exposures longer than 30 seconds. The result is that I have to shoot at a very wide aperture (f/3.5) which reduces depth of field, and ISO 400 which adds a lot of noise. Anyone knowing of a reasonably cheap way to take time-lapse photos with a shutter speed of longer than 30 seconds, please let me know!
  • Colors and clouds: Finally, I don't like the colors as much in this photo: the moon was new, resulting in no reflections on the shafthouse and less light in the sky. As a result, the colors of the shaft house were mostly reflections of cars and streetlights, which resulted in much less pleasing colors. In addition, clouds running through the sky resulted in brown smears in the stacked photo -- be careful to find a truly clear night!

Lessons Learned: Here's a big summary for the aspiring star-trail photographer:
  • In gphoto2, use an interval slightly longer than your exposure. This lets the camera keep up with the computer's commands, and also lets the sensor cool (avoiding weird "purple clouds" in photos.

  • Charge your batteries! ... duh.

  • Use Incandescent white balance. Unless you feel like processing 100+ RAW files, you'll need to choose a good white balance ahead of time. Incandescent white balance makes the sky appear bluer and more natural.

  • Shoot when the moon is moderately full. This helps highlight objects in the photo and adds more light in the sky, helping get more natural photos with better light balance.

  • Get there early, set up, and focus. Another big problem was that I waited until the sun was mostly down to set up my rig. As a result, focusing was difficult (and sharpness wasn't helped by the large aperture). I also had a hard time composing properly, since the viewfinder was much too dark to see through. Get to your location early, set up your equipment, focus and compose. Then set everything to manual mode and leave it until you're ready to start.

If you have any questions, feel free to leave a comment!

Sunday, September 27, 2009

Quincy Stars - Take #1

Star trails over the Quincy Mine #2 shaft-rockhouse
Star trails over the Quincy #2 - click for a larger size.

I've always enjoyed playing around with long exposures, and for a while I've been working on my star trail photos. Taking a single very long exposure is impractical, because the sensors of digital cameras overheat and add bright purple clouds of color to the image. So, the solution is to take many shorter photos, and "stack" them together into one photo.

In order to take that many photos, I needed a way to control the camera. Some cameras have built-in features to do this, but in my case, I used gphoto2, which I previously used to take some time lapse videos of the Portage Lake Lift Bridge.

This photo is a stack of 40 images, each of which was a 30-second long exposure at f/3.5 and ISO 400. Things did not work out perfectly: my camera went crazy at one point (gphoto isn't perfect), and after 20 minutes my battery died (I failed to fully charge it before!). I've learned a lot, so I'm planning to head out and try again next weekend!

Thursday, May 14, 2009

Lift Bridge Time-Lapse (Part 2: Fun with Photo Slicing)

The Portage Lake lift bridge, made up of 36 vertical stripes from 36 photos taken around sunset.
The Portage Lake lift bridge sunset, together in a single photo

Here's my next bit of fun with time-lapse photography: putting it all together in one photo! This photo is made up of 36 vertical slices. Reading from left to right, they span approximately 1.5 hours centered around sunset -- from 8:30 until 10:00 pm. These are the same images that went into my time lapse video of the lift bridge. The sharp edges are a bit annoying, but that could be solved by taking even more photos (something I hope to do shortly).

For those interested -- how did I do this? I can certainly tell you how I didn't do this: I definitely did not slice and assemble 36 photos by hand! Instead, starting with my 36 image files, I used magic -- actually, ImageMagick -- to do this for me. First, I ran the following shell script:
#!/bin/bash
off=$[0]
for ((i=2861;i<=2896;i++)) do
convert -crop 107x2385!+$off+0 DSC_$i.jpg Crop_$i.jpg;
off=$[$off + 107];
done
This script runs through the images, which were named DSC_2861.jpg through DSC_2896.jpg, in order. For each of them, it uses ImageMagick's convert command to crop the image into a single slice, 107 pixels wide and 2385 pixels tall. Each slice is 107 pixels to the right of the previous image's slice, so that the slices would all line up. I came up with these numbers pretty simply: 107 is the width of my images, divided by 36, while 2385 is the height of my images. After that, all I had to do was
convert Crop*.jpg +append bridge.jpg
which stitches the images together horizontally into a single image. (That's what +append does. Using -append stacks them vertically, in case you wanted to do a vertical time-lapse photo.)

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.