x264-go
provides H.264/MPEG-4 AVC codec encoder based on x264 library.
C source code is included in package. If you want to use external shared/static library (i.e. built with asm and/or OpenCL) use -tags extlib
go get -u github.com/samespace/x264-go
extlib
- use external x264 librarycompat
- enable compat mode (for versions < 0.153.x, used with extlib)pkgconfig
- enable pkg-config (used with extlib)
See screengrab example.
package main
import (
"bytes"
"image"
"image/color"
"image/draw"
"github.com/samespace/x264-go"
)
func main() {
buf := bytes.NewBuffer(make([]byte, 0))
opts := &x264.Options{
Width: 640,
Height: 480,
FrameRate: 25,
Tune: "zerolatency",
Preset: "veryfast",
Profile: "baseline",
LogLevel: x264.LogDebug,
}
enc, err := x264.NewEncoder(buf, opts)
if err != nil {
panic(err)
}
img := x264.NewYCbCr(image.Rect(0, 0, opts.Width, opts.Height))
draw.Draw(img, img.Bounds(), image.Black, image.ZP, draw.Src)
for i := 0; i < opts.Width/2; i++ {
img.Set(i, opts.Height/2, color.RGBA{255, 0, 0, 255})
err = enc.Encode(img)
if err != nil {
panic(err)
}
}
err = enc.Flush()
if err != nil {
panic(err)
}
err = enc.Close()
if err != nil {
panic(err)
}
}
For AAC encoder see aac-go.