libheif icon indicating copy to clipboard operation
libheif copied to clipboard

Expose SVT-AV1 parameter avif=1 in libheif for significantly lower memory usage when encoding still images

Open Dinika opened this issue 2 weeks ago • 2 comments

While running benchmarks for still-image AVIF encoding using libheif + SVT-AV1, I noticed that the memory usage is significantly higher than when using SVT-AV1 directly. It appears that libheif does not forward the SVT encoder parameter --avif 1, even when explicitly specified using svt:avif=1.

According to the SVT-AV1 logs, enabling avif=1 activates optimizations for still images (reduced parallel picture sets, different rate-control mode, etc.).

Below is a reproducible example.


1. Encoding via libheif (high RAM usage, SVT warning shown)

Command:

/usr/bin/time -v heif-enc --avif -p "threads=1" -p "speed=9" --quality=44 -o test.avif parrot-jpg.jpg

Relevant log:

Svt[info]: Number of PPCS 42
...
Svt[info]: BRC mode / rate factor : CRF / 35
...
Svt[info]: Only a single picture was passed in. Consider setting avif=1 for improved efficiency and reduced memory usage.
...
... some more /usr/bin/time logs
...
Percent of CPU this job got: 100%
Maximum resident set size (kbytes): 82856

2. Encoding via SVT-AV1 directly (much lower RAM usage)

Equivalent parameters using ffmpeg + SvtAv1EncApp:

bash -c "ffmpeg -y -i parrot-jpg.jpg -pix_fmt yuv420p -f yuv4mpegpipe - |  /usr/bin/time -v  SvtAv1EncApp -i stdin --preset 9 --crf 35 --lp 1 --avif 1 -b  testsvt.avif"

Relevant log:

...
Svt[info]: Number of PPCS 2
Svt[info]: BRC mode / CQP Assignment : CQP / 35
...
... some more /usr/bin/time logs
...
Percent of CPU this job got: 65%
Maximum resident set size (kbytes): 34216

In summary being able to pass --avif 1 to SVT is helping reduce RAM and CPU usage, the resulting image is smaller in size, and the encoding time is also lower. avif=1 is a documented SVT-AV1 parameter intended specifically for still-image encoding.

Given the above benefits it would be very helpful if libheif exposed a way to pass avif=1 to SVT-AV1, e.g.:

-p svt:avif=1

or simply enable it automatically when encoding a single image with --avif.

If this change aligns with libheif’s design goals, I’m happy to prepare a PR.


Additional info

In the above example I'm using the following image but I am able to reproduce RAM and CPU usage differences with any image:

Image

And here is SVT's documentation for avif parameters.

Dinika avatar Dec 09 '25 17:12 Dinika

I tried to add it (edcb909c796a9ef8c7c1a572f72cb84e8340f68b), but it seems that avif=true is currently not working: https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/2245

I also get the error

Svt[error]: Error: A picture has already been sent. The library only supports one picture in AVIF mode.

even though only one picture is encoded.

farindk avatar Dec 13 '25 18:12 farindk

Thanks so much for looking into this and sharing the link to SVT issue @farindk Looks like some early work for fixing the issue was recently merged. Hoping the fixes are released soon :)

Dinika avatar Dec 16 '25 09:12 Dinika