1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# go-avif [](https://travis-ci.org/Kagami/go-avif) [](https://godoc.org/github.com/Kagami/go-avif)
go-avif implements
AVIF ([AV1 Still Image File Format](https://aomediacodec.github.io/av1-avif/))
encoder for Go using libaom, the [high quality](https://github.com/Kagami/av1-bench)
AV1 codec.
## Requirements
Make sure libaom is installed. On typical Linux distro just run:
#### Debian (and derivatives):
```bash
sudo apt-get install libaom-dev
```
#### RHEL (and derivatives):
```bash
sudo dnf install libaom-devel
```
## Usage
To use go-avif in your Go code:
```go
import "github.com/Kagami/go-avif"
```
To install go-avif in your $GOPATH:
```bash
go get github.com/Kagami/go-avif
```
For further details see [GoDoc documentation](https://godoc.org/github.com/Kagami/go-avif).
## Example
```go
package main
import (
"image"
_ "image/jpeg"
"log"
"os"
"github.com/Kagami/go-avif"
)
func main() {
if len(os.Args) != 3 {
log.Fatalf("Usage: %s src.jpg dst.avif", os.Args[0])
}
srcPath := os.Args[1]
src, err := os.Open(srcPath)
if err != nil {
log.Fatalf("Can't open sorce file: %v", err)
}
dstPath := os.Args[2]
dst, err := os.Create(dstPath)
if err != nil {
log.Fatalf("Can't create destination file: %v", err)
}
img, _, err := image.Decode(src)
if err != nil {
log.Fatalf("Can't decode source file: %v", err)
}
err = avif.Encode(dst, img, nil)
if err != nil {
log.Fatalf("Can't encode source image: %v", err)
}
log.Printf("Encoded AVIF at %s", dstPath)
}
```
## CLI
go-avif comes with handy CLI utility `avif`. It supports encoding of JPEG and
PNG files to AVIF:
```bash
# Compile and put avif binary to $GOPATH/bin
go get github.com/Kagami/go-avif/...
# Encode JPEG to AVIF with default settings
avif -e cat.jpg -o kitty.avif
# Encode PNG with slowest speed
avif -e dog.png -o doggy.avif --best -q 15
# Lossless encoding
avif -e pig.png -o piggy.avif --lossless
# Show help
avif -h
```
Static 64-bit builds for Windows, macOS and Linux are available at
[releases page](https://github.com/Kagami/go-avif/releases). They include
latest libaom from git at the moment of build.
## Display
To display resulting AVIF files take a look at software listed
[here](https://github.com/AOMediaCodec/av1-avif/wiki#demuxers--players). E.g.
use [avif.js](https://kagami.github.io/avif.js/) web viewer.
## License
go-avif is licensed under [CC0](COPYING).
|