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

Progress indication when writing multiple frames #7433

Open
LeXofLeviafan opened this issue Oct 1, 2023 · 4 comments · May be fixed by #7435
Open

Progress indication when writing multiple frames #7433

LeXofLeviafan opened this issue Oct 1, 2023 · 4 comments · May be fixed by #7435

Comments

@LeXofLeviafan
Copy link

Processing all frames of an animated image file (i.e. GIF, APNG, WebP) can take a while, and there's no indication of any sort for progress there, nor is there any way to keep track of it. Thus, I suggest adding to save_all implementation at least one of the following:

  • a log output (either at INFO or DEBUG level) after every frame (e.g. the way it's done by convert -verbose)
  • an (optional) custom progress tracking callback parameter (which should be given the current frame index and possibly total n_frames & filename of the first file as well); this can be used for customizing log output or for GUI progress indication
    • log only when no progress tracking callback is provided?
    • alternatively, if there's a callback and it returns a string, print it out as logging output?
@radarhere
Copy link
Member

radarhere commented Oct 1, 2023

Could you give an example of the pixel size and number of frames in the scenarios that you're dealing with, and how long it is taking you to save in a particular format?

Also, be aware that GIF and APNG do not simply process each image and then finish - first they loop through the images to try and determine the differences between one frame and the next, and then there is a second loop writing the images. So measuring progress won't be completely simple.

filename of the first file as well

This might be minor, but if I'm understanding you correctly, it sounds like you're combining multiple files and saving them as one. Pillow doesn't store the filenames of the images that it opens, meaning that when saving, it doesn't know the filename of any files, except for the one being created.

@LeXofLeviafan
Copy link
Author

LeXofLeviafan commented Oct 1, 2023

Could you give an example of the pixel size and number of frames in the scenarios that you're dealing with, and how long it is taking you to save in a particular format?

For example, converting a single 123-frame 400x700px GIF file to WebP [method=6] took me about half a minute (and it's not exactly good UX to just leave the user hanging for that long).

Also, be aware that GIF and APNG do not simply process each image and then finish - first they loop through the images to try and determine the differences between one frame and the next, and then there is a second loop writing the images. So measuring progress won't be completely simple.

I imagine it should be either "keep track of the loop which usually takes up most of the duration", or "have one more parameter in the callback/log output to indicate the step" (…or you can pass None/step name instead of total number of frames if it's only available during the last one).

Pillow doesn't store the filenames of the images that it opens, meaning that when saving, it doesn't know the filename of any files, except for the one being created.

…This statement doesn't seem to be entirely correct.

(…Although come to think of it, it's probably a better idea to print the filename of the file currently being processed, rather than always the 1st one; and if the filename is not available, something like #3.gif could be passed instead – i.e. list index starting from 1 + image format)

@radarhere
Copy link
Member

Oh, right, sorry, I was just looking at the code for Image, not ImageFile.

@radarhere radarhere linked a pull request Oct 2, 2023 that will close this issue
@radarhere
Copy link
Member

I've created PR #7435 to resolve this.

I haven't included logging as you suggested - Pillow has some, but not much, logging, and given that it is mostly not present, I would rather not add to it. This shouldn't stop you from running your own logging in the callback function though.

@radarhere radarhere changed the title feature request: progress indication for writing multiple frames Progress indication when writing multiple frames Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants