AOMediaCodec / libavif

libavif - Library for encoding and decoding .avif files
Other
1.53k stars 195 forks source link

libpng warning: iCCP: known incorrect sRGB profile #1889

Closed atbsi closed 5 months ago

atbsi commented 9 months ago

libpng warning: iCCP: known incorrect sRGB profile

I've come across an image that won't convert correctly when batch converting images. I'm not sure if it's a bug or if this is a normal reaction. Note that this PNG image converts properly to .jxl.

win 10 64 Version: 1.0.3 (dav1d [dec]:1.2.1-0-g8a6f054, aom [enc/dec]:3.8.0) libyuv : available (1864)

CL: avifenc.exe "D:\1.PNG" "D:\out.avif"

https://github.com/atbsi/pic/releases/download/1.1/1.PNG

y-guyon commented 9 months ago

Thank you for the report.

avifenc -q 90 -s 9 1.IMG 1.avif (at 995f89f) results in:

1q90 avif

(this is not a PNG image; this is an AVIF file renamed to end with .png so that the GitHub UI accepts and displays it)

I cannot perceive the visual difference with the original PNG when viewing both in Chrome.
Please note that it is 12-bit encoded because the input PNG is 16-bit.

I've come across an image that won't convert correctly when batch converting images.

What do you mean by "won't convert correctly"?
If this is only about the warning message, "libpng warning: iCCP: known incorrect sRGB profile" is printed by libpng, a dependency of libavif used to read PNG files. I did not search whether this can be silenced, and even so I am not sure it should be.

Note that this PNG image converts properly to .jxl.

Using cjxl? I wonder what library libjxl uses as a dependence to read PNG files.

atbsi commented 9 months ago

请使用我所使用的命令行来重现。我没有使用任何参数。(当然,我测试使用你的参数后,转换正常了。) "无法正常转换",这也需要解释?我有几千张图片都用 CLI 转换生成了 avif 图片,只有这张没生成,并且报错,我反馈"无法正确转换",这有任何难以理解的地方吗? 我说这个图片可以转换为 .jxl,是要说明这个图片本身没有问题,其他软件可以正常读取转换它。

哦,抱歉,你是理解为生成的图片像素不正确。没有,是完全没有生成图片。

y-guyon commented 9 months ago

Translated with Google Translate:

Please use the command line I used to reproduce. I'm not using any parameters. (Of course, after I tested using your parameters, the conversion was normal.) "Unable to convert normally", does this also need an explanation? I have thousands of images that have been converted to avif images using CLI. Only this one was not generated and an error was reported. I reported "cannot be converted correctly". Is there anything difficult to understand about this? When I say that this picture can be converted to .jxl, it means that there is nothing wrong with the picture itself, and other software can read and convert it normally.

Oh, sorry, you understood that the generated image pixels are incorrect. No, no pictures are generated at all.


Answering your questions:

Please use the command line I used to reproduce. I'm not using any parameters.

You are correct, I tried some parameters seemingly unrelated to ICC handling (-s 9) and some that could have an impact (-q 90, -q 100, --lossless).

I just tried avifenc 1.PNG 1.avif on Debian GNU/Linux and still see no difference with the original image.

I have not tried on Windows yet.

(Of course, after I tested using your parameters, the conversion was normal.)

Good to know there is a workaround.

Only this one was not generated and an error was reported.

I got the same warning "libpng warning: iCCP: known incorrect sRGB profile" but the output was generated, hence my questions.
Does the issue repeats itself consistently?
What is the whole output of avifenc?

I say that this picture can be converted to .jxl because it means that the picture itself has no title and other software can read and convert it normally.

I understand now why you mentioned JPEG XL. I too am able to open the source 1.PNG image in Chrome and GIMP.

atbsi commented 9 months ago

"libpng warning: iCCP: known incorrect sRGB profile" is all that's reported as an error.

Yes, I can reproduce it. When I compare the generated avif images with the original images, I found 3 images that were not converted, all png images.

On Window platform, the reported error makes the images not generated.

Also, sorry, I didn't notice the translation extension in effect and thought you were replying in Chinese.

y-guyon commented 9 months ago

I tried on a Windows VM:

git clone https://github.com/AOMediaCodec/libavif.git
cd libavif
git checkout 995f89f
cd ext
libyuv.cmd
libjpeg.cmd
zlibpng.cmd
:: had to -DAOM_TARGET_CPU=generic and install strawberry perl for libaom to build
aom.cmd
cd ..
mkdir build
cd build
cmake -G Ninja .. -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_EXAMPLES=OFF -DAVIF_BUILD_TESTS=OFF -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LOCAL_JPEG=ON -DAVIF_LOCAL_ZLIBPNG=ON -DBUILD_SHARED_LIBS=OFF
ninja
:: LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

avifenc.exe 1.PNG 1.avif

Output:

libpng warning: iCCP: known incorrect sRGB profile
Successfully loaded: 1.PNG
AVIF to be written: (Lossy)
 * Resolution     : 1747x2541
 * Bit Depth      : 12
 * Format         : YUV444
 * Alpha          : Absent
 * Range          : Full
 * Color Primaries: 2
 * Transfer Char. : 2
 * Matrix Coeffs. : 6
 * ICC Profile    : Present (3144 bytes)
 * XMP Metadata   : Absent
 * Exif Metadata  : Absent
 * Transformations: None
 * Progressive    : Unavailable
Encoding with AV1 codec 'aom' speed [6], color quality [60 (Medium)], alpha quality [100 (Lossless)], tileRowsLog2 [0], tileColsLog2 [0], 2 worker thread(s), please wait...
Encoded successfully.
 * Color AV1 total size: 71552 bytes
 * Alpha AV1 total size: 0 bytes
Wrote AVIF: 1.avif

I cannot reproduce your issue.
How did you build avifenc? Which version of libavif was used?
Could you try building at 995f89f like I did above?

atbsi commented 9 months ago

I downloaded it here: https://ci.appveyor.com/project/louquillio/libavif

Can you upload the 995f89f avifenc.exe you compiled?

y-guyon commented 9 months ago

I downloaded it here: https://ci.appveyor.com/project/louquillio/libavif

Which commit did you use? I tried https://ci.appveyor.com/project/louquillio/libavif/builds/48799163 to match 995f89f above but got the other issue https://github.com/AOMediaCodec/libavif/issues/1896.

Can you upload the 995f89f avifenc.exe you compiled?

We should try to fix the release process instead.
I also added the building steps above https://github.com/AOMediaCodec/libavif/issues/1889#issuecomment-1866046537.

atbsi commented 9 months ago

Sorry I'm not a programmer, I tried to compile it but kept running into errors. I can't compile it correctly. I downloaded the latest #1898 avifenc.exe from ci.appveyor.com and it still won't convert, the error is still "libpng warning: iCCP: known incorrect sRGB profile".

y-guyon commented 9 months ago

Sorry I'm not a programmer, I tried to compile it but kept running into errors. I can't compile it correctly.

Thank you for trying. I too went through several trial and error steps in https://github.com/AOMediaCodec/libavif/issues/1889#issuecomment-1866046537.

I downloaded the latest https://github.com/AOMediaCodec/libavif/pull/1898 avifenc.exe from ci.appveyor.com and it still won't convert, the error is still "libpng warning: iCCP: known incorrect sRGB profile".

Once https://github.com/AOMediaCodec/libavif/issues/1896 is fixed I can try to reproduce your issue again.

atbsi commented 9 months ago

I came across a jpg file that could not be converted, no avif image was generated and the error reported was:

XMP extraction failed: invalid multiple standard XMP segments

Cannot read input file: D:\1.jpg

Directly copied JPEG pixel data (no YUV conversion): D:\1.jpg

Again, it can still be converted correctly to .jxl

1.zip

y-guyon commented 9 months ago

I came across a jpg file that could not be converted

This one is expected, there is an issue with the input XMP metadata. libavif itself (not libjpeg) treats it as an error but other software may be more lenient.
You may pass --ignore-xmp to avifenc to bypass that issue, but take care not to leave out any important metadata such as ownership and copyright information this way.

Please note --ignore-icc also exists for your original issue but libpng may still report a warning on its own.

y-guyon commented 9 months ago

Once https://github.com/AOMediaCodec/libavif/issues/1896 is fixed I can try to reproduce your issue again.

Trying https://github.com/AOMediaCodec/libavif/issues/1889#issuecomment-1866046537 at 3ec01ce: same output (libpng warning shown but it works). \ ~Trying Appveyor's avifenc at same commit: still get setlocale failed. I reopened https://github.com/AOMediaCodec/libavif/issues/1896.~

y-guyon commented 9 months ago

Trying Appveyor's avifenc at same commit: still get setlocale failed. I reopened #1896.

I was testing the wrong commit, sorry. Let me correct:

Trying Appveyor's avifenc at same commit:

image

So there is an issue, although I still got the command line output that was missing in atbsi's case.

y-guyon commented 9 months ago

@atbsi Could you try avifenc.exe contained in this archive please? We are evaluating another binary generation process.

atbsi commented 9 months ago

Yes, it works properly now. iCCP warnings are retained. (To my credit the avif file is only 75kb) Thanks for your work.

libpng warning: iCCP: known incorrect sRGB profile
Successfully loaded: D:\1.PNG
AVIF to be written: (Lossy)
 * Resolution     : 1747x2541
 * Bit Depth      : 12
 * Format         : YUV444
 * Alpha          : Absent
 * Range          : Full
 * Color Primaries: 2
 * Transfer Char. : 2
 * Matrix Coeffs. : 6
 * ICC Profile    : Present (3144 bytes)
 * XMP Metadata   : Absent
 * Exif Metadata  : Absent
 * Transformations: None
 * Progressive    : Unavailable
Encoding with AV1 codec 'aom' speed [6], color quality [60 (Medium)], alpha quality [100 (Lossless)], tileRowsLog2 [0], tileColsLog2 [0], 12 worker thread(s), please wait...
Encoded successfully.
 * Color AV1 total size: 71552 bytes
 * Alpha AV1 total size: 0 bytes
Wrote AVIF: D:\1.avif
wantehchang commented 8 months ago

I think this bug may be the AVX-512 instruction bug in the latest version of Visual Studio 2022 discussed in this av1-discuss thread: https://groups.google.com/a/aomedia.org/g/av1-discuss/c/1dFej-YOZFM

Here are the evidences:

  1. The AppVeyor avifenc.exe downloaded from https://ci.appveyor.com/project/louquillio/libavif/builds/48905179/artifacts works on my Windows laptop, which has a 11th generation Core i7 CPU that supports AVX-512.
  2. The AppVeyor build log at https://ci.appveyor.com/project/louquillio/libavif/builds/48905179 shows it is using a newer version of Visual Studio 2022: MSVC 19.38.33130.0
  3. The GitHub build log at https://github.com/AOMediaCodec/libavif/actions/runs/7475650469/job/20344235012 shows it is using an older version of Visual Studio 2022: MSVC 19.37.32826.1

@atbsi @y-guyon Do you know if the CPU in your Windows computer supports AVX-512?

As an additional experiment, could you please set the following environment variable and then try the AppVeyor avifenc.exe downloaded from https://ci.appveyor.com/project/louquillio/libavif/builds/48905179/artifacts?

set AOM_SIMD_CAPS_MASK=0x17f

Note: This environment variable value forcibly disables the AVX2 code in libaom. So if the AVX2 code incorrectly contains AVX-512 instructions, we won't get a crash when running on a CPU that doesn't support AVX-512.

y-guyon commented 8 months ago

@atbsi @y-guyon Do you know if the CPU in your Windows computer supports AVX-512?

Processor is Intel Xeon.

As an additional experiment, could you please set the following environment variable and then try the AppVeyor avifenc.exe downloaded from https://ci.appveyor.com/project/louquillio/libavif/builds/48905179/artifacts?

I tried set AOM_SIMD_CAPS_MASK=0x17f followed by avifenc.exe 1.PNG 1.avif and it still failed.

wantehchang commented 8 months ago

Yannis: Could you do another experiment? Please try the following before running the AppVeyor avifenc.exe:

set AOM_SIMD_CAPS_MASK=0x13f

The 0x13f value also disables the AVX code in libaom, in addition to AVX2. Thanks a lot!

Could you get the Intel Xeon model number in your Windows machine?

I am still wondering why the AppVeyor avifenc.exe doesn't crash on my Windows laptop.

jzern commented 8 months ago

Yannis: Could you do another experiment? Please try the following before running the AppVeyor avifenc.exe:

set AOM_SIMD_CAPS_MASK=0x13f

The 0x13f value also disables the AVX code in libaom, in addition to AVX2. Thanks a lot!

Could you get the Intel Xeon model number in your Windows machine?

I am still wondering why the AppVeyor avifenc.exe doesn't crash on my Windows laptop.

On a non-AVX-512 machine I see:

Unhandled exception at 0x00007FF7A50DDA2F in avifenc.exe: 0xC000001D: Illegal Instruction.

The illegal instruction is from AVX-512:

00007FF7A50DDA2F  vmovdqu32   xmm17,xmmword ptr [r8] 

Setting the environment variable doesn't help nor does AOM_SIMD_CAPS. It's possible the environment is being ignored or that the instruction is being generated outside of the optimized functions in libaom. In any case, we know Visual Studio 17.8.x to be buggy: https://developercommunity.visualstudio.com/t/Illegal-Instruction-AVX512/10511452.

wantehchang commented 8 months ago

James: Thank you for testing.

Yannis: You don't need to do the set AOM_SIMD_CAPS_MASK=0x13f experiment. Would still be good to get the Intel Xeon model number.

jzern commented 8 months ago

The binaries from #1889#issuecomment-1884984241 do still contain AVX-512 instructions, but encoding this particular file works for me.

Visual Studio 2022 17.8.x is known to be broken and windows-current is using one of those versions. If an older image is available it would be better to use that for now or we should wait until the issue is fixed before releasing binaries.

jzern commented 8 months ago

Visual Studio 2022 17.8.x is known to be broken and windows-current is using one of those versions. If an older image is available it would be better to use that for now or we should wait until the issue is fixed before releasing binaries.

Maybe https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md.

y-guyon commented 8 months ago

Would still be good to get the Intel Xeon model number.

msinfo32 only gives Intel(R) Xeon(R) CPU @ 2.30GHz, 2300 Mhz, 1 Core(s), 2 Logical Processor(s).
hwinfo shows Intel Xeon 22nm A0 Haswell-EP Socket R3 (LGA2011-3) 1/2 cores 32+32-L1 256-L2 45M-L3 caches and AVX-512 Foundation Instructions: NOT supported.
As this is a Cloud VM, it may explain the difficulty to obtain hardware information.

wantehchang commented 8 months ago

Yannis: Thank you for the processor info.

Until the Visual Studio 2022 AVX-512 instruction bug is fixed, we can consider building libaom with clang-cl.

wantehchang commented 5 months ago

I think we can close this issue now. In commit 877a2742671849dd393f9b54cd39328c63c6ee4e we started to build libaom with clang-cl.