Provides high level information about the AVIF container.

Clone this repo:

Branches

  1. 5f1a4c3 Update README by Yannis Guyon · 2 weeks ago main
  2. 885bf32 Add Rust implementation by Yannis Guyon · 6 months ago
  3. 524cad4 Use FreeBox instead of custom invalid box type by Yannis Guyon · 6 months ago
  4. 8d8b58a Merge "Minor fixes and small refactor in libavifinfo" into main by Yannis Guyon · 7 months ago
  5. 6bbb0fa Minor fixes and small refactor in libavifinfo by Yannis Guyon · 7 months ago

AVIF-info

libavifinfo is a standalone library that can be used to extract the width, height, bit depth, number of channels and other metadata from an AVIF payload.

See avifinfo.h for details on the API and avifinfo.c for the implementation. See tests/avifinfo_demo.cc for API usage examples.

How to use

libavifinfo can be used when only a few AVIF features are needed and when linking to or including libavif is not an option. For decoding an image or extracting more features, please rely on libavif.

Note: The C implementation AvifInfoGetFeatures() is designed to return the same avifImage field values as avifDecoderParse(). However libavifinfo is often more permissive and may return features of images considered invalid by libavif.

C implementation

Coding style

Google C/C++ Style Guide is used in this project.

Build

avifinfo.c is written in C. To build from this directory:

cmake -S . -B build && \
cmake --build build --config Release

Test

GoogleTest is required for the C++ tests (e.g. sudo apt install libgtest-dev).

cmake -S . -B build -DAVIFINFO_BUILD_TESTS=ON && \
cmake --build build --config Debug && \
ctest --test-dir build build

PHP implementation

The PHP implementation of libavifinfo is a subset of the C API.

libavifinfo was implemented into php-src natively and is available through getimagesize() at head. If it is not available in the PHP release version you use, you can fallback to avifinfo.php instead.

See tests/avifinfo_test.php for a usage example.

PHP test

cd tests && \
php avifinfo_test.php

Rust implementation

The Rust implementation of libavifinfo is similar to the C API.

cargo build

See tests/avifinfo_test.rs for a usage example.

Rust test

cargo test

Development

Submitting patches

If you would like to contribute to libavifinfo, please follow the steps for libaom at https://aomedia.googlesource.com/aom/#submitting-patches. Summary:

  • Log in at https://aomedia.googlesource.com
  • Sign in at https://aomedia-review.googlesource.com
  • Execute the contributor agreement if necessary, see http://aomedia.org/license
  • Test all implementations as described in this document
  • Copy the commit message hook: cd libavifinfo && curl -Lo .git/hooks/commit-msg https://chromium-review.googlesource.com/tools/hooks/commit-msg && chmod u+x .git/hooks/commit-msg
  • Create a commit
  • git push https://aomedia.googlesource.com/libavifinfo/ HEAD:refs/for/main
  • Request a review from a project maintainer

Known users of libavifinfo

  • Chromium uses the C impl to extract the gain map item for HDR tone mapping (removed in Oct 2024).
  • PHP-src uses the C impl to parse image features without relying on libavif or libheif.
  • WordPress uses the PHP impl to support AVIF images with older versions of PHP.

Bug reports

Bug reports can be filed in the Alliance for Open Media issue tracker.