-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
heif: Unsupported feature: Unsupported codec (4.3000) #4050
Comments
There are a bunch of others getting this same error. There doesn't seem to be a conclusive answer out there other than "upgrade to the latest version" which I have. I've also tried backdating to version 3.32. I've also tried every workaround/fix in every issue with the same error, so I'm pretty sure this isn't a duplicate. |
I can confirm, if I downgrade to 0.26.2 and it works as stated in #2518 This confirms it's not a problem with my setup or implementation, but a problem with sharp. Is modern sharp going to support heic files anytime soon? I need to know, since using a pinned version is not going to be considered a viable option in my case for security reasons, long term. Also, it might be worth mentioning that sharp 3+ does't support heic files in the readme until it's fixed. |
The prebuilt binaries do not support the patented HEVC compression, as used by HEIC images. Processing HEIC images requires that sharp be built from source against a globally-installed libvips that itself has been compiled with support for libheif+libde256. This works with the latest version of sharp, and requires some additional dependencies that are listed in the documentation. https://sharp.pixelplumbing.com/install#custom-libvips
The latest version of sharp v0.33.3 requires libvips v8.15.2. Line 190 in 0981b24
https://sharp.pixelplumbing.com/install#building-from-source
At install time, sharp logs all decisions it makes relating to its ability to build from source. If you are still having problems, please provide the complete output of running |
I'll provide more details shortly, but in debugging locally, I encountered this error:
I installed libvips locally with Any idea what that means, and why Napi::Buffer doesn't have NewOrCopy? Thanks, |
Actually, I got this error earlier, and installed the latest version of node-gyp (10.1.0) as a result.
EDIT: I think I got it. I was missing node-addon-api as well, which was documented in the link provided in the error. Somehow I missed this the first time around. I will take some more diagnostic info from our beta environment, then we should be able to answer the original question. |
Here's the response of npm install sharp --build-from-source --verbose --foreground-scripts from our debian based docker environment (the official node:20 image, base tag) For context, this was run in a docker environment on an M1 mac (see specs above), reproducing our production builds, which happen in a linux x64 github action, and are run in an x64 linux environment (ubuntu) The test docker image was built and run using: docker build --platform linux/arm64 -t my-app . && docker run -it --rm --name my-running-app my-app /bin/sh
The obvious question is what are the optional dependencies, and why are they failing? Just as a reminder, we are using yarn 4, so behavior might differ slightly from NPM |
Thanks for the log, the optional dependencies are not important here. Because you intend to build from source, what is important here is the lack of evidence of any install script having run. Please ensure you are allowing scripts to run, for example ensure that you've not set https://docs.npmjs.com/cli/v10/commands/npm-install#ignore-scripts |
I must have run npm install first, and it probably skipped sharp because it was already built or something. I ran the same command in the same environment, ensuring that there is no pre-existing node_modules folder, and I got something a lot more useful. It is too long to post the full output, but here is the part where it tries to build the binaries. The rest of it just looks like it's downloading dependencies.
|
Here are more details from the file it references at the end:
|
What is the output of |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm going to be working on this today/tomorrow. Is there any additional diagnostic info besides this that you'd like to see? I will try to get you both at the same time. |
Hi, I'm also facing the issue. In case it can help, I've created a Dockerfile: FROM node:20 as builder
WORKDIR /opt/src
RUN apt-get update && \
apt-get install -y libvips libvips-dev libheif-dev libde265-dev
RUN npm install sharp --build-from-source --verbose --foreground-scripts
RUN wget https://heic.digital/download-sample/soundboard.heic
ARG CACHEBUST=1
RUN pkg-config --modversion vips-cpp
RUN pkg-config --cflags --libs libheif
RUN echo 'const sharp = require("sharp");' > script.js && \
echo 'sharp("soundboard.heic").jpeg().toFile("output.jpg", (err, info) => { console.log(info, err); });' >> script.js && \
node script.js and then if build it with the following command: I get the following:
Anything that I'm missing in the Dockerfile? Thank you in advance, |
https://sharp.pixelplumbing.com/install#custom-libvips
Line 190 in 55466f1
You are using libvips 8.14.1, which does not satisfy the semver range |
Hi, Thanks, so I tried with the following Dockerfile (switched to Alpine because this is where I found the right version of libvips) FROM node:20-alpine
WORKDIR /opt/src
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk add --no-cache --update \
build-base \
vips-dev=8.15.2-r0 \
fftw-dev \
gcc \
g++ \
make \
python3 \
wget \
vips-dev=8.15.2-r0
RUN npm install node-addon-api && \
npm install node-gyp
RUN npm install sharp --build-from-source --verbose --foreground-scripts
ARG CACHEBUST=1
RUN wget https://heic.digital/download-sample/soundboard.heic
RUN pkg-config --modversion vips-cpp
RUN echo 'const sharp = require("sharp");' > script.js && \
echo 'sharp("soundboard.heic").jpeg().toFile("output.jpg", (err, info) => { console.log(info, err); });' >> script.js && \
node script.js and building with The results:
There are some changes. Now it doesn't tell me anymore about the unsupported codec. But it seems that it can't handle the image. Anything missing? Or anything I can test with? Thanks in advance |
@DidierHoarau HEIC / AVIF support is available in the |
Hi, Thanks a lot. So with this Dockerfile: FROM node:20-alpine
WORKDIR /opt/src
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk add --no-cache --update \
build-base \
vips-dev=8.15.2-r0 \
fftw-dev \
gcc \
g++ \
make \
python3 \
wget \
vips-dev=8.15.2-r0 \
vips-heif=8.15.2-r0
RUN npm install node-addon-api && \
npm install node-gyp
RUN npm install sharp
ARG CACHEBUST=1
RUN wget https://heic.digital/download-sample/soundboard.heic
RUN pkg-config --modversion vips-cpp
RUN echo 'const sharp = require("sharp");' > script.js && \
echo 'sharp("soundboard.heic").jpeg().toFile("output.jpg", (err, info) => { console.log(info, err); });' >> script.js && \
node script.js (So I didn't even have to add the --build-from-source, it it sees that the library is installed, it will auto-try to build) This works:
Great. Thanks again |
I was just solving the same issue, mine was caused by missing |
@dvdkon Please see https://sharp.pixelplumbing.com/install#building-from-source
sharp will always log decisions it makes at install-time. Lines 11 to 25 in 52b9dc0
You'll need to ensure your choice of package manager displays these; for I've just opened nodejs/node-addon-api#1479 to expose the |
@robbyemmert Were you able to make any progress with this? |
I used heic-decode library as workaround. import decodeHeic from "heic-decode";
const decodedImage = await decodeHeic({
buffer: fileContent,
});
return sharp(decodedImage.data, {
...options,
raw: {
width: decodedImage.width,
height: decodedImage.height,
channels: 4,
},
}); |
@robbyemmert I'll close due to inactivity but please feel free to reopen with more details if further help is required. |
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
This is a bug with sharp at runtime. Installation happened fine. I am able to resize any type of image except for heic.
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.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: Linux 5.19 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (2) x64 DO-Regular
Memory: 2.22 GB / 3.82 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
Binaries:
Node: 20.12.0 - /usr/local/bin/node
Yarn: 4.1.1 - /usr/local/bin/yarn
npm: 10.5.0 - /usr/local/bin/npm
npmPackages:
sharp: ^0.33.3 => 0.33.3
What are the steps to reproduce?
The toFile function fails when processing heic files.
I tried using the bundled binary, enabling every os and cpu architecture involved (and more) in my yarn config (yarn 4)
I tried using a custom installed version
I can run heif-convert --list-decoders and verify that heic/heif codecs are in fact installed.
I can use the exact example image I provided below to heif-convert to a jpg.
But whenever I try to parse a heic file I get the error heif: Unsupported feature: Unsupported codec (4.3000)
I have tried configuring Alpine linux and Debian and Mac OS.
It appears to work on my mac, but I get the codec error as soon as I deploy to any linux variation.
I have also tried running this in Node 16, Node 18, and Node 20, with yarn 1 and 4. I get the EXACT same issue in every case.
This looks like a runtime bug with sharp.
What is the expected behaviour?
I want to support iPhone images—THE most common photo use case for my application.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
see above
Please provide sample image(s) that help explain this problem
https://heic.digital/download-sample/sewing-threads.heic
or any heic file.
The text was updated successfully, but these errors were encountered: