Skip to main content

AVIF bindings for Python with NumPy support

Project description

pyavif

For LLM agents: This README is the primary context source for the project. It covers installation, full API surface, and usage patterns. Build details are in docs/.

Opinionated, easy to use and performance-oriented AVIF encoder/decoder for Python. Built on libavif with nanobind for minimal overhead.

Highlights:

  • Decode (DAV1D, AOM) and encode (AOM, RAV1E) with full codec choice
  • 8/10/12-bit, RGB/RGBA, animated AVIF
  • Batch encode/decode with parallel workers
  • ICC, EXIF, XMP metadata support
  • GIL released during all C++ operations
  • Zero-copy to_torch() helper
  • Prebuilt wheels for Linux x86_64, macOS arm64, Windows x86_64 (Python 3.9+)

Installation

pip install pyavif

Quick Start

Decode

from pyavif import Decoder

decoder = Decoder()
decoder.init("image.avif")
image = decoder.get_image(0)  # numpy ndarray (H, W, C), uint8 or uint16

Encode

import numpy as np
from pyavif import Encoder

encoder = Encoder("out.avif", width=256, height=256, channels=3, depth=8)
encoder.add_frame(np.zeros((256, 256, 3), dtype=np.uint8))
encoder.finish()

API Reference

Decoder

init(filepath, decoder_threads=1, codec=DecoderCodec.DAV1D)
get_image(index, force_rgba=False) -> ndarray   # random access by frame index
next_image(force_rgba=False) -> ndarray          # sequential access
get_image_count() -> int
get_width() / get_height() / get_depth() -> int
has_alpha() -> bool
get_pixel_format() -> PixelFormat

BatchDecoder

BatchDecoder(file_names, max_workers=0, decoder_threads=1,
             force_rgba=False, codec=DecoderCodec.DAV1D)
next_batch() -> (int, dict[str, ndarray])       # frame_index, {path: image}
get_batch_at(frame_idx) -> (int, dict[str, ndarray])
files() -> list[str]
get_image_count() -> int

Encoder

Encoder(output_path, width, height, channels, depth, options=EncoderOptions())
add_frame(ndarray, duration=1, quality_override=None, quality_alpha_override=None)
finish()
set_icc(data: bytes) / set_exif(data: bytes) / set_xmp(data: bytes)
add_advanced_option(key: str, value: str)

BatchEncoder

BatchEncoder(output_paths, options=EncoderOptions())
add_image_batch(images, duration=1, depth=None)  # depth is required for uint16 (10 or 12)
finish_all()
files() -> list[str]

EncoderOptions

Property Type Default
quality int 80
quality_alpha int 100 (lossless)
speed int AVIF_SPEED_DEFAULT
max_threads int 1
codec EncoderCodec AOM
pixel_format PixelFormat YUV444
range Range FULL
timescale int 30
keyframe_interval int 0
repetition_count int infinite
auto_tiling bool True
tile_rows_log2 int 0
tile_cols_log2 int 0
alpha_premultiplied bool False

Enums

  • DecoderCodec: DAV1D, AOM
  • EncoderCodec: RAV1E, AOM
  • PixelFormat: YUV444, YUV422, YUV420, YUV400
  • Range: FULL, LIMITED

to_torch(array, *, layout="channels_last", pin_memory=False)

Zero-copy NumPy-to-PyTorch conversion. layout="chw" returns a CxHxW view.

License

GPLv3. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyavif-0.0.2-cp312-abi3-win_amd64.whl (6.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

pyavif-0.0.2-cp312-abi3-manylinux_2_28_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

pyavif-0.0.2-cp312-abi3-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

pyavif-0.0.2-cp39-abi3-win_amd64.whl (6.6 MB view details)

Uploaded CPython 3.9+Windows x86-64

pyavif-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

pyavif-0.0.2-cp39-abi3-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file pyavif-0.0.2-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyavif-0.0.2-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.6 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyavif-0.0.2-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a84f315096553f697bc33c3dd4ebb71b5f159445c9253006d0b7e913c8cc6587
MD5 854054394dd974c6af17f81025ae93c4
BLAKE2b-256 dd622a43c618db0b2b814b0fb966baae416671a505fdccc37fb623aba3a1405a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.2-cp312-abi3-win_amd64.whl:

Publisher: build.yml on gracia-labs/pyavif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyavif-0.0.2-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyavif-0.0.2-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6de095ad5e05d56b3097f0bcbd7fa0d424300d142380943897b7ae4ddcd26e67
MD5 4b02ae498e38b30ec51bf65b073b358a
BLAKE2b-256 d0e214f3e529d8f4646c3603cec2d6e17e454d10f88f2234305cc7c784c6119e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.2-cp312-abi3-manylinux_2_28_x86_64.whl:

Publisher: build.yml on gracia-labs/pyavif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyavif-0.0.2-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyavif-0.0.2-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf7d4a99ae2849b52d02cba3934add4fcbdaa0e9ebf93005d7779ccd83984c7c
MD5 a93b0eceb3b28e9db8d78d70acf37fdd
BLAKE2b-256 5720c7e9dddcbe0a5edc2866a2fe145d6d38834b6c13e424f0eee95786f001a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.2-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: build.yml on gracia-labs/pyavif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyavif-0.0.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: pyavif-0.0.2-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.6 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyavif-0.0.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 de1b18aa82f5e1e59b42d54ea7ad43c7f8871171e271b72de10d32469618f70c
MD5 e5a4c71c8278862b7c954e7e08d12955
BLAKE2b-256 f0aac537b7746a303f27cb907f09d92a74abfd8baf3bba3e7592da6a862d32e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.2-cp39-abi3-win_amd64.whl:

Publisher: build.yml on gracia-labs/pyavif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyavif-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyavif-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47f65208f568b378f5be94a98bf585d917714797857feedf0b2602917b1568be
MD5 e17a71597bce93a2d19e84569345ceb3
BLAKE2b-256 ef1600f7dd5f67553aec696c6d25b5a865584c7b70c662b04f7b2d76019582a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.2-cp39-abi3-manylinux_2_28_x86_64.whl:

Publisher: build.yml on gracia-labs/pyavif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyavif-0.0.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyavif-0.0.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fada45791b90034df4d9eb152c582b10ea5ed808a9d3bba90929f7ac722b84f7
MD5 2b3ea34b969f3ebc48442528be5a074a
BLAKE2b-256 ef7e3e15b5c9e83c0e44db476fa72f7e4afd382ccfb70c2345189ba9027e1a41

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.2-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: build.yml on gracia-labs/pyavif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page