Making Looping Animated .webp Files

PREAMBLE:

Krita 5.0.0 (the nightly build) now has .webm video as an output option for animation rendering. One day, this will be available in the formal release.
However, I’ve found that it doesn’t give a looping animation.

The animated .gif rendered output does give a looping animation but this can have quite a large file size and has the expected palettisation speckle and gradient banding problems that you get with .gif. The new forum file upload size limit of 3MB puts limitations on long/large .gif animations.

With .mp4, you get good quality and small size but no looping and it can’t be uploaded anyway. You need a link to a video hosting service.

After digging and scratching around in various places, I’ve found a way to make a looping .webp animation using simple on-PC facilities.
I haven’t been able to find a way of doing it with a Windows system but it’s quite easy on Linux.

If anybody knows of a different and/or better way of doing it (especially on Windows) then please say so.

DOING IT ON LINUX:

Installing the facilities:

On Debian and Ubuntu (and probably Linux Mint):
sudo apt-get update
sudo apt-get install webp

This gives a variety of available commands:
img2webp, cwebp, dwebp, vwebp, webpmux and webpinfo
You can read the man pages for them but img2webp is the one to use for animated looping animations.

You can also read this: https://developers.google.com/speed/webp/docs/img2webp

Note: The Per-frame options go before the input file name when it’s ‘*.png’, as I eventually figured out.

And maybe this, which gives a better explanation of the ‘-m’ option:
https://developers.google.com/speed/webp/docs/cwebp
I’ve found that the -m option isn’t much practical use though it can give a small reduction in output file size for ‘-m 5’ and ‘-m 6’ but it takes much longer to complete all the processing.

Making an animated .webp file:

Render your animation out to an Image Sequence into a folder created for the purpose, which will then contain all the output frames as a sequence of .png files.

Open a terminal and cd into that folder.
Do, (with optional -m option of 5 or 6):
img2webp -loop 0 -d 67 -lossy -q 93 (-m 5/6) *.png -o out.webp

‘-loop 0’ makes it loop forever.
‘-d 67’ gives 67ms between frames = 15fps. Choose your own value for this.
‘-q 93’ is the quality level, which has an effect on file size. I find that q variation between 80 and 95 has a noticeable effect of size/quality tradeoff. This may depend on the nature of the images so your experience may vary.

That’s it. You can read about and play with the other options yourself.

A Result:

For an old animation I have, which is 640 x 640, 162 frames at 15fps giving 10.8 seconds, the animated .gif output is an 11.4 MB file.
Using the img2webp command as above, I get a .webp file of 2.7MB with no significant visible artifacts as shown here. If I adjust ‘-q’ for lower quality then I can get it down to 2.1MB but blocky artifacts start to become apparent.

2 Likes