You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
heif() with compression 'hevc' fails with 'Invalid parameter value (5.2006)' due to default tune 'auto' #4621
Is this a possible bug in a feature of sharp, unrelated to installation?
Running npm install sharp completes without error.
Running node -e "import 'sharp'" completes without error.
Are you using the latest version of sharp?
I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
Not available. This runs inside the public.ecr.aws/lambda/nodejs:24 image (Amazon Linux 2023, x86_64, Node.js 24), not on a host where I can run envinfo. The setup is:
sharp 0.35.5, built from source (SHARP_FORCE_GLOBAL_LIBVIPS=1 npm run build) against a globally installed libvips
libvips 8.18.7
libheif 1.23.6 with the x265 4.2 encoder, libde265 1.1.3 and libaom 3.15.1
The build is https://github.com/zoellner/sharp-heic-lambda-layer, an AWS Lambda layer that provides HEIC support. The prebuilt sharp binaries don't include x265, so this probably only shows up with a globally installed libvips whose libheif has the x265 encoder.
Does this problem relate to file caching?
Adding sharp.cache(false) does not fix this problem.
N/A, this is an encoder parameter error.
Does this problem relate to images appearing to have been rotated by 90 degrees?
Using rotate() or keepExif() does not fix this problem.
N/A.
What are the steps to reproduce?
With sharp using a libvips whose libheif has the x265 encoder, encode HEIF with compression: 'hevc' and don't set tune:
Error: heif: Invalid parameter value (5.2006)
at Sharp.toBuffer (.../node_modules/sharp/dist/output.cjs:159:17)
5.2006 is heif_error_Usage_error / heif_suberror_Invalid_parameter_value.
The cause seems to be this chain:
sharp always sets tune, which defaults to 'auto' (heifTune: 'auto', passed via ->set("tune", baton->heifTune.c_str()) in src/pipeline.cc).
libvips heifsave forwards it to heif_encoder_set_parameter_string(encoder, "tune", ...). It ignores only heif_suberror_Unsupported_parameter, not Invalid_parameter_value.
libheif's AV1 (libaom) plugin accepts auto, but its x265 plugin only accepts psnr, ssim, grain and fastdecode. It returns Invalid_parameter_value for auto, so every HEVC encode fails unless tune is set explicitly. There is also no way to choose "no tune" from sharp.
Setting tune: 'ssim' or tune: 'psnr' explicitly works around it.
What is the expected behaviour?
heif({ compression: 'hevc' }) should encode successfully with the default options, as it did before tune was added.
A possible fix is to skip setting tune when it is 'auto'. libheif's aom plugin already treats auto as its default, so AV1 output would be unchanged. An alternative is to set tune only when compression is 'av1'.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
constsharp=require('sharp');(async()=>{// Throws: heif: Invalid parameter value (5.2006)awaitsharp('input.heic').resize({width: 320}).heif({compression: 'hevc',quality: 50}).toBuffer();})();
Thanks for reporting, I recall somewhere along the lines that libheif was planning to allow "auto" for other encoders, but that's clearly not the case so commits 43cc2dc and 203f6e6 fix this.
Activity
Ensure HEVC compression defaults to SSIM tuning #4621
lovell commentedon Oct 9, 2026
Thanks for reporting, I recall somewhere along the lines that libheif was planning to allow "auto" for other encoders, but that's clearly not the case so commits 43cc2dc and 203f6e6 fix this.