This AVIF coder plugin currently support AVIF still image decoding. Including alpha channel, as well as 10bit/12bit/16bit HDR images.
The AVIF encoding is also supported now. Which always encode as 8-bit depth images.
AVIF image spec is still in evolve. And the current upstream AVIF codec is a simple implementation. The encoding time may be long for large images.
Since we rely on the external codec libavif. We may periodically update the dependency and bump version. Make sure you're using the latest version as possible as you can :)
aom && dav1d && rav1e
libavif is a still image codec. But AVIF is based on the AV1 Video standard. So it need a AV1 codec for support. This relationship is just like HEIF(image) and HEVC(video) codec.
By default, libavif is built with aom codec support. aom is the first AV1 codec during the standard draft implementation.
dav1d is the new and next generation AV1 codec, focused on speed and correctness.
From v0.3.0, libavif can built with dav1d. For CocoaPods user, you can simply use the subspec for this. Carthage for optional dav1d codec is not supported currently.
rav1e is the fastest and safest AV1 encoder. Which use Rust programming to provide fast and safe codec compared to aom. Its current form it is most suitable for cases where libaom (the reference encoder) is too slow.
See more about performance
From v0.4.3, libavif can built with rav1e. For CocoaPods user, you can simply use the subspec for this. Carthage for optional rav1c codec is not supported currently.
Note rav1e currently only support iOS && macOS. watchOS and tvOS supports need Rust community upstream support.
Note that for CocoaPods user, rav1e is prebuilt binary (to avoid developer to install rust toolchain) and hosted on GitHub Git LFS. Make sure you have git-lfs installed.
brew install git-lfs git lfs install
- iOS 8
- macOS 10.10
- tvOS 9.0
- watchOS 2.0
SDWebImageAVIFCoder is available through CocoaPods. To install it with default aom AV1 codec, simply add the following line to your Podfile:
Note: From version 0.4.0, if you want to use rav1e or dav1e instead aom for faster AV1 codec, control the subspec of libavif instead:
pod 'SDWebImageAVIFCoder' pod 'libavif', :subpsecs => [ 'libdav1d', 'librav1e' ]
Note: From version 0.2.0, the dependency libavif and libaom use the portable C implementation to works on Apple platforms. If you need the pre-built library with SIMD/AVX and assembly optimization, try the 0.1.0 version.
SDWebImageAVIFCoder is available through Carthage.
Carthage does not support like CocoaPods' subspec, it only supports libaom for AVIF decoding && encoding.
Swift Package Manager (Xcode 11+)
SDWebImageAVIFCoder is available through Swift Package Manager.
The framework through SwiftPM only supports libaom for AVIF decoding && encoding.
let package = Package( dependencies: [ .package(url: "https://github.com/SDWebImage/SDWebImageAVIF.git", from: "0.5") ] )
To use AVIF coder, you should firstly add the
SDImageAVIFCoder.sharedCoder to the coders manager. Then you can call the View Category method to start load AVIF images.
SDImageAVIFCoder *AVIFCoder = SDImageAVIFCoder.sharedCoder; [[SDImageCodersManager sharedManager] addCoder:AVIFCoder]; UIImageView *imageView; [imageView sd_setImageWithURL:url];
let AVIFCoder = SDImageAVIFCoder.shared SDImageCodersManager.shared.addCoder(AVIFCoder) let imageView: UIImageView imageView.sd_setImage(with: url)
The images are from AV1 Still Image File Format Specification Test Files.
AVIF Image Viewer
AVIF is a new image format, which lack of related toolchains like Browser or Desktop Viewer support.
You can try AVIFQuickLook QuickLook plugin on macOS to view it in Finder.
You can also try using avif.js to view it online by using Chrome's AV1 codec.
SDWebImageAVIFCoder use GitHub Actions for testing. Each merge request will run the test cases to ensure the AVIF decoding/encoding function works.
Current test cases use macOS command line tools, to compare the AVIF sample decoding result with ImageMagick.
We have also the XCTest unit test target, you can run it by using Xcode's Test action.
SDWebImageAVIFCoder is available under the MIT license. See the LICENSE file for more info.
You may find interesting
0.6.1 - Fix libavif >= 0.7.2 compile issue - 2020-05-14 09:38:27
- Refactoring & fix a bug & add tests to increase code coverage. #18
- Fix/support libavif v0.7.3 #20
0.6.0 - Performance && ColorProfile - 2020-03-13 06:42:47
- Output grayscale images as possible #11
- Reduces up to 66% memory usage.
- Support libavif v0.60 and set proper color space as possible. #13
- Decoding images with alpha planes becomes faster 13%~25% than before
- Scale alpha planes [0, (1 << bit-depth) - 1] to [0, 65536] #14
- The dependency of libavif bumped to v0.6.0 #13
Unit tests and remove inappropriate debugging code - 2020-02-25 12:27:22
- Added unit tests and code coverage. #10
- Remove inappropriate debugging code, this slightly effect the performance. #10
Fix AVIF decoding for odd dimensions - 2020-02-12 02:44:15
- Handle images with odd dimensions and fix color matrix #9
- Add CI to check decoding functions #9
Performance && SwiftPM - 2020-01-24 03:09:15
- use vImage framework to accelerate conversion from YUV to RGB(A) #7. Thanks @ledyba-z
- Support Swift Package Manager #8
Support libavif 0.4.0 - 2019-10-08 06:56:01
- Upgrade libavif to 0.4.0 support #6
Support libavif 0.3.11 - 2019-10-08 06:28:57
- Upgrade libavif to 0.3.11 support, last 0.3.x version #5
Upgrade libavif to 0.3.0, support dav1d faster codec - 2019-10-08 05:18:57
- Upgrade libavif to 0.3.0, support dav1d instead aom for decoding, which is faster #4
Compatible for libavif 0.2.0 - 2019-08-21 08:43:01
- Fix the compatible for libavif 0.2 API changes #3
Compatible for liabavif 1.0.4 - 2019-08-21 07:31:49
- Fix the compatible for libavif 1.0.4 version #2
Supports AVIF encoding - 2019-04-29 10:05:24
- Upgrade the libavif version, supports the AVIF encoding feature #1
- CocoaPods now support tvOS && watchOS. Do not use t he pre-built Static Library and make it works for Dynamic Framework
Initial version - supports AVIF decoding with alpha and HDR - 2019-04-29 10:00:53
- Support AVIF image decoding
- Support alpha channel
- Support HDR (High Depth like 10bit or 12bit color)