WebP image decoder and encoder, a VP8 video codec and a VP9 video decoder, in pure Go.
A port of libwebp and libvpx, exact against them. No CGo, no dependencies.
SIMD support for amd64 (SSE2, AVX2), arm64 (NEON) and riscv64 (RVV, with GORISCV64=rva23u64).
Build with -tags noasm for pure Go everywhere.
img, err := webp.Decode(r)webp.Decode returns the planes the bitstream carries, *image.NYCbCrA in 4:2:0 for a lossy image and *image.NRGBA for a lossless one,
and registers itself with image.RegisterFormat. An animation frame is composited and comes back as *image.RGBA.
The vp8 package decodes the bitstream on its own, a frame at a time, and decodes video as well as
the key frames a still is made of:
d := vp8.Decoder{}
pic, err := d.DecodeFrame(data)The vp9 package decodes VP9, a container sample at a time; vp9.NewReader reads an IVF file:
d := vp9.Decoder{}
err := d.Send(sample)
pic, err := d.Receive()err := webp.Encode(w, img, webp.EncodeOptions{Quality: 90})EncodeOptions.Lossless writes VP8L, which is exact. webp.EncodeAll writes an animation.
The vp8 package encodes video, a key frame and then frames predicted from it:
e := vp8.Encoder{}
key, err := e.Encode(pic, vp8.EncodeOptions{Quality: 90})
next, err := e.EncodeInter(pic2, vp8.EncodeOptions{Quality: 90})There is no container that carries an inter frame yet, so a video stream needs a muxer of your own.
- WebP: lossy and lossless stills, alpha, animation with disposal and blending, and the
VP8Xcontainer with ICC, Exif and XMP, both ways - VP8 video, both ways
- VP9 decoding: all four profiles, 8, 10 and 12 bit, 4:2:0, 4:2:2, 4:4:0 and 4:4:4
Everything is exact against the reference: stills against libwebp in both directions, the VP8 and VP9 test vectors against
vpxdec, and the encoded VP8 video against libvpx.
WebP decoding is 1.09x to 1.21x slower than libwebp and lossy encoding 1.11x slower; lossless encoding is faster, by 1.07x and 1.9x on the two files measured. Threading is worth 1.41x on a 1080p still and 1.55x on a lossy encode, and every encode path allocates nothing per call.
The WebP decoder and encoder are a port of libwebp, BSD-3-Clause, in COPYING, with parts taken from webpkit, whose notice is in COPYING.webpkit. The VP9 decoder, and the VP8 tables taken from libvpx, are under libvpx's BSD-3-Clause, in COPYING.libvpx.
This project is an implementation of codecs. It gives you no special rights on the VP8 and VP9 patents. Please read the WebM patent grant that applies to the WebM codecs.