padavan
padavan

Reputation: 884

Determine if an AVIF file is an animation without using third-party programs

How is it possible to determine if an AVIF file is an animation without using third-party programs?

I try this with, but its all dont work

  1. "44" byte for animation

    0, 0, 0, 44, 102, 116 for animated files

https://stackoverflow.com/a/77907580/12782236

  1. 'ftypavif' и 'anim'. "anim" by the number of occurrences also doesn't work, because I have examples with 2 occurrences although there are more than 80 frames.

  2. Counting the "av01"

  3. I tried to find it by the number of "trak", but it turns out that in animation there can be only 1 tag.

I studied the post about the structure by @dimitri-podborski https://stackoverflow.com/a/66555075/12782236

and about avif container by @daniel-a-simona-novomeská https://stackoverflow.com/a/66239407/12782236

Example 2 animated avif

https://drive.google.com/file/d/1dZIeBLItrlr81W2APZWMtxW4ni2V1j_H/view?usp=sharing https://drive.google.com/file/d/1dZIeBLItrlr81W2APZWMtxW4ni2V1j_H/view?usp=sharing

Upvotes: 1

Views: 50

Answers (1)

VC.One
VC.One

Reputation: 15936

"I tried to find it by the number of "trak"

Not every AVIF has a trak entry.

Following info below is true for your shown example file ...

(1) Check ftyp section:

00 00 00 2C 66 74 79 70 61 76 69 73                     ...,ftypavis

The ftyp is avis (where avis means "image sequence", or avif means "image file").

  • Skip first 8 bytes from start of file (eg: skip [0] up to [7]).
  • From position [8], read the next 4 bytes as a String.

However anyone could change the last letter from f to being s.
To confirm that it is avis for sure, try step (2) below.

(2) Check stsz section:

00 00 01 70 73 74 73 7A 00 00 00 00 00 00 00 00         ...pstsz........
00 00 00 57                                             ...W

Your example file has one trak box, and this same trak also contains an stsz box.
This section stsz tells the byte lengths of each frame. The important part is that it also tells how many frames are in the file, so if the number is "more than 1" then you can assume that it is some animated AVIF.

  • Find start position of bytes 73 74 73 7A for "stsz" (is listing each sample/frame sizes).
    note: Previous 4 bytes before 73 74 73 7A tells the 32-bit size of total "stsz" data.
    Any "size" number above 16 suggests there is multiple images or frames.
  • Jump ahead +12 bytes (moving from start position of above first 73).
  • Now you can read next 4 bytes 00 00 00 57 as one 32-bit integer.
  • The 32-bit integer says 87 entries for (frame) byte sizes.

So are you expecting 87 frames? Why would a still image AVIF also have 87 pictures?
At this point, we can assume this one is an animated AVIF.

Upvotes: 1

Related Questions