VP8 and VP9 decoders in pure Go, no cgo. Packages vp8 and vp9 decode
packets to planar YUV (VP9 profiles 0 and 1; profiles 2 and 3 return
vpx.ErrVP9NotImplemented). The shared vpx package holds Image and the
error sentinels.
d, err := vp9.New(vp9.Options{MaxWidth: 4096, MaxHeight: 2304, Threads: 4, RowMT: true})
// ...
if err := d.DecodeWithPTS(packet, pts); err == nil {
if img, ok := d.NextFrame(); ok { /* img is valid until the next decode */ }
}This release is a port of the decoder subset of
govpx v0.5.3 (BSD-3-Clause), extracted by
tools/portgovpx (a per-declaration closure of the decoder, written in Go with a
test), so that every later change is made here and measured against libvpx.
The design is in docs/design/vpx-decoder.md.
At M0 the decoded picture is vpx.Image, a view of the decoder's buffers; the
design's Picture type replaces it later. The package has no extra behaviour
over govpx v0.5.3: the same 376 libvpx test vectors decode to the same md5 of
every picture, with 0 and with 4 threads.
Changes from govpx v0.5.3 (each is also noted in the file): internal/vpx/buffers/aligned.go
rounds up to a power of two with math/bits, because govpx's v >> 32 does not compile
for 32-bit targets.
Since v0.3.0 the amd64 hot loops come from
go-videodsp/kernels (AVX2, chosen at run time by
cpu.HasAVX2, the previous code as the fallback): the VP9 loop filters and 8-tap convolutions, and
since v0.5.0 the VP8 loop filters and six-tap/bilinear predictors. On a Ryzen 9 7950X, one core,
crowd_run 1080p, VP8 decodes in 3437 µs per frame against 4942 for v0.4.0 (1.44x); the table is in
docs/perf/speed-log.md.
LIBVPX_VECTORS_DIR=DIR go test ./...decodes libvpx's 376 decoder vectors and compares every picture's md5 with libvpx's.go run ./tools/vpxfetch --manifests testdata/libvpx --dir DIR(a module of its own, intools/) downloads them. Without the variable the vector tests are skipped and say so.- Fuzz targets with committed corpora:
FuzzReadBool(the boolean decoder against RFC 6386, far past the end of the data),FuzzVP8DecodeandFuzzVP9Decode(any two packets; the size cap bounds allocation). - The ported tree (
internal/) is not held to the 100 % coverage gate of the sibling repositories: it is measured by the vectors. Hand-written code is.
BSD-3-Clause, see LICENSE. Derived files cite their govpx path
(third_party/govpx/), and where govpx cites a libvpx source file, that file's
licence and patent grant are in third_party/libvpx/. The AV1-derived SIMD
kernels carry goav1's licence in third_party/goav1/ and the AOM patent grant is
PATENTS.