stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Feature Request]: AVIF Lossless Support

Open Rabcor opened this issue 4 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

Stable Diffusion Webui already supports avif, but there is no setting to make it lossless like webp.

Also of note, if I pass an avif image through an upscaler in extras, the resulting avif's colorspace, color primaries and color transfer settings will be changed (to bt601,bt709 and srgb)

The whole idea here is to use AVIF to extract frames losslessly (or near losslessly I guess) from a video, upscale those frames in sdwebui's extras tab and saving them as an AVIF with the same paramaters as the AVIF that was loaded in.

Proposed workflow

  1. A lossless setting for avif next to the 'Use lossless compression for webp images' setting.
  2. The setting should ideally try to account for colorspace, color primaries, and color transfer of the original image. (Otherwise it cannot be called lossless as the colors will change from the conversion of those attributes to different ones)

Additional information

You can extract a frame from any video as avif with ffmpeg as avif using this command:

ffmpeg -i <input_video> -ss <timestamp> -cpu-used 4 -c:v libaom-av1 -aom-params lossless=1 -frames:v 1 <output_image>.avif

Alternatively below is an example avif image.

I had to rename the extension to png because github said so.

Simply download it and rename it's extension to .avif.

Image

Rabcor avatar Jul 15 '25 05:07 Rabcor

you sure we don't support losses AVIF?

  • https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/15610
Image

w-e-w avatar Jul 19 '25 02:07 w-e-w

you sure we don't support losses AVIF?

Setting avif quality to 100%, like with jpeg, does not make it lossless, it would need to be a separate tickable setting like with the webp. And the lossless compression for webp setting does not make avif lossless, I've checked that.

A lossless parameter needs to be set, this remains true for all av1 libraries I tested except for rav1e which doesn't support lossless av1 at all.

For example with ffmpeg to create lossless avif one of the below combinations of settings is required, there's also a quality setting but as I said, setting it to 100 is not the same as lossless.

#svtav1
 -c:v libsvtav1 -svtav1-params lossless=1
#libaom-av1
 -c:v libaom-av1 -aom-params lossless=1

The pixel format and colorspace conversions would also still be a rather big issue.

Rabcor avatar Jul 21 '25 11:07 Rabcor