Saturday, July 12, 2008

Fixing EXIF Date/Time Stamp in Photos

[UPDATE] I've uploaded source code to the SVN repository on SourceForge.net that is capable of changing the date and time stamps in JPEG EXIF images. The software is barebones, but feel free to contribute should you so desire. Eventually, a GUI would be nice. This project depends on the Exiv2 library and on Expat. You will need to link to Exiv2 and have its header files in your include path, and will need to have the Expat DLLs either installed in a globally accessable path or in the program executable directory. This software comes with no warrantee, so please use it at your own discretion and MAKE BACKUPS OF YOUR PHOTOS prior to running the software!

=====================================

It's been bothering me for a few years now -- my girlfriend's camera has an incorrect date/time setting. As a result, any photos that I import from her camera get sorted incorrectly by date by programs like Picasa or Windows Explorer (view -> details shows "Date Picture Taken").


The date and time data are not stored concurrently with the file access/create/modify data, but are instead stored inside the JPEG file, in the metadata portion. This portion is known as EXIF data, and provides a space for your camera to record all sorts of good information about the photo, such as resolution, shutter speed, F-stop, flash settings, and more. However, this data proves to be a formidable data structure to tackle independently. Luckily for me, I found a lovely library known as Exiv2. Exiv2 provides a cross-platform library for reading and writing the EXIF and metadata inside JPEG files. Using the library, it is possible to add, modify, or remove this metadata.

Some very useful scenarios for this include
  • setting the date of a scanned photo
  • correcting the date of photos from a digital camera that was not configured properly
  • storing other, extra information about a photo inside the photo itself.
For my scenario, I will be using the library to systematically correct the 1,000+ photos taken by my girlfriend's Pentax Optio S40 camera, whose date is off by 7 days, 21 hours, and 56 minutes. I'll start off by opening a JPEG, checking to see if it was captured using that model of camera, then adjusting 3 different timestamp fields: "Exif.Image.DateTimeOriginal", "Exif.Photo.DateTime", and "Exif.Photo.DateTimeDigitized".

I'll be posting my source code to SourceForge as soon as the project is approved. Check back for more info.

[UPDATE]: After I spent time successfully writing software to perform this action, it appears as if my efforts are futile. Every time I turn on the Pentax Optio S40, the time changes by 1 hour and 20 minutes. By turning on and off the camera repeatedly, I find this to be fairly consistent.

I turned the camera on/off within seconds, and noticed the time change:
  • 7/3/2008 10:02pm
  • 7/3/2008 8:42pm
  • 7/3/2008 7:22pm
  • 7/3/2008 6:02pm
It looks to me like a systematic software bug. The camera has version 1.0 of the firmware (found by holding down the Menu button at power-on). I have found no path for upgrading firmware for the Optio S40 via the Pentax website either.

I still plan on posting the source code to my application on SourceForge, pending approval.

No comments: