[FFmpeg-devel] [PATCH v2] avcodec/pngenc: support writing iCCP chunks
Niklas Haas
ffmpeg at haasn.xyz
Sat Mar 12 13:10:47 EET 2022
On Fri, 11 Mar 2022 12:18:13 +0100 Andreas Rheinhardt <andreas.rheinhardt at outlook.com> wrote:
> 2. Using an AVBPrint with its dynamic reallocations is probably not good
> here at all: It is easy to get a good upper bound via deflateBound()
> which allows to omit the reallocations/the loop. (I should probably have
> applied
So, I rewrote the code to only use a single av_bprint_get_buffer() call,
rather than looping through it. This is semantically identical to doing
an extra malloc(), but also allows the 1K buffer on the stack.
I did a survey of all (compressed) iCCP chunks found in PNG files in my
"collection" (home folder..), and this is what I found:
Min. 1st Qu. Median Mean 3rd Qu. Max.
275 2619 2639 3000 2639 14813
Only roughly 11.57% of files are below the "1K" cutoff threshold for
using the small buffer optimization.
In light of this, I don't think the 1K optimization is hugely important.
But, using the AVBPrint does make the code slightly easier to work with
in my eyes.
The cleanest alternative, I think, would be to store the deflateBound
on the ICC profile somewhere in the PNGEncContext, and then use
av_malloc to get a temporary buffer inside `png_get_iccp`. It's of
course possible to somehow write directly to the output packet buffer,
but I don't think avoiding a ~4K malloc/memcpy is worth the hassle and
bug risk of sidestepping png_write_chunk in favor of some custom chunk
writing code.
Thoughts?
More information about the ffmpeg-devel
mailing list