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

Animated gif skips frames #8397

Open
muitdebos opened this issue Sep 19, 2024 · 2 comments
Open

Animated gif skips frames #8397

muitdebos opened this issue Sep 19, 2024 · 2 comments
Labels

Comments

@muitdebos
Copy link

muitdebos commented Sep 19, 2024

Hi, there have been several threads related to saving an animated gif where frames get skipped under certain circumstances. From what I can tell, the most recent thread was the following: #7613

As that thread is closed and my use-case is different, I open this new one.

What did you do?

I have a bunch of .pngs as render output from Blender. I want to merge these into an animated .gif using a specific palette. This all works fine, except that there are sometimes multiple transparent frames after one-another. I need these to be actual separate frames, so the total frame count remains equal to the amount of input images. This is important as the .gif is used as input for another quite old program which requires separate and an equal amount of frames.

What did you expect to happen?

In this case, 240 png's in, convert to animated .gif, end result has only exactly 240 frames. By setting optimize=False I would expect no optimisation to happen, including no skipping of frames.

What actually happened?

240 png's in, conversion is successful, but only contains 200 frames. Consecutive same frames get skipped / merged, despite optimize=False

What are your OS, Python and Pillow versions?

  • OS: Mac Sonoma 14.5, M1
  • Python: 3.9.6
  • Pillow: 10.4.0

To clarify, the below code works and most settings are more or less required to get the output I want, minus the fact that it's using less frames than required.

processed_images[0].save('output.gif',
    append_images = processed_images[1:],
    background = 0,
    transparency = 255,
    disposal = 2,
    save_all = True, 
    optimize = False,
    palette = some_palette,
    loop = 0,
    duration = 0)
@radarhere
Copy link
Member

Hi. Combining duplicate frames is intended as a feature - there is no visual difference, and the final file size is smaller.

#7613 was resolved once I explained the situation. If you know of more issues that find this functionality inconvenient, please let us know.

The scenario where you explicitly need duplicate frames is unusual. Would you mind sharing what the old program is that requires this?

@radarhere radarhere added the GIF label Sep 19, 2024
@muitdebos
Copy link
Author

muitdebos commented Sep 20, 2024

Thanks for the quick reply. Indeed, it is a fairly specific scenario. I make animations in Blender for a mod for the game Diablo 2, the old version, which uses pre-rendered sprites. It's an isometric game with rotating characters, so the animations need to have the exact same framecount in all directions for each animation. In addition, this game uses a 256-color palette. This also applies to missiles or other special effects which might have varying levels of transparency that get quantised to the same 256-color palette, using blackness as transparency with a screen blendmode. Some of those frames end up becoming completely black because of this quantisation, thus causing the discrepancy in frame count when they get deduplicated.

To be complete; there is an in-between step, where there is a program called Cv5 that is able to convert a .gif (as long as it meets the requirements) to the proprietary format the game uses, but since that was made specifically for this purpose (not by me I might add), it also expects the same amount of frames.

I completely understand in 99% of usecases it's highly desirable to combine duplicate frames. If it's not feasible to do something on this at a library level maybe I'll have to look into making a fork. Anyway, that's my situation.

--edit: If you're interested / it helps, the full python code is here muitdebos/d2gifcompile.py though it is quite messy because it's an out-of-hand hobby project. However, as you might see, there is a quite some processing going on before the actual output gif gets saved.

$1S1LITDTHTH
$1TRLITDTHTH

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

No branches or pull requests

2 participants