Main Menu

Fix GPS Date and Time?

Started by deb27, June 30, 2016, 05:33:47 PM

Previous topic - Next topic

deb27

Due to a bug in Android, raw photos taken on my Nexus 5X phone in (DNG) format have incorrect date/time stamps.

The filenames are in the format: ProShot_YYYYMMDD_HHMMSS.dng

Thanks to the following great thread I was able to fix the DateTimeOriginal and ModifyDate fields by setting them to the value found in the file name.
https://exiftool.org/forum/index.php/topic,6636.0.html

However I can't figure out how to fix the GPS Date Stamp and GPS Time Stamp.
The GPS Date and Time are presumably UTC (i.e. not corrected for local time zone). So based on where my photos were taken, I need to add 4 hours to the GPS Date and Time.

I fixed EXIF:DateTimeOriginal by doing this:

Quoteexiftool "-datetimeoriginal<filename" ProShot_20160616_201321.dng

How do I get the EXIF:GPSTimeStamp and EXIF:GPSDateStamp to be the same as DateTimeOriginal plus 4 hours (which of course may change the date if the time rolls past midnight)?

Thanks


Phil Harvey

I think that reading the notes for these tags in the GPS tags documentation will explain how to do this.

- 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 ($).

deb27

Unfortunately it didn't tell me how to add a value to the date and time values such that it takes into account the midnight roll over.
I can add a value to one of the fields. But that doesn't solve the problem

First I started by getting the GPS Date and Time Stamp fields to match the DateTimeOriginal by doing this:

Quoteexiftool "-gpstimestamp<datetimeoriginal" file.dng
exiftool "-gpsdatestamp<datetimeoriginal" file.dng

My test file has the following values:
Quote[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 20:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21
I tried adding 4 hours by doing this:
Quoteexiftool "-gpstimestamp+=0000:00:00 04:00" file.dng

which resulted in:
Quote[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 00:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21

unfortunately the date is still June 16.

So I still don't know how to shift the GPS date/time values to be UTC which, in my case means adding 4 hours.



Hayo Baan

This behaviour is easily explained: Because you apply the timeshift to a field that only has a time, the date is not shifted when there is a roll over.

In this case I think what would work is to shift the datetimeoriginal (I'm pretty sure Phil has implemented date roll over) and write that into the two gps tags like you did already.

HTH,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Quote from: deb27 on June 30, 2016, 10:47:47 PM
Unfortunately it didn't tell me how to add a value to the date and time values such that it takes into account the midnight roll over.

But it did...

0x0007   GPSTimeStamp   rational64u[3]   (UTC time of GPS fix. When writing, date is stripped off if present, and time is adjusted to UTC if it includes a timezone)

0x001d   GPSDateStamp   string[11]   (when writing, time is stripped off if present, after adjusting date/time to UTC if time includes a timezone. Format is YYYY:mm:dd)


So all you need to do is add the time zone:

exiftool "-gpstimestamp<${datetimeoriginal}+04:00" "-gpsdatestamp<${datetimeoriginal}+04:00" file.dng

- 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 ($).

deb27

I must be missing something. Below is what I started with and what I got when I executed the command that Phil suggested.
It appears to have subtracted (instead of adding) the 4 hours from the gps time stamp (since it went from 20 to 16).

Here's what I started with:
QuoteG:\temp>exiftool -g -G -GPSDateStamp -gpstimestamp -datetimeoriginal *21.dng
[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 20:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21
Here's what I executed
QuoteG:\temp>exiftool "-gpstimestamp<${datetimeoriginal}+04:00" "-gpsdatestamp<${datetimeoriginal}+04:00" *21.dng
    1 image files updated
Here's what I got:
G:\temp>exiftool -g -G -GPSDateStamp -gpstimestamp -datetimeoriginal *21.dng
Quote[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 16:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21

I tried a slightly different method using +=04:00 to the gps values. That didn't work either but I got different results.
First I reset all the values to their original values as shown:
QuoteG:\temp>exiftool -g -G -GPSDateStamp -gpstimestamp -datetimeoriginal *21.dng
[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 20:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21
Then I executed the following command
QuoteG:\temp>exiftool "-gpsdatestamp+=04:00" "-gpstimestamp+=04:00" *21.dng
    1 image files updated
And this is what I got. This time it updated the time stamp correctly by adding 4 but it did not update the date
QuoteG:\temp>exiftool -g -G -GPSDateStamp -gpstimestamp -datetimeoriginal *21.dng
[EXIF]          GPS Date Stamp                  : 2016:10:16
[EXIF]          GPS Time Stamp                  : 00:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21
So, did I miss something?

Hayo - I could do what you suggested although it makes for extra steps and takes more time as I'd have to modify the datetimeoriginal to be UTC, write that to the GPS variables and then change datetimeoriginal back to the local time zone. But I assume that it would work. Thanks.

Phil Harvey

Quote from: deb27 on July 01, 2016, 09:40:00 PM
Here's what I started with:
QuoteG:\temp>exiftool -g -G -GPSDateStamp -gpstimestamp -datetimeoriginal *21.dng
[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 20:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21
Here's what I executed
QuoteG:\temp>exiftool "-gpstimestamp<${datetimeoriginal}+04:00" "-gpsdatestamp<${datetimeoriginal}+04:00" *21.dng
    1 image files updated
Here's what I got:
G:\temp>exiftool -g -G -GPSDateStamp -gpstimestamp -datetimeoriginal *21.dng
Quote[EXIF]          GPS Date Stamp                  : 2016:06:16
[EXIF]          GPS Time Stamp                  : 16:13:21
[EXIF]          Date/Time Original              : 2016:06:16 20:13:21

Yes, this is correct.  2016:06:16 20:13:21+04:00 is 2016:06:16 16:13:21 UTC.  A positive time zone has a time greater than UTC, so it is subtracted to get back to UTC again.

- 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 ($).

deb27

I must admit, I don't understand your definition of "positive time zone" but regardless I think the following works.  DateTimeOriginal is set to Eastern Daylight Time which is 4 hours earlier than UTC.

Set DateTimeOriginal to the date/time embedded in the filename
exiftool "-datetimeoriginal<filename" file.dng
Set GPS time/date to DateTimeOriginal plus 4 hours (even though the command below says minus)
exiftool "-gpstimestamp<${datetimeoriginal}-04:00" "-gpsdatestamp<${datetimeoriginal}-04:00" file.dng

Phil Harvey

I'm glad you got it working.

[quote author=deb27 link=topic=7342.msg37213#msg37213 date=1467510372]
I must admit, I don't understand your definition of "positive time zone"

[/quote]

All I meant was a time zone with a "+" sign (indicating a time ahead of UTC, ie. east of Greenwich).

Time zones can be a bit confusing sometimes.

- 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 ($).