Documentation ¶
Overview ¶
Package avif implements a AVIF image encoder.
The AVIF specification is at https://aomediacodec.github.io/av1-avif/.
Example ¶
package main import ( "image" _ "image/jpeg" "log" "os" "github.com/Kagami/go-avif" ) const usageHelp = "Usage: %s src.jpg dst.avif" func main() { if len(os.Args) != 3 { log.Fatalf(usageHelp, 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) }
Output:
Index ¶
Examples ¶
Constants ¶
const ( MinSpeed = 0 MaxSpeed = 8 MinQuality = 0 MaxQuality = 63 )
Encoder constants.
Variables ¶
var DefaultOptions = Options{ Threads: 0, Speed: 4, Quality: 25, SubsampleRatio: nil, }
DefaultOptions defines default encoder config.
Functions ¶
func Encode ¶
Encode writes the Image m to w in AVIF format with the given options. Default parameters are used if a nil *Options is passed.
NOTE: Image pixels are converted to RGBA first using standard Go library. This is no-op for PNG images and does the right thing for JPEG since they are normally stored as BT.601 full range with some chroma subsampling. Then pixels are converted to BT.709 limited range with specified chroma subsampling.
Alpha channel and monochrome are not supported at the moment. Only 4:2:0 8-bit images are supported at the moment.
Types ¶
type EncoderError ¶
type EncoderError int
An EncoderError reports that the encoder error has occured.
func (EncoderError) Error ¶
func (e EncoderError) Error() string
func (EncoderError) ToString ¶
func (e EncoderError) ToString() string
type MuxerError ¶
type MuxerError string
A MuxerError reports that the muxer error has occured.
func (MuxerError) Error ¶
func (e MuxerError) Error() string
type Options ¶
type Options struct { Threads int Speed int Quality int SubsampleRatio *image.YCbCrSubsampleRatio }
Options are the encoding parameters. Threads ranges from 1, 0 means use all available cores. Speed ranges from MinSpeed to MaxSpeed. Quality ranges from MinQuality to MaxQuality, lower is better, 0 means lossless encoding. SubsampleRatio specifies subsampling of the encoded image, nil means 4:2:0.
type OptionsError ¶
type OptionsError string
An OptionsError reports that the passed options are not valid.
func (OptionsError) Error ¶
func (e OptionsError) Error() string