New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HEIC: Converted JPG has wrong orientation #1064
Comments
For that one part of your issue, see here: I can’t speak to the rotation issue though. |
See #1052 (comment) We need orientation tags of all related files to debug this. The HEIC converter is external software, so there might or might not be issues. Going to improve primary JPEGs selection based on quality & size, see #926. |
If you need JPEGs, just use them straight away so that you don't need extra storage and transcoding. Most software doesn't support HEIC yet or just with tradeoffs like in this case. |
I'd be great to have test images for debugging... you're welcome to mail them to hello@photoprism.app Please let us know if we have permission to add them to our public test suite to avoid regressions 👍 No problem if not, we'll help you anyway. |
As it turns out, Apparently HEIF support may be compiled in imagemagick, but their compiled 7.x version doesn't include it. Ubuntu still ships 6.x. Fail. We then tried to compile the latest version from https://github.com/strukturag/libheif on our own:
The whole point of the tool is to read this file format. Unsupported Codec? Maybe JPEG? It's pretty new and probably needs extra work 👯 |
We now manually detect and change the rotation, the imaging autorotation functionality was disabled for our core use-cases. anymore.
Once this dependency is fixed, it should work just fine. It will also work when installed directly on a Mac as we use Apple's The refactoring lays the foundation for further improvements like #464. |
Found another NodeJS-based converter, but it was 12 times slower and didn't preserve any Exif data at all. Ended up implementing a wrapper for |
Not needed anymore with updated heif-convert version.
I'm still having this issue where the .heic files in portrait orientation are always rotated 90 degrees into landscape when converted to JPEG for preview. |
Could you provide us with a test file and specify which version of PhotoPrism you are using? Note that we offer a number of different Docker images, for example based on Ubuntu or Debian. Also note that previously created JPEGs will not be replaced after upgrading to a (hopefully) fixed version, so you will need to recreate them. |
Sure, is there an email I can send a sample file to? I saw a couple floating around. I'm using the photoprism/photoprism:latest image, and I first installed it today, so it's a brand new library and installation. The only change I made is turn Dynamic Previews on, but there doesn't seem to be a difference before/after turning that on/off. |
Yes, it is described on our website: https://photoprism.app/contact Sample image and video files can be sent to samples@photoprism.app. Please include the format and GitHub issue number or other helpful reference in the subject line, and let us know if we have permission to upload your files to dl.photoprism.app/samples for future use. It might also be possible to attach files to comments on GitHub Issues, or you could add a link to a file uploaded to your own server and service like Google Drive. |
Sent an email with two original HEIC images, a converted JPEG version of one of them, and screenshots of the orientations shown in the PhotoPrism UI. Hope that helps |
Unfortunately, we could not reproduce this. Note that even if you use an image with the You can perform a manual upgrade as described in our docs at https://docs.photoprism.app/getting-started/updates/#docker-compose. Some tools like Portainer also set a custom |
Signed-off-by: Michael Mayer <michael@photoprism.app>
Can confirm the rotation in the previews is correct now using the I'd like to help. How can I test the Debian and Ubuntu ones? Do you mean test the 0.12 vs 0.13 libheif versions somehow, or test the Debian vs Ubuntu photoprism images? |
Let's say you have Docker installed and want to test Debian 12 "Bookworm", you can simply run this command to open a terminal: docker run --rm -v ${PWD}:/heic -w /heic -ti debian:bookworm bash This will mount the current working directory as A complete list of available Ubuntu and Debian images can be found on Docker Hub: Now install the packages you want to test via apt update
apt install -y libheif-examples exiftool Finally, run the
To view the image metadata, run
Rotation and Orientation are the important values you should pay attention to and compare. The rotation is in degrees. The 8 Exif orientation values are numbered from 1 to 8:
|
@melyux We have added information to our Developer Guide on how to install packages into Docker images and run commands there:
Hope this helps! |
I had this issue as well. Can confirm that updating to latest After the upgrade, I did a Could we maybe get a way to limit |
Generally yes, that might be possible. It would help a lot if you could test As thumbs get generated based on hashes, I don't think the force option is needed which should accelerate the update significantly. |
Converted sidecar images (from original HEIC) was re-created when using |
Did you update the index in between? Without looking at the code, I can't tell you where the hashes come from but it seems entirely possible that these are retrieved from the index database and thus the new preview hashes won't get recognized without indexing. |
@lastzero, I did a |
@joachimtingvold The latest heif-convert version should finally fix all these issues: It may take a while before a new stable version is available for you, as it also includes many other changes that need to be tested. |
@lastzero , excellent. Can confirm that |
@joachimtingvold As that looks like a preview version, you should upgrade to today's stable version after reading the full release notes for Build 221102-905925b4d 👍 |
Hi, it appears this fix is not applied when running PhotoPrism without Docker (ie. as Proxmox LXC). Is that correct? |
@martin-g-it we do not offer LXC images for PhotoPrism yet and can't help much with third party installations. A potential issue could be that your installation uses a different version of the library that is used for heif conversion. |
Hi @graciousgrey, it's not really a third party installation I build up PhotoPrism by; I expect the conversion of heic > jpg being done by: Or did I miss any other place where I should look? |
Building from source results in custom builds. Make sure you follow all steps in the Dockerfile and install the same build tools and dependencies, for example the exact same version of libheif, as those tiny little differences are what makes your build custom. It's not all in the source we provide. |
The libheif is all OK, it's just the orientation that is incorrect when .HEIC files were converted to .jpg. I expect because the convert_jpeg.go converts using heif-convert without the exif correction (like done in the Docker script). https://github.com/photoprism/photoprism/blob/727b3eb55255e79fdff64943648ced1f8f3fae42/internal/photoprism/convert_jpeg.go line 171:
This resulted in .HEIC files being converted/imported correctly.. :-) Small disadvantage though; while importing .HEIC files; the sidecar folder size is growing due to the converted .HEIC.jpg files. Another option (or workaround) is to convert the .HEIC files upfront before importing into PhotoPrism library; |
What do you mean by "libheif is all OK"? Is it the same version we use or the one that e.g. comes with the Linux distribution you use? This is the correct version with bug fixes: |
Maybe thats the thing.. I took the package installed via: Running Debian GNU/Linux 11 (bullseye) This one works fine converting .HEIC into .jpg. It's just the orientation that is wrong (which is how I ended up in this thread) and which can be corrected by the exiftool command. I tried the version you've referred, but ran into libjpeg.so.8 is missing errors.. |
It's the metadata and orientation that we've fixed (pulled from upstream and built, to be exact). |
Also, Bullseye is outdated compared to Ubuntu Jammy plus Debian doesn't ship libjpeg, only libjpeg-turbo, so you'd have to build it yourself. That's the reason we use Docker - it's impossible to get it right otherwise. |
Right, makes sense now... Thanks for the swift reply! Will try to upgrade to Bookworm or run a fresh install on that release to see whether this will resolve. |
The version we are using, and that has proven to be bug free, is v1.13.0. As far as I remember, all versions that shipped with Debian had problems. Also, libjpeg-turbo, which ships with Debian, does not support ICC profiles in combination with libheif, so libheif had to add code to handle this. It is not known if this code works without any bugs and does the same as our solution. |
Just as an extra data point, running |
I meant to go deeper in this (I still have wrong rotation out of HEIF files) and I wonder if this is right:
Orientation 0 + rotation 270 ⇒ orientation 1. |
No, that's the problem. Exif Orientation and QuickTime rotation add up, causing the wrong orientation in the end. You can either update libheif or use a wrapper script to fix this. Both can be found in our code base. |
Note that browsers show JPEG images and not native QuickTime or HEIC. So the Exif Orientation field should be used. JPEG readers typically don't know much about video metadata. |
FreeBSD ports should be more up-to-date than most Linux distributions. The libheif version that finally worked for us was released last year, although newer versions could theoretically have a regression. Unfortunately, we have very little time to focus on this given all the other work. |
Just in case anyone with Xiaomi phone is interested: this is the produced metadata with the 4 possible orientation of the phone:
Image is physically rotated, the already applied rotation is shown in QuickTime data (only for HEIC, for JPG it is not done), and EXIT orientation is either 1 (normal) or 0 (undefined) for all 3 other rotations.
My only regret is that this way the "original rotation" is lost, but I can't keep that unless I de-rotate the actual image too, and I don't want to touch the image itself, only metadata. I'll maybe add it as a custom EXIF meta, just for the sake of it. |
Glad you got this sorted out! Keep in mind that the behavior changes depending on the libheif version. |
iPhone 12 mini running iOS 14.4 and Nextcloud 3.3.0.5 Beta (auto-uploads pictures/videos to originals folder)
Took a motion picture, first noticed Photoprism needs manual reindex after I upload new media to originals folder from Nextcloud, still have to figure that out. Then I noticed my most recent picture was a blurred image, turns out Photoprism had made the primary image a preview JPG of the mov file, learned how to change the primary to the converted JPG of the HEIC file.
But now I noticed the converted JPG of the HEIC is rotated, I downloaded the HEIC from Photoprism and that is not rotated, so not sure how it got rotated during the conversion. I think for now I might just experiment with using the compatibility iOS camera option so Photoprism won't have to convert to JPG in the first place.
The text was updated successfully, but these errors were encountered: