Go bindings for x264
Go to file
2023-09-28 16:20:09 +08:00
.github/workflows Update actions 2022-12-04 09:21:21 +01:00
examples Update modules 2023-03-07 11:34:34 +01:00
x264c Update modules 2022-12-04 09:48:22 +01:00
yuv Update modules 2022-12-04 09:48:22 +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 Expose ratecontrol options, issue #26 2023-04-28 06:42:54 +02:00
encode.go Export PTS and DTS as they are required for downstream muxers 2023-09-28 16:20:09 +08:00
go.mod Update modules, issue #23 2022-12-24 05:45:16 +01:00
go.sum Update modules, issue #23 2022-12-24 05:45:16 +01:00
README.md Update actions 2022-12-04 09:21:21 +01: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 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.