LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
202 stars 39 forks source link

HEIF files (HEIC extension) #101

Closed Spectre5 closed 2 years ago

Spectre5 commented 2 years ago

Per this comment, my understanding is that HEIC files should be supported now. However, it does not work for me, see below. I'm running Linux.

exiv2 does support it:

$ exiv2 --version
exiv2 0.27.5

$ exiv2 IMG_4236.HEIC
File name       : IMG_4236.HEIC
File size       : 2006004 Bytes
MIME type       : image/heic
Image size      : 4032 x 3024
Thumbnail       : None
Camera make     : Apple
Camera model    : iPhone SE (2nd generation)
Image timestamp : 2020:07:29 12:59:24
File number     : 
Exposure time   : 1/60 s
Aperture        : F1.8
Exposure bias   : 0 EV
Flash           : No, auto
Flash bias      : 
Focal length    : 4.0 mm
Subject distance: 
ISO speed       : 125
Exposure mode   : Auto
Metering mode   : Multi-segment
Macro mode      : 
Image quality   : 
White balance   : Auto
Copyright       : 
Exif comment    :

But when I use pyexiv2 (2.8.0), it does not work correctly:

>>> import sys
>>> sys.version
'3.9.12 (main, Aug  6 2022, 20:04:53) \n[GCC 11.2.0]'
>>> import pyexiv2
>>> pyexiv2.__version__
'2.8.0'
>>> pyexiv2.Image('IMG_4236.HEIC').read_exif()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/scott/.local/lib/python3.9/site-packages/pyexiv2/core.py", line 15, in __init__
    self.img = exiv2api.Image(filename.encode(encoding))
RuntimeError: IMG_4236.HEIC: The file contains data of an unknown image type
Spectre5 commented 2 years ago

Maybe related: https://github.com/Exiv2/exiv2#support-for-bmff-files-cr3-heif-heic-and-avif

I see that you download a specific release and build it using pybind11 to link to Python, so maybe in the distributed version on PyPI the build does not include bmff support. My separate exiv2 does:

$ exiv2 -Vv
...
enable_bmff=1
...
LeoHsiao1 commented 2 years ago

Exiv2 does not enable BMFF by default, because of copyright risk, so I do the same. https://github.com/LeoHsiao1/pyexiv2/blob/master/docs/Tutorial.md#bmff

Spectre5 commented 2 years ago

So is building/installing pyexiv2 from source with the appropriate changes the only way then?

LeoHsiao1 commented 2 years ago

No, pyexiv2 adds BMFF when compiling Exiv2. https://github.com/LeoHsiao1/pyexiv2/blob/087c4eb22898ecbba86c69e5257bca6b8333f23d/.github/workflows/build_exiv2.yml#L45

Users can enable it by calling a function: https://github.com/LeoHsiao1/pyexiv2/blob/master/docs/Tutorial.md#bmff

Spectre5 commented 2 years ago

A, I see, thanks!