jointakahe / takahe

An ActivityPub/Fediverse server
BSD 3-Clause "New" or "Revised" License
1.12k stars 86 forks source link

Uploaded GIF files lose their animation #173

Closed kromonos closed 1 year ago

kromonos commented 1 year ago

Uploaded via Takahe: https://mws.bka.li/takahe/attachments/2022/12/15/1mtymoknw-6_rSdQNEAW4m4zCxs.webp Original GIF: https://mws.bka.li/sharex/2022/12/347235-Sleep-Well.gif

andrewgodwin commented 1 year ago

Yes, this is a limitation of our current resizer, it's not animation-aware. We also need to work out if uploaded GIFs should actually be turned into video rather than pictures.

It's likely we won't fix this super soon - it's only a medium priority for me right now.

shuuji3 commented 1 year ago

I recently learned WebP format also supports the animated image too. Maybe we can use WebP at least for GIF since probably it's relatively easier than implementing video conversion.

Pillow also supports conversion from animated GIF to animated WebP by specifying the specific flag save_all=True (ref. Image file formats - Pillow (PIL Fork) 9.4.0 documentation).

Safari hasn't supported WebP for a long time but they finally added its support just 4 months ago: https://caniuse.com/webp

Here's an example of animated WebP: Animated WebP image example - https://mathiasbynens.be/demo/animated-webp

I confirmed it's working on iPhone emulator (Safari), Android (Chrome), macOS (Safari, Chrome, Firefox), and Ubuntu (Chrome).

Some additional information about animated WebP: Q. Why should I use animated WebP? | Frequently Asked Questions  |  WebP  |  Google Developers

TkTech commented 1 year ago

I had an experimental change that does video (including gif and apng) conversion, but @andrewgodwin wanted to avoid it for now. I believe there are concerns because we don't have real background workers and the memory overhead.

andrewgodwin commented 1 year ago

Yeah, I want to think about this more. I will rename this ticket to represent the feature of "uploading videos" though, as that is the correct way to treat GIFs.

(I don't know if save_all will work here because the resize pass will drop the other frames anyway?)

andrewgodwin commented 1 year ago

Going to close this in favour of the more general https://github.com/jointakahe/takahe/issues/378

shuuji3 commented 1 year ago

(I don't know if save_all will work here because the resize pass will drop the other frames anyway?)

You're right. Before saving as animated WebP, resizing needs to apply to each GIF frame.

Another option is using gif2webp: https://developers.google.com/speed/webp/docs/gif2webp