Skip to content

Conversation

masaishi
Copy link
Contributor

@masaishi masaishi commented Jan 31, 2024

What does this PR do?

This PR introduces an fps (frames per second) argument to the export_to_gif function in the Diffusers library, with a default value of 10 fps. This feature allows users to specify the frame rate of the GIFs they generate, providing greater control over the animation's speed.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten @DN6

Reference

Pillow documentation

duration
May not be present. The time to display the current frame of the GIF, in milliseconds.

@@ -37,7 +37,7 @@ def export_to_gif(image: List[PIL.Image.Image], output_gif_path: str = None) ->
save_all=True,
append_images=image[1:],
optimize=False,
duration=100,
duration=1000 // fps,
Copy link
Collaborator

@DN6 DN6 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay to add the FPS argument, but I think you get unexpected results setting duration in this way. e.g. You have 100 frames, and you set FPS to 10. One would expect a 10 second GIF. But what you actually end up with is a 100 millisecond GIF.

Duration should be calculated with something like:

duration = (len(images) // fps) * 1000

Or optionally we provide a duration argument that defaults to 100 milliseconds and the FPS argument can override it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing.

Since duration can specify the number of seconds in ms to display one frame, I think it will work correctly at 1000 // fps.

I attached gifs I actually tried my code at fps 1 and 10. I generated 16 frames by PIA example code.

1 fps -> 1000 duration
Pia Animation 1fps

10 fps -> 100 duration
Pia Animation 10fps

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. Misunderstood how duration was applied. Looks good to me 👍🏽

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@DN6 DN6 merged commit 8de7800 into huggingface:main Feb 8, 2024
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
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

Successfully merging this pull request may close these issues.

3 participants