matplotlib icon indicating copy to clipboard operation
matplotlib copied to clipboard

[ENH]: Support avif as output format

Open rotsee opened this issue 1 year ago • 6 comments

Problem

Since v3.6.0, Matplotlib supports webp output (yay!), but I couldn't find a ticket tracking Avif support, so here's a feature request for savefig to support saving as .avif.

relevant links:

Proposed solution

No response

rotsee avatar Sep 12 '24 14:09 rotsee

I think this would need to wait for pillow to support?

jklymak avatar Sep 12 '24 14:09 jklymak

While Pillow support is a prerequisite (and probably sufficient) condition for savefig to support AVIF, animations actually may have some support already.

Newer versions of ffmpeg support AVIF (though I could not test easily because the version in my distro's repository is too old).

The imagemagick writer did save an AVIF file. However, it may have only saved a single frame... (Not 100% sure if that is a viewer program problem or file output problem)

ani.save("test.avif", writer="imagemagick")

Gives: (zipped AVIF file because github doesn't allow AVIF directly) test.zip

ksunden avatar Sep 12 '24 17:09 ksunden

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide.

We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication channels.

github-actions[bot] avatar Sep 13 '24 20:09 github-actions[bot]

Until that PR is merged you can use a separate package, pillow-avif-plugin, to allow Pillow to save AVIF images.

fdintino avatar Sep 19 '24 01:09 fdintino

hello, has this been worked on yet? Am I able to work on this as my first issue?

u7228810 avatar Oct 10 '24 08:10 u7228810

what would be the difficulty level of this issue?

u7228810 avatar Oct 10 '24 08:10 u7228810

I have successfully added this functionality by adding the pillow-avif-plugin library to all relevant files. I am working on making a pull request with these changes. I added the pillow-avif-plugin library to all the requirements files where pillow is listed, so it is automatically installed.

sgcartwright avatar Feb 05 '25 03:02 sgcartwright

We want to keep our dependencies small. Therefore, I don't think we should add the plugins to our requirements.

timhoffm avatar Feb 05 '25 08:02 timhoffm

There seems to be progress on this upstream: https://github.com/python-pillow/Pillow/pull/5201

rotsee avatar Feb 05 '25 08:02 rotsee

Pillow now supports avif (when built from source) https://pillow.readthedocs.io/en/stable/releasenotes/11.2.1.html

rotsee avatar Apr 13 '25 10:04 rotsee

So, would it make sense to try implementing support for AVIF now, or should we wait until it's officially included in the Pillow binaries (if that's supposed to happen)?

MiniX16 avatar May 17 '25 01:05 MiniX16

Hi! I’d like to work on this issue. Is anyone else already working on it or are there any specific guidelines I should follow? (this is my first contribution)

AtharvaJaiswal005 avatar May 24 '25 08:05 AtharvaJaiswal005

With Pillow 1.3 avif support is now included in Pillow’s wheels (except some):

https://pillow.readthedocs.io/en/stable/releasenotes/11.3.0.html#avif-support-in-wheels

rotsee avatar Jul 01 '25 11:07 rotsee

Is there anything to do on our side? I'd expect that saving will "just work" with 1.3?

timhoffm avatar Jul 14 '25 15:07 timhoffm

Is there anything to do on our side? I'd expect that saving will "just work" with 1.3?

With matplotlib==3.10.3 and pillow==11.3.0 I still get:

> import matplotlib.pyplot as plt
> fig = plt.figure()
> fig.savefig('test.avif')

/.../

`ValueError: Format 'avif' is not supported (supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff, webp)

rotsee avatar Jul 14 '25 19:07 rotsee

Ah, we need to internally register the format. Changes should be analogous to #21274.

timhoffm avatar Jul 16 '25 05:07 timhoffm