最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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

  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

and about avif container by @daniel-a-simona-novomeská

Example 2 animated avif

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/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/a/66555075/12782236

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

Example 2 animated avif

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

Share Improve this question edited Feb 14 at 14:51 Christoph Rackwitz 15.5k5 gold badges39 silver badges51 bronze badges asked Feb 14 at 6:49 padavanpadavan 8732 gold badges10 silver badges27 bronze badges 4
  • pick a programming language please. – Christoph Rackwitz Commented Feb 14 at 11:22
  • @ChristophRackwitz any js, C#, java, go. It doesn't matter, the answer will be easy to adapt to any language. – padavan Commented Feb 14 at 14:47
  • so what's the question? are you asking for someone to find you the format specification and how to parse a file accordingly? are you asking for libraries? – Christoph Rackwitz Commented Feb 14 at 14:50
  • To determine whether an .avif file is animated or not, based on the bytes/ASCII. – padavan Commented Feb 14 at 21:58
Add a comment  | 

1 Answer 1

Reset to default 0

"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.

发布评论

评论列表(0)

  1. 暂无评论