cavif icon indicating copy to clipboard operation
cavif copied to clipboard

[question] How to get the best quality?

Open megapro17 opened this issue 4 years ago • 2 comments

I want to convert old jpg's to this format. After some testing I came to this command cavif -i 1.png --rate-control q --crf 10 --row-mt --tile-rows 2 --tile-columns 2 --threads 4 -o 1.avif CRF mode as written in many guides is stands for the most recommended mode. Is it right to this case? When value is 10 I can't spot any difference between original, but size decreased significantly 7,16 MB -> 519 KB. The program is eating 10 GB RAM, is this how it should be? Also, how to disable alpha channel? In photo proprieties I can see color depth is 32 bit, but original was 24.

megapro17 avatar Apr 04 '20 19:04 megapro17

Thank you for using cavif!

cavif -i 1.png --rate-control q --crf 10 --row-mt --tile-rows 2 --tile-columns 2 --threads 4 -o 1.avif

If you really want to achieve best quality at the expense of encoding/decoding speed, I also recommend these options:

  • disabling --row-mt, --tile-rows, and --tile-cols
    • If these options is set, each separeted image are encoded independently. In general, it is expected to be encoded more efficiently if using the information of the whole image.
    • I think you set these options to make encoding or decoding fast.
      But if the quality is improve by these options, please tell me.
  • --cpu-used 0 (default: --cpu-used 1)
    • --cpu-used 0 tells encoder to use more and more computation resources to achieve best quality.
    • However, this is extremely and unbelievably slow. Really.
  • --enable-cdef (default: disabled)
    • CDEF is a kind of post-process filter. It is said CDEF improves subjective image quality.
    • However, this makes decoding time longer and longer. In my environment, it takes 5 times slower to decode.

CRF mode as written in many guides is stands for the most recommended mode. Is it right to this case?

Yes. To tell you the truth, "--crf 10" is the libaom (underlying library)'s default value: (We currently use this command to convert image to low bit rate, thus "--crf 32" is cavif's default now. I might change this default value.)

https://github.com/link-u/libaom/blob/d0b3d306aebb5ef6cc89f49f56dd7adaee41f696/av1/av1_cx_iface.c#L173

Anyway, I recommend you to check the quality with some images with your eyes, before encoding tons of images.

When value is 10 I can't spot any difference between original, but size decreased significantly 7,16 MB -> 519 KB.

Great!

The program is eating 10 GB RAM, is this how it should be?

It depends on the image size, however, "10GB" sounds lager than the ordinary image. Could you tell me the width and height of the image, try disabling --row-mt, --tile-rows, and --tile-cols, and check the eaten RAM again? If it won't improve, could you give me some sample images to debug?

Here is our example images: https://github.com/link-u/avif-sample-images We encode and decode daily in Github Actions, a virtual machine with 7GB RAM.

Also, how to disable alpha channel? In photo proprieties I can see color depth is 32 bit, but original was 24.

Alpha is disabled by default (If you want to enable it, you must encode twice).

I think your software uses 32bit RGBA for AVIF currently, to make easy to support AVIF. davif and SDWebImageAVIFCoder handles (Monochrome/Monochrome+Alpha/RGB/RGBA) images correctly, but it is very confusing work. Could you tell me what software you use to view encoded avif?

ledyba-z avatar Apr 05 '20 04:04 ledyba-z

I forgot to introduce this option:

--enable-full-color-range (default: disabled)

AV1 is derived from video codec. In video, we often don't use all 255^3 colors (in historical reason). Instead, 229 * 224 * 224 colors are used (about 70%).

When this flag is enabled, encoder/decoder uses all colors. This flag makes encoded files a little bigger, but you can get images with better color reproductions. It might be useful for images with gradients.

ledyba-z avatar Apr 05 '20 10:04 ledyba-z