The current algorithm is just "try all the combinations, and pick the best". It's not very fast either, probably due to a lot of copying, but will do for an initial implementation.
51ca703 apng: Support inter-frame compression
libavcodec/pngenc.c | 420 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 384 insertions(+), 36 deletions(-)