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
28.41k stars 1.28k forks source link

avif/heic/heif detection problem #3576

Closed mhf-ir closed 1 year ago

mhf-ir commented 1 year ago

Possible bug

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

Are you using the latest version of sharp?

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 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 1.31 GB / 15.04 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.14.2 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.5.0 - /usr/bin/npm
  npmPackages:
    sharp: ^0.31.3 => 0.31.3 

What are the steps to reproduce?

const sharp = require("sharp");

// default is webp
const outProps = {
  quality: 80,
  alphaQuality: 5,
  effort: 6,
  force: true,
};

// works well
// const fileName = "2.avif";

// not working
const fileName = "1.avif";

(async () => {
  await sharp(fileName, { animated: true })
    .rotate()
    .resize({
      width: 10,
      height: 10,
      fit: "inside",
    })
    .webp(outProps)
    .toBuffer();

})();

What is the expected behaviour?

work like charm

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

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

Not working version: https://colinbendell.github.io/webperf/animated-gif-decode/1.avif

Working version: 2.zip

mime type

$ file --mime-type 1.avif 
1.avif: image/avif
$ file --mime-type 2.avif 
2.avif: image/avif

Exif output of not working version:

[
  {
    "SourceFile": "1.avif",
    "ExifToolVersion": 12.4,
    "FileName": "1.avif",
    "Directory": ".",
    "FileSize": 475994,
    "FileModifyDate": "2023:02:28 14:09:29+03:30",
    "FileAccessDate": "2023:02:28 14:10:01+03:30",
    "FileInodeChangeDate": "2023:02:28 14:09:29+03:30",
    "FilePermissions": 100664,
    "FileType": "MP4",
    "FileTypeExtension": "MP4",
    "MIMEType": "video/mp4",
    "MajorBrand": "avis",
    "MinorVersion": "0.0.0",
    "CompatibleBrands": [
      "avis",
      "msf1",
      "miaf",
      "MA1B"
    ],
    "PrimaryItemReference": 1,
    "ImageWidth": 800,
    "ImageHeight": 450,
    "ImageSpatialExtent": "800 450",
    "PixelAspectRatio": "1 1",
    "AV1ConfigurationVersion": 1,
    "ChromaFormat": 3,
    "ChromaSamplePosition": 0,
    "ImagePixelDepth": "8 8 8",
    "MovieHeaderVersion": 0,
    "CreateDate": "2020:09:13 22:30:30",
    "ModifyDate": "2020:09:13 22:30:30",
    "TimeScale": 1000,
    "Duration": 10.845,
    "PreferredRate": 1,
    "PreferredVolume": 1,
    "PreviewTime": 0,
    "PreviewDuration": 0,
    "PosterTime": 0,
    "SelectionTime": 0,
    "SelectionDuration": 0,
    "CurrentTime": 0,
    "NextTrackID": 2,
    "TrackHeaderVersion": 0,
    "TrackCreateDate": "0000:00:00 00:00:00",
    "TrackModifyDate": "2020:09:13 22:30:30",
    "TrackID": 1,
    "TrackDuration": 10.845,
    "TrackLayer": 0,
    "TrackVolume": 0,
    "MatrixStructure": "1 0 0 0 1 0 0 0 1",
    "MediaHeaderVersion": 0,
    "MediaCreateDate": "0000:00:00 00:00:00",
    "MediaModifyDate": "2020:09:13 22:30:30",
    "MediaTimeScale": 30000,
    "MediaDuration": 10.8441666666667,
    "MediaLanguageCode": "und",
    "HandlerType": "pict",
    "HandlerDescription": "GPAC avifs",
    "GraphicsMode": 0,
    "OpColor": "0 0 0",
    "OtherFormat": "av01",
    "MediaDataSize": 473148,
    "MediaDataOffset": 2788,
    "ImageSize": "800 450",
    "Megapixels": 0.36,
    "AvgBitrate": 349026
  }
]

Exif output of working version:

[
  {
    "SourceFile": "2.avif",
    "ExifToolVersion": 12.4,
    "FileName": "2.avif",
    "Directory": ".",
    "FileSize": 3734,
    "FileModifyDate": "2022:10:30 15:59:05+03:30",
    "FileAccessDate": "2023:02:28 14:10:07+03:30",
    "FileInodeChangeDate": "2023:02:28 14:09:52+03:30",
    "FilePermissions": 100664,
    "FileType": "AVIF",
    "FileTypeExtension": "AVIF",
    "MIMEType": "image/avif",
    "MajorBrand": "avif",
    "MinorVersion": "0.0.0",
    "CompatibleBrands": [
      "mif1",
      "miaf"
    ],
    "HandlerType": "pict",
    "PrimaryItemReference": 1,
    "ImageWidth": 259,
    "ImageHeight": 195,
    "ImageSpatialExtent": "259 195",
    "AV1ConfigurationVersion": 1,
    "ChromaFormat": 0,
    "ChromaSamplePosition": 0,
    "ImagePixelDepth": "8 8 8",
    "MediaDataSize": 3492,
    "MediaDataOffset": 242,
    "ImageSize": "259 195",
    "Megapixels": 0.050505
  }
]
lovell commented 1 year ago

This looks like an AVIF sequence file (the mime type is image/avif-sequence), which are unsupported. Please see https://github.com/lovell/sharp/issues/2870#issuecomment-908972088

mhf-ir commented 1 year ago

how do you detect mime type?

detect it as image/avif

lovell commented 1 year ago
$ heif-info <(curl -s https://colinbendell.github.io/webperf/animated-gif-decode/1.avif)
MIME type: image/avif-sequence
main brand: avis
compatible brands: avis, msf1, miaf, MA1B

https://manpages.ubuntu.com/manpages/jammy/man1/heif-info.1.html

lovell commented 1 year ago

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