Monday, July 30, 2012

fixing incorrect dates in JPEGs on (x)ubuntu

Have you ever faced the problem of incorrectly set date in your camera?
I have, and realized it only after copying data to my laptop.

In my case year was set to previous one. For the solution description, please keep this in mind as I fix the date shift only, however the tools used could fix any other incorrect date setup as well.

Fixing it for the future pics is easy, just update your settings in camera, however how to fix it for the already created pics?
There are 2 places where date update is required:
- fix file properties as well as
- fix EXIF data.

Fixing file date
In linux it's easy. My case was I set up last year instead of this one => after having all the jpegs in one dir, I just ran:
touch -d '+0 year' *
(solution ideas were inspired by: http://superuser.com/questions/122863/linux-shell-change-a-files-modify-timestamp-relatively)

How to fix EXIF data?
Exiftool (http://www.sno.phy.queensu.ca/~phil/exiftool/) seems to do the job easily. Date shift feature using exiftool is described in more detail on: http://www.sno.phy.queensu.ca/~phil/exiftool/Shift.html

I Instaled it first:
sudo apt-get install libimage-exiftool-perl
Moreover there are multiple dates in EXIF, to list them I ran this on the particular file (using exiftool):
exiftool -k IMGP0184.JPG | grep Date
File Modification Date/Time     : 2012:07:30 22:27:57+02:00
Modify Date                     : 2011:07:22 12:48:12
Date/Time Original              : 2011:07:22 12:48:12
Create Date                     : 2011:07:22 12:48:12
Date                            : 2011:07:22
Manufacture Date                : 2011:10:07
-- press RETURN --
To fix EXIF dates on all the relevant files I ran:
exiftool "-AllDates+=1:0:0 0:0:0" *.JPG
That should be it. Let's check the result rerunning the EXIF data listing command:
exiftool -k IMGP0184.JPG | grep Date
File Modification Date/Time     : 2012:07:30 22:28:16+02:00
Modify Date                     : 2012:07:22 12:48:12
Date/Time Original              : 2012:07:22 12:48:12
Create Date                     : 2012:07:22 12:48:12
Date                            : 2011:07:22
Manufacture Date                : 2011:10:07
-- press RETURN --
OK, that worked for me :) Hope it helps you as well.

One more thing, to cleanup backup files created by exiftool I ran following:
rm *.JPG_original

No comments: