Geotag mp4 from gpx?

Started by Marsu42, August 26, 2023, 01:55:12 PM

Previous topic - Next topic

Marsu42

I see that exiftools supports copying a static gps location data from an image file to mp4: https://exiftool.org/forum/index.php?topic=12240

However, if I try to -geotag mp4 from a gpx (which works just fine for image files - thanks!) the output is just "Warning: No writable tags set from file.mp4"

I'm using (latest) exiftool 12.65 on Win64.

The information page https://www.exiftool.org/geotag.html indicates that Keys:GPSCoordinates is not among the supported tags - correct?

If I'm not missing something, I'd like to feature request this. I know video files are a can of works, but you're half way there :-) and it's not a stream tag.

The workaround would probably be to create a .xmp (or dummy image file) with the same datetime, -geotag this, and then manually -tagsfromfile to the mp4 - I didn't try this yet.


StarGeek

The xmp sidecar is probably your only option at this point

Phil will have to comment on whether or not to add Keys:GPSCoordinates to the Geotag option, but he is away for a few weeks and will be back mid-September.
* 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).

Marsu42

Quote from: StarGeek on August 26, 2023, 03:37:20 PMPhil will have to comment on whether or not to add Keys:GPSCoordinates to the Geotag option

Thanks so far - it's not urgent, my .mp4 or .gpx aren't going anywhere - so I'll wait for an answer if Keys:GPSCoordinates might be added to -geotag or I'll have to use the .xmp workaround.

StarGeek

Actually, have you tried writing to a mp4? I haven't tested it, but it should write to the XMP:GPSLatitude and XMP:GPSLongitude tags.  From there, it would be an easy copy in to the Keys:GPSCoordinates tag.
exiftool "-Keys:GPSCoordinates<$XMP:GPSLatitude, $XMP:GPSLongitude" /path/to/files/

You would have to use the -Geotime tag to make sure the correct time is used.  Either
exiftool -GeoTag file.gpx "-Geotime<${CreateDate}+00:00" file.mp4
or
exiftool -api QuickTimeUTC -GeoTag file.gpx "-Geotime<CreateDate" file.mp4

The CreateDate in a video is supposed to be already set to UTC, which is what the GPS track should be set to.  Using +00:00 prevents exiftool from using the local time zone on the file and the -api QuickTimeUTC option tells exiftool to convert the CreateDate to local time, which is then converted back to UTC to match the GPS track.
* 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).

Phil Harvey

Right now I would rather not get into the issue of automatically writing GPSCoordinates.  You mention Keys:GPSCoordinates, but about half of my sample files use UserData:GPSCoordinates where it may be written 2 different ways.  Also, Google Photos writes this in the ItemList metadata.  There seems to be no standardization in video metadata.

I think the best solution for now is the write XMP, then run a second command to copy this to Keys:GPSCoordinates for each file.

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

Phil Harvey

#5
ExifTool 12.68 will have the ability to write GPSCoordinates directly with the -geotag feature.  A command would be:

exiftool "-geotag=file.gpx" "-quicktime:geotime<createdate" FILE.mp4

The key here is to specify QuickTime:Geotime as an indication that the QuickTime GPSCoordinates should be written.  By default, this writes ItemList:GPSCoordinates, but you may specify keys:geotime, userdata:geotime or itemlist:geotime instead of quicktime:geotime in the command to write GPSCoordinates wherever you like.

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

xmnboy

Quote from: Phil Harvey on October 12, 2023, 09:13:15 PMexiftool "-geotag=file.gpx" "-quicktime:geotime<createdate" FILE.mp4

Google Photos won't read the GPS tags in a video file (MP4) if they exceed five decimal digits. So I modified my geotag log file (GPX) so that the GPS data points in it contain no more than five decimal digits. I used the command-line above to set the truncated GPS tags into the video files. Unfortunately, I didn't think about the interpolation arithmetic resulting in data points with more than five decimal digits.

Is there a way to tell Exiftool to truncate GPS values to five decimal digits after performing the interpolation arithmetic on the geotag data?

Here's an example of what I am seeing:

======== PX9_2643.MP4
[QuickTime:ItemList] GPSCoordinates             : 35.00918 135.674765813333 148.120352016449
[Composite]     GPSAltitude                     : 148.120352016449
[Composite]     GPSAltitudeRef                  : 0
[Composite]     GPSLatitude                     : 35.00918
[Composite]     GPSLongitude                    : 135.674765813333
[Composite]     GPSPosition                     : 35.00918 135.674765813333
======== PX9_2647.MP4
[QuickTime:ItemList] GPSCoordinates             : 35.00918 135.67475 149.363360835592
[Composite]     GPSAltitude                     : 149.363360835592
[Composite]     GPSAltitudeRef                  : 0
[Composite]     GPSLatitude                     : 35.00918
[Composite]     GPSLongitude                    : 135.67475
[Composite]     GPSPosition                     : 35.00918 135.67475
======== PX9_2661.MP4
[QuickTime:ItemList] GPSCoordinates             : 35.0089697133334 135.67483 150.468739340623
[Composite]     GPSAltitude                     : 150.468739340623
[Composite]     GPSAltitudeRef                  : 0
[Composite]     GPSLatitude                     : 35.0089697133334
[Composite]     GPSLongitude                    : 135.67483
[Composite]     GPSPosition                     : 35.0089697133334 135.67483
======== PX9_2668.MP4
[QuickTime:ItemList] GPSCoordinates             : 35.00911 135.674765271667 149.082772843997
[Composite]     GPSAltitude                     : 149.082772843997
[Composite]     GPSAltitudeRef                  : 0
[Composite]     GPSLatitude                     : 35.00911
[Composite]     GPSLongitude                    : 135.674765271667
[Composite]     GPSPosition                     : 35.00911 135.674765271667

Phil Harvey

I'm surprised that Google hasn't fixed this after 3 years.  A solution is to do a 2nd pass on the file to reduce the resolution.  See this post for a command to do this.

Someone should report this to Google to see if they can fix the problem.

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

xmnboy

Thank you for the reply and solution reference, Phil. I'll post my net results when I get things working correctly, in case it helps others.

xmnboy

Ultimately, this is what worked for me to truncate the digits after the decimal point in the geo latitude and longitude values. After geotagging the MP4 files using exiftool and a GPS log file (gpx or kml) on Linux:

exiftool -c \"%.5f\" -ext MP4 -TagsFromFile %d%f.%e -quicktime:all %d%f.%e -progress *.mp4
What I ended up with is modeled after this cheat-sheet:

https://github.com/jonkeren/Exiftool-Commands?tab=readme-ov-file#exiftool-write-all-incl-gps-location-tags-from-mp4-files-to-corresponding-xmp-files

Thank you, Phil, for Exiftool. :)

xmnboy

An update regarding using a geo log (gpx file) and Google's weird restrictions regarding the geo numbers (no more than four digits to the right of the decimal point). When applying a log file to videos I am also seeing elevation as one of the geotags getting written into the MP4 by the -geotag operation. The lat/long numbers are shortened by the -c formatting option, but the format option does not truncate the GPSAltitude number.

I suspect the GPSAltitude number may also be subject to the rule, but I can't figure out how to test my theory. I removed the elevation numbers from the gpx log file and that removed them from the written -geotag and narrowed down the possibilities. Google either does not like the altitude number or it wants the number to be truncated, like the lat and long numbers.

Is there a way to force write the altitude value in order to test this theory? I couldn't figure out how to do it.

wywh

#11
I tested Google Photos today and the max decimals it reads in Keys:GPSCoordinates is 5 decimals for GPS and 4 decimals for Altitude in .mp4, .m4v and .mov. So Google Photos does not read location after this:

exiftool -m -P -overwrite_original -Keys:GPSCoordinates='-36.123456789, -66.123456789, 119.1234' movie.mp4

exiftool -a -G1 -s -n -Keys:GPSCoordinates movie.mp4                                                     
[Keys]          GPSCoordinates                  : -36.123456789 -66.123456789 119.1234

But after truncating GPS to 5 decimals it does read GPS:

exiftool -m -P -overwrite_original -ext mp4 -ext m4v -ext mov -c '%.5f' -TagsFromFile @ -Keys:GPSCoordinates movie.mp4

exiftool -a -G1 -s -n -Keys:GPSCoordinates movie.mp4                                                                 
[Keys]          GPSCoordinates                  : -36.12346 -66.12346 119.1234

But this does not work because there are 5 decimals in the Altitude. Why doesn't that command truncate also the altitude to 4 decimals? Or is it possible to truncate GPS to 5 decimals and Altitude to 4 decimals (my DJI P3P movies altitude has only 1 decimal so currently I do not need to do that).

exiftool -a -G1 -s -n -Keys:GPSCoordinates movie.mp4                                               
[Keys]          GPSCoordinates                  : -36.12345 -66.12345 119.12345

exiftool -m -P -overwrite_original -ext mp4 -ext m4v -ext mov -c '%.4f' -TagsFromFile @ -Keys:GPSCoordinates movie.mp4

exiftool -a -G1 -s -n -Keys:GPSCoordinates movie.mp4                                                                 
[Keys]          GPSCoordinates                  : -36.1234 -66.1235 119.12345

...It is a pain to copy GPS from Google Maps (ctrl-click a location and copy the coordinates) because there are up to 15 decimals that must then be truncated for movies.

- Matti

Phil Harvey

The -c option handles latitude/longitude coordinates, not elevation.  Here is an example of how you could limit them all to 5 decimals:

> exiftool a.mov -gpscoordinates#="-36.123456789 -66.123456789 119.123456789"
    1 image files updated
> exiftool a.mov -gpscoordinates#
GPS Coordinates                 : -36.123456789 -66.123456789 119.123456789
> exiftool a.mov '-gpscoordinates#<${gpscoordinates#;my @a=map {sprintf("%.5f",$_)} split " ";$_="@a"}'
    1 image files updated
> exiftool a.mov -gpscoordinates#
GPS Coordinates                 : -36.12346 -66.12346 119.12346

The above quoting is for Mac/Linux.  In Windows CMD the command would look like this:

exiftool a.mov "-gpscoordinates#<${gpscoordinates#;my @a=map {sprintf('%.5f',$_)} split ' ';$_=qq(@a)}"

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

wywh

Thanks, this fixes those pesky decimals for Google Photos (none of my apps read ItemList:GPSCoordinates so I explicitly write to Keys):

exiftool -m -P -overwrite_original '-Keys:GPSCoordinates#<${GPSCoordinates#;my @a=map {sprintf("%.4f",$_)} split " ";$_="@a"}' .
p.s. I have considered switching from Google Photos to immich which looks promising.

- Matti

StarGeek

Quote from: wywh on May 03, 2024, 01:46:23 AMp.s. I have considered switching from Google Photos to immich which looks promising.

There has been a lot of good buzz about immich. The team behind it appears to have been very responsive.  If I ever figure out how to safely expose my Raspberry Pi to the net (still haven't figured out authentication and fail2ban), I'll be looking into it using a docker.
* 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).