FixTweet / FxTwitter

Fix broken Twitter/X embeds! Use multiple images, videos, polls, translations and more on Discord, Telegram and others
https://fxtwitter.com
MIT License
2.62k stars 77 forks source link

Feature Request: gif support #310

Closed SpiritAxolotl closed 6 months ago

SpiritAxolotl commented 1 year ago

Twitter, as far as I know, pretends .mp4s are .gifs. If you could add ".gif" (or maybe even ".apng") to the end of a twitter link and it would embed the gif as a native gif, I feel like that could be a pretty neat feature. I don't know how hard this would be to implement.

dangeredwolf commented 1 year ago

Yeahhhh, the sort of issue is that Twitter does indeed serve GIFs as MP4s. I don’t know if they even store GIF versions of them on their server at all (I would bet not, animated GIFs are very inefficient). It is possible to convert, but certainly annoying and adds a lot of latency to the request versus just serving it as an MP4.

Also, I forget how Discord handles it but Telegram actually treats the audio-less MP4s as GIFs.

Sure, we could make serving actual GIFs as an opt-in, but writing an entire media converter for what I would imagine is an obscure and seldom used feature of FixTweet? I’m not personally convinced it makes the most sense. FixTweet’s purpose is ultimately to improve Tweet embeds and provide related data services, so I’m not sure if adding GIF conversion makes a ton of sense as a feature?

Either way, actual GIFs are heavy and users will be waiting multiple seconds extra for an embed to show up if we implemented this. I’m just not sure how worth it that it would be?

SpiritAxolotl commented 1 year ago

Then don't sweat it. Thanks for the reply!

PsnDth commented 1 year ago

Either way, actual GIFs are heavy and users will be waiting multiple seconds extra for an embed to show up if we implemented this. I’m just not sure how worth it that it would be?

It's not listed on the comparison, but this is one reason some people prefer vxtwitter, they loop the mp4 to 30s if it's a gif. I personally am not a fan of this implementation but it's slightly better than a 1s mp4 in some cases. Not sure if this issue will be revisited but I think it's worth looking into perhaps as a subdomain or smtg

dangeredwolf commented 1 year ago

@PsnDth @SpiritAxolotl I might revisit the idea of implementing this, at least for Discord users. At least for small GIFs, and perhaps a subdomain to force it anyway for larger ones.

dangeredwolf commented 1 year ago

Okay, I'm working on this, and I have a working server implementation that can download videos, transcode them using ffmpeg on the fly, and feed them to the client. It uses node.js streams so it starts encoding immediately as soon as it starts receiving bytes from the server, which helps it respond to requests faster, which is kinda neat! ... Though Discord's media proxy server seems to not be a fan of it being streamed the data, so I might have to buffer the output so Discord doesn't get upset.

I somehow remember Discord treating GIFs in embeds like actual GIFs, but it isn't doing that for me at all, even with vxTwitter, so maybe they changed something or I misremembered.

But yeah, I'm wondering if you guys actually need .gif files or if generating looping silent mp4s for Discord would work well by default? Since using Discord, they seem to work about the same at least to me, with the exception of what file type gets downloaded...

That said, I could implement actual GIF conversion as well on an opt-in basis, but I just would like to know how people plan to use this feature and what would meet their use cases. Thanks!

PsnDth commented 1 year ago

I like the idea of looping silent mp4s being the default and optionally being able to access the gif separately. But for my usecase (and the ones I typically see), silent looping mp4s are more than enough

Yay295 commented 7 months ago

Any progress on this? vxtwitter's 30s looping is broken now.

dangeredwolf commented 7 months ago

I've been working recently on a multi-purpose media server that can handle tasks like transcoding, remuxing, and can also be employed for this, but I've been encountering issues with specifically ffmpeg's handling of fragmented mp4 format, as Discord pulls the duration from the metadata and when fragmented, ffmpeg sets the duration metadata incorrectly even though it already knows the input length. That said, this particular issue wouldn't have much of an impact on gif looping, so I could probably just deploy it as-is fairly soon. I'll let you know when I have further updates cause I could potentially start pushing it out within the next few days.

dangeredwolf commented 6 months ago

"A few days" haha... Yeah between IRL stuff, struggling with my own code, struggling with ffmpeg and QSV acceleration, and having to set this up on multiple systems only to have to migrate systems... I was hoping to get this out sooner. But, the good news is that I have finally deployed it for users on Discord. If you encounter any issues please open a new issue.

Yay295 commented 6 months ago

Did you go with actual gifs, or looping videos? What is considered a gif for this?

dangeredwolf commented 6 months ago

Looping videos, because I found that Discord treats them essentially identically. It will automatically loop the mp4 for up to 30 seconds. Theoretically we could make it convert to actual .gifs but Discord will seemingly just put it in the same video player so seems kinda pointless for that case as they do NOT loop that way. Maybe I could add native GIF encoding for the API cause I can still see it being useful for some cases.