Skip to content

vp8enc

vp8enc

github.com/go-avkit/avkit/vp8enc writes WebM video in pure Go, with no cgo and no libvpx: frames in, a VP8 track in a WebM file out. The bitstream comes from thesyncim/govpx (v0.5.3 from avkit v0.20.3); the file is written by container.WebMMuxer.

Build with GOEXPERIMENT=simd

govpx has Go 1.27 SIMD kernels (amd64 AVX2, arm64). They are compiled only when the final program is built with GOEXPERIMENT=simd; a plain go build runs scalar fallbacks. A library cannot set the experiment for the programs that import it, so the choice is yours:

GOEXPERIMENT=simd go build ./...

The output is byte-identical between the two builds, so nothing else changes. CI runs the suite in both, and one test holds the same output hash in every lane.

Measured at 720p, 800 kbit/s, on one core of an AMD Ryzen 9 7950X (Zen 4):

presetscalar (plain build)GOEXPERIMENT=simdgain
good, CPUUsed 440 fps146 fps3.6x
default (CPUUsed 5)259 fps423 fps1.6x

The good preset measures 45.60 dB in both builds.

Profile-guided optimization

Go applies a default.pgo file only to the main package being built. avkit has no main package, so it cannot ship a profile: the profile belongs to your program. Record a CPU profile of it encoding representative frames (runtime/pprof, or go test -cpuprofile for a harness that encodes), merge several with go tool pprof -proto a.prof b.prof > default.pgo, save the result as default.pgo next to your main, and build with GOEXPERIMENT=simd as above. go build uses it without a flag, and the output stays byte-identical.

Measured at 720p, good CPUUsed 4, one core, six interleaved rounds, on clips the profile was not trained on:

profile trained ontest clipgain
one UI sequence (1280x720)scrolling text screen+4.0 %
samepanned photograph 1+3.7 %
samepanned photograph 2+3.2 %
sameUI sequence 1366x768+3.3 %
text screen + photograph 1UI sequence 1280x720+6.2 %
samepanned photograph 2+3.4 %
sameUI sequence 1366x768+5.5 %

Two copies of the same binary differ by up to 1 % in the same rounds, so the gain is real but modest: about 3 to 6 %. A profile from several kinds of content did better than one from a single clip. The “natural” clips are pans across photographs with temporal noise, not video, and the default preset (CPUUsed 5) was not measured.