
I made some progress optimizing animated Webp compression. Simple windows batch scripts for now as I improve with Bash.
This takes Screenshot (X).png files and renames them to 01.png 02.png 03.png frames for ffmpeg processingThis scales the frames to 50% size and crops them to 540x540, assuming source is 1920x1080. Also exports them to a new png_444 folder.@setlocal EnableDelayedExpansion & set n=1 for %%f in (*.png) do ren "%%f" "!n:~ -2!.png" & set /a n+=101This converts the png_444 frames into an intermediate RGB video file, may not be necessary...@echo off & setlocal EnableDelayedExpansion mkdir png_444 & for %%f in (*.png) do ffmpeg -hide_banner -i "%%f" -vf "scale=iw/2:ih/2,crop=540:540:(iw-540)/2:(ih-540)/2" -y "png_444/%%~nf.png"ffmpeg -framerate 1 -i %%02d.png ^ -c:v libvpx-vp9 -cpu-used 4 -r 1 -g 1 ^ -b:v 0 -crf 0 -qmin 0 -qmax 0 -pix_fmt gbrp out.webm

This allows you to click and drag the RGB video file, reverse it, and splice the original with the reversed variant to create a smooth animation loop.Converts back to sRGB PNG frames. I need to splice this with the above but it works separately for now.@echo off ffmpeg -i "%~1" ^ -filter_complex "[0:v]split[v1][v2];[v2]reverse[vr];[v1][vr]concat=n=2:v=1:a=0[vout]" ^ -map "[vout]" -c:v libvpx-vp9 -cpu-used 4 -g 1 -r 1 ^ -b:v 0 -crf 0 -qmin 0 -qmax 0 -pix_fmt gbrp ^ "%~dpn1_reversed.webm"ffmpeg -hide_banner -loglevel quiet -color_primaries bt709 -color_trc iec61966-2-1 -i "%~1" %%02d.png
img2webp
This is the biggest headache for now, I know the first frame duration needs to be longer than the rest to create a "bouncing" feeling of the animation loop but I don't know how to do it without manually punching in all frames in.
For my OP animated Webp there were a total of 16 final sRGB PNG frames created 01.png to 16.png but god dam there must be a better way to do this
Also img2webp does not seem to contain the -pre 2 parameter that cwebp contains so I'm unable to mitigate color banding through it. Possible ffmpeg filter analogue might exist, don't know which one though.
img2webp -q 80 -min_size -m 6 -loop 0 -d 600 01.png -d 50 02.png -d 50 03.png -d 50 04.png -d 50 05.png -d 50 06.png -d 50 07.png -d 50 08.png -d 50 09.png -d 50 10.png -d 50 11.png -d 50 12.png -d 50 13.png -d 50 14.png -d 50 15.png -d 50 16.png -o q80.webp
Webm related is the intermediate RGB video file (before reversal), it's locked at 1 FPS, might be possible to assign a dynamic framerate and skip frame duration signaling in img2webp