Go bindings for x264
Go to file
2020-06-05 14:55:39 +02:00
examples Remove camgrab example so travis can build 2018-02-16 13:37:20 +01:00
x264c Recompile analyse for linux/386 2020-06-05 14:55:39 +02:00
.appveyor.yml Initial commit 2018-02-16 00:37:05 +01:00
.travis.yml Update travis 2018-02-16 13:41:29 +01:00
AUTHORS Update AUTHORS 2020-04-20 16:43:01 +02:00
COPYING Initial commit 2018-02-16 00:37:05 +01:00
encode_test.go Test flush 2018-03-05 18:23:36 +01:00
encode.go Fix buffer memory leaks on Encode() 2020-04-20 16:41:21 +02:00
README.md Update README.md 2018-03-06 04:58:00 +01:00
ycbcr_test.go Initial commit 2018-02-16 00:37:05 +01:00
ycbcr.go Change memcpy parameter 3 to size_t 2020-04-20 16:42:24 +02:00

x264-go

TravisCI Build Status AppVeyor Build Status GoDoc Go Report Card

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.

Installation

go get -u github.com/gen2brain/x264-go

Examples

See screengrab example.

Usage

package main

import (
	"bytes"
	"image"
	"image/color"
	"image/draw"

	"github.com/gen2brain/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)
	}
}

More

For AAC encoder see aac-go.