Copy GPS tags to files without them

Started by davidcpreston, March 05, 2025, 02:47:17 PM

Previous topic - Next topic

davidcpreston

I have all of my files named using yyyy-mm-dd_hh-mm-ss from CreateDate. Some files have GPS data and some don't. What I want to do is populate the GPS data in files where it is missing from the preceding file that it was found in.
i.e. if I don't know the location I will assume it is at the last known location, but I don't know how to achieve this?

Phil Harvey

Copying the GPS from the previous file would be tricky.  But perhaps better would be to interpolate the GPS based on the timestamps of the nearest images which do have GPS:

1. exiftool -p gpx.fmt -fileorder filename DIR > out.gpx

2. exiftool -geotag out.gpx -if "not $gpslatitude" DIR

Where I have used quoting compatible with a Windows CMD shell.

Note that this will only work for images which are within 30 minutes of an image with GPS coordinates.  Or you can set -api GeoMaxIntSecs=0 and -api GeoMaxExtSecs=99999999 in the 2nd command to force ExifTool to choose the GPS of the nearest image in time, regardless of how far away it is.

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

StarGeek

You would have to download the gpx.fmt file first and save it to the current directory.

See Inverse Geotagging for more details on creating the GPX file.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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

LaurentG

There is also a solution I personally would use (because not requiring "deep" knowledge of ExifTool) consisting in exporting GPS coordinates of all files in a csv file, then filling missing data in csv file with excel, then reimporting csv file.

It's not "glorious", but easy to implement, even without being a pro of ExifTool....

StarGeek

Actually, a CSV file would also work as a GPS track without having to fill in the missing values. It just has to be formatted according to the ExifTool CSV Log File Format

Looking that over, you would use the -csv option with GPSLatitude/GPSLongitude and a time stamp. Some editing would probably have to be done with the time stamp, though, since the GPS time stamps may not exist in the files.  *off to do some testing*
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

davidcpreston

Wow, thanks as ever guys, some great options there. I'd loved to be able to interpolate but I think that won't be possible. The best I will have is a photo taken at or near the beginning of taking a drone video, which could last for up to 20 minutes. The images I want to tag are frames taken from the video. There is a possibility that the encrypted flight records can be processed to produce a KML file, which I know Exiftool can process, but I'm waiting on whether that has timestamps. Failing that I'll have to resort to copying from the nearest known one to the start of the flight.

Phil Harvey

It would be best if you could produce the GPX file from the drone video.  ExifTool should be able to do that with my first command, but just add a -ee option and use the .mp4 file as input.  And if that doesn't work, send me a sample drone video and I'll see about adding support (philharvey66 at gmail.com).

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

davidcpreston

Thanks Phil,
I had no idea that the GPS data was stored in the video, but having researched it seems it is; every day's a school day.
I assumed that as frames saved from a video with Windows Photos weren't geotagged the data wasn't there, maybe it's an option with some software?

davidcpreston

#9
You sir, are a genius; just reading about the timezone issue as they all failed, about 4 hours different. I'm in the UK so we're on UTC at the moment but move to BST later in month UTC+1 until October

StarGeek

Quote from: davidcpreston on March 06, 2025, 01:21:49 AMI assumed that as frames saved from a video with Windows Photos weren't geotagged the data wasn't there, maybe it's an option with some software?

Maybe with specialized software from the maker of the drone, but not with other software like ffmpeg.

The problem is that GPS tracks in videos are non-standard. ExifTool currently reads 103 different types of timed GPS metadata from video files. It's an immense undertaking and I haven't heard of any other program that even tries to come close.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

davidcpreston

#11
I had 2 problems, the first was that DateTimeOriginal was missing in some files, so I copied them from CreateDate, and I wasn't getting anything from the drone mp4 files. I noted there was a warning about the ExtractEmbedded option, so after adding -ee I have a huge out.gpx, which is fine as the results are spot on.
I opened the gpx in Google Earth and it covers the whole shoot from camera and drone and flight, well impressed

PH Edit: Inlined image:

Screenshot 2025-03-06 164032.jpg