Skip to content

Split APNG frame durations too large for a single fcTL chunk - #10064

Closed
niukanen1 wants to merge 3 commits into
python-pillow:mainfrom
niukanen1:split-apng-large-duration
Closed

niukanen1 wants to merge 3 commits into
python-pillow:mainfrom
niukanen1:split-apng-large-duration

Conversation

@niukanen1

@niukanen1 niukanen1 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10063. Alternative to #10070

Saving an APNG with a frame duration whose fractional delay has a numerator over the 16-bit fcTL limit raised ValueError: cannot write duration instead of saving, even when the individual frame delays were representable — the merge of identical consecutive frames can push a summed duration over the limit (the example from the issue: two identical frames with duration=[32768, 32769] merge into a single 65537 ms frame that no longer fits).

Following the direction from #10063 (comment), the duration is now split across consecutive identical frames, each with a delay that fits, so the animation replays the full duration. The split only triggers when a delay doesn't fit, and the total duration is preserved exactly.

from PIL import Image

frame_a = Image.new("RGB", (1, 1), "green")
frame_b = Image.new("RGB", (1, 1), "red")

# used to raise ValueError: cannot write duration
frame_a.save("output.png", format="PNG", save_all=True,
             append_images=[frame_b, frame_b], duration=[100, 32768, 32769])

When saving an APNG, a frame duration whose fractional delay has a
numerator over the 16-bit fcTL limit raised ValueError instead of
saving. The duration is now split across consecutive identical frames,
each with a delay that fits, so the animation replays the full duration
@radarhere

Copy link
Copy Markdown
Member

I've created #10070 as an alternative that I think is simpler. See what you think.

@niukanen1

Copy link
Copy Markdown
Contributor Author

Agreed, yours is simpler and it also keeps the animation where the split approach loses it: two identical frames with something like [32768000, 32768000] combine into a single frame and the existing one-frame short-circuit writes a static PNG, while #10070 keeps both frames. Closing in favour of #10070

@niukanen1 niukanen1 closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to preserve identical consecutive APNG frames when saving

2 participants