Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a HEIF (.heic) image?

For a c++ project, I need to open and show a HEIF (.heic) image. What I know (if I'm right) is that the HEIF images are based on the ffmpeg standard, and requires a H265 codec to be read.

I found several open-source H265 codecs:

  • OpenHEVC (https://github.com/OpenHEVC/openHEVC)
  • x265 (https://bitbucket.org/multicoreware/x265/downloads/)
  • libde265 (https://github.com/strukturag/libde265)

I can open and show H265 encoded video files with each of them, but I'm unable to simply open, show or convert a .heic image. All of them return an error, or just do nothing.

To be honest I'm a little puzzled, because the HEIF standard seem to be a well kept secret. I'm unable to find a relevant info that could allow me to walk to a solution. Those I found are just tricks and workarounds, like e.g. forcing the device (I'm speaking here about the Apple iPhone using the new iOS11) to generate a jpg image instead of a heic, or using a third party application like dr.fone. Of course these solutions are irrelevant for me.

So, somebody can tell me which codec I should use with a .heif image, and how I can use it to open it? Or are there open source libraries or examples that allow to manipulate this type of image file? Somebody can point me to the good direction?

like image 734
Jean-Milost Reymond Avatar asked Sep 12 '17 23:09

Jean-Milost Reymond


People also ask

How do I view HEIF images?

HEIC files are the default format for images across your Apple devices, so it should be easy to open them on your Mac. Just right-click on the file and select Open with Preview – the file should then launch in the Preview program. Alternatively, you can import the files to your Photos app or upload them to Dropbox.

What program opens HEIF files?

On your iOS device (iOS 11 and later), use iOS Photos to open a HEIF file. On PCs running Windows 10, you'll need to install the HEIF Image and HEVC Video Extensions from the Microsoft Store before you can open a HEIF file with selected programs such as Windows Photo Viewer.

How do I open an image HEIC?

To open an HEIC file in Windows, you will need to update to version 18.09 of Windows 10 or later. You can then install the HEIF Image Extensions support tool from the Microsoft Store. To ensure your HEIC files retain their video functionality, you will also need to purchase the HEVC Video Extensions tool.


2 Answers

An example viewer specific for HEIF from Nokia is available here. I also tested directly with FFmpeg and it's able to open (play/decompress) the provided conformance files.

like image 115
Ronald S. Bultje Avatar answered Sep 20 '22 10:09

Ronald S. Bultje


libheif seems to be a pretty active LGPL library for HEIF, with a C API. From the README:

The library has a C API for easy integration and wide language support. Note that the API is still work in progress and may still change.

Loading the primary image in an HEIF file is as easy as this:

heif_context* ctx = heif_context_alloc();
heif_context_read_from_file(ctx, input_filename, nullptr);

// get a handle to the primary image
heif_image_handle* handle;
heif_context_get_primary_image_handle(ctx, &handle);

// decode the image and convert colorspace to RGB, saved as 24bit interleaved
heif_image* img;
heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_24bit, nullptr);

int stride;
const uint8_t* data = heif_pixel_image_get_plane_readonly(img, heif_channel_interleaved, &stride);

A nice, Emscripten-powered demo is available which actually allows you to load and view HEIF files directly inside a browser.

like image 34
mwfearnley Avatar answered Sep 17 '22 10:09

mwfearnley