Python's Pillow doesn't seems to support AVIF files yet, and other packages like pyheif, only support reading. Is there any Python tool to convert jpg images to the new avif format?
3 回答
2
您可以使用枕头和枕头-avif-plugin做到这一点:
from PIL import Image
import pillow_avif
JPGimg = Image.open(<filename> + 'jpg')
JPGimg.save(<filename> + '.AVIF','AVIF')
您需要安装枕头 AVIF 才能做到这一点。
于 2021-10-14T07:34:50.447 回答
1
到目前为止,我能想到的最好的方法是安装 libavif:
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 图像的一些推荐设置。
于 2021-10-14T08:19:10.067 回答