fhanau / Efficient-Compression-Tool

Fast and effective C++ file optimizer
Apache License 2.0
596 stars 41 forks source link

[Enhancement] Animated PNG (APNG) support #130

Closed T-3B closed 1 year ago

T-3B commented 1 year ago

I would like to know if APNG support is planned or wanted.

For now, ECT does not recognized ".apng" files. It's valid to have animated PNG stored in a ".png" file, so I gave the attached PNG to ECT. In fact, ECT will only optimize the first frame of the animation (like a player would only show the first frame if it doesn't support displaying animation). Calling ECT with -strip will only keep the first frame in the file (all others are dropped).

The attached PNG only contain 4 frames, each of them only of one color. Once extracted, all the frames can be optimized to 90 bytes (with ect -9 frame_x.png), while if we pass directly the animated PNG to ECT, the file size decrease to 954 bytes.

I really wish ECT to support APNG too, so please consider my selfish demand.

025

fhanau commented 1 year ago

I have no plans to support APNG at this time. To properly optimize images like this support for the acTL, fcTL and fdAT chunks would be needed, implementing color type reductions which would be required to see a significant improvement on this file would be particularly difficult as the best valid color type across a number of frames needs to be found. To safely optimize APNG files, you must use the --reuse flag in addition to not using strip, otherwise the color type of the first frame may be updated whereas the data of the following frames remains the same, resulting in those frames becoming corrupted. Unfortunately, this also results in a paltry file size improvement (24 bytes on this file using level 9).

T-3B commented 1 year ago

Thank you for your answer.

I understand that you have no plan to support APNG, which is not as used as PNG, JPEG, ZIP, GZ.

Now I'm wondering if it is simple (or not) to "stupidly" process each frames in an APNG with --reuse flag?

As a side note, the APNG attached in the OP can be found here: https://philip.html5.org/tests/apng/tests.html This website has lots of different APNG files, in order to test (almost?) all possibles chunks.

fhanau commented 1 year ago

There won't be an easy way to do this with ECT alone – there should be tools that allow you to extract and recompress deflate streams, which would lead to the same result, although I haven't tried that myself and can't give specific recommendations. For APNG, I'd imagine that there's tools that allow you to extract all frames from the file or compose a new APNG from a set of frames – depending on how those tools work they might be able to construct an APNG without re-encoding the individual frames. However, this would require the APNG encoder to detect that the frames share a color type, so this might not be supported in the APNG tools you're using so far.

vrubleg commented 4 months ago

@fhanau Maybe it's time to reconsider the decision? APNG became part of the PNG spec, and already used in a lot of places, e.g. all the animations on Steam are APNG. Having a good APNG optimizer would be useful.