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

Unable to open AVIF images #7983

Open
ponponon opened this issue Apr 16, 2024 · 5 comments · May be fixed by #5201
Open

Unable to open AVIF images #7983

ponponon opened this issue Apr 16, 2024 · 5 comments · May be fixed by #5201

Comments

@ponponon
Copy link

ponponon commented Apr 16, 2024

I have a picture here in avif format:https://img10.360buyimg.com/n7/jfs/t1/194600/2/37658/144533/652f464dF8dc6bd47/3aada6e1078054ae.jpg.avif

图片

╭─ponponon@MBP13ARM ~/Pictures
╰─➤  mediainfo jd002.avif
General
Complete name                            : jd002.avif
Format                                   : avif
Codec ID                                 : avif (avif/mif1/miaf/MA1A)
File size                                : 11.4 KiB

Image
ID                                       : 1
Format                                   : av01
Codec ID                                 : av01
Width                                    : 220 pixels
Height                                   : 220 pixels
Color space                              : YUV
Bit depth                                : 8 bits
Stream size                              : 11.1 KiB (98%)
Color range                              : Full
Color primaries                          : BT.709
Transfer characteristics                 : sRGB/sYCC
Matrix coefficients                      : BT.601
Codec configuration box                  : av1C


╭─ponponon@MBP13ARM ~/Pictures
╰─➤  mediainfo --version
MediaInfo Command line,
MediaInfoLib - v24.03

Opening with pillow results in an error

In [1]: from PIL import Image

In [2]: 

In [2]: Image.open('/Users/ponponon/Pictures/jd002.avif')
---------------------------------------------------------------------------
UnidentifiedImageError                    Traceback (most recent call last)
Cell In[2], line 1
----> 1 Image.open('/Users/ponponon/Pictures/jd002.avif')

File ~/.local/share/virtualenvs/image_vector-8oWws01B/lib/python3.10/site-packages/PIL/Image.py:3186, in open(fp, mode, formats)
   3184 for message in accept_warnings:
   3185     warnings.warn(message)
-> 3186 raise UnidentifiedImageError(
   3187     "cannot identify image file %r" % (filename if filename else fp)
   3188 )

UnidentifiedImageError: cannot identify image file '/Users/ponponon/Pictures/jd002.avif'
╰─➤  pip show pillow                                                                                   
Name: Pillow
Version: 9.3.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: [email protected]
License: HPND
Location: /Users/ponponon/.local/share/virtualenvs/image_vector-8oWws01B/lib/python3.10/site-packages
Requires: 
Required-by: image2vector, ImageHash, torchvision
╰─➤  python --version                                           
Python 3.10.10
╰─➤  sw_vers
ProductName:            macOS
ProductVersion:         14.2.1
BuildVersion:           23C71
@radarhere
Copy link
Member

Yes, this is format that Pillow does not support yet. See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html for the formats Pillow does support.

#5201 has been created as a possible solution.

@radarhere radarhere changed the title Unable to open images in avif format Unable to open AVIF images Apr 16, 2024
@radarhere radarhere linked a pull request Apr 18, 2024 that will close this issue
@bigcat88
Copy link
Contributor

bigcat88 commented Nov 29, 2024

Here's my question: when the linked PR is merged, will it still be possible to write a plugin for AVIF or modify the linked PR (or Pillow) to allow specifying not only the format during read and write operations but also a specific codec to use?

I’m asking because I know several people who specifically want to use the SVT-AV1 codec instead of aom. If Pillow does not support having multiple ImageFile.ImageFile instances for the same format in parallel, I would avoid putting in the effort to add SVT-AV1 support to pillow_heif, as it wouldn’t be usable after the linked PR is merged.

Thank you!


Edited:

I understand that people can build from source with the necessary encoder/decoder, but most people use Windows, and there it is a pain with this, and they need binary wheels with the codecs they need.

If try to put all the encoders/decoders into binary wheels, then this is simply an unrealistic release size(from my point of view at least)

@radarhere
Copy link
Member

If Pillow does not support having multiple ImageFile.ImageFile instances for the same format in parallel

It does.

Naturally, you can only open or save an image using one format at a time, and the extension ".avif" can only pick one ImageFile when saving.

However, if you wanted to have two ImageFiles registered at once, one could have the format of "AVIF1", and then Image.open("in.avif", formats=["AVIF1"]) or im.save("out.avif", format="AVIF1") would use that. See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.open and https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.save for the documentation.

@Popolon
Copy link

Popolon commented Dec 12, 2024

AVIF is widely supported now, at least among browsers, viewers, converters (ImageMagick, GraphicsMagick, libgd), image editors. But looks like the proposed patch has not been applied? It is pending a reviewer since 2021.

@radarhere
Copy link
Member

The reviewing process has picked up speed in the last two months.

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 a pull request may close this issue.

4 participants