Merge JSON GPS data from Google Photos to MOV files

Started by bobross, April 08, 2019, 03:19:19 PM

Previous topic - Next topic

bobross

I recently decided to leave Google Photos. The JPEG files seem to have retained the tags I care about. However, MOV files are another story....

I downloaded a sample MOV/JSON pair with Takeout. I would like to merge the photoTakenTime and geoData tags into the downloaded MOV files. Could I get assistance with a script for that purpose?

Apologies, if this has been addressed elsewhere. I couldn't locate another post.

{
  "title": "IMG_2676.MOV",
  "description": "",
  "url": "https://[redacted]",
  "imageViews": "0",
  "creationTime": {
    "timestamp": "1477937983",
    "formatted": "Oct 31, 2016, 6:19:43 PM UTC"
  },
  "modificationTime": {
    "timestamp": "1554595301",
    "formatted": "Apr 7, 2019, 12:01:41 AM UTC"
  },
  "geoData": {
    "latitude": [redacted],
    "longitude": [redacted],
    "altitude": [redacted],
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },
  "geoDataExif": {
    "latitude": [redacted],
    "longitude": [redacted],
    "altitude": [redacted],
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },
  "photoTakenTime": {
    "timestamp": "1477659459",
    "formatted": "Oct 28, 2016, 12:57:39 PM UTC"
  }
}

StarGeek


The basic command is for doing this is
exiftool -tagsfromfile "%d/%F.json" "-TAG<JSONTAG" FileOrDir

Run exiftool on the JSON file to get the name of the JSONTAG.  You then replace TAG and JSONTAG with the names of the tags you wish to copy to/from.  You repeat that for each tag you wish to copy.

With regards to time stamps, it's easiest to copy the tags that end with "Timestamp" and use -d %s (see -d (dateFormat) option), e.g. "-DateTimeOriginal<PhotoTakenTimeTimestamp" -d %s.  The part to watch out for is any differences in time zone, as the timestamp from the JSON file will be listed as UTC.

I believe the JSON tags for GPS data are GeoDataLatitude and GeoDataLongitude.  But I will point out that according to your example JSON listing, the GPS data should already be in the MOV file.  The "geoDataExif" section of the JSON is the data that Google Photos extracted from the original MOV file.  This is copied to the "geoData" section.  The only time the "geoData" section would be different is if you entered different data on the Google Photos website.  You should run exiftool on your MOV file to double check the data, exiftool -gps* IMG_2676.MOV, for example.

* 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).

bobross

#2
Thanks for you help. I did run exiftool on the video files. However, the GPS data isn't there, even though it's clearly in the JSON data so I've having to go this route.

Getting the error below when running the following script. Do you see any issues? The JSON file isn't open in Notepad or any other application.


exiftool -tagsfromfile "%d/%F.json" "-GPSLatitude<GeoDataLatitude" IMG_0032.MOV

Warning: Error opening file - /IMG_0032.MOV.json
    0 image files updated
    1 image files unchanged



I got the script to run using a period instead of directly referencing a file. See below. However, there are two issues.

1. Exiftool is creating a new section with the data that isn't readable by outside applications. Did I use the correct exiftool and JSON tag names?
2. The create date is in UTC rather than local time. I tried invoking "-api quicktimeutc" but that didn't work. Example below should read 10:41:17. I am -5 or -6 depending on time of year.

See results below, and thank you again!

exiftool -tagsfromfile "%d/%F.json" "-GPSLatitude<GeoDataLatitude" "-GPSLongitude<GeoDataLongitude" "-GPSAltitude<GeoDataAltitude" "-CreateDate<PhotoTakenTimeTimestamp" -d %s. .


XMP Toolkit                     : Image::ExifTool 11.25
GPS Altitude                    : 511 m
GPS Latitude                    : [redacted]
GPS Longitude                   : [redacted]
Create Date                     : 2018:03:22 15:41:17
Avg Bitrate                     : 6.9 Mbps
GPS Latitude Ref                : North
GPS Longitude Ref               : West
Image Size                      : 1920x1080
Megapixels                      : 2.1
Rotation                        : 0
GPS Position                    : [redacted]

StarGeek

Quote from: bobross on April 08, 2019, 05:03:22 PM
1. Exiftool is creating a new section with the data that isn't readable by outside applications. Did I use the correct exiftool and JSON tag names?

Unfortunately, exiftool has limited ability to metadata to a video file.  You command will write the GPS coordinates to the XMP group.  That data, I think, can be read by Adobe software, such as Lightroom.  The trouble is that very few other programs can read it.  If the GPS data is in the Quicktime:GPSCoordinates tag, then exiftool can edit it if it already exists (with the newest version of exiftool) but can't create it if it doesn't.  If the GPS data is in an EXIF block, then I don't believe that exiftool can edit it and I'm not sure how high adding that ability is on Phil's list.

Quote2. The create date is in UTC rather than local time. I tried invoking "-api quicktimeutc" but that didn't work. Example below should read 10:41:17. I am -5 or -6 depending on time of year.

Which is what I mentioned as a possible problem.  How to deal with it is a puzzle I haven't taken time to work out yet, as I don't know how Google Photos decides what time zone it uses when it adjusts the time to UTC.  You probably have to fix them by using GlobalTimeShift option and copying the appropriate tags back with -TagsFromFile option.  Or maybe (I haven't tested it) adding the global time shift option when you copy the time stamps in the first place.
* 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).

bobross

Thanks for trying. If anyone else can think of a work around, I'd really like to get the GPS data merged. Appreciate it.

Phil Harvey

I'm continuing to work on ExifTool's video writing ability.  Maybe sometime soon you will be able 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 ($).

bobross


Phil Harvey

You can follow the news feed: feed://exiftool.org/rss.xml

or you can watch the ExifTool github project:

https://github.com/exiftool/exiftool

or you can watch for updates on sourceforge.

There are probably other ways too, but those come to mind.

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