LeoHsiao1 / pyexiv2

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

Large exif data #125

Closed tdhancock closed 7 months ago

tdhancock commented 7 months ago

Hello! Thanks for creating this tool, it works great. I was wondering if there is a way to exclude reading some of the exif data? In some images I am reading exif data from, there is a specific exif tag called "Exif.Photo.MakerNote" that I do not need. It is an incredibly large amount of data, and it is slowing down my process a lot having to read that unecessary information. Is there a way to exclude reading that when using the read_exif() API?

LeoHsiao1 commented 7 months ago

Hi! pyexiv2 accesses image metadata by calling exiv2's API. While exiv2 provides only one method readMetadata() to read all metadata at the same time. https://exiv2.org/doc/classExiv2_1_1Image.html#a198b8d5924d6441748aa162130c96a5f

The process of reading image metadata can be divided into three steps:

  1. Read the entire image file from disk into memory, which is a piece of binary data. The duration here can be reduced by using SSD disk.
  2. exiv2 reads the image file in memory and parses out metadata such as EXIF, IPTC, XMP, etc. The duration here is negligible.
  3. exiv2 passes the image metadata to pyexiv2, causing pyexiv2.Image.read_exif() to return value. Using print(img.read_exif()['key1']) instead of print(img.read_exif()) , which avoids printing all the metadata to the terminal, but does not reduce the duration on step 1 and 2 .
tdhancock commented 7 months ago

Thank you for the answer. I was hoping there was a way to avoid reading it in step 1, but it doesn't seem like that's possible with the exiv2 API.