SDWebImage / SDWebImageAVIFCoder

A SDWebImage coder plugin to support AVIF(AV1 Image File Format) image
MIT License
55 stars 14 forks source link

`AVIF_RESULT_NO_CODEC_AVAILABLE` when encoding AVIF files #59

Closed mgenware closed 11 months ago

mgenware commented 11 months ago

I'm on latest 0.11.0. Couldn't get the README example code to work on macOS Sonoma:

    let lossyAVIFData = SDImageAVIFCoder.shared.encodedData(with: img, format: .AVIF, options: [.encodeCompressionQuality: 0.6])
    try lossyAVIFData?.write(to: dest)
image

My current lock file:

  - SDWebImage (5.18.2):
    - SDWebImage/Core (= 5.18.2)
  - SDWebImage/Core (5.18.2)
  - SDWebImageAVIFCoder (0.11.0):
    - libavif/core (>= 0.11.0)
    - SDWebImage (~> 5.10)

It seems that libaom is missing from SDWebImageAVIFCoder dependencies.

As per SDWebImageAVIFCoder README:

aom By default, libavif is built with aom codec support. aom is the first AV1 codec during the standard draft implementation. The aom support both decodinng and encoding

This seems not true anymore. The libavif repo instead says "No AV1 codecs are enabled by default. Enable them by enabling any of the following CMake options (e.g. -DAVIF_CODEC_AOM=ON)".

mgenware commented 11 months ago

Seems like a regression introduced in 0.11.0, 0.10.1 works fine.

dreampiggy commented 11 months ago

libavif/core

This subspec is not enough. libavif/core does not contain any codec, just dummy.

Seems break change. But this is the only way to avoid aom default inject to your dependencies. (For user who don't want aom at all)

You at leat need to choose one codec when you use CocoaPods

If you need aom:

pod 'libavif/libaom`

If you don't need aom at all, but need AVIF encoding, use:

pod 'libavif/librav1e`

or

pod 'libavif/svt-av1`
dreampiggy commented 11 months ago

aom By default

This is no-longer correct for CocoaPods. I'll change the readme.

Previouslly aom actually default and not avoidable, you can not disable aom. It always download and link to your App, which is not we want.

dreampiggy commented 11 months ago

@mgenware Please check the updated README again 🙏

https://github.com/SDWebImage/SDWebImageAVIFCoder/commit/10b939f7e576bdaeed781f449734c64ae744a689

dreampiggy commented 11 months ago

For your case, if you choose to use aom, use pod 'libavif/libaom' is ok

or if you want faster AVIF encoding (aom using C-based software encoding is slowwwwwww), use:

pod 'libavif', :subspecs => ['libdav1d', 'librav1e']

See our demo's Podfile: https://github.com/SDWebImage/SDWebImageAVIFCoder/blob/master/Example/Podfile#L6

The rav1e is 10x faster than aom for our Demo's AVIF file...So this is why I not recommended to use aom for encoding

mgenware commented 11 months ago

Thanks for the update. Right, libaom is so slow it's barely usable on any apple devices at the moment. Will use rav1e instead.