yekeskin / flutter_avif

A flutter plugin to view and encode avif images.
https://pub.dev/packages/flutter_avif
MIT License
47 stars 15 forks source link

flutter_avif ignores the very first frame of the AVIF animation. #16

Closed simnalamburt closed 1 year ago

simnalamburt commented 1 year ago

In other words, flutter_avif plays from the second frame of the image.

flutter_avif calls avifDecoderNextImage() to parse each frame of AVIF images from the beginning, but avifDecoderReadMemory() also parses the very first frame since it internally calls avifDecoderNextImage(). Therefore, the current implementation results in discarding the very first frame of the animation.

To fix this, there is two solution:

  1. instead of calling avifDecoderNextImage() and then parsing the frame, parse the frame and then call avifDecoderNextImage(). (It's like to use a do-while statement instead of a plain while statement)
  2. Manually call avifDecoderSetIO*(), avifDecoderParse(), avifDecoderNextImage() interface instead of avifDecoderReadMemory() all-in-one interface.

If you don't understand my explanation, please comment. Thanks!

References
simnalamburt commented 1 year ago

NOTE: When the animation finishes the loop and comes back to the beginning, then the first frame is played normally, so you probably didn't notice.

yekeskin commented 1 year ago

I applied the second solution you suggested with e191e6be4e2c861cb1d1431244e67e8e1185b2ac. It will be available in the next release. Thanks for your help.

simnalamburt commented 1 year ago

Closed by https://github.com/yekeskin/flutter_avif/commit/e191e6be4e2c861cb1d1431244e67e8e1185b2ac