ffgoconv

package module
v0.0.0-...-40ddcf5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 8 Imported by: 3

README

ffgoconv

A real-time transmuxer with full control of individual streamers and the final muxing process.

Note

This library is heavily a work-in-progress and is deemed alpha. Although it works as-is, function signatures and functionality may change without notice.

Installing

go get github.com/Clinet/ffgoconv

Documentation

Auto-generated documentation can be found below.

GoDoc

Example

An example can be found in the example directory. It provides a bare-minimum implementation of ffgoconv and takes a time duration (in seconds) and ffmpeg stream locations as parameters, outputting audio to example/test.mp3.

License

The source code for ffgoconv is released under the MIT License. See LICENSE for more details.

Donations

All donations are appreciated and helps me focus on these projects more. Even if it's not much, it helps a lot in the long run!

Donate

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFFmpegNotRunning    = errors.New("ffgoconv: FFmpeg: not running")
	ErrFFmpegFilepathEmpty = errors.New("ffgoconv: filepath must not be empty")
)

Functions

This section is empty.

Types

type FFmpeg

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

FFmpeg contains all the data required to keep an FFmpeg process running and usable.

func NewFFmpeg

func NewFFmpeg(filepath string, args []string) (*FFmpeg, error)

NewFFmpeg returns an initialized *FFmpeg or an error if one could not be created.

If filepath is empty, the FFmpeg process will not start. You can specify any location supported by FFmpeg, such as a network location or a local filepath.

If args is nil or empty, the default values will be used. Do not specify your own arguments unless you understand how ffgoconv functions.

func (*FFmpeg) Close

func (ff *FFmpeg) Close()

Close closes the FFmpeg process gracefully and renders the struct unusable.

func (*FFmpeg) Err

func (ff *FFmpeg) Err() error

Err returns the last stored error. Error histories are not kept, so check as soon as something goes wrong.

func (*FFmpeg) IsRunning

func (ff *FFmpeg) IsRunning() bool

IsRunning returns whether or not the FFmpeg process is running, per the knowledge of ffgoconv.

func (*FFmpeg) Read

func (ff *FFmpeg) Read(data []byte) (n int, err error)

Read implements an io.Reader wrapper around *FFmpeg.stdout.

func (*FFmpeg) ReadError

func (ff *FFmpeg) ReadError(data []byte) (n int, err error)

ReadError implements an io.Reader wrapper around *FFmpeg.stderr.

func (*FFmpeg) Write

func (ff *FFmpeg) Write(data []byte) error

Write implements an io.Writer wrapper around *FFmpeg.stdin.

type Streamer

type Streamer struct {
	FFmpeg *FFmpeg
	Volume float64
	// contains filtered or unexported fields
}

Streamer contains all the data required to run a streaming session.

func NewStreamer

func NewStreamer(filepath string, args []string, volume float64) (*Streamer, error)

func (*Streamer) Close

func (streamer *Streamer) Close()

func (*Streamer) Err

func (streamer *Streamer) Err() error

Err returns the last stored error. Error histories are not kept, so check as soon as something goes wrong.

func (*Streamer) IsRunning

func (streamer *Streamer) IsRunning() bool

func (*Streamer) ReadSample

func (streamer *Streamer) ReadSample() (float64, error)

ReadSample returns the next audio sample from the streaming session.

func (*Streamer) SetVolume

func (streamer *Streamer) SetVolume(volume float64)

func (*Streamer) WriteSample

func (streamer *Streamer) WriteSample(sample float64) error

WriteSample writes a new audio sample to the streaming session.

type Transmuxer

type Transmuxer struct {
	sync.Mutex

	Streamers    []*Streamer
	FinalStream  *Streamer
	MasterVolume float64
	// contains filtered or unexported fields
}

Transmuxer contains all the data required to run a transmuxing session.

func NewTransmuxer

func NewTransmuxer(streamers []*Streamer, outputFilepath, codec, format, bitrate string, masterVolume float64) (*Transmuxer, error)

NewTransmuxer returns an initialized *Transmuxer or an error if one could not be created.

If streamers is nil, it will be initialized automatically with an empty slice of *Streamer.

If codec is not specified, the ffmpeg process will not start. A list of possible codecs can be found with "ffmpeg -codecs".

If format is not specified, the ffmpeg process will not start. A list of possible formats can be found with "ffmpeg -formats".

If bitrate is not specified, the ffmpeg process will not start.

The variable masterVolume must be a floating-point number between 0 and 1, representing a percentage value. For example, 20% volume would be 0.2.

If outputFilepath is empty, a buffer of float64 PCM values will be initialized and the returned *Transmuxer can be then used as an io.Reader.

If outputFilepath is "pipe:1", the FinalStream *Streamer can be used as an io.Reader to receive encoded audio data of the chosen codec in the chosen format.

func (*Transmuxer) AddRunningStreamer

func (transmuxer *Transmuxer) AddRunningStreamer(streamer *Streamer) (*Streamer, error)

AddRunningStreamer adds a pre-initialized *Streamer to the transmuxing session

func (*Transmuxer) AddStreamer

func (transmuxer *Transmuxer) AddStreamer(filepath string, args []string, volume float64) (*Streamer, error)

AddStreamer initializes and adds a *Streamer to the transmuxing session, or returns an error if one could not be initialized. See NewStreamer for info on supported arguments.

func (*Transmuxer) Close

func (transmuxer *Transmuxer) Close()

func (*Transmuxer) Err

func (transmuxer *Transmuxer) Err() error

Err returns the last stored error. Error histories are not kept, so check as soon as something goes wrong.

func (*Transmuxer) IsRunning

func (transmuxer *Transmuxer) IsRunning() bool

func (*Transmuxer) Read

func (transmuxer *Transmuxer) Read(data []byte) (n int, err error)

Read implements an io.Reader wrapper around *Transmuxer.FinalStream.FFmpeg.stdout.

func (*Transmuxer) Run

func (transmuxer *Transmuxer) Run()

func (*Transmuxer) SetMasterVolume

func (transmuxer *Transmuxer) SetMasterVolume(volume float64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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