Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/diffusers/utils/export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def buffered_writer(raw_f):
f.flush()


def export_to_gif(image: List[PIL.Image.Image], output_gif_path: str = None) -> str:
def export_to_gif(image: List[PIL.Image.Image], output_gif_path: str = None, fps: int = 10) -> str:
if output_gif_path is None:
output_gif_path = tempfile.NamedTemporaryFile(suffix=".gif").name

Expand All @@ -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 👍🏽

loop=0,
)
return output_gif_path
Expand Down