gostreamer

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

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 10 Imported by: 0

README

gostreamer

go package for playing with the gstreamer (gstlaunch) cli.

supported image formats (DataSinks):

  • GRAY8
  • RGB
  • BGR
  • RGBA
  • BGRA

opencv support:

  • you can also produce gocv Mat objects from video sinks

TODO:

  • audiosink support (DataSink)
  • better documentation
  • support more image formats for DataSinks

NOTES:

  • FdSink does not work on windows

example:

package main

import (
	"context"
	"fmt"
	"runtime"

	"github.com/tinogoehlert/gostreamer/gocv"

	"github.com/tinogoehlert/gostreamer"
	"gocv.io/x/gocv"
)

func main() {
	runtime.LockOSThread()
	gst, _ := gostreamer.NewGstreamer()
	fdsink := gostreamer.NewFdSink()
	gst.AddStr("avfvideosrc").
		AddStr("videoconvert").
		AddStr("video/x-raw, framerate=25/1,format=BGR").
		AddStr("videoscale").
		AddSink(fdsink)

	imager := gocvstreamer.NewCvImager(fdsink)
	window := gocv.NewWindow("Simple test")
	defer window.Close()

	imager.ProduceMat(context.Background(), func(mat gocv.Mat) error {
		window.IMShow(mat)
		if window.WaitKey(1) >= 0 {
			return fmt.Errorf("interrupted")
		}
		return nil
	})
}

Documentation

Index

Constants

View Source
const (
	// GstCapsFilter cap we will rely on
	GstCapsFilter = "GstCapsFilter"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Caps

type Caps struct {
	Width       int
	Height      int
	Framerate   int
	PixelFormat string
	Channels    int
	Type        string
	Name        string
}

Caps represents caps

type CommonSink

type CommonSink struct {
	Sinker
}

CommonSink represents a common sink (e.g. videosink, autovideosink or udpsink)

func NewCommonSink

func NewCommonSink(cmds ...string) *CommonSink

NewCommonSink creates a new common sink (e.g. videosink, autovideosink or udpsink)

func (*CommonSink) Start

func (s *CommonSink) Start(ctx context.Context) (*Caps, error)

Start starts the pipeline with the given sink (blocking)

type DataSink

type DataSink interface {
	Sink
	DataChan() chan []byte
}

DataSink represents a sink which returns data

type FdSink

type FdSink struct {
	Sinker
}

FdSink represents an fdsink element

func NewFdSink

func NewFdSink() *FdSink

NewFdSink creates a new fdsink

func (*FdSink) Start

func (s *FdSink) Start(ctx context.Context) (*Caps, error)

Start starts the pipeline with the given fdsink. Blocks until GstCapsFilter was found. use DataChan() to receive image buffers

type Gstreamer

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

Gstreamer represents a gstreamer pipe

func NewGstreamer

func NewGstreamer(args ...string) (*Gstreamer, error)

NewGstreamer creates a new Gstreamer instance

func NewGstreamerFromPath

func NewGstreamerFromPath(gstBin string, args ...string) (*Gstreamer, error)

NewGstreamerFromPath creates a new Gstreamer instance, uses given path to gst-launch binary

func (*Gstreamer) Add

func (gp *Gstreamer) Add(p GstreamerPlugin) *Gstreamer

Add add a GstreamerPlugin to the pipe

func (*Gstreamer) AddSink

func (gp *Gstreamer) AddSink(sink Sink) Sink

AddSink adds a sink to pipe

func (*Gstreamer) AddStr

func (gp *Gstreamer) AddStr(p ...string) *Gstreamer

AddStr Creates a GstreamerGenericPlugin from given string and adds it to the pipe

func (*Gstreamer) PipeString

func (gp *Gstreamer) PipeString() (out string)

PipeString outputs the current pipe

type GstreamerGenericPlugin

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

GstreamerGenericPlugin generic gstreamer plugin

func (GstreamerGenericPlugin) Cmds

func (p GstreamerGenericPlugin) Cmds() []string

type GstreamerPlugin

type GstreamerPlugin interface {
	Cmds() []string
}

GstreamerPlugin gstreamer plugin interface

func Queue

func Queue() GstreamerPlugin

Queue returns the queue plugin

type Imager

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

Imager produces go image objects

func NewImager

func NewImager(sink DataSink) *Imager

func (*Imager) ProduceImage

func (im *Imager) ProduceImage(ctx context.Context, cb func(mat image.Image) error) error

type Sink

type Sink interface {
	Gst() *Gstreamer
	Cmds() []string
	Run()
	Start(ctx context.Context) (*Caps, error)
	// contains filtered or unexported methods
}

Sink generic sink interface

type Sinker

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

Sinker generic sinker

func (*Sinker) CapsAll

func (s *Sinker) CapsAll() *map[string]Caps

CapsAll returns all captured caps

func (*Sinker) Cmds

func (s *Sinker) Cmds() []string

Cmds returns list of given commands

func (*Sinker) DataChan

func (s *Sinker) DataChan() chan []byte

DataChan returns a channel to receive the data from the sink.

func (*Sinker) Gst

func (s *Sinker) Gst() *Gstreamer

Gst returns the parent Gstreamer instance

func (*Sinker) Run

func (s *Sinker) Run()

Run runs the pipeline with the given sink

Directories

Path Synopsis
examples
dnn
rtp

Jump to

Keyboard shortcuts

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