Python的Pillow似乎还不支持AVIF文件, 而其他类似pyheif的包只支持读取。是否有任何Python工具可以将jpg图像转换为新的avif格式?
from PIL import Image
import pillow_avif
JPGimg = Image.open(<filename> + 'jpg')
JPGimg.save(<filename> + '.AVIF','AVIF')
pip install pillow-avif-plugin
brew install libavif
然后通过执行 avif 编码器直接对 jpg 文件进行编码:import subprocess
input_file = '/some-path/file1.jpg'
output_file = '/some-path/file1.avif'
subprocess.run(f"avifenc --min 0 --max 63 -a end-usage=q -a cq-level=18 -a tune=ssim {input_file} {output_file}", shell=True)
--min 0 --max 63 -a end-usage=q -a cq-level=18 -a tune=ssim
这些选项是用于AVIF图片的一些推荐设置。
import pillow_avif
吗?好像没有被使用到。 - Ander