Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read/write AVIF raster driver #10621

Merged
merged 11 commits into from
Sep 10, 2024
Merged

Add read/write AVIF raster driver #10621

merged 11 commits into from
Sep 10, 2024

Conversation

rouault
Copy link
Member

@rouault rouault commented Aug 21, 2024

Requires libavif. Mostly intended to be used to read/write tiles (as a replacement of JPEG or PNG). No dedicated geospatial capabilities

gdalinfo --format AVIF
  Short Name: AVIF
  Long Name: AV1 Image File Format
  Supports: Raster
  Extension: avif
  Mime Type: image/avif
  Help Topic: drivers/raster/avif.html
  Supports: Raster subdatasets
  Supports: Open() - Open existing dataset.
  Supports: CreateCopy() - Create dataset by copying another.
  Supports: Virtual IO - eg. /vsimem/
  Creation Datatypes: Byte UInt16

<CreationOptionList>
  <Option name="CODEC" type="string-select" description="Compression CODEC" default="AUTO">
    <Value>AUTO</Value>
    <Value>AOM</Value>
  </Option>
  <Option name="QUALITY" type="int" description="Quality for non-alpha channels (0=worst, 100=best/lossless)" default="60" min="0" max="100" />
  <Option name="QUALITY_ALPHA" type="int" description="Quality for alpha channel (0=worst, 100=best/lossless)" default="100" min="0" max="100" />
  <Option name="SPEED" type="int" description="Encoder speed (0=slowest, 10=fastest)" default="6" min="0" max="10" />
  <Option name="NUM_THREADS" type="string" description="Number of worker threads for compression. Can be set to ALL_CPUS" default="ALL_CPUS" />
  <Option name="WRITE_EXIF_METADATA" type="boolean" description="Whether to write EXIF metadata" default="YES" />
  <Option name="WRITE_XMP" type="boolean" description="Whether to write XMP metadata" default="YES" />
  <Option name="SOURCE_ICC_PROFILE" type="string" description="ICC profile encoded in Base64" />
  <Option name="NBITS" type="int" description="Bit depth. Valid values are 8, 10, 12." />
  <Option name="YUV_SUBSAMPLING" type="string-select" description="Subsampling factor for YUV colorspace (for RGB or RGBA)" default="444">
    <Value>444</Value>
    <Value>422</Value>
    <Value>420</Value>
  </Option>
</CreationOptionList>

@rouault rouault added this to the 3.10.0 milestone Aug 21, 2024
@coveralls
Copy link
Collaborator

coveralls commented Aug 21, 2024

Coverage Status

coverage: 69.357%. remained the same
when pulling 272efa8 on rouault:avif
into cf67174 on OSGeo:master.

@rouault
Copy link
Member Author

rouault commented Aug 22, 2024

CC @bradh

@bradh
Copy link
Contributor

bradh commented Sep 8, 2024

I tried this with an AVIF file I'd previously created with libheif.

gdalinfo ~/testbed20/silvereye/smalltiles_2024-06-29/complex_osm_tile_aom_q100.avif 
Driver: AVIF/AV1 Image File Format
Files: /home/bradh/testbed20/silvereye/smalltiles_2024-06-29/complex_osm_tile_aom_q100.avif
Size is 256, 256
Image Structure Metadata:
  YUV_SUBSAMPLING=420
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  256.0)
Upper Right (  256.0,    0.0)
Lower Right (  256.0,  256.0)
Center      (  128.0,  128.0)
Band 1 Block=256x1 Type=Byte, ColorInterp=Red
Band 2 Block=256x1 Type=Byte, ColorInterp=Green
Band 3 Block=256x1 Type=Byte, ColorInterp=Blue

However

bradh@audax:~/coding/gdal_rouault/build$ gdal_translate ~/testbed20/silvereye/smalltiles_2024-06-29/complex_osm_tile_aom_q100.avif out.png
Input file size is 256, 256
ERROR 1: avifDecoderNextImage() failed with: No codec available
ERROR 1: libpng: No IDATs written into file
bradh@audax:~/coding/gdal_rouault/build$ gdal_translate ~/testbed20/silvereye/smalltiles_2024-06-29/complex_osm_tile_aom_q100.avif out.tiff
Input file size is 256, 256
0ERROR 1: avifDecoderNextImage() failed with: No codec available

Sample data
smalltiles_2024-06-29.zip

@rouault
Copy link
Member Author

rouault commented Sep 8, 2024

ERROR 1: avifDecoderNextImage() failed with: No codec available

@bradh I can successfully decode those 2 images with my build using libavif from Ubuntu 22.04. From the error message, I would assume that your libavif build has been done without any codec at all (aom, dav1d or libgav1), which is quite surprising that its build system would allow that. Can you check how it has been built ?
For the write side, "gdalinfo --format AVIF" will show which encoding codecs are available. On my build:

  <Option name="CODEC" type="string-select" description="Compression CODEC" default="AUTO">
    <Value>AUTO</Value>
    <Value>AOM</Value>
  </Option>

@bradh
Copy link
Contributor

bradh commented Sep 9, 2024

From the error message, I would assume that your libavif build has been done without any codec at all (aom, dav1d or libgav1), which is quite surprising that its build system would allow that. Can you check how it has been built ?

Yes, this was the problem. I built from source, and the default is for the codecs to be disabled. I had assumed it would pick up the system versions.

With some configuration of the the cmake, it now gives me:

Format Details:
  Short Name: AVIF
  Long Name: AV1 Image File Format
  Supports: Raster
  Extension: avif
  Mime Type: image/avif
  Help Topic: drivers/raster/avif.html
  Supports: Raster subdatasets
  Supports: Open() - Open existing dataset.
  Supports: CreateCopy() - Create dataset by copying another.
  Supports: Virtual IO - eg. /vsimem/
  Creation Datatypes: Byte UInt16

<CreationOptionList>
  <Option name="CODEC" type="string-select" description="Compression CODEC" default="AUTO">
    <Value>AUTO</Value>
    <Value>AOM</Value>
    <Value>RAV1E</Value>
    <Value>SVT</Value>
  </Option>
  <Option name="QUALITY" type="int" description="Quality for non-alpha channels (0=worst, 100=best/lossless)" default="60" min="0" max="100" />
  <Option name="QUALITY_ALPHA" type="int" description="Quality for alpha channel (0=worst, 100=best/lossless)" default="100" min="0" max="100" />
  <Option name="SPEED" type="int" description="Encoder speed (0=slowest, 10=fastest)" default="6" min="0" max="10" />
  <Option name="NUM_THREADS" type="string" description="Number of worker threads for compression. Can be set to ALL_CPUS" default="ALL_CPUS" />
  <Option name="WRITE_EXIF_METADATA" type="boolean" description="Whether to write EXIF metadata" default="YES" />
  <Option name="WRITE_XMP" type="boolean" description="Whether to write XMP metadata" default="YES" />
  <Option name="SOURCE_ICC_PROFILE" type="string" description="ICC profile encoded in Base64" />
  <Option name="NBITS" type="int" description="Bit depth. Valid values are 8, 10, 12." />
  <Option name="YUV_SUBSAMPLING" type="string-select" description="Subsampling factor for YUV colorspace (for RGB or RGBA)" default="444">
    <Value>444</Value>
    <Value>422</Value>
    <Value>420</Value>
  </Option>
</CreationOptionList>

I did a conversion from TIFF to AVIF. It rendered fine, and I'm pretty confident that it was using the libavif implementation (rather than libheif) based on the file type compatible brands including MA1A.

Copy link
Contributor

@bradh bradh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick look over the code. As expected, nothing important.

frmts/heif/heifdataset.cpp Outdated Show resolved Hide resolved
frmts/heif/heifdataset.cpp Outdated Show resolved Hide resolved
frmts/heif/heifdataset.cpp Outdated Show resolved Hide resolved
frmts/avif/avifdataset.cpp Outdated Show resolved Hide resolved
@rouault rouault merged commit 54bec3d into OSGeo:master Sep 10, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants