Aller au contenu

avif

Convertisseur:

squoosh-cli

Supporte mozjpeg, webp, avif, jxl, wp2

Les options sont visibles dans codecs.ts

Installation:

$ npm i -g @squoosh/cli

Usage:

Usage: squoosh-cli [options] <files...>

Options:
  -d, --output-dir <dir>                                 Output directory (default: ".")
  -s, --suffix <suffix>                                  Append suffix to output files (default: "")
  --max-optimizer-rounds <rounds>                        Maximum number of compressions to use for auto optimizations (default: "6")
  --optimizer-butteraugli-target <butteraugli distance>  Target Butteraugli distance for auto optimizer (default: "1.4")
  --resize [config]                                      Resize the image before compressing
  --quant [config]                                       Reduce the number of colors used (aka. paletting)
  --rotate [config]                                      Rotate image
  --mozjpeg [config]                                     Use MozJPEG to generate a .jpg file with the given configuration
  --webp [config]                                        Use WebP to generate a .webp file with the given configuration
  --avif [config]                                        Use AVIF to generate a .avif file with the given configuration
  --jxl [config]                                         Use JPEG-XL to generate a .jxl file with the given configuration
  --wp2 [config]                                         Use WebP2 to generate a .wp2 file with the given configuration
  --oxipng [config]                                      Use OxiPNG to generate a .png file with the given configuration
  -h, --help                                             display help for command
$ squoosh-cli --webp true -d webp ./2022-04-28_Biche_8247_8b.png
1/1  Squoosh results:
 ./2022-04-28_Biche_8247_8b.png: 2.18MB
   webp/2022-04-28_Biche_8247_8b.webp  75.00KB (3.37%)
$ squoosh-cli --output-dir 'squoosh-cli' --mozjpeg '{
   "quality":70,
   "baseline":false,
   "arithmetic":false,
   "progressive":true,
   "op timize_coding":true,
   "smoothing":0,
   "color_space":3,
   "quant_table":3,
   "trellis_multipass":false,
   "trellis_opt_zero":false,
   "trellis_opt_table":false,
   "trellis_loops":1,
   "auto_subsample":true,
   "chroma_sub sample":2,
   "separate_chroma_quality":false,
   "chroma_quality":75
}' png/2022-04-16_Brocard_8990_8b.png

1/1  Squoosh results:
 2022-04-16_Brocard_8990_8b.png: 1.93MB
   2022-04-16_Brocard_8990_8b.jpg  83.67KB (4.24%)
find . -name "*.jpg" -exec bash -c 'file="{}"; squoosh-cli --mozjpeg auto "$file"' \;
$ squoosh-cli --output-dir 'squoosh-cli' --avif '{
        "cqLevel":33,
        "cqAlphaLevel":-1,
        "denoiseLevel":0,
        "tileColsLog2":0,
        "tileRowsLog2":0,
        "speed":6,
        "subsample":1,
        "chromaDeltaQ":false,
        "sharpness":0,
        "tune":0
        }' png/*.png

$ squoosh-cli --output-dir 'squoosh-cli' --avif "{}" png/*.png

ImageMagick

Mettre des options avec define.

Usage:

 magick -quality 75 png/2022-04-16_Brocard_8990_8b.png magick/2022-04-16_Brocard_8990_8b.avif

❯ magick -define heic:speed=2 png/2022-04-16_Brocard_8990_8b.png magick/2022-04-16_Brocard_8990_8b_2.avif

❯ convert -define heic:speed=2 png/2022-04-16_Brocard_8990_8b.png magick/2022-04-16_Brocard_8990_8b_2.avif
 for image in png/*.png ; do convert "$image" "${image%.*}.avif" ; done

avif-cli

Installation:

$ npm install avif

Usage:

 npx avif --input="5_2019.jpg" --quality=70 npx avif --input="**/*.{png}" --output="./avif-cli" --quality=70
#!/bin/sh
set -o noglob
IFS=$'\n'

quality=70
#quality='lossless'
images=$(find ./png -type f -name *.png)

for img in $images; do
    file=$(basename "$img")
    avif_out="avif-cli"

    #webp_out=$img.webp

    if [ ! -f $avif_out ]; then
        if [ "$quality" != "lossless" ]; then
            npx avif --input="$img" --output="./$avif_out" --quality=$quality
        else
            npx avif --input="$img" --output="./$avif_out" --lossless
        fi
    fi

done

cavif-rs

Convert JPEG/PNG images to AVIF image format (based on AV1/rav1e)

Installation:

$ cargo install cavif

Usage:

 cavif --quality 90 2022-04-16_Brocard_8990_8b.png
2022-04-16_Brocard_8990_8b.avif: 524KB (522893B color, 0B alpha, 242B HEIF)
#!/bin/sh
set -o noglob
IFS=$'\n'

quality=70
images=$(find ./png -type f -name *.png)

for img in $images; do
    file=$(basename "$img")
    avif_out="cavif/${file%.*}_q$quality.avif"

    if [ ! -f $avif_out ]; then
        cavif --quality $quality $img -o $avif_out
    fi

done

sharp

Installation:

$ npm install sharp

Usage:

sharp-example.js

const sharp = require('sharp')

const convertToAVIF = () => {
    sharp('path_to_image')
    .toFormat('avif', {palette: true})
    .toFile(__dirname + 'path_to_output_image')
}

convertToAVIF() 
# path_to_image : ./imgs/example.jpg
# path_to_output_image : /sharp-compressed/compressed-example.avif

$ node sharp-example.js

libheif

libheif is an ISO/IEC 23008-12:2017 HEIF and AVIF (AV1 Image File Format) file format decoder and encoder.

Installation:

./autogen.sh
./configure
go env -w GO111MODULE=off
make

Usage:

 heif-enc 2022-04-28_Biche_8247_8b.png -A -o 2022-04-28_Biche_8247_8b_3.avif
libpng warning: iCCP: known incorrect sRGB profile

❯ heif-enc 2022-04-28_Biche_8247_8b.png -A -L -p chroma=444 --matrix_coefficients=0 -o 2022-04-28_Biche_8247_8b_3.avif (lossless)
libpng warning: iCCP: known incorrect sRGB profile
# Paramètres par défaut heif-enc -P
Parameters for encoder `x265 HEVC encoder (3.4+31-6722fce1f)`:
  quality, default=50, [0;100]
  lossless, default=false
  preset, default=slow, { ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo }
  tune, default=ssim, { psnr,ssim,grain,fastdecode }
  tu-intra-depth, default=2, [1;4]
  complexity, [0;100]
  chroma, default=420, { 420,422,444 }
#!/bin/sh
set -o noglob
IFS=$'\n'

#quality=70
quality='lossless'
images=$(find ./png -type f -name *.png)

for img in $images; do
    file=$(basename "$img")
    avif_out="heif-enc/${file%.*}_q$quality.avif"

    #webp_out=$img.webp

    if [ ! -f $avif_out ]; then
        if [ "$quality" != "lossless" ]; then
            heif-enc "$img" -A -q $quality -o "$avif_out"
        else
            heif-enc "$img" -A -L -p chroma=444 --matrix_coefficients=0 -o "$avif_out"
        fi
    fi

done

avifenc

https://web.dev/compress-images-avif/

x64

Installation:

$ brew install joedrago/repo/avifenc

Usage:

$ avifenc --max 63 image.jpg image.avif

avifenc (libavif)

Installation:

$ brew install libavif

Usage:

 avifenc --min 0 --max 63 -a end-usage=q -a cq-level=18 -a tune=ssim png/2022-04-16_Brocard_8990_8b.png avifenc/2022-04-16_Brocard_8990_8b.avif
# 8 thread avifenc --min 0 --max 63 -a end-usage=q -a cq-level=18 -a tune=ssim --jobs 8 png/2022-04-16_Brocard_8990_8b.png avifenc/2022-04-16_Brocard_8990_8b.avif
 avifenc --speed 0 --min 25 --max 35 png/2022-04-16_Brocard_8990_8b.png avifenc/2022-04-16_Brocard_8990_8b.avif
libpng warning: iCCP: known incorrect sRGB profile
Successfully loaded: png/2022-04-16_Brocard_8990_8b.png
AVIF to be written: (Lossy)
 * Resolution     : 1600x1067
 * Bit Depth      : 8
 * Format         : YUV444
 * Alpha          : Not premultiplied
 * Range          : Full
 * Color Primaries: 2
 * Transfer Char. : 2
 * Matrix Coeffs. : 6
 * ICC Profile    : Present (3144 bytes)
 * XMP Metadata   : Absent (0 bytes)
 * EXIF Metadata  : Absent (0 bytes)
 * Transformations: None
 * Progressive    : Unavailable
Encoding with AV1 codec 'aom' speed [0], color QP [25 (Medium) <-> 35 (Low)], alpha QP [0 (Lossless) <-> 0 (Lossless)], tileRowsLog2 [0], tileColsLog2 [0], 1 worker thread(s), please wait...
Encoded successfully.
 * Color AV1 total size: 70133 bytes
 * Alpha AV1 total size: 0 bytes
Wrote AVIF: avifenc/2022-04-16_Brocard_8990_8b.avif
#!/bin/sh
set -o noglob
IFS=$'\n'

#quality=70
quality='lossless'
images=$(find ./png -type f -name *.png)

for img in $images; do
    file=$(basename "$img")
    avif_out="avifenc/${file%.*}_q$quality.avif"

    #webp_out=$img.webp

    if [ ! -f $avif_out ]; then
        if [ "$quality" != "lossless" ]; then
            #npx avif --input="$img" --output="./$avif_out" --quality=$quality
            avifenc --min 0 --max 63 -a end-usage=q -a cq-level=18 -a tune=ssim --jobs 8 $img $avif_out
        else
            #npx avif --input="$img" --output="./$avif_out" --lossless
            avifenc -l --jobs 8 $img $avif_out
        fi
    fi

done

go-avif

go-avif implements AVIF (AV1 Still Image File Format) encoder for Go using libaom, the high quality AV1 codec. x64

AVIFQuickLook

Bench

Conversion de 70 PNG 8bits:

avif-cli avifenc (libavif) cavif heif-enc (libheif) squoosh-cli
148s 23s 183s 92s 107s

Dernière mise à jour: November 9, 2023