LinuxCommandLibrary

cavif

Convert images to AVIF format

TLDR

Convert a JPEG file to AVIF, saving it to file.avif

$ cavif [path/to/image.jpg]
copy

Adjust the image quality and convert a PNG file to AVIF
$ cavif --quality [1..100] [path/to/image.png]
copy

Specify the output location
$ cavif [path/to/image.jpg] --output [path/to/output.avif]
copy

Overwrite the destination file if it already exists
$ cavif --overwrite [path/to/image.jpg]
copy

SYNOPSIS

cavif [OPTIONS] <INPUT_FILE>...
cavif [OPTIONS] <INPUT_FILE> -o <OUTPUT_FILE>
cavif [OPTIONS] <INPUT_FILE>... --dir <OUTPUT_DIRECTORY>

PARAMETERS

-Q, --quality <QUALITY>
    Sets the quality level for AVIF encoding, ranging from 0 (lowest quality, smallest file) to 100 (highest quality, largest file). Default is usually 60-80.

-s, --speed <SPEED>
    Determines the encoding speed, from 0 (slowest, best compression) to 10 (fastest, less compression). Higher speed means faster encoding but larger file sizes.

-p, --parallel <NUM_THREADS>
    Specifies the number of threads to use for encoding, leveraging multi-core processors for faster processing.

--depth <DEPTH>
    Sets the bit depth for the output AVIF image (e.g., 8, 10, or 12 bits). Higher depths allow for more color precision, but increase file size.

-o, --output <OUTPUT_FILE>
    Specifies the output file path for a single input file. If omitted for a single input, it defaults to a new file with .avif extension in the current directory.

--dir <OUTPUT_DIRECTORY>
    Designates an output directory when converting multiple input files. Each input file will be converted to an AVIF file in this directory with its original name and .avif extension.

--lossless
    Encodes the image in a lossless manner. This typically results in larger file sizes but preserves every detail of the original image.

--alphar
    Encodes the alpha channel losslessly. This is useful for images with transparency where preserving alpha fidelity is critical.

--overwrite
    Allows overwriting existing output files without prompting for confirmation.

-q, --quiet
    Suppresses informational output, showing only errors.

-v, --verbose
    Enables verbose output, providing more details about the encoding process.

-h, --help
    Displays a help message with available options and usage.

DESCRIPTION

cavif is a command-line tool written in Rust designed to convert various image formats, predominantly JPEG and PNG, into the modern and highly efficient AVIF (AV1 Image File Format). AVIF utilizes the advanced compression capabilities of the AV1 video codec, offering superior compression ratios compared to traditional formats like JPEG, which often results in significantly smaller file sizes with minimal or no perceptible loss in image quality. This makes AVIF an excellent choice for web optimization, reducing bandwidth usage, and efficient image storage.

The tool acts as a user-friendly front-end to the underlying libavif library, abstracting away complex details and providing straightforward options for encoding parameters such as quality, speed, and color depth. cavif supports features like transparency (alpha channel), various chroma subsampling options, and allows users to balance encoding speed against compression efficiency. Its implementation in Rust often contributes to its performance and memory efficiency, making it suitable for batch conversions or integration into automated image processing workflows.

CAVEATS

cavif is a third-party utility and not part of standard Linux core utilities. It requires Rust and Cargo for installation (typically via cargo install cavif).
While AVIF offers excellent compression, its adoption is still growing, and not all image viewers or web browsers fully support it. Always test compatibility with your target audience or platform.
Encoding large images or using very high quality/slow speed settings can be CPU-intensive and time-consuming.

<B>INSTALLATION</B>

To install cavif, you typically need to have Rust and its package manager, Cargo, installed on your system. Once they are set up, you can install cavif directly from crates.io using the command:
cargo install cavif.
Ensure your Cargo binary directory (e.g., ~/.cargo/bin) is in your system's PATH to execute the command directly.

<B>USE CASES</B>

cavif is primarily used for:

Web Image Optimization: Reducing image file sizes for websites to improve loading times and user experience.
Archival and Storage: Efficiently storing large collections of images with minimal quality loss.
Automated Workflows: Integrating into scripts or build processes for automatic image conversion during development or deployment.
Reducing Bandwidth Costs: For services that serve many images, smaller files can significantly reduce data transfer costs.

HISTORY

cavif emerged as a modern, Rust-based command-line interface for encoding images to the AVIF format. The AVIF format itself is relatively new, based on the open and royalty-free AV1 video codec developed by the Alliance for Open Media (AOMedia). As AVIF gained traction as a successor to formats like JPEG due to its superior compression and features like transparency, tools like cavif were developed to make the encoding process accessible to users outside of complex video encoding pipelines. Its development in Rust is a notable aspect, often associated with performance and reliability. It became a popular choice for web developers and users looking for an efficient way to optimize images for the web or for storage.

SEE ALSO

avifenc(1) (Official AVIF encoder utility from libavif), cwebp(1) (WebP image encoder), ffmpeg(1) (Multimedia framework that can encode AVIF), convert(1) (ImageMagick command-line tool for image manipulation and conversion)

Copied to clipboard