joemck / ExtractMotionPhotos

Extract Motion Photos created by Samsung phones to mp4 videos and plain jpg photos
MIT License
143 stars 20 forks source link

Reassembling a valid motion photo again? #5

Closed JM-Lemmi closed 2 years ago

JM-Lemmi commented 2 years ago

[We can also move this to the discussion tab if you enable it, just wanted to brainstorm a bit with other interested people]

I looked through the original XDA thread as well as the source code but I didn't come to a solution.

If I understand the format correctly, its a full mp4 and full jpg file just slapped together with the MotionPhoto_Data divider in the middle. So manually reassembling a motion photo from two different images should be possible.

In a first step I tried assembling the image of one motion photo and the video of another together. My S10e recognizes it as a motion photo, but when pressing play it stays at 0:00 and does not play a video. I'm guessing there is some other metadata you have to adjust?

The ultimate goal would be to combine any picture and video into a motion photo, but as a first step I would try recombinin existing motion photos.

JM-Lemmi commented 2 years ago

Of course shortly after making this post I find the first step myself:

You have to adjust the Container:Item Item:Length in the xmp metadata to the new videos length.

joemck commented 2 years ago

I honestly have no idea if there's any requirements as to tags on the JPEG half or codec or metadata on the MP4 side. I do the same as the XDA code, just looking for the "MotionPhoto_Data" divider and splitting it there. I also don't plan to add motion photo creation to this program.

You might try taking the unmodified jpg and mp4 that my program spits out, and simply tacking them back together with the divider in between. If you're assembling it with multiple files and copy /b, use a hex editor to make sure your divider is plain ASCII text and doesn't have any garbage stuck on like a UTF-8 BOM at the start or a line break at the end. The result should be byte identical to the input file since I don't mess with either half. Once you have that, you might try small changes like simply re-saving the jpg half and see if that breaks it somehow.

JM-Lemmi commented 2 years ago

If you have no plans to add this to this program, I will be developing on my own package, thats fine.

Just taping them back together without any changes does not work, since there is XMP metadata. But it does seem to be a google standard. Couldn't find their documentation though, maybe its not public.