ExifTool Forum

ExifTool => Archives => Topic started by: Archive on May 12, 2010, 08:54:32 AM

Title: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:32 AM
[Originally posted by r4ndom on 2009-03-17 14:23:56-07]

Hi,

after reading about every post regarding this topic, I still couldn't find a hint how to solve my problem.

I shoot with my camera set to UTC and now want to re-write my timestamps like this:

(1) Create and populate GPSDateStamp and GPSTimeStamps tags from DateTimeOriginal (=UTC).

(2) Run ExifTool to re-write CreateDate and DateTimeOriginal with timezone adjustment (say +3 hours for UTC+3); add - like Phil suggested in an earlier post - the timezone appendix "+03:00" to both EXIF tags, even though this is not standard-compliant.

(3) Populate IPTC:DateCreated, IPTC:TimeCreated and XMP:CreateDate with the time-zoned values (+03:00).

I modified the .ExifTool_config file to create user variables for a set of UTC deviations:

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {

        # Variable takes UTC from DateTimeOriginal
        UTC => {
            Require => 'DateTimeOriginal',
            ValueConv => '$val',
        },

       
        # Variable takes UTC timestamp from camera and shifts timezone
        UTCplus1 => {
            Require => {
                0 => 'DateTimeOriginal',
            },
            ValueConv => q{
                require 'Image/ExifTool/Shift.pl';
                # 'n' is the added timezone value, +1 is forward, -1 is back
                Image::ExifTool::ShiftTime($val[0], '1', +1);
                return $val[0];
            },
            PrintConv => '$self->ConvertDateTime($val)',
        },

(etc.)

Code:
   },
);

#------------------------------------------------------------------------------
1;  #end

In order to modify my files, I use the following statement:

Code:
exiftool -n -overwrite_original '-GPSDateStamp<UTC' '-GPSTimeStamp<UTC' '-CreateDate<${UTCplus1}+01:00' '-DateTimeOriginal<${UTCplus1}+01:00' '-IPTC:DateCreated<UTCplus1' '-IPTC:TimeCreated<UTCplus1' DIR

Unfortunately, this doesn't do what I expected. It doesn't create the GPSDateTime tags, for instance. The tags I get as a result are

Code:
---- IPTC ----
Date Created       : 2009:03:14
Time Created       : 12:07:53+01:00
---- ExifIFD ----
Date/Time Original : 2009:03:14 12:07:53+01:00
Create Date        : 2009:03:14 12:07:53+01:00
---- Composite ----
Date/Time Created  : 2009:03:14 12:07:53+01:00
Date/Time Original : 2009:03:14 12:07:53+01:00.22

UTC          : 2009:03:14 12:07:53+01:00
UT Cminus 1  : 2009:03:14 11:07:53+01:00
UT Cminus 10 : 2009:03:14 02:07:53+01:00
UT Cminus 11 : 2009:03:14 01:07:53+01:00
UT Cminus 12 : 2009:03:14 00:07:53+01:00
UT Cminus 2  : 2009:03:14 10:07:53+01:00
UT Cminus 3  : 2009:03:14 09:07:53+01:00
UT Cminus 4  : 2009:03:14 08:07:53+01:00
UT Cminus 5  : 2009:03:14 07:07:53+01:00
UT Cminus 6  : 2009:03:14 06:07:53+01:00
UT Cminus 7  : 2009:03:14 05:07:53+01:00
UT Cminus 8  : 2009:03:14 04:07:53+01:00
UT Cminus 9  : 2009:03:14 03:07:53+01:00
UT Cplus 1   : 2009:03:14 13:07:53+01:00
UT Cplus 10  : 2009:03:14 22:07:53+01:00
UT Cplus 11  : 2009:03:14 23:07:53+01:00
UT Cplus 12  : 2009:03:15 00:07:53+01:00
UT Cplus 2   : 2009:03:14 14:07:53+01:00
UT Cplus 3   : 2009:03:14 15:07:53+01:00
UT Cplus 4   : 2009:03:14 16:07:53+01:00
UT Cplus 5   : 2009:03:14 17:07:53+01:00
UT Cplus 6   : 2009:03:14 18:07:53+01:00
UT Cplus 7   : 2009:03:14 19:07:53+01:00
UT Cplus 8   : 2009:03:14 20:07:53+01:00
UT Cplus 9   : 2009:03:14 21:07:53+01:00

Any idea what I have missed?

Thanks,

Leo
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by r4ndom on 2009-03-17 14:30:43-07]

Oh, sorry, there's something I forgot to add:

The image of the above example was shot at 2009:03:14 11:07:53 UTC, my local time zone was UTC+1. So, the "UTC" tag above is wrong for a start, "UTCplus1" is also one hour fast.

... and the user variables did not contain spaces as shown.

Leo
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-17 14:59:52-07]

Hi Leo,

The GPS date/time tags aren't set because you used the -n option.
The -n option bypasses the date/time reformatting, so the date and time
won't be extracted for GPSDateStamp and GPSTimeStamp from the date/time value
you are passing.

You can sometimes get a clue about the problem by using the -v3
option.  In this case it shows the following errors:

Code:
String too long for GPS:GPSDateStamp
 Too many values specified (3 required) for GPS:GPSTimeStamp

- Phil
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by r4ndom on 2009-03-18 05:51:55-07]

Hi Phil,

thanks for the quick reply!

(1) If I drop the -n option though, I cannot re-write the EXIF timestamps with the added timezone extension (+01:00). Is there a way to do both without using a second exiftool statement (i.e. doubling processing time on n images)?

(2) What have I done wrong with the .ExifTool_config that the user variable UTC is one hour fast (12:07 instead of 11:07)? I am not familiar with Perl, but I should have thought that my definition sets the new user variable UTC to the initial DateTimeOriginal value (= 11:07 = UTC).

(3) Finally, do you have any idea why the other UTC user variables - I called them UTCplus1, UTCplus2... UTCminus1, UTCminus2... - are displayed with spaces? Is that just a side-effect of my exiftool -n -g1 -w %d%f_alltags.txt DIR statement or would they actually have been divided by spaces?

Thanks, Leo
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-18 17:43:01-07]

Hi Leo,

Sorry for the delay.  The CPAN forum email notification appears
to be broken.

1. The only way to avoid the -n is to create user-defined
tags to extract the date and time from a date/time value.

2. Your UTC tag is derived from the value of DateTimeOriginal.
If DateTimeOriginal is 12:07 (which it is), then your UTC tag will have
the same value.

3. ExifTool creates a tag "Description" if it doesn't exist in the tag
definition by adding spaces before capital letters in the tag name.
But you can add whatever Description you want.

- Phil
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by r4ndom on 2009-03-18 18:11:42-07]

Hi Phil,

delay? What delay? There's hardly any other place where substantial replies are fired back as fast as here.

(1) Hm, I am not at all familiar with Perl, could you give me a hint, how such a user variable would be defind in the .ExifTool_config? I would like to simply append the +/-hh:mm timezone extension to the variable like I did in my

Code:
exiftool '-DateTimeOriginal<${UTCplus1}+01:00' DIR
statement.

Thanks a lot,

Leo
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-18 18:34:16-07]

Hi Leo,

I was talking about creating Composite tags so you could continue
to use the -n option, not the other way around:

Code:
exiftool -n "-gpsdatestamp<mydate" "-gpstimestamp<mytime" ...

This is one way these tags could be defined:

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Require => 'DateTimeOriginal',
            ValueConv => '$val=~/^([:\d]+) ([:\d]+)/ ? $1 : undef',
        },
        MyTime => {
            Require => 'DateTimeOriginal',
            ValueConv => '$val=~/^([:\d]+) ([:\d]+)/ ? $2 : undef',
        },
);

- Phil
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by r4ndom on 2009-03-19 13:42:21-07]

That works like a treat. Thanks a lot, Phil!

I don't mean to keep you busy, but maybe you could briefly help me with a clarification regarding EXIF and XMP tags. (I read all I could find about that on your ExifTool pages and in the IPTC/Exif/XMP manuals, but I just don't get it.)

(1) Do "-XMP:DateTimeOriginal" and "-EXIF:DateTimeOriginal" actually write different tags? When looking at the resulting files, it seems to me that the XMP parameters of

Code:
exiftool -overwrite_original -n "-EXIF:DateTimeOriginal<UTCplus1" "-EXIF:CreateDate<UTCplus1" "-EXIF:ModifyDate<UTC" "-XMP:DateTimeOriginal<${UTCplus1}+01:00" "-XMP:DateTimeDigitized<${UTCplus1}+01:00" "-XMP:ModifyDate<${UTC}+00:00" DIR

just overwrite the three corresponding EXIF tags at the beginning of the statement.

(2) I had read in a previous post that XMP allows timezone extensions while EXIF does not. If my assumption of (1) is true that would not make sense.

Thanks again,

Leo
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-19 13:57:25-07]

Yes, The XMP and EXIF DateTimeOriginal are different tags.
Use -a -G1 when you extract information to see
both tags and where they came from.  (This is FAQ number 3)

- Phil
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by r4ndom on 2009-03-19 14:30:17-07]

I found what's wrong: the above "exiftool -overwrite_original -n ..." statement doesn't write my XMP timestamps properly. I just ran a test that worked, using plain strings instead of my variables:

Code:
... -XMP:DateTimeOriginal="2008:03:17 20:00:00+01:00" ...

It seems that neither the user variables from my above .ExifTool_config file nor the timezone extensions are written properly into XMP. EXIF values are filled correctly, though.

Any idea what I could have messed up?

Thanks again,

Leo
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by exiftool on 2009-03-19 14:45:43-07]

Hi Leo,

If you're on Unix or a Mac, you must use single quotes around
any argument that contains a '$' sign.

- Phil
Title: Re: Re-writing timestamps with timezones
Post by: Archive on May 12, 2010, 08:54:33 AM
[Originally posted by r4ndom on 2009-03-19 14:49:21-07]

That was it. Thanks a lot!

- Leo