Skip to content

APNG encoding optimization#26849

Merged
asmorkalov merged 6 commits intoopencv:4.xfrom
sturkmen72:apng-writeanimation
Mar 5, 2025
Merged

APNG encoding optimization#26849
asmorkalov merged 6 commits intoopencv:4.xfrom
sturkmen72:apng-writeanimation

Conversation

@sturkmen72
Copy link
Copy Markdown
Contributor

@sturkmen72 sturkmen72 commented Jan 27, 2025

related #26840

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov
Copy link
Copy Markdown
Contributor

I propose to add simple performance test.

@vrabaud
Copy link
Copy Markdown
Contributor

vrabaud commented Jan 27, 2025

An animation with 1 frame is not the same as one image (though it will be displayed the same).

@sturkmen72
Copy link
Copy Markdown
Contributor Author

sturkmen72 commented Jan 27, 2025

An animation with 1 frame is not the same as one image (though it will be displayed the same).

It should be like that for webp and avif. But when an animated png saved with only one frame, the only thing that changes actually is being 10 times slower.

following code just writes IHDR and IDAT chunks like imwrite

    Mat m(2000,3000,CV_8UC4);
    Animation tanimation;
    tanimation.frames.push_back(m);
    tanimation.durations.push_back(10);

    imwriteanimation("read_c.png", tanimation);c

@sturkmen72
Copy link
Copy Markdown
Contributor Author

anyway let me work on this PR a bit more. creating a performans test and maybe rethinking on one frame apng

@sturkmen72 sturkmen72 marked this pull request as draft January 27, 2025 22:43
@asmorkalov asmorkalov changed the title APNG - Use common write function when frames size < 2 APNG encoding optimization Jan 29, 2025
@sturkmen72
Copy link
Copy Markdown
Contributor Author

it was Z_BEST_COMPRESSION used for writing ( even writing with IMWRITE_PNG_COMPRESSION param)
now Z_BEST_SPEED ( 1 ) is default and IMWRITE_PNG_COMPRESSION param works

@asmorkalov asmorkalov added this to the 4.12.0 milestone Jan 29, 2025
@asmorkalov asmorkalov marked this pull request as ready for review January 29, 2025 13:00
@asmorkalov asmorkalov self-requested a review January 29, 2025 13:00
@sturkmen72 sturkmen72 marked this pull request as draft January 31, 2025 08:52
@sturkmen72 sturkmen72 force-pushed the apng-writeanimation branch 3 times, most recently from 4cae20b to e70f4eb Compare February 4, 2025 08:39
@asmorkalov
Copy link
Copy Markdown
Contributor

@sturkmen72 Please rebase and fix conflict after you PR merge.

SANITY_CHECK_NOTHING();
}

PERF_TEST_P(PNG, DISABLED_params_filter_max_compression, testing::ValuesIn(PNGFilterFlags))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it disabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a common user run it takes so long time ( --perf_force_samples default value is 100 )

IMWRITE_PNG_NO_FILTERS = 0, //!< Disables all filtering. No filters will be applied when saving the image.
IMWRITE_PNG_FILTER_NONE = 8, //!< Applies no filter to the PNG image (useful when you want to save the raw pixel data without any compression filter).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is difference between IMWRITE_PNG_NO_FILTERS and IMWRITE_PNG_FILTER_NONE? Why do we need both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they produces different sized outputs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMWRITE_PNG_NO_FILTERS removed. with libpng IMWRITE_PNG_NO_FILTERS and IMWRITE_PNG_ALL_FILTERS gives same results. with libspng IMWRITE_PNG_NO_FILTERS and IMWRITE_PNG_FILTER_NONE gives same results.

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@asmorkalov i will try to write tests using PngSuite - Image filtering / PNG-files

@asmorkalov
Copy link
Copy Markdown
Contributor

Ok, please try to use existing files in opencv-extra and do not add more. We have some subset of the suite already.

@sturkmen72 sturkmen72 force-pushed the apng-writeanimation branch 3 times, most recently from 22186b6 to cf59c0c Compare February 23, 2025 20:01
@asmorkalov
Copy link
Copy Markdown
Contributor

@sturkmen72 Please rebase and fix conflicts.

@sturkmen72 sturkmen72 force-pushed the apng-writeanimation branch 4 times, most recently from eda302f to e9f5c7e Compare February 25, 2025 13:28
@sturkmen72 sturkmen72 marked this pull request as ready for review March 1, 2025 11:57
@sturkmen72 sturkmen72 requested a review from asmorkalov March 1, 2025 11:57
@asmorkalov
Copy link
Copy Markdown
Contributor

@vrabaud I'm ready to merge the patch. Do you have any remarks?

@asmorkalov
Copy link
Copy Markdown
Contributor

@vrabaud Please take a look again.

@asmorkalov asmorkalov merged commit dbd4e45 into opencv:4.x Mar 5, 2025
28 checks passed
@sturkmen72 sturkmen72 deleted the apng-writeanimation branch March 5, 2025 08:18
@asmorkalov asmorkalov mentioned this pull request Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants