macOS Photos app ignores GPS Data on mp4 file import

Started by gpsaddict, November 21, 2023, 05:53:24 PM

Previous topic - Next topic

wywh

Quote from: gpsaddict on November 22, 2023, 02:10:37 PMI thought it might be a more refined version of the previous solution

The last version was meant for a scenario where the original .mov files are in another folder and the re-encoded same-name .mp4 destination files in another folder. I thought you asked that, but now re-reading your old post, maybe that was not the case because you wrote:

> how do I point ExifTool to the folder with the files instead of a single file?

I usually cd to the folder (i.e. "working directory") where the files are and then issue the command. For example, to then check almost all location data from all files (the dot '.' at the end means "this folder"):

exiftool -a -G1 -s -api LargeFileSupport=1 -Location:All -n -ee .
I already mentioned this version where the source .mov files and the same-name .mp4 files are in the same folder. So cd to that folder and then:

exiftool -m -overwrite_original -api QuickTimeUTC=1 -api LargeFileSupport=1 -TagsFromFile '%-.0f.mov' -All:All '-FileCreateDate<QuickTime:CreateDate' '-FileModifyDate<QuickTime:CreateDate' *.mp4
I hope this helps,

- Matti

Phil Harvey

Matti, thanks for the samples.  The problem file has the Keys tags embedded in a UserData atom for some reason.  I tested this and the good news is that you can fix it and preserve all of the known Keys tags with a single command:

exiftool -keys:all= -tagsfromfile @ -keys:all bad.mp4

The unknown keys tags that would be lost with this command are: MajorBrand, MinorVersion, CompatibleBrands, CreationTime and Encoder.  I will do some checking to see if I should add support for any of these.

- 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

Quote from: Phil Harvey on November 22, 2023, 10:19:59 PMThe problem file has the Keys tags embedded in a UserData atom

Thanks for solving what causes this issue.

It seems to be related to ffmpeg because if I use the options that should preserve metadata (Keys in the input.mp4):

ffmpeg -i input.mp4 -c copy -movflags use_metadata_tags -map_metadata 0 output.mp4
...I get the same kind of UserData as with Shutter Encoder's preserve metadata option (exiftool v3 output attached), and it can be fixed with that simple TagsFromFile command.

ffmpeg.txt

- Matti

Phil Harvey

#18
I wonder why they are doing this.

BTW, for this specific issue, the exiftool -G5 output gives a clear indication of where this is stored:

[MOV-Movie-UserData-Meta-Keys] Major Brand      : mp42
[MOV-Movie-UserData-Meta-Keys] Minor Version    : 1
[MOV-Movie-UserData-Meta-Keys] Compatible Brands: isommp41mp42
[MOV-Movie-UserData-Meta-Keys] Creation Time    : 2001-01-01T10:00:00.000000Z
[MOV-Movie-UserData-Meta-Keys] Author           : Author
[MOV-Movie-UserData-Meta-Keys] Creation Date    : 2001:01:01 12:00:00+02:00
[MOV-Movie-UserData-Meta-Keys] Description      : Description
[MOV-Movie-UserData-Meta-Keys] Keywords         : Keywords 1,Keywords 2
[MOV-Movie-UserData-Meta-Keys] GPS Coordinates  : 36.610100 S, 66.915150 W, 119.9 m Above Sea Level
[MOV-Movie-UserData-Meta-Keys] User Rating      : 3
[MOV-Movie-UserData-Meta-Keys] Title            : Title
[MOV-Movie-UserData-Meta-Keys] Encoder          : Lavf60.14.100

and after this command (ExifTool 12.70):

exiftool test.mp4 -keys:all= -tagsfromfile @ -keys:all

you get this:

[MOV-Movie-Meta-Keys] Author                    : Author
[MOV-Movie-Meta-Keys] Creation Date             : 2001:01:01 12:00:00+02:00
[MOV-Movie-Meta-Keys] Description               : Description
[MOV-Movie-Meta-Keys] Keywords                  : Keywords 1,Keywords 2
[MOV-Movie-Meta-Keys] GPS Coordinates           : 36.610100 S, 66.915150 W, 119.9 m Above Sea Level
[MOV-Movie-Meta-Keys] User Rating               : 3
[MOV-Movie-Meta-Keys] Title                     : Title

- Phil

P.S. I'll add support for writing "Keys:Encoder" so it will be preserved with this command for ExifTool 12.71 and later, but I'm not going to add the other unknown tags yet because they seem like more of a hack to me.
...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

Quote from: Phil Harvey on November 23, 2023, 08:45:53 AMexiftool -G5 output gives a clear indication of where this is stored

Thanks for the hint about G5! So this seems to be the problem with ffmpeg (somebody please chime in if I am missing some option that might preserve metadata):

ffmpeg -i input.mov -c:v libx265 -tag:v hvc1 -c:a aac -movflags use_metadata_tags -map_metadata 0 ffmpeg_output.mp4
ffmpeg version 4.4.4 Copyright (c) 2000-2023 the FFmpeg developers

exiftool -a -G5 -s -n -api QuickTimeUTC=1 -Keys:All -QuickTime:CreateDate .
======== ./input.mov
[MOV-Movie-Meta-Keys] Author                    : Author
[MOV-Movie-Meta-Keys] Description               : Description
[MOV-Movie-Meta-Keys] Keywords                  : Keyword 1,Keyword 2
[MOV-Movie-Meta-Keys] UserRating                : 3
[MOV-Movie-Meta-Keys] Title                     : Title
[MOV-Movie-Meta-Keys] GPSCoordinates            : -36.6101 -66.91515 119.9
[MOV-Movie-Meta-Keys] CreationDate              : 2001:01:01 12:00:00+02:00
[MOV-Movie-MovieHeader] CreateDate              : 2001:01:01 12:00:00+02:00
======== ./ffmpeg_output.mp4
[MOV-Movie-UserData-Meta-Keys] MajorBrand       : qt
[MOV-Movie-UserData-Meta-Keys] MinorVersion     : 0
[MOV-Movie-UserData-Meta-Keys] CompatibleBrands : qt
[MOV-Movie-UserData-Meta-Keys] CreationTime     : 2001-01-01T10:00:00.000000Z
[MOV-Movie-UserData-Meta-Keys] Author           : Author
[MOV-Movie-UserData-Meta-Keys] Description      : Description
[MOV-Movie-UserData-Meta-Keys] Keywords         : Keyword 1,Keyword 2
[MOV-Movie-UserData-Meta-Keys] UserRating       : 3
[MOV-Movie-UserData-Meta-Keys] Title            : Title
[MOV-Movie-UserData-Meta-Keys] GPSCoordinates   : -36.6101 -66.91515 119.9
[MOV-Movie-UserData-Meta-Keys] CreationDate     : 2001:01:01 12:00:00+02:00
[MOV-Movie-UserData-Meta-Keys] Encoder          : Lavf58.76.100
[MOV-Movie-MovieHeader] CreateDate              : 2001:01:01 12:00:00+02:00

p.s. it seems ffmpeg '-movflags use_metadata_tags' tries to preserve those Keys, and '-map_metadata 0' only preserves 'QuickTime:CreateDate'.

- Matti

wywh

ffmpeg 6.1.1 still copies Keys:GPSCoordinates embedded in UserData atom that Apple's apps do not read (the same applies to all Keys tags like CreationDate, Title, DisplayName, Author, Description, Keywords, Make, Model, Software etc):

ffmpeg6 -i input.mp4 -c copy -movflags use_metadata_tags -map_metadata 0 output.mp4

exiftool -a -G5 -s -n -Keys:GPSCoordinates .                                                 
======== ./input.mp4
[MOV-Movie-Meta-Keys] GPSCoordinates            : -36.6101 -66.91515 119.9
======== ./output.mp4
[MOV-Movie-UserData-Meta-Keys] GPSCoordinates   : -36.6101 -66.91515 119.9

-> Surprisingly subsequent exiftool updates also go to the same incorrect place in that movie:

exiftool -m -P -overwrite_original -Keys:GPSCoordinates='14.79354, 75.40448, 99.9' .

exiftool -a -G5 -s -n -Keys:GPSCoordinates .                                       
======== ./input.mp4
[MOV-Movie-Meta-Keys] GPSCoordinates            : 14.79354 75.40448 99.9
======== ./output.mp4
[MOV-Movie-UserData-Meta-Keys] GPSCoordinates   : 14.79354 75.40448 99.9

...rebuilding metadata fixes it:

exiftool -m -P -overwrite_original -All= -tagsFromFile @ -All:All -Unsafe -ICC_Profile output.mp4

exiftool -a -G5 -s -n -Keys:GPSCoordinates .                                                     
======== ./input.mp4
[MOV-Movie-Meta-Keys] GPSCoordinates            : 14.79354 75.40448 99.9
======== ./output.mp4
[MOV-Movie-Meta-Keys] GPSCoordinates            : 14.79354 75.40448 99.9

- Matti

Phil Harvey

Hi Matti

Video metadata is such a hairball.  ExifTool only creates a new Keys section if it didn't already exist, otherwise it writes to the existing one.  My thought was that it would be better to be flexible like this rather than force it into a specific location, in keeping with the untamed nature of the video metadata landscape.

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