Definitions for Keys:CameraLensModel and Keys:CameraFocalLength35mmEquivalent

Started by wywh, August 20, 2024, 12:06:35 PM

Previous topic - Next topic

gsparx

Is there no mechanism to be able to retain these keys in a way that is recognized by Photos.app / iCloud photos? I'm trimming MOV videos shot on an iPhone in an automated fashion, and I would like to be able to retain all metadata including the lens information if possible.

Saving to the XMP-exifEX tags retains the info of course, but I would like to have Photos.app display it.

StarGeek

Using this command will copy the Keys tags mentioned here
exiftool -TagsFromFile source.mp4 -All:All target.mp4

But if the data you want to keep is actually EXIF data (use the command in FAQ #3 to see the group it belongs to), then no. The best you can do is copy it to the XMP tags. EXIF data is non-standard in a video file and every company forces it into the file in different ways.

But it's doubtful that the photo app would be reading EXIF data in the first place because it is non-standard. Wywh would know more about it than I would.
"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

wywh

Quote from: gsparx on January 12, 2025, 04:58:52 PMIs there no mechanism to be able to retain these keys in a way that is recognized by Photos.app / iCloud photos?

You can copy almost all iPhone movie metadata to re-encoded movies in a format Photos.app can read with the exiftool command below. That track-level lens info is an exception so I have copied it to XMP for now.

I just tested and macOS 15 Sequoia QuickTime Player can trim and Photos.app can also edit and re-encode iPhone movies to H.265/264 so that lens info and all other metadata is preserved (Keys:CreationDate and other Keys are preserved -- QuickTime:CreateDate is the trim/edit date. Apple's apps prefer reading date from Keys or UserData anyway. GPS is otherwise preserved but altitude is reset to zero in the re-encoded movie).

exiftool -m -overwrite_original -api QuickTimeUTC=1 -api LargeFileSupport=1 -tagsFromFile input.mov -All:All '-FileCreateDate<Keys:CreationDate' '-FileModifyDate<Keys:CreationDate' output.mp4
ffmpeg v4-7 and ffmpeg-related GUIs do not properly copy movie metadata so it is best not to even try to preserve movie metadata with ffmpeg.

https://trac.ffmpeg.org/ticket/4209#comment:26
https://exiftool.org/forum/index.php?topic=15418.msg82847#msg82847

- Matti

gsparx

Quote from: wywh on January 13, 2025, 04:08:07 AMffmpeg v4-7 and ffmpeg-related GUIs do not properly copy movie metadata so it is best not to even try to preserve movie metadata with ffmpeg.

Unfortunately that's exactly what I'm trying to do :o Automate trimming a video with ffmpeg based on audio thresholds (calculated in a previous step) and time offsets

Something like:

ffmpeg -ss <start_time_s> -i input.mov -t <duration_s> -avoid_negative_ts disabled -map 0:0 -c:0 copy -tag:0 hvc1 -map 0:1 -c:1 copy -map_metadata 0 -movflags use_metadata_tags -movflags +faststart -default_mode infer_no_subs -ignore_unknown -y output.mov

and then recovering the mangled metadata with exiftool (by copying it from the input.mov) before importing it back to Photos.app.

It's working pretty well aside from the missing lens info like I mentioned. I'm storing it in XMP for now like wywh suggested (thanks for that).

If anyone is trying to do something similar, I did just discover `avconvert` which is a binary that ships with MacOS that does retain all metadata from an input.mov shot on an iPhone when trimming. My hunch is that this is the same or similar code that Quicktime is using for its trim functionality, but it's callable via command line.

I couldn't find any official documentation for it other than the manpage. It has a passthrough preset which is perfect for my goal.

For example to accomplish the same as the ffmpeg trim above

avconvert --start <start_time_s> --duration <duration_s> --source input.mov --output output.mov --replace --disableMetadataFilter --preset PresetPassthrough

The output.mov retains all of the metadata including the track specific metadata (including the lense info) and it's properly recognized by Photos.app.

It does seem slower than the ffmpeg trim command, so it may be doing an actual re-encode as opposed to the ffmpeg command which is just splitting on iframes and muxing.

wywh

Quote from: gsparx on January 15, 2025, 01:55:57 AM`avconvert` which is a binary that ships with MacOS that does retain all metadata from an input.mov shot on an iPhone when trimming. My hunch is that this is the same or similar code that Quicktime is using for its trim functionality, but it's callable via command line.
Thanks for the info about /usr/bin/avconvert! Like QuickTime Player and Photos.app it can preserve also Lens info in its output. I did a quick test:

With iPhone 16 Pro ProRes & PCM .mov as an input, and that trim command to .mov it correctly preserves Keys tags as well as Lens info in the Track data. Keys:CreationDate is the original, and QuickTime:CreateDate is the trim date.

With another .m4v with extra added Keys tags as an input, and .mp4 as trim output it converts Keys to UserData tags (Author, Description, LocationInformation) which Apple's apps can also read. But with .mp4 output it ignores some Keys tags (Make, Model). (avconvert refuses .mp4 output for that iPhone 16 Pro ProRes & PCM .mov because "specified file extension:mp4 not valid with preset:PresetPassthrough").

FWIW you can fix movie metadata from ffmpeg output with the exiftool command below. But copying tags from the original with tagsFromFile is a better fix because otherwise ffmpeg converts some movie tags with unexpected results.

exiftool -m -overwrite_original -api LargeFileSupport=1 -Keys:All= -tagsFromFile @ -Keys:All output.mov
- Matti

StarGeek

Quote from: gsparx on January 15, 2025, 01:55:57 AMIt does seem slower than the ffmpeg trim command, so it may be doing an actual re-encode as opposed to the ffmpeg command which is just splitting on iframes and muxing.

Yes, if it is anything slower than the ffmpeg command, then it is a lossy conversion. It's up to you to decide if keeping the metadata is more important than the video data.
"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

wywh

I compared avconvert and ffmpeg passthrough with a 7.4 GB HD input .mp4.

Both output with not much CPU/GPU activity the same file size as input, with essentially the same bitrate and other MediaInfo details. So also avconvert seems to do a non-lossy passthrough without re-encoding. ffmpeg is a lot faster, though:

64 seconds (same without --disableMetadataFilter):

avconvert -s input.mp4 --disableMetadataFilter -p PresetPassthrough -o output.mov
30 seconds with .mp4 output:

avconvert -s input.mp4 -p PresetPassthrough -o output.mp4
8 seconds with ffmpeg 4:

ffmpeg -i input.mp4 -c copy output.mp4
With .mov output avconvert seems to convert essentially all metadata with --disableMetadataFilter. avconvert -h: "Disable the metadata filter. Use with caution. This will allow privacy sensitive source metadata to be preserved in the output file." Without that option GPSCoordinates and all other Keys tags except CreationDate, Make, Model, Software, and track data Lens info are omitted from the output.

Annoyingly with .mp4 output --disableMetadataFilter converts a few Keys to UserData tags (DateTimeOriginal, Author, DisplayName as Title, Description, LocationInformation) which Apple's apps can also read, though. With .m4v output it converts a few Keys as UserData (LocationInformation) and ItemList (ContentCreateDate, Author, DisplayName as Title, Title, Make as UserData_mak). Apple's apps read ItemList tags in a more limited manner. I wonder why Apple does not use only Keys tags which its apps more widely support.

- Matti

StarGeek

Quote from: wywh on January 15, 2025, 12:54:43 PMSo also avconvert seems to do a non-lossy passthrough without re-encoding. ffmpeg is a lot faster

Good to know
"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

ExifTool 13.13 will have the ability to write LensModel and FocalLengthIn35mmFormat to the video track.  I've introduced a new family 1 group name called "VideoKeys" to facilitate writing of Keys-type metadata to the video track.  Currently only these 2 tags are supported for writing.

- Phil

Edit: I found a few more VideoKeys tags in my samples, and will add write support for these as well:  CameraIdentifier, FrameReadoutTime and CaptureMode.

Edit2: I'll also define an AudioKeys group to allow tags to be written to the Audio track.
...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 ($).

gsparx

Quote from: Phil Harvey on January 16, 2025, 04:04:48 PMExifTool 13.13 will have the ability to write LensModel and FocalLengthIn35mmFormat to the video track.  I've introduced a new family 1 group name called "VideoKeys" to facilitate writing of Keys-type metadata to the video track.  Currently only these 2 tags are supported for writing.

Great to hear. Thank you!

Will that include CameraFocalLength35mmEquivalent and CameraLensModel as well? Or are those the same keys you mentioned?

[Keys]          Model                          : iPhone 15 Pro
[Keys]          Software                        : 18.2
[Keys]          CreationDate                    : 2025:01:09 18:34:09-08:00
[Track1]        CameraLensModel-und-US          : iPhone 15 Pro back camera 6.765mm f/1.78
[Track1]        CameraLensModel                : iPhone 15 Pro back camera 6.765mm f/1.78
[Track1]        CameraFocalLength35mmEquivalent-und-US: 27
[Track1]        CameraFocalLength35mmEquivalent : 27

Phil Harvey

Those are the same tags that I mentioned.  I'm using the names I mentioned to improve interoperability with EXIF.

ExifTool 13.13 will report them with the tag names that I used.  I plan to release this version on Monday.

- 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 January 16, 2025, 04:04:48 PMExifTool 13.13 will have the ability to write LensModel and FocalLengthIn35mmFormat to the video track

Thanks, also Lens metadata can now be copied to re-encoded movies the same way they were in the originals.

For example copy all metadata including Lens info from one movie to another and set file dates (all Track*Date, Media*Date, Keys might not be updated if they do not exist in the source). Some Keys and XMP (via -Geolocate) tags were added to the source.mov, destination.mp4 had essentially no metadata.

exiftool -m -overwrite_original -api QuickTimeUTC=1 -api LargeFileSupport=1 -tagsFromFile source.mov -All:All '-FileCreateDate<QuickTime:CreateDate' '-FileModifyDate<QuickTime:CreateDate' destination.mp4

exiftool -a -G1 -s -n -api QuickTimeUTC=1 destination.mp4
[ExifTool]      ExifToolVersion                 : 13.13
[MacOS]         FileCreateDate                  : 2024:08:11 14:30:19+03:00
[System]        FileModifyDate                  : 2024:08:11 14:30:19+03:00
[QuickTime]     CreateDate                      : 2024:08:11 14:30:19+03:00
[Keys]          CreationDate                    : 2024:08:11 14:30:19+03:00
[Keys]          GPSCoordinates                  : 29.9792 31.1342 138.5
[Keys]          LocationName                    : Kirdāsah, Giza, Egypt
[Keys]          LocationAccuracyHorizontal      : 110.666667
[Keys]          Make                            : Apple
[Keys]          Model                           : iPhone 12 mini
[Keys]          Software                        : 17.5.1
[Keys]          Author                          : Author
[Keys]          Title                           : Title
[Keys]          DisplayName                     : DisplayName
[Keys]          Description                     : Description
[Keys]          Keywords                        : Keyword 1,Keyword 2
[Keys]          UserRating                      : 4
[VideoKeys]     LensModel                       : iPhone 12 mini back camera 4.2mm f/1.6
[VideoKeys]     LensModel-fin-FI                : iPhone 12 mini back camera 4.2mm f/1.6
[VideoKeys]     FocalLengthIn35mmFormat         : 27
[VideoKeys]     FocalLengthIn35mmFormat-fin-FI  : 27
[XMP-iptcCore]  CountryCode                     : EG
[XMP-photoshop] City                            : Kirdāsah
[XMP-photoshop] Country                         : Egypt
[XMP-photoshop] State                           : Giza

Or maybe store info from multiple cameras to an edited movie although XMP might be a better place for this:

exiftool -m -P -overwrite_original '-VideoKeys:LensModel=RF35mm F1.8 MACRO IS STM, iPhone 16 Pro back camera 6.765mm f/1.78' '-VideoKeys:FocalLengthIn35mmFormat=35, 25' '-Keys:Make=Canon, Apple' '-Keys:Model=Canon EOS R6, iPhone 16 Pro' '-Keys:Software=1.5.1, 18.2' '-XMP-exifEX:LensModel=RF35mm F1.8 MACRO IS STM, iPhone 16 Pro back camera 6.765mm f/1.78' '-XMP-exifEX:LensInfo=35, 25' multicamera.m4v

exiftool -a -G1 -s -Keys:All -VideoKeys:All -XMP:All multicamera.m4v
[Keys]          Make                            : Canon, Apple
[Keys]          Model                           : Canon EOS R6, iPhone 16 Pro
[Keys]          Software                        : 1.5.1, 18.2
[VideoKeys]     LensModel                       : RF35mm F1.8 MACRO IS STM, iPhone 16 Pro back camera 6.765mm f/1.78
[VideoKeys]     FocalLengthIn35mmFormat         : 35, 25
[XMP-exifEX]    LensModel                       : RF35mm F1.8 MACRO IS STM, iPhone 16 Pro back camera 6.765mm f/1.78
[XMP-exifEX]    LensInfo                        : 35 25

macOS 15 Sequoia Photos.app can display also that Lens info (Photos.app displays at least that Lens as "Wide Camera — 26 mm ƒ1.6". If I put Canon Keys Make/Model tags to the mix then Photos.app would display the same Lens info as exiftool above):

Photos.jpg

- Matti

gsparx

Quote from: Phil Harvey on January 18, 2025, 09:13:38 PMThose are the same tags that I mentioned.  I'm using the names I mentioned to improve interoperability with EXIF.

ExifTool 13.13 will report them with the tag names that I used.  I plan to release this version on Monday.

- Phil

Amazing. Tested out the new update and I can now retain lens information after trimming with ffmpeg. Thank you so much for making that change!

Phil Harvey

Great.

Note that I found a small bug in 13.13:  If writing both Audio/Video tags and ItemList tags in the same command, the ItemList tags may not be written if no Audio/Video or ItemList tags previously existed in the file.

This will be fixed in 13.14.

- Phil

Edit: 13.14 is now available
...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 ($).