lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.36k stars 1.3k forks source link

heif: Error while loading plugin: No decoding plugin installed for this compression format #4204

Closed taylorhakes closed 2 months ago

taylorhakes commented 2 months ago

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

yes, version 0.33.5

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 7.63 GB / 64.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.11.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 10.2.4 - /usr/local/bin/npm
  npmPackages:
    sharp: ^0.33.5 => 0.33.5

Does this problem relate to file caching?

The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows. Use sharp.cache(false) to switch this feature off.

Does this problem relate to images appearing to have been rotated by 90 degrees?

Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.

What are the steps to reproduce?

Installed sharp with node and installed libvips on OSX. I tried building from source as well.

I get the following when running the code:

import sharp from 'sharp';
const buffer = await sharp('<FILE_PATH>')
      .toFormat('png')
      .toBuffer();
Error: <FILE_NAME>.HEIC: bad seek to 1586768
heif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003)

What is the expected behaviour?

Convert to PNG

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

Install sharp in OSX and try to convert HEIC files.

Please provide sample image(s) that help explain this problem

N/A

lovell commented 2 months ago

installed libvips on OSX

What is the output of running vips copy input.heic output.png at the command line for your sample input image?

divporter commented 2 months ago

I have the same problem but with jpeg (tried png also to match above issue).

Running vips on the command line works for both png and jpeg for me.

cryptofyre commented 2 months ago

Experiencing the same as above, just on a Linux container environment.

vips copy works fine, but I get a seeking error like the OP.

lovell commented 2 months ago

Please remember that reading HEIC images requires sharp to be built from source against a globally-installed libvips + libheif + libde265 combo - see https://sharp.pixelplumbing.com/install#building-from-source

For those using a custom, globally-installed libheif, my best guess would be that this relates to its plugin system, which can be switched off at compile time using the -DENABLE_PLUGIN_LOADING flag (set it to one of 0, NO or OFF) as others have been directed to do at https://github.com/strukturag/libheif/issues/1250

lukaspanni commented 2 months ago

I have the same problem, using an ubuntu-based container that should contain all the required libraries. This is the relevant snippet from my dockerfile:

RUN apt update && apt install -y libvips-dev libheif-dev
ENV SHARP_FORCE_GLOBAL_LIBVIPS=1

Using heif-convert from the heif-examples package works fine. heif-convert --list-decoders output:

HEIC decoders:
- libde265 = libde265 HEVC decoder, version 1.0.15
AVIF decoders:
- aom = AOMedia Project AV1 Decoder v3.8.2
JPEG decoders:
JPEG 2000 decoders:
uncompressed: yes

I suppose sharp is not correctly building from source and does not use the globally installed libraries. How can I verify/debug this?

lovell commented 2 months ago

I suppose sharp is not correctly building from source and does not use the globally installed libraries. How can I verify/debug this?

All decisions are logged at install time. You might need to add the npm install --foreground-scripts flag to display them.

https://sharp.pixelplumbing.com/install#building-from-source

lukaspanni commented 2 months ago

Thank you for the hint. This revealed that the ubuntu packaged libvips has a version-mismatch with the latest version of sharp and is thus not building correctly. Building the correct versions of the libraries should resolve the issue for me.

lovell commented 2 months ago

I hope this information helped. Please feel free to re-open with more details if further assistance is required.

mattiLeBlanc commented 1 month ago

@lovell I am getting this error on a JPEG file, that came from my iphone together with a couple of other photos. Only this specific one is causing this error:

INFO    Error: source: bad seek to 2298319
heif: Error while loading plugin: No decoding plugin installed for this compression format (11.6003)
    at V.ro [as toBuffer] (/opt/nodejs/node_modules/sharp/lib/index.js:2:56542)
    at Runtime.handler (/var/task/index.js:29:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

IMG_4838 is causing the error. IMG_4538

IMG_4537 is from the same group and works fine:

IMG_4537

When I run the resize on my mac, it works fine by the way. But on the Lambda using release-x64.zip version 0.35. Any idea what to do about this?

It seems that IMG_4538.jpeg can also not be displayed in Github....but it works fine on my mac in Finder.

lovell commented 1 month ago

@mattiLeBlanc IMG_4838 is an HEVC-encoded HEIC image rather than a JPEG.

$ file 380390049-c42700ad-920f-4862-ad39-0589518e835d.jpeg 
380390049-c42700ad-920f-4862-ad39-0589518e835d.jpeg: ISO Media, HEIF Image HEVC Main or Main Still Picture Profile
$ heif-info 380390049-c42700ad-920f-4862-ad39-0589518e835d.jpeg 
MIME type: image/heic
main brand: heic
compatible brands: mif1, miaf, MiHB, heic

image: 3024x4032 (id=49), primary
  tiles: 6x8, tile size: 512x512
  colorspace: YCbCr, 4:2:0
  bit depth: 8
mattiLeBlanc commented 1 month ago

@lovell Is there any support for that, to convert HEICs? Or should I create a new build for that?