简体   繁体   English

如何从 avif 文件中获取图像尺寸?

[英]How to get image dimensions from an avif file?

I'm looking for a (fast) way to retrieve image metadata from an avif-file in my java-application.我正在寻找一种(快速)方法来从我的 java 应用程序中的 avif 文件中检索图像元数据。 This is currently done for many image formats by analyzing the raw header bytes of a file.这目前通过分析文件的原始 header 字节对许多图像格式完成。

I can recognize a file as avif through the magic byte sequence at the beginning of the file: ftypavif .我可以通过文件开头的魔术字节序列将文件识别为 avif: ftypavif But I'm not able to find any information how to parse the (max) image width & height of contained images.但我无法找到任何信息如何解析包含图像的(最大)图像宽度和高度 For JPEG2000 for example I can search for SIZ marker 0xFF51 and parse dimensions afterwards, but even after spending a lot of time reading through specifications of avif, I'm not able to find something similar for it.例如,对于 JPEG2000,我可以搜索 SIZ 标记0xFF51并在之后解析尺寸,但即使在花费大量时间阅读 avif 的规范之后,我也无法找到类似的东西。

Is my approach incorrect and I can't parse the image dimensions without decoding the image(s)?我的方法是否不正确,如果不解码图像就无法解析图像尺寸? Or is there any documentation (or even usable library) I missed to retrieve width & height from an avif-file?或者是否有任何文档(甚至是可用的库)我错过了从 avif 文件中检索宽度和高度的信息?

Any hints appreciated!任何提示表示赞赏!

Some of the AVIF files have ftypavis (contains animation) and I also saw AVIF with ftypmif1一些 AVIF 文件有ftypavis (包含动画),我还看到了带有 ftypmif1 的ftypmif1

If you want to parse AVIF alone, you need to understand ISOBMFF format and HEIF container first.如果要单独解析AVIF,需要先了解ISOBMFF格式和HEIF容器 There are various properties (like Image spatial Extents (ispe)), then various transformations (crop, rotation, mirror).有各种属性(如图像空间范围(ispe)),然后是各种变换(裁剪、旋转、镜像)。 Images can be stored in a form of image grid...图像可以以图像网格的形式存储...

Search for 'ispe' box (this is a mandatory box/item), skip 4 bytes after the type (FullBox version and flags) read 4 bytes for image width, read 4 bytes for image height.搜索'ispe'框(这是一个强制框/项目),在类型(FullBox 版本和标志)之后跳过 4 个字节读取图像宽度的 4 个字节,读取图像高度的 4 个字节。 Profit;)利润;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM