Setting local time in IPTC from EXIF time in UTC

Started by Andreas Yankopolus, March 14, 2013, 09:24:23 PM

Previous topic - Next topic

Andreas Yankopolus

I keep my cameras set to UTC and have been relying on Aperture to determine the local time upon import. You set the camera's time zone, the location time zone, and it does the rest, taking into account current DST state.

Is there a way to mimic Aperture's functionality using exiftool? I've used it for basic functions in the past. I'm quite familiar with bash scripting and would add this to my existing pre-processing script.

—Andreas

Phil Harvey

Hi Andreas,

Interesting that Aperture can read the camera's time zone because this is proprietary information, and not part of the EXIF specification.

ExifTool can probably do what you want, but it may involve a couple of steps.  The exact steps depend on the format and location of the time zone information.  I can provide more details if I know the camera model.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Andreas Yankopolus

Phil,

Thanks for the response. Aperture isn't reading the EXIF time zone info—it simply presents a dialogue box where you select the camera time and actual time. I leave camera time (and the camera's clock) set to UTC and then set actual time to whatever timezone I happen to be visiting. The handy part, and the one I'm trying to duplicate with exiftool, is that the actual time dialogue options include region (US Eastern, etc.) and city names (Paris, etc.), which Aperture converts to UTC±hh:mm based on DST. This is really helpful for visiting Europe, as they run a different DST changeover schedule than the US.

One step on my import script is to geotag based on the gpx file:

exiftool -geotag foo.gpx '-geotime<${DateTimeOriginal}+00:00' .

The "+00:00" is because my computer doesn't reside in UTC, and exiftool by default uses the computer's time zone settings.

I'm wondering what the best approach would be to set the timezone info and local shot time. I admit to being somewhat puzzled on how this is recorded in the metadata. Best I can tell, the EXIF time doesn't include a time zone, but there are multiple time fields in the IPTC section for different purposes. So I'm not 100% sure what my end goal is at this point...

I'm primarily using an Olympus EM-5 these days.

—Andreas

Phil Harvey

Hi Andreas,

OK, this is easy.  It sounds like what you want to do is shift the EXIF date/time tags to a specific time zone.  For example, this command subtracts 4 hours from DateTimeOriginal, CreateDate and ModifyDate, for all images in directory DIR:

exiftool -alldates-=4 DIR

This would shift GMT to EDT for example.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Andreas Yankopolus

Would this have the effect of storing "UTC-05:00" somewhere in the metadata? If so, I'm good to go.

I think that I can calculate offsets using date and references to /usr/share/zoneinfo.

—Andreas

Phil Harvey

Hi Andreas,

Quote from: Stubb on March 15, 2013, 09:40:45 AM
Would this have the effect of storing "UTC-05:00" somewhere in the metadata? If so, I'm good to go.

No, but reading the topic title I see you want the time in IPTC.  So after shifting the EXIF times you can copy them to IPTC and add the timezone like this:  (here I do only the CreateDate)

exiftool '-iptc:datecreated<exif:createdate' '-iptc:timecreated<${exif:createdate}-04:00' DIR

(but you must be careful if the image times may span a DST transition).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Andreas Yankopolus

Thanks, I'll fiddle with this over the weekend and post results.

—Andreas

Phil Harvey

Oops.  I just noticed that IPTC:DateCreated is not the analogue of EXIF:CreateDate.  Instead I should have used IPTC:DigitalCreationDate.  Go figure.  See the MWG Tags documentation for the MWG-recommended mappings.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Andreas Yankopolus

Here's the resulting shell script (developed on OS X Mountain Lion). It assumes that the camera clock is set to UTC and takes two arguments. The first is the time zone in which the images were made. The second is a image file, directory, or wildcard expression. The script calculates the time zone offset, shifts the EXIF time accordingly, and copies the EXIF time to the IPTC time along with the shift. This is done for ease of matching up the times with a GPS track log. Feel free to use as is. Any comments would be appreciated!

Note that the script does not handle the case where the files span a DST change...


#!/bin/bash
# Send comments to Andreas Yankopolus (andreas@yank.to).
# First argument is the time zone in which the photos were made
TZ=$1

# The shell will expand wildcards. Get all the command-line args
# and chop off the first one, which will be the time zone. The
# rest will be the file(s) to process.
FILES=`echo "$@" | sed "s|^$1||"`

# Make sure that the specified time zone exists.
find /usr/share/zoneinfo | cut -c21- | grep -x $TZ > /dev/null
# Check the return code from find.
if [ $? != 0 ]
then
   echo "Unknown time zone $TZ"
   exit 1
fi

# Get the time zone's offset from UTC.
OFFSET=`TZ=$TZ date +%z`

# Add a colon between the hours & minutes for exiftool.
PARSED=`echo $OFFSET | sed 's/[0-9][0-9]$/:&/'`

# Strip the +/- from the front.
ABS=`echo $PARSED | sed 's/^.//'`

# Check if the offset is minus or plus and construct the shift command
# that we'll pass to exiftool.
echo $PARSED | grep \- > /dev/null
if [ $? != 0 ]
then
   SHIFT="+=$ABS"
else
   SHIFT="-=$ABS"
fi

# Adjust the EXIF date & time
exiftool -overwrite_original_in_place "-EXIF:DateTimeOriginal$SHIFT" "-EXIF:CreateDate$SHIFT" $FILES

# Write the IPTC date & time, writing in the time zone offset.
exiftool -overwrite_original_in_place "-IPTC:DigitalCreationDate<EXIF:CreateDate" "-IPTC:DigitalCreationTime<\${EXIF:CreateDate}$PARSED" $FILES

Alan Clifford

I store dates in the xmp:datetimeoriginal (recommended by Phil) so my photos end up having

exiftool -a -G -datetimeoriginal hs30_0232.jpg
[EXIF]          Date/Time Original              : 2013:02:09 13:13:10
[XMP]           Date/Time Original              : 2013:02:09 09:13:10-04:00

and then I match up my external gps file to the xmp version.

I keep my time offsets in a file that a perl script accesses to get the time offset, usually just having something like this in it

photofilename   actual  datetimeoriginal
default              -4       0

I'm beginning to move away from using UTC now so that I end up with the exif:datetimeoriginal showing local time whilst the xmp version has the time offset.  I take a photo of my watch that shows both local and GMT so that I don't forget the offset.





Andreas Yankopolus

Alan—what's your thinking in leaving the EXIF alone and only modifying the XMP data? I may be showing my age by modifying the IPTC section instead of the newer XMP one. It's my understanding that XMP contains IPTC along with many other fields, including custom ones, so maybe I should modify my script accordingly. It seems like XMP started out as a sidecar file has since moved into the image file itself.

Alan Clifford

First of all, Phil is the person to advise on xmp versus iptc; I don't know enough about it.

My current thinking is that I want the datetimeoriginal to be local time so that a photo taken at, say, 4pm, doesn't have a time stamp of 8 pm.  I used to keep it a utc so that I could match up with gps but I can deal with that now.  My Nikon can use local time and store the time offset in other fields and I've decided I should keep the photos from other camera on local.  I did this for the first time this January with my dive camera.

I do store the xmp:datetimeoriginal in the photo file but create a sidecar file for movie files in filename.mov.xmp.

Phil Harvey

Regarding XMP vs IPTC.  If you want compatibility with older applications, use IPTC, otherwise I would recommend XMP.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Andreas Yankopolus

Thanks for the advice. Changing from IPTC to XMP was a simple matter of replacing the last line in my script with:


exiftool -overwrite_original_in_place "-XMP-xmp:CreateDate<\${EXIF:CreateDate}$PARSED" $FILES


Where $PARSED holds the GMT offset as a string like "-04:00".