Skip to content
Go bindings for x264
Go
Branch: master
Clone or download
Latest commit 58f5861 Mar 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Remove camgrab example so travis can build Feb 16, 2018
x264c Fix arm64 Mar 5, 2018
.appveyor.yml Initial commit Feb 15, 2018
.travis.yml Update travis Feb 16, 2018
AUTHORS Initial commit Feb 15, 2018
COPYING Initial commit Feb 15, 2018
README.md Update README.md Mar 6, 2018
encode.go Initial commit Feb 15, 2018
encode_test.go Test flush Mar 5, 2018
ycbcr.go Golint Feb 15, 2018
ycbcr_test.go Initial commit Feb 15, 2018

README.md

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.

You can’t perform that action at this time.