提问人:questionto42 提问时间:8/23/2023 最后编辑:questionto42 更新时间:8/23/2023 访问量:133
exifread.process_file() 会抛出 “KeyError: 'hdlr'” 和 “NoParser: hdlr Output is truncated.” 对于 HEIC 图像,即使 exifread 可以处理 HEIC
exifread.process_file() throws "KeyError: 'hdlr'" and "NoParser: hdlr Output is truncated." for a HEIC image even though exifread can deal with HEIC
问:
根据 ExifRead 3.0.0 的指南,该指南说它可以处理 HEIC 图像,以及如何在 Python 中使用 HEIC 图像文件类型的示例,我尝试读取 HEIC 文件的元数据:
p = Path(r'C:\Users\Admin\Pictures\Apple media files\gallery\202204')
l=list(p.glob('**/*.HEIC'))
print(l[0])
# Open image file for reading (must be in binary mode)
f = open(l[0], 'rb')
# Return Exif tags
# tags = exifread.process_file(f)
# tags
exifread.process_file(f)
C:\Users\Admin\Pictures\Apple media files\gallery\202204\IMG_1234.HEIC
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
c:\Users\Admin\anaconda3\envs\scrape\lib\site-packages\exifread\heic.py in get_parser(self, box)
170 try:
--> 171 return defs[box.name]
172 except (IndexError, KeyError) as err:
KeyError: 'hdlr'
The above exception was the direct cause of the following exception:
NoParser Traceback (most recent call last)
in
9 # tags
10
---> 11 exifread.process_file(f)
c:\Users\Admin\anaconda3\envs\scrape\lib\site-packages\exifread\__init__.py in process_file(fh, stop_tag, details, strict, debug, truncate_tags, auto_seek)
135
136 try:
--> 137 offset, endian, fake_exif = _determine_type(fh)
138 except ExifNotFound as err:
139 logger.warning(err)
c:\Users\Admin\anaconda3\envs\scrape\lib\site-packages\exifread\__init__.py in _determine_type(fh)
...
--> 173 raise NoParser(box.name) from err
174
175 def parse_box(self, box: Box) -> Box:
NoParser: hdlr
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
如何使用“exifread”Python 模块获取 HEIC 文件的元数据?
答:
1赞
questionto42
8/23/2023
#1
这只是为了分享我在网上找到的解决此问题的内容。检查 HEIC 处理错误:Apple Silicon #4 上的 hdlr。
因此,您应该降级到低于 3.0.0 的版本:
(scrape) C:\Users\Admin>conda install -c conda-forge "exifread<3"
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\Admin\anaconda3\envs\scrape
added / updated specs:
- exifread[version='<3']
The following packages will be downloaded:
package | build
---------------------------|-----------------
exifread-2.3.2 | pyhd8ed1ab_0 35 KB conda-forge
------------------------------------------------------------
Total: 35 KB
The following packages will be DOWNGRADED:
exifread 3.0.0-pyhd8ed1ab_0 --> 2.3.2-pyhd8ed1ab_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
exifread-2.3.2 | 35 KB | ################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
在 2.3.2 版本中重新启动 Kernel/file/VSCode 以重新加载 exifread,它可以工作:
C:\Users\Admin\Pictures\Apple media files\gallery\202204\IMG_1234.HEIC
{'Image Make': (0x010F) ASCII=Apple @ 146,
...,
...}
评论