Merge photo and video for LivePhoto

Started by Yorian, January 25, 2024, 04:20:41 AM

Previous topic - Next topic

Yorian

Hi,

I'm trying to "merge back" together two files: a mp4 file and a jpeg file that I got off an old android phone and want to import them into the Photos app on Mac. Both of these files have very little metadata currently.

I've been able to add the original time a photo was taken and its location using exiftool (that information I do have) and that works fine so thank you! For quite a few photos I also have an mp4 which, combined with the jpeg, is the "Live Photo". I've been able to convert the .mp4 to .mov using ffmpeg but now I want to "merge" them such that Apple Photos picks it up as well (instead of importing two seperate files).

I read something about a "Content Identifier", a "PhotoIdentifier" and "LivePhotoVideoIndex" and tried setting them but that failed (I think they are part of the Makernotes, but how would I then set them). Also I read this: https://stackoverflow.com/questions/32508375/apple-live-photo-file-format but couldn't quite understand how to apply it.

Could anyone provide some help?

greybeard

Its not as simple as modifying the metadata - you have to create a Photos asset and then add the resources (i.e. the still image and the video file) and store it in the Photos library.

I don't know any way of doing it without coding in Swift - I've done something similar - creating a raw/jpg asset by combining separate raw and jpg images - but it did require programming.

Yorian2

Hi greybeard,

Thanks for the quick reply. I couldn't log back in to the forum of this so had to create a new account (because I am not receiving password reset emails either). With regards to your response: I don't mind programming (I'm a python/javascript developer myself) but have no experience with Swift.

greybeard

OK - I got it to work without needing a program but its a bit messy.

The key metadata item appears to be what ExifTool displays as ContentIdentifier - has to exist and be identical in both files - but I couldn't get ExifTool to store ContentIdentifier if the tag didn't already exist (which would be the case if the original files weren't live photos).

So what I did was to take an existing Live Photo and export it as two separate files (in my case HEIC and MOV).

I then copied all the metadata from these two files into my non-live image and video files:

exiftool -TagsFromFile <Source>.MOV "-all:all>all:all" <Target>.mp4

exiftool -TagsFromFile <Source>.HEIC "-all:all>all:all" <Target>.HEIC

Then replaced these two files in the Live Photos folder and imported into Photos.

Maybe Phil or StarGeek can help with some method of copying ContentIdentifier without all the other metadata.

Phil Harvey

I can't test this because I don't have any MOV or HEIC samples which contain ContentIdentifier.

But ContentIdentifier is stored deep within the Apple-specific metadata, so writing it (if possible) would require at least copying something like the entire MakerNotes block.

- 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: greybeard on January 26, 2024, 09:16:52 AMI got it to work without needing a program but its a bit messy

Thanks for the info! So the key metadata item in Live photos is ContentIdentifier. It has to be identical in both the image and the movie. Even the file names do not have to match -- Photos.app shows only the imported image's filename. Also the matching movie can be from a completely different footage such as .mp4.

======== ./IMG_2158.JPG
[Apple]         ContentIdentifier               : F906FE4C-506A-4F85-B9BE-5F862ED06C90
======== ./IMG_2158.MOV
[Keys]          ContentIdentifier               : F906FE4C-506A-4F85-B9BE-5F862ED06C90

So if all metadata is stripped from from that pair and renamed as a.jpg and a.mov, they can be made a Live Photo pair again:

Copy Apple makernotes from some other Live Photo image -- IMG_2160.JPG in the example below (currently exiftool can write Apple makernotes in images only as a block, not as individual tags):

exiftool -overwrite_original -TagsFromFile IMG_2160.JPG '-All:All<All:All' a.jpg
Then copy Apple:ContentIdentifier from either image (IMG_2160.JPG or a.jpg) to Keys:ContentIdentifier in a.mov:

exiftool -overwrite_original -TagsFromFile a.jpg '-Keys:ContentIdentifier<Apple:ContentIdentifier' a.mov

exiftool -a -G1 -s -ContentIdentifier .                                                                
======== ./a.mov
[Keys]          ContentIdentifier               : DBDA7F31-8133-4E79-8A2E-35624C26EABB
======== ./a.jpg
[Apple]         ContentIdentifier               : DBDA7F31-8133-4E79-8A2E-35624C26EABB

macOS 14 Sonoma Photos.app imports both the edited "a" and the donor "IMG_2160" pairs OK.

- Matti