simplevid

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: LGPL-2.1 Imports: 5 Imported by: 0

README

simplevid-go

simplevid-go は、とても簡単に利用できるGo言語向けビデオエンコーダです。

  • エンコーダに渡したコールバックが1フレームごとに呼び出されるので、その中で画素を描画するだけでビデオを作成することができます。
  • 現時点では、フォーマットは H264 YUV420 に固定されています。
  • 使用例は imageencoder_test.go, callbackencoder_test.go をお読みください。

必須環境

  • 以下のいずれかのOS
    • Windows + WSL
    • Linux
    • macOS(動作はしますが、作成された動画はQuicktimeで再生できない場合があります)
  • 依存ライブラリ
    • libavcodec
    • libavutil
    • libavformat
# Ubuntu
sudo apt install libavcodec-dev libavutil-dev libavformat-dev

ライセンス

libav公式サンプル をベースに実装しているため、これと同様に LGPL 2.1 or later とします。

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackEncoder added in v0.2.0

type CallbackEncoder interface {
	Encoder
	// Options は、このエンコーダに指定されたオプションを返します。
	Options() EncoderOptions
	// Frame は、現在エンコード中のフレーム番号を返します。
	Frame() int
	// SetY は、Yチャンネルの位置 (x, y) における画素値を設定します。
	SetY(x, y int, value uint8)
	// SetU は、Uチャンネルの位置 (x*2, y*2) - (x*2+1, y*2+1) における画素値を設定します。
	SetU(xHalf, yHalf int, value uint8)
	// SetV は、Vチャンネルの位置 (x*2, y*2) - (x*2+1, y*2+1) における画素値を設定します。
	SetV(xHalf, yHalf int, value uint8)
}

CallbackEncoder は、コールバック中で画素を描画するビデオエンコーダです。

Example
filename := "example-callback-encoder.mp4"
os.Remove(filename)

opts := simplevid.EncoderOptions{
	Width:   1280,
	Height:  720,
	BitRate: 4 * 1024 * 1024,
	GOPSize: 10,
	FPS:     30,
}
e := simplevid.NewCallbackEncoder(opts, func(e simplevid.CallbackEncoder) bool {
	frame := e.Frame()
	if frame == 30 {
		return false
	}
	opts := e.Options()
	for y := 0; y < opts.Height; y++ {
		for x := 0; x < opts.Width; x++ {
			e.SetY(x, y, uint8(x+y+frame*3))
		}
	}
	for y := 0; y < opts.Height/2; y++ {
		for x := 0; x < opts.Width/2; x++ {
			e.SetU(x, y, uint8(128+y+frame*2))
			e.SetV(x, y, uint8(64+x+frame*5))
		}
	}
	return true
})
if err := e.EncodeToFile(filename); err != nil {
	panic(err)
}

if _, err := os.Stat(filename); err != nil {
	panic(err)
}
fmt.Printf("%s is created.\n", filename)
Output:

example-callback-encoder.mp4 is created.

func NewCallbackEncoder added in v0.2.0

func NewCallbackEncoder(opts EncoderOptions, onDraw func(CallbackEncoder) bool) CallbackEncoder

NewCallbackEncoder は、新しい CallbackEncoder を返します。

type Encoder

type Encoder interface {
	// EncodeToFile は、ビデオをエンコードしてファイルに保存します。
	EncodeToFile(filename string) error
}

Encoder は、ビデオエンコーダです。

func NewImageEncoder added in v0.2.0

func NewImageEncoder(opts EncoderOptions, ch <-chan image.Image) Encoder

NewImageEncoder は、フレーム画像をチャネル経由で Image として渡す方式の新しい Encoder を返します。

type EncoderOptions

type EncoderOptions struct {
	// Width は、ビデオ画面の横幅 [px] です。
	Width int
	// Height は、ビデオ画面の縦幅 [px] です。
	Height int
	// BitRate は、ビットレート [byte/sec] です。
	BitRate int
	// GOPSize は、GOP (Group Of Picture) フレーム数です。
	GOPSize int
	// FPS は、1秒あたりのフレーム数です。
	FPS int
}

EncoderOptions は、ビデオエンコーダのオプションです。

Jump to

Keyboard shortcuts

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