Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram: animated stickers #874

Closed
Oreolek opened this issue Aug 13, 2019 · 9 comments
Closed

Telegram: animated stickers #874

Oreolek opened this issue Aug 13, 2019 · 9 comments
Labels

Comments

@Oreolek
Copy link

Oreolek commented Aug 13, 2019

Telegram introduced animated stickers in TGS format. They don't get converted to PNG. And the browsers can't show them either. Maybe convert them to APNG?

@42wim
Copy link
Owner

42wim commented Aug 17, 2019

Sure, do you know a library that can do that?

@Oreolek
Copy link
Author

Oreolek commented Aug 18, 2019

No and we'll have to wait until this will be in the open source Telegram version.

@TomTheDragon
Copy link

The only tool that could do something like this (right now) is the python package TGS. It could convert those files into video or GIFs.
https://gitlab.com/mattia.basaglia/tgs

@BenWiederhake
Copy link
Contributor

There is the python library lottie, and after a single pip3 install lottie cairosvg you can convert stickers like this:

$ lottie_convert.py example.tgs example.webp
WebP frame rendering completed
WebP Writing to file...

Which results in a webp file (and GitHub can't deal with WebP yet).

Can this plus tengo do this? I hope that the image is already somewhere on the filesystem, in which case Tengo would need to intercept the outgoing message, call lottie_convert.py --input-format lottie /path/to/the.tgs.webp /path/to/the.webp, and modify the message to point to the new file instead (/path/to/the.webp).

Is there anyone here who knows tengo well enough?

BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 17, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 17, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 17, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 25, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 26, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 26, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Jul 27, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Aug 20, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Aug 20, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
BenWiederhake added a commit to BenWiederhake/matterbridge that referenced this issue Aug 21, 2020
This is half a fix for 42wim#874

This patch introduces two new config flags:
- MediaConvertTgsToWebP
- MediaConvertTgsToPNG

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

I will propose new text for the Wiki in the PR for this patch.
(Should be 42wim#1173 or so.)
42wim pushed a commit that referenced this issue Aug 23, 2020
This is half a fix for #874

This patch introduces a new config flag:
- MediaConvertTgs

These need to be treated independently from the existing
MediaConvertWebPToPNG flag because Tgs→WebP results in an
*animated* WebP, and the WebP→PNG converter can't handle
animated WebP files yet.

Furthermore, some platforms (like discord) don't even support
animated WebP files, so the user may want to fall back to
static PNGs (not APNGs).

The final reason why this is only half a fix is that this
introduces an external dependency, namely lottie, to be
installed like this:

$ pip3 install lottie cairosvg

This patch works by writing the tgs to a temporary file in /tmp,
calling lottie to convert it (this conversion may take several seconds!),
and then deleting the temporary file.
The temporary file is absolutely necessary, as lottie refuses to
work on non-seekable files.
If anyone comes up with a reasonable use case where /tmp is
unavailable, I can add yet another config option for that, if desired.

Telegram will bail out if the option is configured but lottie isn't found.
@42wim
Copy link
Owner

42wim commented Aug 23, 2020

Fixed in #1173

@42wim 42wim closed this as completed Aug 23, 2020
@Drjacky
Copy link

Drjacky commented Feb 27, 2021

@BenWiederhake I did exactly what you said but, it doesn't find the lottie_convert.py!
Screen Shot 2021-02-27 at 13 31 50

And when I run the command directly from the downloaded release:
Screen Shot 2021-02-27 at 13 40 12

@BenWiederhake
Copy link
Contributor

Well, yes, as you observed correctly, it has to be actually installed.

@Drjacky
Copy link

Drjacky commented Mar 1, 2021

@BenWiederhake My bad. After installed https://pillow.readthedocs.io/en/stable/installation.html, it worked But, the result wasn't good enough. I've tested this sticker to JSON:
https://t.me/addstickers/RickAndMorty
In a few frames, the picture gets black-white. For sample:
untitled folder.zip

@BenWiederhake
Copy link
Contributor

Well, yes, as you observed correctly, lottie has bugs. If you improve lottie, I'll buy you a drink.

42wim pushed a commit that referenced this issue May 13, 2021
this was buried and wanted to bring it up in the config

Convert Tgs (Telegram animated sticker) images to PNG before upload.
This is useful when your bridge also contains platforms that do not support animated WebP files, like Discord.
This requires the external dependency `lottie`, which can be installed like this:
`pip install lottie cairosvg`
#874

#1173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants