Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: input buffer is not a HEIC image #22

Closed
zeke opened this issue Sep 5, 2022 · 4 comments
Closed

TypeError: input buffer is not a HEIC image #22

zeke opened this issue Sep 5, 2022 · 4 comments
Labels
invalid This doesn't seem right

Comments

@zeke
Copy link

zeke commented Sep 5, 2022

Hi @catdad 馃憢馃徏 馃悎鈥嶁瑳

Human-dad here. Thanks for writing these modules. 馃檹馃徏

I"m trying to use heic-convert to convert a bunch of files exported from Google Photos with Google Takeout, but getting an error input buffer is not a HEIC image.

I created a repro repo here: https://github.com/zeke/heic-convert-test

Am I missing something obvious?


$ file flower.heic 

flower.heic: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=10, manufacturer=Apple, model=iPhone SE (2nd generation), orientation=upper-right, xresolution=167, yresolution=175, resolutionunit=2, software=15.1, datetime=2022:01:13 13:23:04, hostcomputer=iPhone SE (2nd generation)TIFF image data, big-endian, direntries=10, manufacturer=Apple, model=iPhone SE (2nd generation), orientation=upper-right, xresolution=167, yresolution=175, resolutionunit=2, software=15.1, datetime=2022:01:13 13:23:04, hostcomputer=iPhone SE (2nd generation)], baseline, precision 8, 4032x3024, components 3
{
  inputBuffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff e1 17 0a 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 0a 01 0f 00 02 00 00 00 06 00 00 ... 2150157 more bytes>
}
TypeError: input buffer is not a HEIC image
    at decodeBuffer (/Users/z/Desktop/heic-convert-test/node_modules/heic-decode/index.js:48:11)
    at module.exports (/Users/z/Desktop/heic-convert-test/node_modules/heic-decode/index.js:69:46)
    at convert (/Users/z/Desktop/heic-convert-test/node_modules/heic-convert/index.js:39:25)
    at module.exports (/Users/z/Desktop/heic-convert-test/node_modules/heic-convert/index.js:56:70)
    at /Users/z/Desktop/heic-convert-test/index.js:9:30
@zeke
Copy link
Author

zeke commented Sep 5, 2022

For future travelers, I found another way with ImageMagick:

find . -name '*.HEIC' -exec mogrify -format jpg {} +

@catdad
Copy link
Member

catdad commented Sep 5, 2022

Usually, you get that error when the image is not a HEIC. file seems to tell you it's a jpeg. Are you sure it is not a jpeg that has the wrong extension? That would not surprise me with Google takeout

@catdad
Copy link
Member

catdad commented Sep 5, 2022

Okay, I can confirm that the flower.heic file uploaded to your repro repo in is fact a jpeg image. It just has the wrong format. You can find a good amount of folks complaining about this actually -- Google Photos will compress images uploaded to it (unless you specifically select "original quality" from the settings). When it does this compression, it converts the images to jpegs but still keeps the .heic file extension on them, which just leads to a lot of confusion.

ImageMagick handles this as it will determine which codec to use to load the image entirely on its own. So with your command, it will see that the image being loaded is a jpeg, load it as a jpeg, and then re-encode it back to a jpeg to write the output. With your particular files (at least judging by flower.heic which was provided as a sample, that's actually a bad idea. Re-encoding jpeg images leads to introducing more and more artifacts every time the image is encoded, leading to worse quality every time. The image you provided it already compressed to 86% of original quality. I would recommend that you do not re-encode these files. Simply rename them to a .jpg file extension.

@catdad catdad added the invalid This doesn't seem right label Sep 5, 2022
@catdad catdad closed this as completed Sep 5, 2022
@zeke
Copy link
Author

zeke commented Sep 7, 2022

@catdad! Thank you for the thorough response! Very helpful.

I am now meagerly sponsoring you! In three to six months I will have bought you a coffee. 馃檹馃徏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants