• Stars
    star
    473
  • Rank 89,925 (Top 2 %)
  • Language
    Rust
  • License
    BSD 3-Clause "New...
  • Created almost 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AVIF image creator in pure Rust

cavif β€” PNG/JPEG to AVIF converter

Encoder/converter for AVIF images. Based on rav1e and avif-serialize, which makes it an almost pure-Rust tool (it uses C LCMS2 for color profiles).

Installation

➑️ Download the latest release ⬅️

The pre-built zip includes a portable static executable, with no dependencies, that runs on any Linux distro. It also includes executables for macOS and Windows.

Usage

Run in a terminal (hint: you don't need to type the path, terminals accept file drag'n'drop)

cavif image.png

It makes image.avif. You can adjust quality (it's in 1-100 scale):

cavif --quality 60 image.png

Advanced usage

You can also specify multiple images. Encoding is multi-threaded, so the more, the better!

cavif [OPTIONS] IMAGES...
  • --quality=n β€” Quality from 1 (worst) to 100 (best), the default value is 80. The numbers are only a rough approximation of JPEG's quality scale. Beware when comparing codecs. There is no lossless compression support, 100 just gives unreasonably bloated files.
  • --speed=n β€” Encoding speed between 1 (best, but slowest) and 10 (fastest, but a blurry mess), the default value is 4. Speeds 1 and 2 are unbelievably slow, but make files ~3-5% smaller. Speeds 7 and above degrade compression significantly, and are not recommended.
  • --overwrite β€” Replace files if there's .avif already. By default the existing files are left untouched.
  • -o path β€” Write images to this path (instead of same-name.avif). If multiple input files are specified, it's interpreted as a directory.
  • --quiet β€” Don't print anything during conversion.

There are additional options that tweak AVIF color space. The defaults in cavif are chosen to be the best, so use these options only when you know it's necessary:

  • --dirty-alpha β€” Preserve RGB values of fully transparent pixels (not recommended). By default irrelevant color of transparent pixels is cleared to avoid wasting space.
  • --color=rgb β€” Encode using RGB instead of YCbCr color space. Makes colors closer to lossless, but makes files larger. Use only if you need to avoid even smallest color shifts.
  • --depth=8 β€” Encode using 8-bit color depth instead of 10-bit. This results in a slightly worse quality/compression ratio, but is more compatible.

Compatibility

Images work in all modern browsers.

  • Chrome 85+ desktop,
  • Chrome on Android 12,
  • Firefox 91,
  • Safari iOS 16/macOS Ventura.

Known incompatibilities

  • Windows' preview and very old versions of android are reported to show pink line at the right edge. This is probably a bug in an old AVIF decoder they use.
  • Windows' preview doesn't seem to support 10-bit deep images. Use --depth=8 when encoding if this is a problem.

Building

To build it from source you need Rust 1.67 or later, preferably via rustup.

Then run in a terminal:

rustup update
cargo install cavif

More Repositories

1

pngquant

Lossy PNG compressor β€” pngquant command based on libimagequant library
C
4,782
star
2

slip

Slip.js β€” UI library for manipulating lists via swipe and drag gestures
JavaScript
2,440
star
3

giflossy

Merged into Gifsicle!
C
968
star
4

dssim

Image similarity comparison simulating human perception (multiscale SSIM in Rust)
Rust
963
star
5

7z

Because 7-zip source code was in a 7z archive [mirror]
C++
472
star
6

ImageAlpha

Mac GUI for pngquant, pngnq and posterizer
Python
471
star
7

cargo-deb

A cargo subcommand that generates Debian packages from information in Cargo.toml
Rust
267
star
8

http-cache-semantics

RFC 7234 in JavaScript. Parses HTTP headers to correctly compute cacheability of responses, even in complex cases
JavaScript
234
star
9

mediancut-posterizer

Lossy PNG compressor for RGBA PNGs. Has two modes: lossy averaging filter (blurizer) that denoises the image and optimal posterization using Median Cut quantization to reduce number of unique colors in the image with minimal visual distortion
C
231
star
10

pngquant-photoshop

Photoshop plug-in for saving PNG images with pngquant compression
C++
201
star
11

rust-security-framework

Bindings to the macOS Security.framework
Rust
197
star
12

jpeg-compressor

Research JPEG encoder
C++
190
star
13

dupe-krill

A fast file deduplicator
Rust
168
star
14

lodepng-rust

All-in-one PNG image encoder/decoder in pure Rust
Rust
93
star
15

rust-rgb

struct RGB for sharing pixels between crates
Rust
88
star
16

imgref

A trivial Rust struct for interchange of pixel buffers with width, height & stride
Rust
51
star
17

libicns

icns2png / libicns for OS X icns files
C
44
star
18

undither

Smart filter to remove Floyd-Steinberg dithering from paletted images
Rust
43
star
19

Sblam

Server-side HTTP spam filter
PHP
39
star
20

rust-lcms2

ICC color profiles in Rust
Rust
38
star
21

mozjpeg-sys

Rust bindings for mozjpeg
Rust
32
star
22

vpsearch

C library for finding nearest (most similar) element in a set
Rust
30
star
23

objc2grammar

Objective-C 2.0 grammar for SableCC 3 parser. Allows reading of Objective-C source files into abstract syntax tree.
Java
21
star
24

yuv

YCbCr to sRGB converter in Rust
Rust
18
star
25

hCardValidator

hCard Microformat Validator
PHP
17
star
26

image-gif-dispose

Implements GIF disposal method (full rendering of frames) for the Rust gif crate
Rust
17
star
27

rgba-hq2x

hq2x scaling algorithm updated to support RGBA
C++
17
star
28

libimagequant-rust

libimagequant (pngquant) bindings for the Rust language
17
star
29

avif-serialize

Minimal pure Rust AVIF writer (bring your own AV1 payload)
Rust
16
star
30

bcrypt

Fast JavaScript implementation of bCrypt
JavaScript
14
star
31

rust-file

Trivial 1-liner for reading files
Rust
13
star
32

Enterprise

HTML5 Game Jam game
JavaScript
11
star
33

avif-decode

Convert AVIF images to PNG (as lossless as possible)
Rust
11
star
34

mysqlcompat

A reimplemenation of as many MySQL functions as possible in PostgreSQL, as an aid to porting
PLpgSQL
11
star
35

core-services

Rust bindings for CoreServices framework
Rust
10
star
36

openjpeg-sys

Rust bindings for the openjpeg library
Rust
10
star
37

atom2rss

XSL stylesheets for converting Atom 0.3 β†’ Atom 1.0 β†’ RSS 2.0.
XSLT
8
star
38

avif-parse

AVIF parser for extracting AV1 payload from image files. Supports alpha channel association. Fork of Firefox's MP4 parser.
Rust
8
star
39

rust-lcms2-sys

Rust bindings for Little CMS liblcms2
Rust
7
star
40

mss_saliency

Detection of visually salient image regions using Maximum Symmetric Surround algorithm
Rust
7
star
41

libjpeg

The old libjpeg
C
7
star
42

pngoo

Automatically exported from code.google.com/p/pngoo
C#
7
star
43

rust-libpng-sys

Build script to get libpng compile on Windows. It's horrible. Stay away.
Rust
4
star
44

CSS-Preprocessor

DEPRECATED; Preprocessor+parser+minifier
PHP
3
star
45

parallel-progressive

Demo site for HTTP/2-parallelized progressive JPEG
JavaScript
3
star
46

crev-proofs

cargo-crev package reviews
2
star
47

read-through-http-cache

Read-through LRU cache that has basic understanding of HTTP cache headers
JavaScript
2
star
48

itunesfixer

Automatically exported from code.google.com/p/itunesfixer
Objective-C
2
star
49

rust-openh264

Unfinished Rust bindings for Cisco's OpenH264
Rust
2
star
50

nota

Not a pragmatic message format
Rust
1
star
51

picture-element

Simplified <picture> element proposal
1
star
52

cargo-static-registry-rfc-proof-of-concept

Testing whether it's feasible to serve crates-io registry over HTTP as static files
Rust
1
star
53

torrentspotlight

Automatically exported from code.google.com/p/torrentspotlight
Objective-C
1
star
54

is-dark-theme

Hacky check whether macOS is configured to use a Dark Mode appearance
Rust
1
star