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.12+)

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
is_keyframe(index) -> bool
nearest_keyframe(index) -> int
get_keyframe_indices() -> list[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.4-cp312-abi3-win_amd64.whl (6.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

pyavif-0.0.4-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.4-cp312-abi3-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyavif-0.0.4-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.12

File hashes

Hashes for pyavif-0.0.4-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a8250a8825297bbc8f32f9ee09d038cca6c3dc6851e0e2451bb370c6f56c0dbb
MD5 0cce70d39f29b07d696eba8481f04acf
BLAKE2b-256 7217fbb44f5fdd99071094fd36dff7d46287234d6c5990e6f15873d04b805318

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.4-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.4-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyavif-0.0.4-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b2fe568e203357456f40ddb8bb752e005f067396b934d184cf061dc1c9c0fac
MD5 6e4393d8e2ca70866dc86bafa15a5b5b
BLAKE2b-256 41fc23619637f97f2ee8e4bc4c22fa88ba56c03ce439566389fff9994abe6ddc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.4-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.4-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyavif-0.0.4-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9048f96da414a962a7cfdd0a20954b5672a5c9d9864cad59103b373e6244c1c3
MD5 41c4aa774e1be0378aa6f90ad0b5070d
BLAKE2b-256 cbf9b7b4c9ee014da5feab861c4018c510fd9c14d96f44bf184f75b0fcaf8a0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyavif-0.0.4-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.

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