Bug 451257

Summary: kimageformats-write-avif fails with 5.92.0
Product: [Frameworks and Libraries] frameworks-kimageformats Reporter: Heiko Becker <heiko.becker>
Component: generalAssignee: Alex Merry <alex.merry>
Status: RESOLVED FIXED    
Severity: normal CC: aacid, dnovomesky, kdelibs-bugs-null
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: test output

Description Heiko Becker 2022-03-07 21:30:06 UTC
STEPS TO REPRODUCE
1. cmake .. && ninja
2. ninja test

OBSERVED RESULT
kimageformats-write-avif fails with the output attached below

EXPECTED RESULT
Test passes

SOFTWARE/OS VERSIONS
KDE Frameworks Version:  5.92.0
Qt Version: latest KDE patch collection 5.15.3_p132
libavif version: 0.9.3
Comment 1 Heiko Becker 2022-03-07 21:31:51 UTC
Created attachment 147353 [details]
test output
Comment 2 Albert Astals Cid 2022-03-07 21:33:40 UTC
Daniel any idea of what may be wrong? I have the same avif version and it seems to work fine for me :/
Comment 3 dnovomesky 2022-03-07 22:08:30 UTC
It would be good to know how libavif was configured.

Libavif can use different encoders: libaom, rav1e, svt-av1.

avifenc or avifdec utilities can print such information about libavif encoders and their versions.
Comment 4 Heiko Becker 2022-03-07 22:17:11 UTC
Version: 0.9.3 (dav1d [dec]:0.9.2, rav1e [enc]:0.5.1 (0.5.1))
libyuv : unavailable
Comment 5 dnovomesky 2022-03-07 23:07:44 UTC
So it happens with rav1e encoder.

Perhaps the reason is that rav1e doesn't have lossless mode? As the following issue indicate:

https://github.com/xiph/rav1e/issues/151
Comment 6 Heiko Becker 2022-03-08 07:31:06 UTC
(In reply to dnovomesky from comment #5)
> So it happens with rav1e encoder.
> 
> Perhaps the reason is that rav1e doesn't have lossless mode? As the
> following issue indicate:
> 
> https://github.com/xiph/rav1e/issues/151

Possibly. Can't test with SVT-AV1 because libavif fails to build with that, but with aom the test passes fine.
Comment 7 Albert Astals Cid 2022-03-08 12:52:08 UTC
I'd say then we should close this bug, it is actually a good way to find if libavif is "compiled with the wrongly expected backend".

Sounds fair?
Comment 8 Heiko Becker 2022-03-08 15:52:32 UTC
(In reply to Albert Astals Cid from comment #7)
> I'd say then we should close this bug, it is actually a good way to find if
> libavif is "compiled with the wrongly expected backend".
 
I may be a bit ignorant here, but how am I supposed to know the wrongly expected encoders? libavif enables none by default (it seems to prefer aom at runtime if multiple encoders are present though).
Btw. after patching libavif to build with recent SVT-AV1, it shows the same problem (and it doesn't support lossless too: https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/1636)

> Sounds fair?

How if I come up with a patch instead, that includes a configure check, that checks if aom is available as encoder and if it isn't the write test is skipped (with a message/warning, or maybe even only the two files)?
Comment 9 dnovomesky 2022-03-08 16:52:18 UTC
What if we just print a message (about known issue with other AV1 encoders) when avif write test fails?
Comment 10 Albert Astals Cid 2022-03-08 18:39:44 UTC
I don't think skipping the test is good, the situation you're in is bad, you have a plugin that when reading the file and saving it again makes changes to the file itself, and that's "bad", so having the test just be skipped or passed is suboptimal, having it fail is a way of saying "you should contact to whoever gave you your libavif and ask them to 'fix it' "

Daniel: If we can detect somehow that people are using a "wrongly configured" libavif and give that as error instead of the current failure, sure that's much better
Comment 11 dnovomesky 2022-03-08 20:05:18 UTC
It is possible to detect encoders via libavif C API.

Do you want to detect it in the write test or in the plug-in?
Comment 12 Albert Astals Cid 2022-03-08 21:45:28 UTC
I think that would be good, Heiko does that satisfy you?
Comment 13 Heiko Becker 2022-03-08 22:09:24 UTC
(In reply to Albert Astals Cid from comment #12)
> I think that would be good, Heiko does that satisfy you?

Not really sure which part of the "or" question above is meant, but I'm fine with either.
Comment 14 dnovomesky 2022-03-09 14:54:38 UTC
The plug-in will print (example):
You are using rav1e encoder. It is recommended to enable libAOM encoder in libavif for better near-lossless compression.

It will print only when quality==100 is requested, which is the situation used on the write test.

For quality below 100, there is no warning because other encoders are good with lossy compression.

https://invent.kde.org/frameworks/kimageformats/-/merge_requests/53
Comment 15 Albert Astals Cid 2022-03-10 13:47:59 UTC
Can we close this now that 53 is merged and we warn users that their setup is "wrong"?
Comment 16 Heiko Becker 2022-03-10 19:55:42 UTC
Yes, thanks for the patch.