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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAW images give "Input file contains unsupported image format", but vips/ImageMagick handle them fine #2867

Closed
paulstraw opened this issue Aug 28, 2021 · 4 comments
Labels

Comments

@paulstraw
Copy link
Contributor

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?

I currently have lovell/sharp specified in package.json, as reproducing this issue requires the fix for #2864.

What are the steps to reproduce?

I've updated the example repo from my last issue with steps: https://github.com/paulstraw/sharp-magick-lambda

What is the expected behaviour?

Metadata can be extracted from camera RAW files.

Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?

https://github.com/paulstraw/sharp-magick-lambda

Are you able to provide a sample image that helps explain the problem?

Sample images in the linked repo

What is the output of running npx envinfo --binaries --system?

npx: installed 1 in 2.449s

  System:
    OS: Linux 5.10 Amazon Linux 2
    CPU: (4) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 667.21 MB / 1.94 GB
    Container: Yes
    Shell: 4.2.46 - /bin/bash
  Binaries:
    Node: 14.17.5 - /var/lang/bin/node
    npm: 6.14.14 - /var/lang/bin/npm
@lovell
Copy link
Owner

lovell commented Aug 30, 2021

RAW images often masquerade as TIFF images, which these examples appear to do also, so libvips will use libtiff to open these however they aren't quite valid TIFF images and fail.

$ vipsheader -a Sony-A550.ARW 
(vipsheader:18334): VIPS-WARNING **: 19:35:37.776: Unknown field with tag 50341 (0xc4a5) encountered
vipsheader: VipsForeignLoad: "Sony-A550.ARW" is not a known file format

#2852 provides a suggested workaround for changing the priority of magickload.

@lovell lovell added question and removed triage labels Aug 30, 2021
@paulstraw
Copy link
Contributor Author

paulstraw commented Aug 30, 2021

Thanks for the information, that's very helpful. The priority workaround in #2852 makes sense, but I'd love the ability to continue using the libvips native TIFF support as well. If I understand correctly, changing the priority would have the same basic effect as configuring libvips --without-tiff?

My plan was to detect raw images based on Sharp's metadata output, then convert them to TIFF with dcraw -w to preserve camera white balance settings. I would then use that TIFF output as input to Sharp for actual additional processing. It kind of seems like my only real option is going to be using IM for the "second generation" TIFF processing as well (since its priority will be higher than vips' internal handler in my custom build). I believe LibRaw has a similar use_camera_wb setting, but as far as I can tell there's no way to set it via libvips/sharp.

@lovell
Copy link
Owner

lovell commented Aug 31, 2021

I've not tried it, but I'm aware that one of the developers at Elastic (who use sharp in some of their tooling) created https://github.com/justinkambic/libraw.js that might help. Given you need to support both TIFF and RAW files, a possible workflow might be when sharp/libvips thinks a file is TIFF but then generates a decoding error, you could fall back to trying libraw.js next.

@paulstraw
Copy link
Contributor Author

paulstraw commented Sep 2, 2021

I'm going to close this issue, as it doesn't sound like there's anything actionable on the sharp side of things. I ended up bypassing sharp for reading metadata entirely. For my case, I need to support as many image input formats as possible, including camera RAW images. My current implementation has to write 1-2 tempfiles to disk, but in my testing that adds 10s of milliseconds to a process that takes 1000s (mostly sharp operations and network transfer), so I'm happy with that tradeoff. Additionally, I do not have to use libvips --without-tiff with this approach, which gives a nice speed boost. Thanks again for your help with this, @lovell. For anyone else who comes across this issue in the future, here's what I did:

  • Install LibRaw from source, which gives access to raw_identify and dcraw_emu
  • Write input to a temporary file (mine comes from the network)
  • Use exiftool-vendored to read metadata from the temp file
    • If tags.MIMEType === 'image/gif', a separate process is run to convert to mp4 via ffmpeg
  • Use raw_identify to determine if the temp file is RAW
    • If it's RAW, use dcraw_emu -w -T tempFilePath to output a tiff, then sharp(`${tmpFilePath}.tiff`)
    • Otherwise, just call sharp with the input buffer
  • Output sharp pipeline to WebP buffer, write back to source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants