From the Canyon Edge -- :-Dustin

Friday, July 2, 2010

Keeping Pictures from Multiple Cameras in Temporal Order


I use as many as 4 different cameras, each serving a slightly different purpose.

In order decreasing order of portability, and increasing order of photo quality:
  1. Pocket -- a low-quality, but always present camera phone (either my Palm Pre or my G1)
  2. Small -- Canon Powershot SD1000
  3. Medium -- Kodak z812 IS
  4. Large -- Canon EOS Digital Rebel XTi
When I'm traveling, I might take 2 or more of these cameras, and shoot pictures all day long on different cameras. Sometimes, I'm shooting with one camera, and Kim is shooting with the other. At the end of the day, I want to merge all of these pictures, and look at them in order.

To keep this straight, I take great care to ensure that the embedded clocks in all of these cameras are perfectly in sync.

And when I'm processing my pictures, I often use gthumb to rename my pictures, embedding the timestamp in the name.


Other times, I'll write a small script to do this for me.

Earlier today, as I was stitching my pictures together from 3 different cameras, I realized that one of the clocks was off by about a day. I used this little script to fix the timestamps:

#!/usr/bin/php
<?php
$dh = opendir(".");
while (($file = readdir($dh)) !== false) {
if (preg_match("/^IMG_/", $file)) {
$s = stat($file);
touch($file, $s[9] - 86400);
}
}
?>
After I did that, I also needed to update the EXIF data embedded in the JPG too. To do that, I used jhead.

jhead -dsft IMG_*

Of course, running jhead on these files modified them yet again, so the file's timestamps are screwed up again. Let's cover our tracks.



#!/usr/bin/php
<?php
$dh = opendir(".");
while (($file = readdir($dh)) !== false) {
if (preg_match("/^IMG_/", $file)) {
$exif_data = exif_read_data($file);
touch($file, strtotime($exif_data['DateTime']));
}
}
?>


Enjoy!

:-Dustin