Wednesday, December 23, 2009

Correct timestamp of digital photos

If your camera clock was reset sometime in the past and the pictures have wrong timestamp written in the EXIF metadata, here's what you can do:

1. Put all the pictures with the wrong time in one folder, like Desktop/Pics
2. Check the time and the date the camera is showing, e.g. 13.1.2009 01:31, and the current time, e.g. 23.12.2009 10:21
3. Now subtract both times:

    23.12.2009 10:21
  - 13.01.2009 01:31
 -------------------
    10.11.0000 08:50
So the difference is 0 years, 11 months, 10 days, 8 hours and 50 minutes.

3. Change the creation dates using exiftool:

> exiftool "-AllDates+=0:11:10 08:05:00" Desktop/Pics

4. If you want to change the file modified and accessed timecode, you can use the following command in cygwin shell:


$ for i in *.JPG ;do exiftool.exe -S -d "%Y%m%d%H%M.%S" -CreateDate $i |awk '{print $2}' |xargs -I % touch -t % $i ;done


This command might take quite some time and may slow down your computer. For my set of 60 pictures it took about 5 minutes. You've been warned.

5. Sadly I couldn't figure out how to change file creation timecode in batch mode.

References:
- http://www.sno.phy.queensu.ca/~phil/exiftool/
- http://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
http://www.perlmonks.org/?node_id=767176