doodspav / motionphoto

Python library for creating Google and Samsung compatible Motion Photos.
Apache License 2.0
6 stars 0 forks source link

Experience with HEIC files #13

Open NightMean opened 1 week ago

NightMean commented 1 week ago

Hello

First of all, thanks for all the hard work put into the Motion photo format research. Truly incredible! I came across this tool from your Exiftool thread where I was looking for the same topic. I'm curious about your note: The only common requirement is that the image format should be JPEG, not HEIC. HEIC occasionally works but is not reliable Could you elaborate more on that? Have you managed to create HEIC photo that is actually a Google Motion photo?

I'm wondering on this because I am currently trying to find the best way to preserve iOS Live Photos with the same quality. I'm not really fan of converting the HEIC image to JPG as JPEG only supports 24 bit color while HEIC supports 32 bit.

Newer Samsung phones already use the HEIC format for motion photos and I think I read somewhere (can't find it right now) that it is also compatible by Google Photos, but I have not been able to confirm this. The sample heic image that I found opens in my Samsung A41 as motion photo but when uploaded to Google Photos, it's not recognized as Motion Photo.

For now, I have been using https://github.com/mihir-io/MotionPhotoMuxer as everyone else it seems.

doodspav commented 1 week ago

Unfortunately I don't have an Android device myself, so when I first wrote this my testing was a combination of asking random people on Discord to open files and uploading to Google Photos.

At the time I had the same issue as you, that Google Photos would not accept the HEIC version, so I disabled it. I think that also i asked someone with a Google Pixel to open the HEIC photo in their native photo viewer, and that didn't work either for them (but potentially I'm misremembering, or there was a bug in my implementation causing that).

The library you linked, MotionPhotoMuxer, is mostly great but in my testing (of my own implementation), some people's Samsung devices weren't compatible with Google's Motion Photo implementation (not sure if it was the native photo viewer, or the Samsung Gallery app). Since I had this issue in my implementation, I just assumed that MotionPhotoMuxer would have the same issue (since it doesn't append Samsung's trailer), but I haven't tested it.

doodspav commented 1 week ago

I was planning on spending this weekend improving the library (just because I want to use it to send my relatives some photos), and I'm glad you brought up MotionPhotoMuxer (MPM).

Since MPM uses a library rather than the exiftool executable, if I can get that to replace exiftool entirely, then I can remove a dependency from this library (although it will pain me to remove exiftool, it was amazing).

I guess I could also add a flag to bypass the JPEG restriction with a warning that it will reduce portability of the resulting MotionPhoto.

NightMean commented 1 week ago

Unfortunately I don't have an Android device myself, so when I first wrote this my testing was a combination of asking random people on Discord to open files and uploading to Google Photos.

I have multiple devices including some Android emulators, feel free to reach out for testing :)

At the time I had the same issue as you, that Google Photos would not accept the HEIC version, so I disabled it. I think that also i asked someone with a Google Pixel to open the HEIC photo in their native photo viewer, and that didn't work either for them (but potentially I'm misremembering, or there was a bug in my implementation causing that).

If you still have some sample file, I'd love to try it. I have thought that this might not be possible at all until I saw your approach so I hope you are on the right track.

The library you linked, MotionPhotoMuxer, is mostly great but in my testing (of my own implementation), some people's Samsung devices weren't compatible with Google's Motion Photo implementation (not sure if it was the native photo viewer, or the Samsung Gallery app). Since I had this issue in my implementation, I just assumed that MotionPhotoMuxer would have the same issue (since it doesn't append Samsung's trailer), but I haven't tested it.

The Samsung Gallery is mostly the same on all newer Samsung devices but it seems you are correct. The Motion Photo created by MPM is not recognized by it. Google Photos only recognizes it once the photo is backed up, without the back up, there is no option to see the motion. It only recognized immediately without the backup after I added the MV prefix which you also mentioned. (Thanks for the tip) Maybe a suggestion for improvement as well, why have the tool let the user know that it requires the MV prefix (if the user didn't use it) instead of adding it automatically?

I guess I could also add a flag to bypass the JPEG restriction with a warning that it will reduce portability of the resulting MotionPhoto.

Sure, yea. Would love to test this if it actually works.

In the meantime, I was just doing some testing and I found some issue but I have opened a new issue https://github.com/doodspav/motionphoto/issues/14 to keep the discussion clean :)

tannerkrewson commented 1 week ago

Hello! Thank you both for your research... I wish I would have found this before I spent yesterday creating a JavaScript version of MotionPhotoMuxer that works with HEIC->JPG (repo here). I independently discovered the same limitations that @NightMean has found, namely that HEIC->JPG loses some color/HDR information, and HEIF with embedded motion should be possible (Samsung photos do it) but Google Photos doesn't seem to show the motion when uploaded via the web UI.

Like you, I'm looking for any HEIC file with embedded motion that will show correctly when uploaded to Google Photos. Let me know if you find one, and I'll let you know if I do! With that sample file, hopefully we can work to reverse engineer it to create a tool that will convert Apple Live Photos losslessly to be uploaded to Google Photos.

tannerkrewson commented 1 week ago

One possibility to retain color/HDR data and the motion would be to use would be to use the Ultra HDR image format, which is a JPG. I can confirm that uploading these sample JPG photos to Google Photos retains the HDR information, although they are not motion photos. If someone has a Pixel phone that can take an Ultra HDR photo with motion enabled, please send us the sample!

However, I imagine converting HEIC HDR to Ultra HDR JPG is not straightforward and is still lossy anyways, so finding a way to use the HEIC directly would still be ideal!

NightMean commented 1 week ago

I spent yesterday creating a JavaScript version of MotionPhotoMuxer that works with HEIC->JPG (repo here).

That's cool! Thanks for that! In the meantime, I wanted to do the same so I started by creating a python script that converts the HEIC images to JPG while keeping the ICC profile so the colors won't look so washed out. To my surprise, I couldn't find any small suitable open source project (except ImageMagick) that does this so I created my own HEIC to JPG

If someone has a Pixel phone that can take an Ultra HDR photo with motion enabled, please send us the sample!

I believe there is a store near me that has demo units of Pixels. I might try to look if they still do. Although, I don't think that Google added support for the motion photos with Ultra HDR JPG image. Motion Photos are barely used on Android compared to iOS.