Soenneker.Libavif.Util
4.0.40
Prefix Reserved
dotnet add package Soenneker.Libavif.Util --version 4.0.40
NuGet\Install-Package Soenneker.Libavif.Util -Version 4.0.40
<PackageReference Include="Soenneker.Libavif.Util" Version="4.0.40" />
<PackageVersion Include="Soenneker.Libavif.Util" Version="4.0.40" />
<PackageReference Include="Soenneker.Libavif.Util" />
paket add Soenneker.Libavif.Util --version 4.0.40
#r "nuget: Soenneker.Libavif.Util, 4.0.40"
#:package Soenneker.Libavif.Util@4.0.40
#addin nuget:?package=Soenneker.Libavif.Util&version=4.0.40
#tool nuget:?package=Soenneker.Libavif.Util&version=4.0.40
Soenneker.Libavif.Util
A cross-platform .NET API for encoding AVIF images with the official libavif command-line tools.
Encode JPEG, PNG, or Y4M files as AVIF without installing avifenc on the host. The required Windows and Linux binaries are included and selected automatically at runtime.
Quick start
Install the package:
dotnet add package Soenneker.Libavif.Util
Register the utility and encode an image:
using Microsoft.Extensions.DependencyInjection;
using Soenneker.Libavif.Util.Abstract;
using Soenneker.Libavif.Util.Options;
using Soenneker.Libavif.Util.Registrars;
await using ServiceProvider provider = new ServiceCollection()
.AddLogging()
.AddLibavifUtilAsSingleton()
.BuildServiceProvider();
ILibavifUtil libavif = provider.GetRequiredService<ILibavifUtil>();
await libavif.Encode("images/photo.jpg", "images/photo.avif", new AvifEncodeOptions
{
Quality = 80,
Speed = 6,
Progressive = true
});
That is all the setup required.
Progressive AVIF
Set Progressive to true to ask libavif for layered progressive encoding:
await libavif.Encode("photo.png", "photo.avif", new AvifEncodeOptions
{
Progressive = true
});
A compatible decoder can display the initial layer before decoding the refinements. Decoder and browser support determines how the image is presented to the user.
Encoding options
AvifEncodeOptions provides the commonly used avifenc controls:
| Option | Default | Description |
|---|---|---|
Quality |
80 |
Color quality from 0 through 100. |
AlphaQuality |
Quality |
Optional alpha-channel quality from 0 through 100. |
Speed |
6 |
Encoder speed from 0 (slowest) through 10 (fastest). |
Lossless |
false |
Enables lossless encoding. |
Progressive |
false |
Enables layered progressive encoding. |
StripMetadata |
true |
Removes EXIF, XMP, and ICC metadata. |
High quality
await libavif.Encode("photo.png", "photo.avif", new AvifEncodeOptions
{
Quality = 90,
AlphaQuality = 100,
Speed = 4
});
Lossless
await libavif.Encode("artwork.png", "artwork.avif", new AvifEncodeOptions
{
Lossless = true,
Speed = 6
});
Preserve metadata
await libavif.Encode("photo.jpg", "photo.avif", new AvifEncodeOptions
{
StripMetadata = false
});
Use additional avifenc options
For options without a dedicated property, build a structured command. Values and paths are quoted safely.
using Soenneker.Libavif.Util.Commands;
using Soenneker.Libavif.Util.Commands.Abstract;
ILibavifCommand command = new AvifCommand()
.AddFlag("progressive")
.AddOption("speed", 6)
.AddArgument("images/source photo.png")
.AddArgument("images/result photo.avif");
IReadOnlyList<string> output = await libavif.Execute(command, log: false);
Prefer Execute over raw argument strings when values contain paths or application-supplied input. Run remains available when direct command-line control is necessary:
IReadOnlyList<string> output = await libavif.Run("--version", log: false);
string version = await libavif.GetVersion();
Dependency injection lifetimes
Both standard lifetimes are available:
services.AddLibavifUtilAsSingleton();
services.AddLibavifUtilAsScoped();
Register only the lifetime used by the application.
Supported environments
| Operating system | Architecture | Bundled tool |
|---|---|---|
| Windows | x64 | avifenc.exe |
| Linux | x64 | avifenc |
Other operating systems and architectures throw PlatformNotSupportedException.
Useful behavior
- Accepts
.jpg,.jpeg,.png, and.y4minputs. - Requires the output path to use the
.avifextension. - Creates missing output directories automatically.
- Writes to a unique temporary file and replaces the destination only after encoding succeeds.
- Supports paths containing spaces and quotes.
- Cleans up temporary output after failures or cancellation.
- Accepts a cancellation token on every asynchronous operation.
- Throws
FileNotFoundExceptionfor a missing input or bundled encoder. - Validates quality and speed values before starting libavif.
The implementation follows the standard Soenneker utility stack for runtime detection, filesystem access, temporary paths, process execution, and pooled command construction.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Libavif.Linux (>= 4.0.6)
- Soenneker.Libavif.Windows (>= 4.0.6)
- Soenneker.Utils.File (>= 4.0.2254)
- Soenneker.Utils.Paths.Resources (>= 4.0.238)
- Soenneker.Utils.Process (>= 4.0.1548)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.40 | 0 | 9/5/2026 |
| 4.0.39 | 0 | 9/5/2026 |
| 4.0.38 | 28 | 9/5/2026 |
| 4.0.37 | 34 | 9/5/2026 |
| 4.0.36 | 37 | 9/4/2026 |
| 4.0.34 | 32 | 9/4/2026 |
| 4.0.33 | 43 | 9/4/2026 |
| 4.0.32 | 35 | 9/4/2026 |
| 4.0.31 | 45 | 9/4/2026 |
| 4.0.30 | 40 | 9/4/2026 |
| 4.0.29 | 38 | 9/4/2026 |
| 4.0.26 | 42 | 9/4/2026 |
| 4.0.25 | 32 | 9/4/2026 |
| 4.0.24 | 30 | 9/4/2026 |
| 4.0.23 | 67 | 9/3/2026 |
| 4.0.22 | 76 | 9/2/2026 |
| 4.0.21 | 88 | 9/1/2026 |
| 4.0.20 | 73 | 9/1/2026 |
| 4.0.16 | 105 | 8/31/2026 |
| 4.0.15 | 85 | 8/31/2026 |