You are here

Decoding HEIF/HEIC on Kodi/Raspberry Pi

I lost track of when Apple started using the High Efficiency Image Format (HEIF/HEIC) for iPhone photos. In my house, we typically look at our photos on a TV connected to a Raspberry Pi running the Kodi (Formerly XBMC) media center which doesn't natively support HEIF images. After some digging, I discovered that you can install the HEIF image decoder add-on from the command line:

$ sudo apt install kodi-imagedecoder-heif

Upon launching Kodi, a pop-up window announced that it had discovered the add-on and I confirmed the installation. After viewing several HEIC images, Kodi crashed. Upon relaunching and trying again, I was able to view several more images and the system froze. So I decided to take a new tack: converting the HEIF images to JPG. The remaining instructions were run on my Ubuntu server, NOT on the raspberry pi.

UPDATE August 2024:
Either my notes were wrong, or something changed, but to install the package on Ubuntu, use the following:

$ sudo apt install libheif-examples

The following installation instructions may be erroneous, outdated, or I may have confused them with MacPorts:

$ sudo apt install heif-convert

The remainder of this article still applies as of August 2024.
---

To convert the HEIC files to jpeg:

$ heir-convert -q 93 <heif_file> <jpeg_file>

Note the value after "-q" is a size/quality range from 1 (smallest/worst) to 100 (largest/best).

heir-convert worked fine on a couple of test images until I noticed that the vertical images were all sideways and some of the horizontal images were upside down. It turns out that although the heir-convert utility honors the rotation within the HEIC metadata (irot field), the image data is rotated, but the metadata stores the original rotation. The net effect is that images are rotated "twice". My solution was to add a second step in the process

$ exiftool -Orientation=1 -n <jpeg_file>

Note that exiftool by default saves the original image file and appends "_original" to the end of the filename. You can either delete these files, or if you want to avoid saving the originals (DANGEROUS), use either -overwrite_original or -delete_original options.