ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: ExifShmexif on April 08, 2021, 02:03:56 AM

Title: Fixing files from Google Photos via Takeout
Post by: ExifShmexif on April 08, 2021, 02:03:56 AM
I received such helpful advice from searching and reading this forum, and the tool itself is amazing, so first of all thank you to all, especially Phil and stargeek. And in some meagre fashion, I wanted to return something by writing up my experience for anyone moving files out of Google Photos via Takeout. Many of the commands here are collected from other posts on this forum, and I'm sure I'll get a few things wrong, but hopefully it'll be helpful.

This will be most useful for anyone who:




Getting images out of Google Photos can be done in two ways.

I'll assume you're doing the first of these. Assuming you selected images from all years in your export, you'll see a set of folders each corresponding to a year. Note: if your collection is larger than 50GB, and you have multiple zips to download and expand I strongly recommend you combine these into one. Takeout doesn't ensure that the media file and associated json are in the same zip, so combining them will fix it.

For any edited file, Takeout also exports both the original and edited files. If you prefer to not have doubles in your collection, you can delete the edits with:

del /s /q *-edited.jpg

You'll also notice that the file creation date for your media has been updated to today. That's probably correct as Takeout sees it, but for media that doesn't have EXIF data with the create date in -- like MP4 files -- your viewing software will probably just use the creation date for ordering, and these files will appear in the wrong place. So, from the Takeout root directory:

exiftool -d "%s" -tagsfromfile %d%f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext mp4 -ext jpg -r .

I've also read that geolocation data may need to be added back to the EXIF data from the JSON file. I didn't find that to be the case for me -- location data seemed intact for the files. But just in case, again from the root:

exiftool -tagsfromfile %d%f.%e.json -description -title "-gpslatitude<GeoDataLatitude" "-gpslatituderef<GeoDataLatitude" "-gpslongitude<GeoDataLongitude" "-gpslongituderef<GeoDataLongitude" ... -ext mp4 -ext jpg -r .

Then, time to get rid of the .json files:

del /s /q *.json

The next part depends on how you want to organise the files. If you want to just dump everything into a directory and let your viewer sort it out -- maybe something like Synology moments -- you're probably done. I personally wanted to organise the files a little better and recreate a directory structure with my best guess of which camera took the image. This has the advantage of helping you identify which photos came from a friend, or any other source.

exiftool "-directory<%d/${model;}" -r .

You also may know that some actions strip exif data, e.g. uploading an image and sending it via some messaging apps or social networks. Additionally, as mentioned, mp4 files generally don't have exif. So if you want to sort further, I found it helpful to sort by image size:

exiftool "-directory<%d/${ImageSize;}" .

.... which helped me identify and group together images that were saved from various sources, like screenshots or movies. (Note that this will save media from the same source in different folders for portrait and landscape, but it's not a big deal to put those together.)

(One final TODO here, is to find a way to edit creation date for files that don't have an associated json file or any exif data, but present the date in the filename, something like 20130602_175206.jpg or 2012-10-16 09.39.07.jpg.)




I hope this has been helpful in some way. Thanks again!
Title: Re: Fixing files from Google Photos via Takeout
Post by: Phil Harvey on April 12, 2021, 08:00:30 AM
Thanks for this write-up.  I'm sure it will be useful for someone else who wants to do this.

- Phil
Title: Re: Fixing files from Google Photos via Takeout
Post by: Nirmitlamed on May 28, 2023, 11:03:25 AM
Wanted to say thank you. It was helpful a lot!
Title: Re: Fixing files from Google Photos via Takeout
Post by: Tyler on September 15, 2023, 05:38:56 PM
In this command:
exiftool -d "%s" -tagsfromfile %d%f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext mp4 -ext jpg -r .

You mention mp4 and jpg but if there are any other extensions, what happens to those?
Title: Re: Fixing files from Google Photos via Takeout
Post by: Phil Harvey on September 19, 2023, 07:52:05 AM
Files with other extensions will be ignored.

- Phil
Title: Re: Fixing files from Google Photos via Takeout
Post by: ythiebault on January 05, 2024, 03:11:44 PM
Thanks a lot for your post, it helped me a lot !

I had to adapt it in order to upload an album to a photo book creator service. In case it would help someone else in a common situation:

# suffix used for edited files. Depend on the lang.
EDITED_FILE_SUFFIX="-edited"

# Replace original files by their edited version
for edited_file in *$EDITED_FILE_SUFFIX* ; do
    original_file=$(echo "$edited_file" | sed s/$EDITED_FILE_SUFFIX//g)
    rm "$original_file"
    mv -v "$edited_file" "./${original_file}"
done

# Convert .HEIC to .jpeg (for iphone/mac users)
for file in *.HEIC; do
    sips -s format jpeg "$file" --out "${file%.HEIC}.jpeg"
    mv -v "$file.json" "${file%.HEIC}.jpeg.json"
    rm $file
done

# Update metadata with exiftool
exiftool -d "%s" -tagsfromfile %f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext jpg -ext jpeg -ext mp4 -ext mov .
Title: Re: Fixing files from Google Photos via Takeout
Post by: Edi Nugroho on August 08, 2024, 01:55:39 PM
I tried the code above, i.e.
exiftool -d "%s" -tagsfromfile %d%f.%e.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -overwrite_original -ext mp4 -ext jpg -r .
but an error message was displayed: "Warning: Error opening file -xxxxnameOfFile".

What went wrong?
Title: Re: Fixing files from Google Photos via Takeout
Post by: Phil Harvey on August 08, 2024, 02:00:06 PM
It looks like maybe you used something that looks like a dash but isn't.  This can happen if you cut-and-paste a command.  Use the dash (minus sign) on the keyboard for the leading dashes.

Or... Is this a .bat file?  If so, all % characters need to be doubled in ExifTool arguments.

- Phil
Title: Re: Fixing files from Google Photos via Takeout
Post by: StarGeek on August 08, 2024, 03:20:16 PM
I strongly suggest double-checking to see if you actually need to do this. Google didn't remove any data when the file was uploaded, so the only problem is if data was entered on the website or if no data was there to begin with.

Run this command to look at all the date/time data. If there is already proper time stamps such as an already existing DateTimeOriginal, then you don't want to run the above command
exiftool -time:all -G1 -a -s file.jpg
Title: Re: Fixing files from Google Photos via Takeout
Post by: revo2wheels on October 25, 2024, 05:03:24 PM
Absolutely 100% a problem for most files from 500GB Download from Google photos takeout. I'm very grateful to the OP for this fix.
Title: Re: Fixing files from Google Photos via Takeout
Post by: alipio on November 25, 2024, 02:24:10 PM
It is definitely a problem for me.

I had mixed results with Google Takeout: most of the time it came with all the data, but a 4.52GB worth of media is coming  up stripped no matter what I do. I'm lucky that I learned about NAS, Syncthing, Immich, etc. because currently I am only using Google Photos as a duplicate to share media.

Thanks for OP!
Title: Re: Fixing files from Google Photos via Takeout
Post by: StarGeek on November 25, 2024, 04:09:19 PM
Quote from: alipio on November 25, 2024, 02:24:10 PMbut a 4.52GB worth of media is coming  up stripped no matter what I do.

Are you 100% certain that it contained data when it was uploaded? If there was no data in the file when it was uploaded, then data isn't going to suddenly appear.

I just check a video I uploaded to Google photos in 2016. It is a binary exact match to the original on my drive.

File system data such and created date you first see when you check the properties on the desktop are always going to be lost because the file isn't on a local drive anymore.
Title: Re: Fixing files from Google Photos via Takeout
Post by: MrSimmo on March 23, 2025, 12:54:42 PM
Hi all,

Just helping out a little, I found that when I ran the above it failed as Google seem to have changed the filenames in the Takeouts to include 'supplemental-metadata' to the JSON file name recently. With the original command I was getting the 'Error opening file [JSON]' error.


I also extended the command to skip files which already had the date/time taken in the exif data, and also to include other file types (as my photos are heif/heic and some videos seem to be mov instead of mp4). Also I added the large file support argument as exiftool skipped all my videos otherwise:

Here is my updated command:
exiftool -d "%s" -tagsfromfile %d%f.%e.supplemental-metadata.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -if 'not defined $DateTimeOriginal' -overwrite_original -ext mp4 -ext jpg -ext heic -ext m4v -ext mov -api largefilesupport=1  -r .


Note: I'm getting the warning "Warning: This tag is Windows/Mac only in File:FileCreateDate (ValueConvInv)" when I run the command on my Linux NAS, but it writes the exif data fine.


Also here is my updated command to fix the missing GPS location data:

exiftool -d "%s" -tagsfromfile %d%f.%e.supplemental-metadata.json "-gpslatitude<GeoDataLatitude" "-gpslatituderef<GeoDataLatitude" "-gpslongitude<GeoDataLongitude" "-gpslongituderef<GeoDataLongitude" -if 'not defined $GPSLatitude' -overwrite_original -ext mp4 -ext jpg -ext heic -ext m4v -ext mov -api largefilesupport=1  -r .


Hope its useful, cheers

Title: Re: Fixing files from Google Photos via Takeout
Post by: StarGeek on March 23, 2025, 01:45:28 PM
As I previously said

Quote from: StarGeek on August 08, 2024, 03:20:16 PMGoogle didn't remove any data when the file was uploaded, so the only problem is if data was entered on the website or if no data was there to begin with.

So double-check your files to make sure you're not overwriting the original data, because when it comes to the date/time values, Google saves it as UTC, not the original time. Copying from the Google takeout files overwrites the correct date with an incorrect one.
Title: Re: Fixing files from Google Photos via Takeout
Post by: MrSimmo on March 24, 2025, 04:01:52 AM
Quote from: MrSimmo on March 23, 2025, 12:54:42 PMHi all,

Just helping out a little, I found that when I ran the above it failed as Google seem to have changed the filenames in the Takeouts to include 'supplemental-metadata' to the JSON file name recently. With the original command I was getting the 'Error opening file [JSON]' error.


I also extended the command to skip files which already had the date/time taken in the exif data, and also to include other file types (as my photos are heif/heic and some videos seem to be mov instead of mp4). Also I added the large file support argument as exiftool skipped all my videos otherwise:

Here is my updated command:
exiftool -d "%s" -tagsfromfile %d%f.%e.supplemental-metadata.json "-DateTimeOriginal<PhotoTakenTimeTimestamp" "-FileCreateDate<PhotoTakenTimeTimestamp" "-FileModifyDate<PhotoTakenTimeTimestamp" -if 'not defined $DateTimeOriginal' -overwrite_original -ext mp4 -ext jpg -ext heic -ext m4v -ext mov -api largefilesupport=1  -r .


Note: I'm getting the warning "Warning: This tag is Windows/Mac only in File:FileCreateDate (ValueConvInv)" when I run the command on my Linux NAS, but it writes the exif data fine.


Also here is my updated command to fix the missing GPS location data:

exiftool -d "%s" -tagsfromfile %d%f.%e.supplemental-metadata.json "-gpslatitude<GeoDataLatitude" "-gpslatituderef<GeoDataLatitude" "-gpslongitude<GeoDataLongitude" "-gpslongituderef<GeoDataLongitude" -if 'not defined $GPSLatitude' -overwrite_original -ext mp4 -ext jpg -ext heic -ext m4v -ext mov -api largefilesupport=1  -r .


Hope its useful, cheers



One more addition (sorry cant find a way to edit my original post) - I just found that Google Photos Takeout also has a random collection of CreateDate tags, where some exist (and are correct) and some are missing; but these don't correlate to the missing DateTimeOriginal tag.

So I run this AFTER the first command: (Note it uses the newly created DateTimeOriginal tag and ignores files that already have this tag in place - the reason why its a separate command is because the files that are missing may not be the same as the files where DateTimeOriginal is missing):

exiftool "-CreateDate<DateTimeOriginal" -if 'not defined $CreateDate' -overwrite_original -ext mp4 -ext jpg -ext heic -ext m4v -ext mov -api largefilesupport=1  -r .
Title: Re: Fixing files from Google Photos via Takeout
Post by: eddified on March 25, 2025, 12:15:18 AM
The Original Post is really great. Thank you!

But, I have some google json files that contain 0 for gps data (ie invalid data):

Quote"geoData": {
    "latitude": 0.0,
    "longitude": 0.0,
    "altitude": 0.0,
    "latitudeSpan": 0.0,
    "longitudeSpan": 0.0
  },

exiftool is writing these 0 values, and I would prefer not to write these 0 values. How can I modify this to only write the data if it's valid and non-zero?

Quoteexiftool -tagsfromfile %d%f.%e.json -description -title "-gpslatitude<GeoDataLatitude" "-gpslatituderef<GeoDataLatitude" "-gpslongitude<GeoDataLongitude" "-gpslongituderef<GeoDataLongitude" ... -ext mp4 -ext jpg -r .
Title: Re: Fixing files from Google Photos via Takeout
Post by: wywh on March 25, 2025, 02:34:25 AM
Quote from: eddified on March 25, 2025, 12:15:18 AMgoogle json files that contain 0 for gps data (ie invalid data)
Yes, .json files might have dummy zero data, and such images erroneously get a wrong GPS in the Atlantic. Here is the fix from StarGeek:

https://exiftool.org/forum/index.php?topic=12905.0 (https://exiftool.org/forum/index.php?topic=12905.0)

I have used this command to copy .json to images:

exiftool -overwrite_original -d %s -tagsFromFile '%d/%F.json' '-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}' '-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Caption-Abstract<Description' '-Description<Description' '-Rating<${Favorited;$_=5 if $_=~/true/i}' '-AllDates<PhotoTakenTimeTimestamp' '-FileCreateDate<PhotoTakenTimeTimestamp' '-FileModifyDate<PhotoTakenTimeTimestamp' -ext jpg -ext heic -ext tif -ext png -ext webp -ext gif .
...and to movies:

exiftool -overwrite_original -d %s -api QuickTimeUTC=1 -api LargeFileSupport=1 -tagsFromFile '%d/%F.json' '-Keys:GPSCoordinates<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}, ${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Keys:Description<Description' '-Keys:UserRating<${Favorited;$_=5 if $_=~/true/i}' '-AllDates<PhotoTakenTimeTimestamp' '-Track*Date<PhotoTakenTimeTimestamp' '-Media*Date<PhotoTakenTimeTimestamp' '-Keys:CreationDate<PhotoTakenTimeTimestamp' '-FileCreateDate<PhotoTakenTimeTimestamp' '-FileModifyDate<PhotoTakenTimeTimestamp' -ext mp4 -ext m4v -ext mov .
You might have to convert single quotes ' to double quotes " in Windows.

- Matti
Title: Re: Fixing files from Google Photos via Takeout
Post by: eddified on March 25, 2025, 10:55:06 AM
Quote from: wywh on March 25, 2025, 02:34:25 AMI have used this command to copy .json to images:


...and to movies:


Thank you, this looks extremely helpful!
Title: Re: Fixing files from Google Photos via Takeout
Post by: eddified on March 25, 2025, 11:00:46 AM
Quote from: wywh on March 25, 2025, 02:34:25 AMI have used this command to copy .json to images:

exiftool -overwrite_original -d %s -tagsFromFile '%d/%F.json' '-GPSLatitude*<${GeoDataLatitude;$_ = undef if $_ eq "0.0"}' '-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}' '-Caption-Abstract<Description' '-Description<Description' '-Rating<${Favorited;$_=5 if $_=~/true/i}' '-AllDates<PhotoTakenTimeTimestamp' '-FileCreateDate<PhotoTakenTimeTimestamp' '-FileModifyDate<PhotoTakenTimeTimestamp' -ext jpg -ext heic -ext tif -ext png -ext webp -ext gif .

What does the asterisk modifier do when used with the "<" writing operator? Ie, "*<". I've searched around and not been able to find it. (Punctuation is not the easiest thing to have search engines look for)
Title: Re: Fixing files from Google Photos via Takeout
Post by: Phil Harvey on March 25, 2025, 11:04:34 AM
"*" and "?" may be used as wildcards in a tag name.

- Phil
Title: Re: Fixing files from Google Photos via Takeout
Post by: eddified on March 25, 2025, 11:41:39 PM
Quote from: wywh on March 25, 2025, 02:34:25 AM'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}'

Update: got it working. See my other post.

This is great and all, but... it doesn't actually work (by "work" i mean: write the tag when non-zero, and don't write the tag when zero). In all my attempts, it either writes the tag for both zero and non-zero cases, or doesn't write the tag for both zero and non-zero cases. The tag names and json are as expected, since I am seeing the tags being written with correct values. I just can't get the conditional nature of the expression to work properly.

I am wondering if it has to do with data type? The json actually uses a number 0.0, not a string "0.0". So I tried replacing the expression with
Quote'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq 0.0}'
and also tried just using 0 (without decimal places). I just can't get it working properly.

Please help.

Update: got it working. See my other post.
Title: Re: Fixing files from Google Photos via Takeout
Post by: eddified on March 25, 2025, 11:50:58 PM
Quote from: eddified on March 25, 2025, 11:41:39 PMPlease help.

Figured it out! When using numbers instead of strings, it suddenly came to me to use `==` instead of `eq`:

Quote'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ == 0}'

It suddenly came to me what was wrong. (I had a little Perl experience from 20 years ago...)
Title: Re: Fixing files from Google Photos via Takeout
Post by: wywh on March 26, 2025, 01:43:40 AM
Quote from: eddified on March 25, 2025, 11:41:39 PM'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq 0.0}'

It should work if "0.0" is double quoted (inside single quotes on the Mac), without them it writes those zero .json GPS locations.

'-GPSLongitude*<${GeoDataLongitude;$_ = undef if $_ eq "0.0"}'
My cheatsheet for Perl operators (https://users.cs.cf.ac.uk/dave/PERL/node37.html).