android-gif-drawable icon indicating copy to clipboard operation
android-gif-drawable copied to clipboard

Add reverse playback (with negative speeds)

Open frmz opened this issue 8 years ago • 4 comments

It would be nice to be able to do reverse playing by using a negative speed value, is there any reason why min is currently 0?

frmz avatar Apr 14 '16 16:04 frmz

Yeah, it would be nice but it is not so easy to implement. First of all in general GIFs cannot be randomly sought, in some cases it is required to render all frames from the beginning to desired frame, see #262 for more details. Even if that optimization from mentioned issue is applicable to given GIF (eg. all frames are fullscreen and opaque) and previous frame can just rendered without any other, there is another piece of code to write. Underlying input sources (byte[], File etc.) are read sequentially, to effectively seek backwards, offset of each frame need to be remembered. However InputStream cannot be sought and can only be reset to mark just before the first frame.

That's how GifDrawable works. In case of GlTextImage2D it may be possible to buffer all frames using OpenGL framebuffers.

koral-- avatar Apr 14 '16 18:04 koral--

Ah ok very clear now, works very much the same way other video format do with key frames and deltas. I don't think its a good idea to load everything on an OpenGL FB, too much memory intensive.

Maybe (if giflib supports this somehow) it would be an option to provide a way to create a reversed Gif so one could then load both and alternate rendering (so just a converter method "reverse" with in/out streams). Once you have both versions than its probably easy to implement using seek even without native support in the library.

frmz avatar Apr 15 '16 12:04 frmz

@frmz seek() could not called in UI thread, so can u show me your implementation ?

luojin avatar Feb 25 '17 04:02 luojin

AFAIK there is no other solution than calling seek... methods family. They are asynchronous by default (in GifDrawable) so result may not be visible immediately moreover seeking backward may be slow. New solution may appear in issue #287.

koral-- avatar Feb 25 '17 21:02 koral--