-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
What did you do?
Attempted to make an animated PNG from a set of images.
What did you expect to happen?
To have a working animated PNG, with the right duration/frame rate.
What actually happened?
The resulting animated PNG only has two frames, instead of 40 frames, and with a very high frame rate.
What are your OS, Python and Pillow versions?
- OS: macOS 13.3.1
- Python: Python 3.11.3
- Pillow: I have checked out this PR: Added alpha_only argument to getbbox() #7123, which fixes a related issue.
This code creates a 40 frame animation, 20 frames of a red square and 20 frames of a blue square which run at 20 fps, which should result in a 2 second animation:
#!/usr/bin/env python3
from PIL import Image, ImageDraw
images = []
for i in range(20):
img = Image.new("RGBA", (300, 300), (255, 255, 255, 255))
draw = ImageDraw.Draw(img)
draw.rectangle((100, 100, 200, 200), fill="red")
img.save(f"frame1-{i}.png")
images.append(img)
for i in range(20):
img = Image.new("RGBA", (300, 300), (255, 255, 255, 255))
draw = ImageDraw.Draw(img)
draw.rectangle((100, 100, 200, 200), fill="blue")
img.save(f"frame2-{i}.png")
images.append(img)
# Should result in a 2 second animation
frame_rate = 20
frame_duration = 1000 / frame_rate
images[0].save(
"test.png", save_all=True, append_images=images[1:], duration=frame_duration, loop=0
)
images[0].save(
"test.gif", save_all=True, append_images=images[1:], duration=frame_duration, loop=0
)These images actually only contain 2 frames, not 40.
One interesting thing to note is the frame rate of these images shown by ffprobe:
$ ffprobe -v quiet -show_entries stream=r_frame_rate,time_base,duration output.gif
[STREAM]
r_frame_rate=100/1
time_base=1/100
duration=2.100000
[/STREAM]
$ ffprobe -v quiet -show_entries stream=r_frame_rate,time_base,duration output.png
[STREAM]
r_frame_rate=100000/1
time_base=1/100000
duration=N/A
[/STREAM]This is confusing to me, as while the GIF duration is roughly correct, the frame rate is not 100 fps.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

