2

I'm looking for a (fast) way to retrieve image metadata from an avif-file in my java-application. This is currently done for many image formats by analyzing the raw header bytes of a file.

I can recognize a file as avif through the magic byte sequence at the beginning of the file: 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.

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?

Any hints appreciated!

Jochen Go
  • 21
  • 3
  • 2
    Here is a library implementation, https://github.com/AOMediaCodec/libavif and here is the standard. https://aomediacodec.github.io/av1-avif/#av1-item-configuration-property – matt Feb 16 '21 at 10:45
  • Thanks for the links, but as stated above I've read through both of it without finding the required Information. Manually including a C-library in my java-application just to get some meta-information doesn't look ideal to me. Any additional hints? – Jochen Go Feb 17 '21 at 06:57
  • "but as stated above I've read through both of it " you didn't state that anywhere. The links are the documentation and a library with a reference implementation. I'm sure the information is in there, but I don't know enough about reading the specs to quickly delve into it. Can you link an example image in your post? – matt Feb 17 '21 at 09:21

2 Answers2

6

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. Profit ;)

enter image description here

Dimitri Podborski
  • 3,714
  • 3
  • 19
  • 31
2

Some of the AVIF files have ftypavis (contains animation) and I also saw AVIF with ftypmif1

If you want to parse AVIF alone, you need to understand ISOBMFF format and HEIF container first. There are various properties (like Image spatial Extents (ispe)), then various transformations (crop, rotation, mirror). Images can be stored in a form of image grid...