Progress indication when writing multiple frames
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
INFOorDEBUGlevel) after every frame (e.g. the way it's done byconvert -verbose) - an (optional) custom progress tracking callback parameter (which should be given the current frame index and possibly total
n_frames&filenameof 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?
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.
filenameof 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.
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)
Oh, right, sorry, I was just looking at the code for Image, not ImageFile.
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.