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

Is there any way to cut flames make 60fps stickers not so slow after converted? #13

Closed
BrunoLiu opened this issue May 8, 2020 · 24 comments

Comments

@BrunoLiu
Copy link

BrunoLiu commented May 8, 2020

As the title. Or is there any solutions to make the converted file play faster?

@bessx
Copy link

bessx commented May 14, 2020

I am also having a problem with the output framerate. After conversion, the gif seems to run in slow motion.

@ed-asriyan
Copy link
Owner

ed-asriyan commented May 15, 2020

To check whether actual gif and tgs FPS values are different I've used the following python script from agtoever's answer on Stackoverflow:

import sys
from PIL import Image

FILENAME = sys.argv[1]

def get_avg_fps(PIL_Image_object):
    """ Returns the average framerate of a PIL Image object """
    PIL_Image_object.seek(0)
    frames = duration = 0
    while True:
        try:
            frames += 1
            duration += PIL_Image_object.info['duration']
            PIL_Image_object.seek(PIL_Image_object.tell() + 1)
        except EOFError:
            return frames / duration * 1000
    return None

def main():
    img_obj = Image.open(FILENAME)
    print(f"Average fps: {get_avg_fps(img_obj)}")


if __name__ == '__main__':
    main()

and two generated gifs:

  1. from https://t.me/addstickers/Mooncalfanimation (60 fps pack)
    a
  2. from https://t.me/addstickers/SnappyCrab (30 fps pack)
    b

Results:

  1. On the first gif python script gives 59.78260869565218 FPS. Average duration of each frame is 30 -- 40 ms.
  2. On the second gif python script gives 29.75206611570248 FPS. Average duration of each frame is 10 -- 20 ms.

So I conclude that tgs-to-gif does not change FPS in result gif image.

Now I can only suggest changing the application for viewing GIFs. For example, the first gif on my phone opened by default gallery app displays normally, but in Google Photos app it displays "in slow motion".

@BrunoLiu BrunoLiu changed the title Is there any way to cut flames make 60fps stickers not so slow afper converted? Is there any way to cut flames make 60fps stickers not so slow after converted? May 15, 2020
@BrunoLiu
Copy link
Author

It seems like the “slow motion” problem are probably caused by the viewer does not support 60fps gif rendering?
BTW I notices the title has been misspelled😂
This tool and telegram bot are very useful, thanks for working and replying.

@ed-asriyan
Copy link
Owner

ed-asriyan commented May 16, 2020

It seems like the “slow motion” problem are probably caused by the viewer does not support 60fps gif rendering?

Seems to be. My observations point to that. If you find out something else, please write here so that I and other people can solve the problem.

This tool and telegram bot are very useful, thanks for working and replying.

Thanks for feedback :)

@bessx
Copy link

bessx commented May 16, 2020

hmm, since I'm viewing them in google chrome, that seems odd. Let me try again with those two sticker packs and see if I'm having the same issue.

EDIT: Perhaps put in a flag so that we can set it as 60 vs 30 fps sticker to get a full speed gifs?

@ed-asriyan
Copy link
Owner

I'm not a specialist in GIF format, but I found good explanation by Maadinsh why it is so: https://video.stackexchange.com/a/30160:

There is no such thing as 60fps GIFs.

GIF files store delay time between frames in whole hundredths of second, so it's impossible to make a GIF with exactly 60fps, because value 1 would give you 100fps and 2 would already have half of that - 50fps. Besides that, many programs (including Google Chrome) ignore value 1 and defaults to much slower animation speed when viewing such files, so 100fps GIFs, while technically possible according to file format, are not commonly used and probably a bad idea, so value 2 (50fps) is the most you can get.

@bessx
Copy link

bessx commented May 16, 2020

SnappyCrab-AgADoAADFkJrCg

So Snappy Crab works beautifully and I can't test MoonCalfAnimation for some reason, but I did Lemurio Sticker Set:

MrLemur-AgAD7QIAAvPjvgs

Plays slow in Windows Photo viewer, google chrome (like right on this page).

https://bestoftelegram.com/animated-stickers/MrLemur
https://t.me/addstickers/mrlemur

The second doesn't even seem to be playing in 50fps, it's more like 30fps or 24fps version of a 60fps sticker.

@ed-asriyan
Copy link
Owner

@bessx Your second gif is slow in my browser too, but... I opened it in default gallery app on my phone (I simply downloaded image from your comment) and it is playing faster than 60 fps (faster then in telegram).

@bessx
Copy link

bessx commented May 16, 2020

Hmmmm, I see. Then is there a way to tell the bot or set a flag to set it as you said, with 2 centiseconds per frame? That way, even if it's slightly slower than 60fps, it will be ~50fps across on all devices?

@ed-asriyan
Copy link
Owner

ed-asriyan commented May 16, 2020

It is not so simple because it uses third party library puppeteer-lottie that uses gifski tool... But is this the right decision anyway? It would be better and easier to create a tgs-to-mp4 bot.

@bessx
Copy link

bessx commented May 17, 2020

It is not so simple because it uses third party library puppeteer-lottie that uses gifski tool... But is this the right decision anyway? It would be better and easier to create a tgs-to-mp4 bot.

I've been thinking about it. If the gif ends up at 10ms duration for each frame (maximum speed that causes compatibility issues), could the bot send back two versions of the gif? One with the 10ms duration and one with the next highest, 20 ms duration?

I think that would be a nice compromise without completely going for an mp4. That way the user themselves can decide version of the gif one to use. I know at that point an mp4 makes more sense but sometimes it's just easier to share a gif.

@AndnixSH
Copy link

Also having the same issue with this sticker https://t.me/addstickers/Peepo_Pepe

@ed-asriyan
Copy link
Owner

I found pretty library rlottie. In examples I found the program that converts lottie to gif. I tried it on sticker from #13 (comment).
At first, I want to say it works much more faster, it is really cool. And resulting gifs have 50fps:
out json

Script #13 (comment) output:

python3 a.py out.json.gif 
Average fps: 50.0

But it does not generate transparent gifs, now I am trying to modify the lib to fix that. When I'll done I want to update the repo sources.

@AndnixSH
Copy link

Nice find!
I realized an online website called ezgif could adjust speed, by 150% it turned gif back to normal speed. I used the website to reduce size to be able to use them as discord emojies
https://ezgif.com/speed

leaving

@ed-asriyan
Copy link
Owner

ed-asriyan commented May 24, 2020

You can try new version that uses rlottie lib.
It stores in branch master-cpp. I also updated Dockerfile, so you can use it under docker container.

I made several tests. It have some artifacts as I see. For example, hat on the koala slightly changes its color during animation:
tgs8 tgs

UPD: the same artefact here:
Mooncalfanimation-AgADqgADYA9NDA

@bessx
Copy link

bessx commented May 25, 2020

oh interesting, it's great that it works!

what's the duration per frame actually set to in these new gifs?

EDIT: It's beyond weird that the artifacting only happens when the background is transparent. I don't see a reason why that should happen in the transparent gif, but not in the one with a background.

@ed-asriyan
Copy link
Owner

ed-asriyan commented May 25, 2020

what's the duration per frame actually set to in these new gifs?

2

EDIT: It's beyond weird that the artifacting only happens when the background is transparent. I don't see a reason why that should happen in the transparent gif, but not in the one with a background.

gif-h does not support transparency, it only has a PR charlietangora/gif-h#7, which is not compiling (Evil-Spirit/gif-h#1 should fix that) and has a color artefact, but it is better than nothing.

@ed-asriyan
Copy link
Owner

I patched puppeteer-lottie in https://github.com/ed-asriyan/puppeteer-lottie/commit/7bbe134d31b56bc33c71e5022a5d787589c6f25d and use it as a dependency in this project. So issue should be resolved.

@LouisWayne
Copy link

Tested the latest version with npm, but I still see slow gifs..

@ed-asriyan
Copy link
Owner

ed-asriyan commented Jul 16, 2020

@LouisWayne,

Note that maximum fps for gifs is 50 (more details: #13 (comment)). If you sure, that fps is lower, please send me link to the sticker to test.

@LouisWayne
Copy link

@ed-asriyan , thanks for reply!

Here is the download link: https://gofile.io/d/aNsus5. It would be great if you can find the solution for this sticker file 😄

@ed-asriyan
Copy link
Owner

ed-asriyan commented Jul 20, 2020

@LouisWayne, please, pull the latest master branch and reinstall npm dependencies (rm -fr node_modules && npm i). Problem should be resolved.

@LouisWayne
Copy link

LouisWayne commented Jul 23, 2020

@ed-asriyan , THANKS A LOT!

Now the generated gif file looks good! I hope the updates will be applied to the Telegram bot soon 😄 You made an amazing library and I really appreciate it. Thanks!

@ed-asriyan
Copy link
Owner

@LouisWayne, the update has already been applied to the Telegram bot. You're welcome!

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

No branches or pull requests

5 participants