Go to file
Cadey Ratio 35de98b1f6 test
Signed-off-by: Xe <me@christine.website>
2022-09-15 16:05:37 +00:00
.github Update FUNDING.yml 2019-07-21 19:44:26 +03:00
cmd/avif make this use avif instead of heif 2022-09-15 15:55:41 +00:00
.envrc make this use avif instead of heif 2022-09-15 15:55:41 +00:00
.gitignore make this use avif instead of heif 2022-09-15 15:55:41 +00:00
.travis.yml Travis CI: Update Linux and macOS build environments 2019-10-14 11:13:00 +02:00
COPYING Initial commit 2019-03-17 15:16:16 +03:00
Makefile Fix travis build 2019-03-17 19:33:07 +03:00
README.md give rhel some love 2022-06-22 18:09:38 -06:00
av1.c Fix build for old libaom 2019-03-17 19:37:27 +03:00
av1.h Initial commit 2019-03-17 15:16:16 +03:00
avif.go Limit max number of threads as per libaom req 2019-08-29 10:43:17 +03:00
example_test.go make this use avif instead of heif 2022-09-15 15:55:41 +00:00
flake.lock make this use avif instead of heif 2022-09-15 15:55:41 +00:00
flake.nix test 2022-09-15 16:05:37 +00:00
go.mod make this use avif instead of heif 2022-09-15 15:55:41 +00:00
go.sum make this use avif instead of heif 2022-09-15 15:55:41 +00:00
gofmt-staged.sh Initial commit 2019-03-17 15:16:16 +03:00
mp4.go test 2022-09-15 16:05:37 +00:00

README.md

go-avif Build Status GoDoc

go-avif implements AVIF (AV1 Still Image File Format) encoder for Go using libaom, the high quality AV1 codec.

Requirements

Make sure libaom is installed. On typical Linux distro just run:

Debian (and derivatives):

sudo apt-get install libaom-dev

RHEL (and derivatives):

sudo dnf install libaom-devel

Usage

To use go-avif in your Go code:

import "github.com/Kagami/go-avif"

To install go-avif in your $GOPATH:

go get github.com/Kagami/go-avif

For further details see GoDoc documentation.

Example

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:

# 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. They include latest libaom from git at the moment of build.

Display

To display resulting AVIF files take a look at software listed here. E.g. use avif.js web viewer.

License

go-avif is licensed under CC0.