-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
Seems like “libheif-1.8.0” is arbitrarily creating unopenable (corrupt?) HEIC files in macOS? #331
Comments
I've tested this on Linux with v1.8.0 on your images, but I cannot see any problem. |
@farindk Thanks for the response! Here is the output of
That
And here is
|
Hm, I have no problems displaying your I noticed that I get corrupted output when decoding this with an old version of libheif. Try, e.g., the online decoder, which is still an old version: https://strukturag.github.io/libheif/ |
@farindk Just checked with the online As for the way I attempt to display them in macOS, I am just using the built in macOS “Preview” application. I converted hundreds of very high res scans this past July 2020 with ImageMagick (which uses |
Just checked. The image above even decodes correctly in libheif v1.0.0. Hence, it's obviously a bug in the online decoder that leads to the corrupted display. I guess it's because of the odd image width. What does the picture in native macOS look like? |
@farindk It doesn’t open at all so I don’t even see a distorted image. When I convert the image it shows no preview image in the Finder and then if I attempt to double-click it to open it, I simply get the message:
If I try to open it with another application — such as Pixelmator — I get a similar message and the image doesn’t open. Screenshots below of the finder with the thumbnail missing and the message I get when I attempt to open it. |
Can you convert it to HEIC using some macOS tools and send that to me? I'd like to see how macOS handles the odd image size in its own encoder. |
Pixelmator probably uses the native macOS API and hence gives the same error. |
@farindk Here is the But what is odd is if I use the online decoder, it shows the same skewed/distorted output while I can see it 100% clear and fine on my desktop. |
FWIW, I just decided to see what happens if I convert the unopenable HEIC to a JPEG with ImageMagick like this:
And magically that HEIC image cleanly converts to a JPEG without any issues. So perhaps there is something in the generated HEIC file that chokes on macOS built-in decoders/tools? |
I analyzed the image written by macOS. The image contains 512x512 tiles arranged into a grid, with the grid size set to the output image size. Libheif, on the other hand, saves the image as a single image with an additional Not sure whether we should do anything about this, as it is a bug in the macOS reader. As a workaround, we would have to write heif images embedded into a tile grid, just to avoid the macOS limitation. But this will lead to larger files. |
@farindk Excellent explanation. For my own purposes I will adjust my ImageMagick scripts to do cropping of 1 pixel from odd numbered widths/heights and then do an HEIC conversion. As for the larger macOS issue, might report this to Apple. Thanks again for the help in tracking this down! |
I have added the option '-E'/'--even-size' to heif_enc which crops the image to even size if necessary. That might be useful in scripts converting to HEIF until there is a fix for macOS or until we have a workaround. |
@farindk Excellent! My solution — for now — is to have ImageMagick round up to the next even pixel size using a command like this. Worked great for my recent needs:
|
@farindk Just a followup but I updated my local Homebrew install of libheif to version 1.9.0 and your new option works great! When I ran this basic command; just like what I have done before:
I get this helpful warning:
And the resulting image is just like before; valid but not openable in macOS. But if I run the same exact command with the
I get a 100% valid HEIC image that is open in macOS! Thanks again for quickly addressing this issue. |
I discovered this issue while using ImageMagick to batch convert some images. Posting here because it seems that something in
libheif-1.8.0
is causing this issue.The longer post with some other details can be found in this ImageMagick issue I posted here when I believed this was simply an ImageMagick issue. The process I am using with ImageMagick runs a simple Bash script to traverse a directory full of JPEG images to convert them to HEIC like this:
This worked fine for converting hundreds of images back in July 2020 when I was using an earlier version of ImageMagick with
libheif-1.7.0
.But now — after doing a Homebrew package update that updated ImageMagick as well as
libheif-1.7.0
— it seems like a few out of every bunch of images I attempt to convert are unopenable and corrupt.This happens to seemingly arbitrary images (not random images) but consistently. Meaning, if I give the script a pile of images to convert — such as
one.jpg
,two.jpg
,three.jpg
, etc… — andtwo.jpg
is converted totwo.heic
which is corrupt, that image will always convert as a corrupt HEIC.The same exact results — some images solid HEIC files and others unopenable/corrupt — can be seen if I use
heif-enc
to convert the images like this:Here are some test images I found (via the Wikimedia commons) that recreates the issue;
1280px-Test_(student_assessment).jpeg
always results in a corrupted and inoperable HEIC image:The text was updated successfully, but these errors were encountered: