AOMediaCodec / libavif

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

identical result with and without CRF style encoding #690

Open adityamavlankar opened 3 years ago

adityamavlankar commented 3 years ago

Hi,

Version: 0.9.1 (aom [enc/dec]:3.1.0) libyuv : unavailable

I am trying out the CRF style encoding (-a end-usage=q) presented here. However, I get identical encodes with and without CRF. For example, the resulting avif file is identical in each of the 6 pairs below:

Pair 1 /tools/libavif/build/avifenc input.png 1.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 /tools/libavif/build/avifenc input.png 2.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4

Pair 2 /tools/libavif/build/avifenc input.png 3.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 -a tune=ssim /tools/libavif/build/avifenc input.png 4.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4 -a tune=ssim

Pair 3 /tools/libavif/build/avifenc 1280x720.png 5.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 /tools/libavif/build/avifenc 1280x720.png 6.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4

Pair 4 /tools/libavif/build/avifenc 1280x720.png 7.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 -a tune=ssim /tools/libavif/build/avifenc 1280x720.png 8.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4 -a tune=ssim

Pair 5 /tools/libavif/build/avifenc 826x464.png a.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 /tools/libavif/build/avifenc 826x464.png b.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4

Pair 6 /tools/libavif/build/avifenc 826x464.png c.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 -a tune=ssim /tools/libavif/build/avifenc 826x464.png d.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4 -a tune=ssim

Speed 8 is where they start to differ slightly. Is that expected or is something amiss? You can repro with any input image, so not attaching those specific input PNG images. Above happens over a wide range of QPs. For example, below are BD rates over a small dataset of 2 images but over a wide range of qualities.

ticket_1 ticket_2
joedrago commented 3 years ago

I believe @wantehchang might be unavailable for the next few days, but I'm sure he has an excellent answer for you on this one.

adityamavlankar commented 3 years ago

BD rates have been computed using this framework. As you can see, the numbers are identical for a given config and the corresponding config ending in "-crf". I've also tried --nclx 1/13/6 but with and without CRF still turns out identical.

wantehchang commented 3 years ago

Hi Aditya,

Sorry about the late reply. I was on vacation.

What does "CRF style encoding" mean? In the rest of my comment I will assume it means the use of the -a end-usage=q option.

In the libavif version that you are using (Version: 0.9.1 (aom [enc/dec]:3.1.0)), libavif speeds 0-7 use libaom's AOM_USAGE_ALL_INTRA mode, and libavif speeds 8-10 use libaom's AOM_USAGE_REALTIME mode. This explains your observation that "Speed 8 is where they start to differ slightly."

Now let's dive into libavif speeds 0-7. The AOM_USAGE_ALL_INTRA mode uses the -a end-usage=q option by default. In addition, libavif/src/codec_aom.c will supply a -a cq-level=QP option, where QP is the average of the min and max quantizers, if the -a cq-level=QP option is not specified explicitly. Therefore, your pair 1:

Pair 1 /tools/libavif/build/avifenc input.png 1.avif -d 8 --nclx 1/13/1 --min 20 --max 22 --speed 4 --codec aom --jobs 4 /tools/libavif/build/avifenc input.png 2.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4

is equivalent to:

Pair 1 /tools/libavif/build/avifenc input.png 1.avif -d 8 --nclx 1/13/1 --min 20 --max 22 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4 /tools/libavif/build/avifenc input.png 2.avif -d 8 --nclx 1/13/1 --min 0 --max 63 -a end-usage=q -a cq-level=21 --speed 4 --codec aom --jobs 4

So the two command lines differ only in their --min and --max values. As long as the cq-level value falls in the range of the --min and --max values, the -a end-usage=q mode ignores the --min and --max values. This is why you get identical encodes from the two command lines.

adityamavlankar commented 3 years ago

Hi Wan-Teh,

Thank you for getting back. Yes, by CRF I meant that particular advanced encoding option/mode where QP is not strictly constant.

My understanding is with -a end-usage=q there is some QP modulation block-to-block. Furthermore, I thought the min and max would be boundaries within which the QP is allowed to modulate. It sounds like that is not the case. Could you please confirm and perhaps throw some light on the lower and upper limits for QP modulation?

adityamavlankar commented 3 years ago

And of course welcome back!