Go bindings for x264
Go to file
2022-08-28 16:25:11 +02:00
.github/workflows Update action 2021-10-14 03:00:35 +02:00
examples Update modules 2021-05-23 21:28:09 +02:00
x264c Test param size 2022-08-28 16:19:59 +02:00
yuv Optimize ToYCbCr 2021-05-23 20:51:53 +02:00
.appveyor.yml Initial commit 2018-02-16 00:37:05 +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 Optimize ToYCbCr 2021-05-23 20:51:53 +02:00
go.mod Update modules 2022-08-28 16:25:11 +02:00
go.sum Update modules 2022-08-28 16:25:11 +02:00
README.md Remove compat tag 2022-08-28 15:57:40 +02:00
ycbcr_test.go Initial commit 2018-02-16 00:37:05 +01:00
ycbcr.go Optimize ToYCbCr 2021-05-23 20:51:53 +02:00

x264-go

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

Build tags

  • extlib - use external x264 library
  • pkgconfig - enable pkg-config (used with extlib)

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.