Copy "DateTimeOriginal" to "GPS Date/Time"

Started by D.Mon, September 06, 2018, 08:15:37 PM

Previous topic - Next topic

D.Mon

Hello,

I have some image files with "GPS Status : Measurement Void".
Therefor the "GPS Time" and "GPS Date" tags (and also the "GPS Date/Time") are not correct.

I tried
exiftool  "-GPSDateTime<DateTimeOriginal" DSC05639.JPG

The result was
1 image files updated
but the GPS Time/Date stamps were unchanged.

How can I copy the "DateTimeOriginal" tag to the GPS Date/Time tags?
And how can I change the GPS Time/Date stamps by a few hours with correct date if midnight was passed?

Greetings from Germany
martin
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

StarGeek

When you write to GPSDateTime, you are only writing to XMP:GPSDateTime.  You probably want to write to GPSTimeStamp and GPSDateStamp.  Normally when you list GPSDateTime, you are getting the Composite Tag which is where exiftool will automatically combine GPSTimeStamp and GPSDateStamp and isn't writable.

Also remember to include the proper timezone when you write GPSTimeStamp if it isn't the same as the the computer's timezone.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

D.Mon

Thank you for your advice.
I was now able to copy the values from DateTimeOriginal to GPSTimeStamp and GPSDateStamp.

I have two more questions:


  • How can I include the timezone?
    When I read -time:all from the unchanged file a timezone is only printed with GPS Date/Time in the form of
    GPS Time Stamp                  : 02:16:38
    GPS Date Stamp                  : 2018:08:26
    GPS Date/Time                   : 2018:08:26 02:16:38Z
  • How can I change the Time Stamp by a couple of hours keeping track of the right date?
    Let´s say I have a time stamp of "1:00:00 2018:08:26" and want to subtract 2 hours to get "23:00:00 2018:08:25".

What I am trying to do:
I have files which have Exif date and time off by -9h an GPS status Void.
The time zone was -7 from GMT (or Z).
I want to change the Exif time and date by -9h, then copy that to GPS and add 7h to gps time and date stamps.
My problem ist to get the correct date in gpsdatestamp.
My English ist not the best. I hope I explained well enough.
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

StarGeek

The GPS tags are always based upon UTC time, that's why you'll see the Z.

To add the time zone, you need to write the command slightly differently.  A dollar sign needs to be added because there is additional info added to the tag copy.  Also, braces need to be added to the tag name so as not to let the tag name run on into the additional info.  As an example:
exiftool "-GPSTimeStamp<${DateTimeOriginal}-07:00" "-GPSDateStamp<${DateTimeOriginal}-07:00"  FileOrDir

Example output:
C:\>exiftool -g1 -a -s -DateTimeOriginal -GPSTimeStamp -GPSDateStamp -GPSDateTime y:\!temp\Test3.jpg
---- ExifIFD ----
DateTimeOriginal                : 2018:09:07 19:55:00

C:\>exiftool -P -overwrite_original "-GPSTimeStamp<${DateTimeOriginal}-07:00" "-GPSDateStamp<${DateTimeOriginal}-07:00" y:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -DateTimeOriginal -GPSTimeStamp -GPSDateStamp -GPSDateTime y:\!temp\Test3.jpg
---- ExifIFD ----
DateTimeOriginal                : 2018:09:07 19:55:00
---- GPS ----
GPSTimeStamp                    : 02:55:00
GPSDateStamp                    : 2018:09:08
---- Composite ----
GPSDateTime                     : 2018:09:08 02:55:00Z


Quote from: maceis on September 07, 2018, 10:22:19 AM
How can I change the Time Stamp by a couple of hours keeping track of the right date?
Let´s say I have a time stamp of "1:00:00 2018:08:26" and want to subtract 2 hours to get "23:00:00 2018:08:25".

Normally, to shift a timestamp, you can use -= or +=. See the docs.  But that won't work with the GPS time stamps as they are separate tags.  I think this would require copying a tag, I'll have to search the archives.

QuoteWhat I am trying to do:
I have files which have Exif date and time off by -9h an GPS status Void.
The time zone was -7 from GMT (or Z).
I want to change the Exif time and date by -9h, then copy that to GPS and add 7h to gps time and date stamps.

I would do this:
exiftool -GlobalTimeShift -9 "-DateTimeOriginal<DateTimeOriginal" "-GPSTimeStamp<${DateTimeOriginal}-07:00" "-GPSDateStamp<${DateTimeOriginal}-07:00" FileOrDir

This uses the GlobalTimeShift option.  It will shift DateTimeOriginal by -9 hours and copy it back onto itself.  It will then take that same shifted time, add the timezone, and copy into the GPS time stamps.

Example output:
C:\>exiftool -g1 -a -s -DateTimeOriginal -GPSDateStamp -GPSTimeStamp -GPSDateTime y:\!temp\Test3.jpg
---- ExifIFD ----
DateTimeOriginal                : 2018:08:26 08:00:00

C:\>exiftool -P -overwrite_original -globalTimeShift -9 "-DateTimeOriginal<DateTimeOriginal" "-GPSTimeStamp<${DateTimeOriginal}-07:00" "-GPSDateStamp<${DateTimeOriginal}-07:00" y:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -DateTimeOriginal -GPSDateStamp -GPSTimeStamp -GPSDateTime y:\!temp\Test3.jpg
---- ExifIFD ----
DateTimeOriginal                : 2018:08:25 23:00:00
---- GPS ----
GPSTimeStamp                    : 06:00:00
GPSDateStamp                    : 2018:08:26
---- Composite ----
GPSDateTime                     : 2018:08:26 06:00:00Z
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

D.Mon

Thank you for your detailed answer.

If I got your first example output right, your file Test3.jpg did not have gpsdate and gpstime when you started.
My Situation ist slightly different and so are my results.
My jpg (and Sony arw) files do habe gpsdate and gpstime but since gps status is void the camera used the values of the last picture that was taken with gps status active.

Here is what I tried and the results:
exiftool -GlobalTimeShift -9 "-DateTimeOriginal<DateTimeOriginal" "-GPSTimeStamp<${DateTimeOriginal}+07:00" "-GPSDateStamp<${DateTimeOriginal}+07:00" DSC05639.JPG

exiftool -g1 -a -s -DateTimeOriginal -GPSDateStamp -GPSTimeStamp -GPSDateTime DSC05639*.JPG
======== DSC05639-original.JPG
---- ExifIFD ----
DateTimeOriginal                : 2018:08:26 02:16:38
---- GPS ----
GPSTimeStamp                    : 00:06:37
GPSDateStamp                    : 2018:08:26
---- Composite ----
GPSDateTime                     : 2018:08:26 00:06:37Z
======== DSC05639.JPG
---- ExifIFD ----
DateTimeOriginal                : 2018:08:25 17:16:38
---- GPS ----
GPSTimeStamp                    : 00:06:37
GPSDateStamp                    : 2018:08:26
---- Composite ----
GPSDateTime                     : 2018:08:26 00:06:37Z


GPSTimeStamp and GPSDateStamp were not changed.
I even tried deleting those tags, but I was not able to create them again:
exiftool -gpsdatestamp= -gpstimestamp= DSC05639.JPG
    1 image files updated

exiftool -GlobalTimeShift -9 "-DateTimeOriginal<DateTimeOriginal" "-GPSTimeStamp<${DateTimeOriginal}+07:00" "-GPSDateStamp<${DateTimeOriginal}+07:00" DSC05639.JPG
Warning: [minor] Error reading PreviewImage - DSC05639.JPG
    1 image files updated

exiftool -g1 -a -s -DateTimeOriginal -GPSDateStamp -GPSTimeStamp -GPSDateTime DSC05639*.JPG
======== DSC05639-original.JPG
---- ExifIFD ----
DateTimeOriginal                : 2018:08:26 02:16:38
---- GPS ----
GPSTimeStamp                    : 00:06:37
GPSDateStamp                    : 2018:08:26
---- Composite ----
GPSDateTime                     : 2018:08:26 00:06:37Z
======== DSC05639.JPG
---- ExifIFD ----
DateTimeOriginal                : 2018:08:25 17:16:38
    2 image files read


What am I missing?
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

StarGeek

First, is the time zone UTC-07:00 (Pacific Coast U.S.) as you previously stated or is it UTC+07:00 (Russia, Mongolia, Vietnam) as you used in your latest post?

Set it to the actual time zone of the location the image was shot.  Exiftool will do the proper computations when writing the GPS time.

Always make sure to show all the output from a command.  It looks like you snipped something at one point because one output has Warning: [minor] Error reading PreviewImage - DSC05639.JPG and the other doesn't.

That error means the EXIF block (which holds the GPS data) is messed up in some way.  Try adding the -m option and see if it writes the GPS times with that.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

D.Mon

#6
Quote from: StarGeek on September 07, 2018, 06:22:44 PM
First, is the time zone UTC-07:00 (Pacific Coast U.S.) as you previously stated or is it UTC+07:00 (Russia, Mongolia, Vietnam) as you used in your latest post?

Set it to the actual time zone of the location the image was shot.  Exiftool will do the proper computations when writing the GPS time.
Thank you for pointing that out.
Actually I have images that were taken in Pacific Time an ones that were taken in Mountain Time (UTC-6:00).

Does exiftool also take care of daylight saving time by itself or do I have to deal with that?
The pictures were taken in August and September.
[EDIT:]I thought about that. Since the camera was set to Central European Summertime CEST (GMT+2:00) this should fall out of the equation.
JFTR: If the pictures were taken between end of DST in Europe and end of DST in the location the pictures were taken I think the number of hours subtracted (or added) with -GlobalTimeShift should be adapted.


Quote from: StarGeek on September 07, 2018, 06:22:44 PM
Always make sure to show all the output from a command.  It looks like you snipped something at one point because one output has Warning: [minor] Error reading PreviewImage - DSC05639.JPG and the other doesn't.

That error means the EXIF block (which holds the GPS data) is messed up in some way.  Try adding the -m option and see if it writes the GPS times with that.
The error showed up only where I posted it (after exiftool -gpsdatestamp= -gpstimestamp= DSC05639.JPG). I only snipped 1 image files updated in the first code example.
The -m oppressed the output of that error but GPS times were not written either.
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

D.Mon

After some intensive and systematic testing I found out that everything seems to work as described by you exept '-GPSTimeStamp<${DateTimeOriginal}-7:00'. I also noticed that the warnings are coming in an unpredictable and (to me) incomprehensible way.

Example code 1:
exiftool -GlobalTimeShift -9  '-DateTimeOriginal<DateTimeOriginal' '-GPSDateStamp<${DateTimeOriginal}-7:00' '-GPSTimeStamp<${DateTimeOriginal}-7:00' test.JPG
Warning: [minor] Error reading PreviewImage - test.JPG
    1 image files updated

exiftool -DateTimeOriginal -GPSTimeStamp -GPSDateStamp -GPSDateTime test*JPG
======== test-original.JPG
Date/Time Original              : 2018:08:26 01:15:00
GPS Time Stamp                  : 00:06:37
GPS Date Stamp                  : 2018:08:26
GPS Date/Time                   : 2018:08:26 00:06:37Z
======== test.JPG
Date/Time Original              : 2018:08:25 16:15:00
GPS Time Stamp                  : 16:15:00
GPS Date Stamp                  : 2018:08:25
GPS Date/Time                   : 2018:08:25 16:15:00Z

Please note that the GPSDateStamp ist calculated correctly but the GPSTimeStamp is not.
The Time is copied but not adapted to the timezone


After realising that I found this workaround:
Example code 2:
exiftool -GlobalTimeShift -9  '-DateTimeOriginal<DateTimeOriginal' '-GPSDateStamp<${DateTimeOriginal}-7:00' '-GPSTimeStamp<$DateTimeOriginal' test.JPG
Warning: [minor] Error reading PreviewImage - test.JPG
    1 image files updated

exiftool -GPSTimeStamp+=7 test.JPG
    1 image files updated

exiftool -DateTimeOriginal -GPSTimeStamp -GPSDateStamp -GPSDateTime test*JPG
======== test-original.JPG
Date/Time Original              : 2018:08:26 01:15:00
GPS Time Stamp                  : 00:06:37
GPS Date Stamp                  : 2018:08:26
GPS Date/Time                   : 2018:08:26 00:06:37Z
======== test.JPG
Date/Time Original              : 2018:08:25 16:15:00
GPS Time Stamp                  : 23:15:00
GPS Date Stamp                  : 2018:08:25
GPS Date/Time                   : 2018:08:25 23:15:00Z
    2 image files read


This leads to the desired results but I don't think it's the way it should work.
I want to try a few more ideas to eliminate the workaround but wanted to share this intermediate result.
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

StarGeek

Make sure you write the time zone correctly.  -07:00.  You need the leading zero.

C:\>exiftool -g1 -a -s -DateTimeOriginal -GPSTimeStamp -GPSDateStamp -GPSDateTime y:\!temp\Test3.jpg
---- ExifIFD ----
DateTimeOriginal                : 2018:08:26 01:15:00
---- GPS ----
GPSTimeStamp                    : 00:06:37
GPSDateStamp                    : 2018:08:26
---- Composite ----
GPSDateTime                     : 2018:08:26 00:06:37Z

C:\>exiftool -P -overwrite_original -GlobalTimeShift -9  "-DateTimeOriginal<DateTimeOriginal" "-GPSDateStamp<${DateTimeOriginal}-07:00" "-GPSTimeStamp<${DateTimeOriginal}-07:00" y:\!temp\Test3.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -DateTimeOriginal -GPSTimeStamp -GPSDateStamp -GPSDateTime y:\!temp\Test3.jpg
---- ExifIFD ----
DateTimeOriginal                : 2018:08:25 16:15:00
---- GPS ----
GPSTimeStamp                    : 23:15:00
GPSDateStamp                    : 2018:08:25
---- Composite ----
GPSDateTime                     : 2018:08:25 23:15:00Z


* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Just for fun, here's an alternative way to do it.  It takes two steps, but it saves the time zone in the file, which can be useful later.

First, save the time zone and shift the DateTimeOriginal
exiftool -OffsetTimeOriginal=-07:00 -GlobalTimeShift -9 '-DateTimeOriginal<DateTimeOriginal' FILE

Then, copy SubSecDateTimeOriginal to the GPSDate/TimeStampSubSecDateTimeOriginal is a composite of DateTimeOriginal and the matching time zone tag, OffsetTimeOriginal.
exiftool '-GPSDateStamp<SubSecDateTimeOriginal' '-GPSTimeStamp<SubSecDateTimeOriginal' FILE
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

D.Mon

Quote from: StarGeek on September 08, 2018, 02:54:05 AM
Make sure you write the time zone correctly.  -07:00.  You need the leading zero.
Thank you so much.
This finally did the trick.

Quote from: StarGeek on September 08, 2018, 03:02:24 AM
Just for fun, here's an alternative way to do it.  It takes two steps, but it saves the time zone in the file, which can be useful later.
This also looks interesting. I will keep that in mind.
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

D.Mon

#11
Just because it fits in here:
If the camera time and/or date was not set correct but GPSTime and GPSDate are valid I think GPSDateTime can be used to calculate the EXIF Date/Time tags:
exiftool -GlobalTimeShift -7 -DateTimeOriginal'<GPSDateTime' -ModifyDate'<GPSDateTime' -CreateDate'<GPSDateTime'  test.JPG

GPSStatus can be used to check if GPSTime and GPSDate are valid for the time the picture was shot.
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)

StarGeek

Here's a quick shortcut for you.  When you want to write DateTimeOriginal, CreateDate, and ModifyDate (the three main EXIF dates), you can use AllDates.  It was a common enough action that Phil made it a built in shortcut long ago.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

D.Mon

Very nice  :).

Actually I am quite impressed about the power of exiftool (not only because of that shortcut).
--
OS X 10.12
exiftool 11.10
processing mainly jpg and arw (Sony)