davidbyttow / govips

A lightning fast image processing and resizing library for Go
MIT License
1.31k stars 203 forks source link

Poor compression from jpeg to avif via code #423

Closed dAvagimyan closed 7 months ago

dAvagimyan commented 7 months ago

Hi there! I'm using govips to convert jpg to avif. And I discovered that conversion from code works worse for me than conversion from the console. Could you help me figure it out? On large files the difference is 3 times. There is no such behavior with webp conversion

I tried effort with different values also with default cnf NewAvifExportParams()

size -> 1327450 -> cats.jpg - original size ->1003222 -> cats.avif - via go code size -> 404594 -> cats_inconsole.avif - via console (vips copy cats.jpg cats.avif )

It is golang code

inputImage, err := vips.NewImageFromFile("resources/cats.jpg")
    if err != nil {
        return err
    }
    defer inputImage.Close()
    if err := inputImage.OptimizeICCProfile(); err != nil {
        return err
    }

    ep := vips.NewAvifExportParams()
    ep.StripMetadata = true
    ep.Quality = 75
    ep.Effort = 1
    ep.Bitdepth = 8
    ep.Lossless = false

    imageBytes, _, err := inputImage.ExportAvif(ep)
    if err != nil {
        return err
    }

    _ = ioutil.WriteFile("cats.avif", imageBytes, 0644)

it is origin; cats

tonimelisma commented 7 months ago

Hey @dAvagimyan, can you check what AVIF library your libvips build is built against, and check the latest libvips documentation for the parameters you can give? Sometimes we have stale parameters as libvips and/or the avif library libvips uses are updated and the govips API is out of date.

dAvagimyan commented 7 months ago

vips version: vips-8.15.1

 heif-enc --list-encoders
HEIC encoders:
AVIF encoders:
- aom = AOMedia Project AV1 Encoder 3.8.2-377-g04d6253 [default]
- svt = SVT-AV1 encoder v1.8.0
JPEG encoders:
- jpeg = libjpeg-turbo 1.2.90 (libjpeg 6.2) [default]
JPEG 2000 encoders:
Uncompressed encoders:
- uncompressed = uncompressed [default]
tonimelisma commented 7 months ago

Yes, could you look at libvips documentation for the parameters you can give? Sometimes the libvips backend has changed or the parameters and govips needs to be updated. Libvips has an impressive speed of development and backend libraries differ even between environments, it's very challenging to maintain govips APIs

dAvagimyan commented 7 months ago

Thanks, I'll take a look. But I tried got it behavior in differents os. (centos 7, ubuntu, also macos)

dAvagimyan commented 7 months ago

Everything is ok! Thanks a lot. Avif conversion in console using quality 50%.