fluentffmpeg

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: Apache-2.0 Imports: 11 Imported by: 2

README

Go Fluent FFmpeg GoDoc

A Go version of node-fluent-ffmpeg.

Installation

go get -u github.com/modfy/fluent-ffmpeg

Requirements

You will need FFmpeg installed on your machine, or you can specify a path to a binary:

// Provide an empty string to use default FFmpeg path
cmd := fluentffmpeg.NewCommand("")

// Specify a path
cmd = fluentffmpeg.NewCommand("/path/to/ffmpeg/binary")

Quick Start

Create and run commands using an API similar to node-fluent-ffmpeg:

err := fluentffmpeg.NewCommand(""). 
		InputPath("/path/to/video.avi").
		OutputFormat("mp4").
		OutputPath("/path/to/video.mp4").
		Run()

You could use context to set the timeout:

ctx, cancel := context.WithTimeout(context.Background(), time.Second * 5)
defer cancel()
err := fluentffmpeg.NewCommand(""). 
		InputPath("/path/to/video.avi").
		OutputFormat("mp4").
		OutputPath("/path/to/video.mp4").
		RunWithContext(ctx)

If you want to view the errors/logs returned from FFmpeg, provide an io.Writer to receive the data.

buf := &bytes.Buffer{}
err := fluentffmpeg.NewCommand("").
		InputPath("./video.avi").
		OutputFormat("mp4").
		OutputPath("./video.mp4").
		Overwrite(true).
		OutputLogs(buf). // provide a io.Writer
		Run()

out, _ := ioutil.ReadAll(buf) // read logs
fmt.Println(string(out))

You can also get the command in the form of an exec.Cmd struct, with which you can have better control over the running process. For example, you can conditionally kill the FFmpeg command:

done := make(chan error, 1)
cmd := fluentffmpeg.NewCommand("").
		InputPath("./video.avi").
		OutputFormat("mp4").
		OutputPath("./video.mp4").
		Overwrite(true).
		Build()
cmd.Start()

go func() {
    done <- cmd.Wait()
}()

select {
case <-time.After(time.Second * 5):
    fmt.Println("Timed out")
    cmd.Process.Kill()
case <-done:
}

FFprobe is also available for use and returns a map[string]interface{} of JSON data:

data := fluentffmpeg.Probe("./video.avi")

Credits

This repo was inspired by node-fluent-ffmpeg and was built upon the work done by @bitcodr in the https://github.com/bitcodr/gompeg

Managed Version

You can deploy this codebase yourself or you an entirely managed api from the creators at https://api.modfy.video

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Probe

func Probe(filePath string) (map[string]interface{}, error)

Probe runs ffprobe with the filePath as input and returns the response as JSON

func SetFfProbePath

func SetFfProbePath(path string)

SetFfProbePath sets the path for the ffprobe executable

Types

type Args

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

Args contains the input and output args set for FFmpeg

func (*Args) GetAspectRatio

func (a *Args) GetAspectRatio() []string

GetAspectRatio returns the arguments for aspect ratio

func (*Args) GetAudioBitrate

func (a *Args) GetAudioBitrate() []string

GetAudioBitrate returns the arguments for bitrate

func (*Args) GetAudioChannels

func (a *Args) GetAudioChannels() []string

GetAudioChannels returns the audio channels

func (*Args) GetAudioCodec

func (a *Args) GetAudioCodec() []string

GetAudioCodec returns the audio codec

func (*Args) GetAudioRate

func (a *Args) GetAudioRate() []string

GetAudioRate returns the arguments for audio rate

func (*Args) GetBufferSize

func (a *Args) GetBufferSize() []string

GetBufferSize returns the buffer size

func (*Args) GetConstantRateFactor

func (a *Args) GetConstantRateFactor() []string

GetConstantRateFactor gets the constant rate factor (CRF) for video encoding

func (*Args) GetFormat

func (a *Args) GetFormat() []string

GetFormat returns the output format

func (*Args) GetFrameRate

func (a *Args) GetFrameRate() []string

GetFrameRate returns the arguments for frame rate

func (*Args) GetFromFormat

func (a *Args) GetFromFormat() []string

GetFromFormat returns the input format

func (*Args) GetInputOptions

func (a *Args) GetInputOptions() []string

GetInputOptions returns additional input options

func (*Args) GetInputPath

func (a *Args) GetInputPath() []string

GetInputPath returns the input file path

func (*Args) GetKeyframeInterval

func (a *Args) GetKeyframeInterval() []string

GetKeyframeInterval returns the key frame interval

func (*Args) GetOutputOptions

func (a *Args) GetOutputOptions() []string

GetOutputOptions returns the additional output options

func (*Args) GetOutputPath

func (a *Args) GetOutputPath() []string

GetOutputPath returns the output path

func (*Args) GetOverwrite

func (a *Args) GetOverwrite() []string

GetOverwrite returns whether or not FFmpeg is set to pipe its output

func (*Args) GetPipeInput

func (a *Args) GetPipeInput() []string

GetPipeInput returns whether or not ffmpeg is set to receive piped input

func (*Args) GetPipeOutput

func (a *Args) GetPipeOutput() []string

GetPipeOutput returns whether or not ffmpeg is set to receive piped output

func (*Args) GetPixelFormat

func (a *Args) GetPixelFormat() []string

GetPixelFormat returns the pixel format

func (*Args) GetPreset

func (a *Args) GetPreset() []string

GetPreset returns the preset

func (*Args) GetQuality

func (a *Args) GetQuality() []string

GetQuality returns the quality

func (*Args) GetVFrames

func (a *Args) GetVFrames() []string

GetVFrames returns the arguments for vframes

func (*Args) GetVideoBitRate

func (a *Args) GetVideoBitRate() []string

GetVideoBitRate returns returns the arguments for video bit rate

func (*Args) GetVideoBitRateTolerance

func (a *Args) GetVideoBitRateTolerance() []string

GetVideoBitRateTolerance returns the arguments for video bit rate tolerance

func (*Args) GetVideoCodec

func (a *Args) GetVideoCodec() []string

GetVideoCodec returns the arguments for video codec

func (*Args) GetVideoMaxBitrate

func (a *Args) GetVideoMaxBitrate() []string

GetVideoMaxBitrate returns the arguments for video max bit rate

func (*Args) GetVideoMinBitrate

func (a *Args) GetVideoMinBitrate() []string

GetVideoMinBitrate returns the arguments for video min bit rate

type Command

type Command struct {
	FFmpegPath string
	Args       *Args
	// contains filtered or unexported fields
}

Command is a struct that holds arguments and their values to run FFmpeg

func NewCommand

func NewCommand(ffmpegPath string) *Command

NewCommand returns a new Command

func (*Command) AspectRatio

func (c *Command) AspectRatio(v string) *Command

AspectRatio gets the aspect ratio. Ex: "16:9"

func (*Command) AudioBitRate

func (c *Command) AudioBitRate(v int) *Command

AudioBitRate sets the audio bit rate

func (*Command) AudioChannels

func (c *Command) AudioChannels(v int) *Command

AudioChannels sets the number of audio channels to use.

func (*Command) AudioCodec

func (c *Command) AudioCodec(v string) *Command

AudioCodec sets the audio codec to use

func (*Command) AudioRate

func (c *Command) AudioRate(v int) *Command

AudioRate sets the audio sampling rate

func (*Command) BufferSize

func (c *Command) BufferSize(v int) *Command

BufferSize sets the buffer size

func (*Command) Build

func (c *Command) Build() *exec.Cmd

Build returns an exec.Cmd struct ready to run the FFmpeg command with its arguments

func (*Command) BuildWithContext

func (c *Command) BuildWithContext(ctx context.Context) *exec.Cmd

BuildWithContext is like Build but includes a context which is used to kill the process

func (*Command) ConstantRateFactor

func (c *Command) ConstantRateFactor(v int) *Command

ConstantRateFactor sets the constant rate factor (CRF) for video encoding

func (*Command) FrameRate

func (c *Command) FrameRate(v int) *Command

FrameRate sets the frames per second

func (*Command) FromFormat

func (c *Command) FromFormat(format string) *Command

FromFormat sets the format of the input

func (*Command) GetArgs

func (c *Command) GetArgs() []string

GetArgs returns the arguments for the FFmpeg command.

func (*Command) InputOptions

func (c *Command) InputOptions(options ...string) *Command

InputOptions sets additional input options

func (*Command) InputPath

func (c *Command) InputPath(v string) *Command

InputPath sets the path of the input file

func (*Command) KeyframeInterval

func (c *Command) KeyframeInterval(v int) *Command

KeyframeInterval sets the keyframe interval.

func (*Command) NativeFramerateInput

func (c *Command) NativeFramerateInput(v bool) *Command

NativeFramerateInput sets the native frame rate

func (*Command) Options

func (c *Command) Options(options ...string) *Command

Options is intended for configuring global options that are not affected by their position in the FFmpeg command

func (*Command) OutputFormat

func (c *Command) OutputFormat(v string) *Command

OutputFormat sets the format of the output

func (*Command) OutputLogs

func (c *Command) OutputLogs(writer io.Writer) *Command

OutputLogs sets the destination to write the FFmpeg log output to

func (*Command) OutputOptions

func (c *Command) OutputOptions(options ...string) *Command

OutputOptions sets additional output options

func (*Command) OutputPath

func (c *Command) OutputPath(v string) *Command

OutputPath sets the path to write the output file

func (*Command) Overwrite

func (c *Command) Overwrite(b bool) *Command

Overwrite configures FFmpeg to overwrite existing files

func (*Command) PipeInput

func (c *Command) PipeInput(input io.Reader) *Command

PipeInput sets the input to be read from an io.Reader

func (*Command) PipeOutput

func (c *Command) PipeOutput(output io.Writer) *Command

PipeOutput sets the output to be written to an io.Writer

func (*Command) PixelFormat

func (c *Command) PixelFormat(v string) *Command

PixelFormat sets the pixel format.

func (*Command) Preset

func (c *Command) Preset(v string) *Command

Preset sets the preset

func (*Command) Quality

func (c *Command) Quality(v int) *Command

Quality sets the quality

func (*Command) Resolution

func (c *Command) Resolution(v string) *Command

Resolution gets the resolution of the media. Ex: "100x100"

func (*Command) Run

func (c *Command) Run() error

Run runs the FFmpeg command. It returns an error if the command fails with exit status code 1. This error message only signifies that the command returned a non-zero status code, read from stderr to see more comprehensive FFmpeg errors.

func (*Command) RunWithContext

func (c *Command) RunWithContext(ctx context.Context) error

RunWithContext is like Run but includes a context which is used to kill the process

func (*Command) VFrames

func (c *Command) VFrames(v int) *Command

VFrames sets the number of frames to output

func (*Command) VideoBitRate

func (c *Command) VideoBitRate(v int) *Command

VideoBitRate gets the video bit rate.

func (*Command) VideoBitRateTolerance

func (c *Command) VideoBitRateTolerance(v int) *Command

VideoBitRateTolerance gets the video bit rate tolerance.

func (*Command) VideoCodec

func (c *Command) VideoCodec(v string) *Command

VideoCodec gets the desired video codec when working with video.

func (*Command) VideoMaxBitrate

func (c *Command) VideoMaxBitrate(v int) *Command

VideoMaxBitrate gets the max bit rate for the video.

func (*Command) VideoMinBitrate

func (c *Command) VideoMinBitrate(v int) *Command

VideoMinBitrate gets the max bit rate for the video.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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