image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.76k stars 589 forks source link

Heic decoding #1375

Open zdcthomas opened 3 years ago

zdcthomas commented 3 years ago

How does one decode an heic encoded image? Is there a current way that I'm missing to decode an heic image, OR convert it to an image format that I can also operate on, like a jpeg?

Overall, I'm trying to resize an heic encoded image.

I saw that there isn't decoding support for avif, but I'm more specifically interested in heic encoded images. Thanks! Sorry if this is an obvious question!

fintelia commented 3 years ago

That isn't possible with this library yet. My suggestion would be to use an external tool to do the conversion like say ImageMagick

zdcthomas commented 3 years ago

Is there something blocking development on that functionality/ is there anyone currently working on that?

HeroicKatora commented 3 years ago

There are a few ways to wrap libheif and mp4parse but I'm not aware of any Rust native crate that is specifically dedicated to generically demuxing isobmff as heif, nor to H.265 decoding. I imagine this is in parts due to the large patent encumbrance surrounding all of MPEG's technical work. This of course precludes the availabilty of HEIC decoding and encoding.

est31 commented 3 years ago

I think instead of HEIC one should focus resources onto AVIF: #1152

The patent situation there is way better.

mleonhard commented 3 years ago

When iOS users enable the "live photo" option, their camera software creates HEIC files. My rust server must process those files.

My plan is to make my app convert all images to JPEG before uploading. I will try the Dart library https://pub.dev/packages/heic_to_jpg in my Flutter app.

yuribudilov commented 2 years ago

Hello everyone. Are there any positive news on this matter now in Dec 2021 ? I would like to use Rust to convert .HEIC photo images to JPG/JPEG photo images and save resulting JPG on disk. Right now I am using a GUI program to do it manually, which works OK but I am looking for a Rust-based programmatic solution to deal with HEIC photos. Thank you for any guidance.

fintelia commented 2 years ago

This issue (like similar issues for other large feature requests) is blocked on either someone coming by that wants to implement it, or else another Rust crate being written that exposes the desired functionality in a way we can use.

I know it is not the answer you were hoping for, but sadly at this point none of the maintainers have the time and energy to make big feature additions. Which means that the majority of development comes down to contributors stepping in to write features they want for themselves, and of course we can't really predict when/if that'll happen for any given request

baumanj commented 2 years ago

Just a note that while mp4parse gets most of the way there on account of AVIF and HEIC being very similar at the container level, the hard problem of HEIC support is that the patents which cover the codec itself are not free. The best way forward would probably be to integrate libheif (perhaps via https://crates.io/crates/libheif-sys) to handle decoding. With that, the changes to mp4parse to get HEIC files demuxed should be pretty minimal.

broes5 commented 1 year ago

I would like be able to use Image-rs to decode .heic files in a program I'd like to write. I wouldn't mind adding support for .heic files. Unfortunately I can't find any specific enough information about the structure of .heic files. If someone could point me in the right direction, I'm sure I'd figure it out eventually.

baumanj commented 1 year ago

HEIC has basically the same container structure as AVIF since they're both based on the ISO/IEC 23008-12:2017 HEIF standard (free download). This library already uses https://github.com/mozilla/mp4parse-rust, which I added AVIF parsing support to, so most of that work is done.

That said, they AVIF and HEIC differ at the codec level. AVIF uses AV1, while HEIC uses HEVC, which is neither free nor open. If you're interested, I'd suggest starting with https://github.com/strukturag/libde265. It doesn't seem to have a rust wrapper yet, so that'd be a nice community addition.

broes5 commented 1 year ago

Thanks. What do you mean when you say that HEVC "is neither free nor open"?

baumanj commented 1 year ago

I mean that unlike AV1, HEVC is not free to use and there's no open source reference implementation

CaiJingLong commented 1 year ago

I would like be able to use Image-rs to decode .heic files in a program I'd like to write. I wouldn't mind adding support for .heic files. Unfortunately I can't find any specific enough information about the structure of .heic files. If someone could point me in the right direction, I'm sure I'd figure it out eventually.

The heic is base of ISO bmff(ISO_base_media_file_format).

https://en.wikipedia.org/wiki/ISO_base_media_file_format https://mpeg.chiariglione.org/standards/mpeg-4/iso-base-media-file-format


I know an open source project of heif: https://github.com/nokiatech/heif

broes5 commented 11 months ago

Is anyone here aware of libheif-rs? It's a wrapper around another library and is dependent on the libheif binary being installed. Has anyone considered using it in this project? I imagine getting image to be able to decode and encode .heic files using libheif-rs would be a lot simpler/easier than implementing the functionality from scratch or using another library.

broes5 commented 11 months ago

Are there any reasons libheif-rs cannot be used or would be undesirable?

fintelia commented 11 months ago

The two concerns with linking to libhief would be:

  1. We have a policy of only allowing non-Rust dependencies behind a disabled by default feature flag
  2. Patents. It'd probably be a headache to figure out what we can and cannot do, and to make sure we're not taking on any legal risk
broes5 commented 11 months ago

There seem to be 3 libraries that are dependent on libheif installed on my laptop. If they can use it, then surly so can image without legal repercussions. Right?

fintelia commented 11 months ago

I have no idea. Maybe they've consulted lawyers and take specific precautions? Or the developers are in a country where it isn't as much of a concern? Or it could just be a matter of time until they run into problems

broes5 commented 11 months ago

One of them is called OpenImageIO.