NAME

Imager::File::AVIF - read and write AVIF files

SYNOPSIS

use Imager;
# will be loaded automatically in later versions of Imager when reading or writing
use Imager::File::AVIF;

my $img = Imager->new;
$img->read(file=>"foo.avif")
  or die $img->errstr;

# type won't be necessary if the extension is avif from Imager 1.016
$img->write(file => "foo.avif", type => "avif")
  or die $img->errstr;

# before 1.016
Imager->add_type_extensions(avif => qw(avif avifs));

use Imager::File::AVIF;
# do we have the codecs needed to read and write?
my $can_read  = Imager::File::AVIF->can_read;
my $can_write = Imager::File::AVIF->can_write;

# library build/runtime information
my $codecs    = Imager::File::AVIF->codecs;
my $libver    = Imager::File::AVIF->libversion;
my $buildver  = Imager::File::AVIF->buildversion;

DESCRIPTION

Implements .avif file support for Imager.

At this point this is a very basic implementation, with limited control over output.

TAGS

Imager::File::AVIF will use the following tags when writing to AVIF and set them in images read from AVIF files:

  • avif_timescale - the base frame rate of the file. This must be a positive integer and is specified in Hz. i.e. if this is 60 and all frames have a duration of 1, the file will be playeed at 60 frames per second.

    This is only read from the first images and controls all frames in the file.

    Default: 1Hz.

  • avif_duration - the number of timescale units for this frame. i.e. if avif_timescale is 60, and avif_duration is 2, the frame will be displayed for 1/30 second. Default: 1.

The following tag is set in image read from an AVIF file:

  • avif_total_duration - the total length of the image sequence in the units controlled by avif_timescale.

METHODS

can_read()
if (Imager::File::AVIF->can_read) {
  # we can read AVIF files
}

Tests whether the libavif codec list includes any codecs capable of reading.

can_write()
if (Imager::File::AVIF->can_write) {
  # we can write AVIF files
}

Tests whether the libavif codec list includes any codecs capable of writing.

buildversion()

Returns the version of the libavif library Imager::File::AVIF was built with.

print Imager::File::AVIF->buildversion, "\n";
libversion()

Returns the version of the libavif library Imager::File::AVIF is linked with. This may be different to buildversion() if libavif is dynamically linked.

print Imager::File::AVIF->libversion, "\n";
codecs()

Returns the codecs libavif was built with, this will look something like:

dav1d [dec]:0.7.1, libgav1 [dec]:0.16.1, aom [enc/dec]:v3.3.0

An entry with dec is required to be able to read AVIF images, and an entry with enc is required to be able to write AVIF images.

print Imager::File::AVIF->codecs, "\n";

INSTALLATION

To install Imager::File::AVIF you need Imager installed and you need libavif installed, along with it's development headers.

Note that the libavif included with Debian bullseye was not built with a write compatible codec, but libavif from bullseye-backports does include a write compatible codec.

If you've installed libavif outside the normal places, install pkg-config and set PKG_CONFIG_PATH to the directory containing the installed libavif.pc when running Makefile.PL, for example:

PKG_CONFIG_PATH=/home/tony/local/libavif-0.10.1/lib/pkgconfig/ perl Makefile.PL

AUTHOR

Tony Cook <tonyc@cpan.org>

SEE ALSO

Imager, Imager::Files.