x264

package module
v0.0.0-...-a066af4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2020 License: GPL-2.0 Imports: 7 Imported by: 0

README

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.

Documentation

Overview

Package x264 provides H.264/MPEG-4 AVC codec encoder based on x264(https://www.videolan.org/developers/x264.html) library.

Index

Constants

View Source
const (
	LogNone int32 = iota - 1
	LogError
	LogWarning
	LogInfo
	LogDebug
)

Logging constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder type.

func NewEncoder

func NewEncoder(w io.Writer, opts *Options) (e *Encoder, err error)

NewEncoder returns new x264 encoder.

func (*Encoder) Close

func (e *Encoder) Close() error

Close closes encoder.

func (*Encoder) Encode

func (e *Encoder) Encode(im image.Image) (err error)

Encode encodes image.

func (*Encoder) Flush

func (e *Encoder) Flush() (err error)

Flush flushes encoder.

type Options

type Options struct {
	// Frame width.
	Width int
	// Frame height.
	Height int
	// Frame rate.
	FrameRate int
	// Tunings: film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency.
	Tune string
	// Presets: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.
	Preset string
	// Profiles: baseline, main, high, high10, high422, high444.
	Profile string
	// Log level.
	LogLevel int32
}

Options represent encoding options.

type YCbCr

type YCbCr struct {
	*image.YCbCr
}

YCbCr is an in-memory image of Y'CbCr colors.

func NewYCbCr

func NewYCbCr(r image.Rectangle) *YCbCr

NewYCbCr returns a new YCbCr image with the given bounds and subsample ratio.

func (*YCbCr) Set

func (p *YCbCr) Set(x, y int, c color.Color)

Set sets pixel color.

func (*YCbCr) ToYCbCr

func (p *YCbCr) ToYCbCr(src image.Image)

ToYCbCr converts image.Image to YCbCr.

Directories

Path Synopsis
examples
Package x264c implements cgo bindings for [x264](https://www.videolan.org/developers/x264.html) library.
Package x264c implements cgo bindings for [x264](https://www.videolan.org/developers/x264.html) library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL