Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scalarhq/go-fluent-ffmpeg

A Go implementation of fluent-ffmpeg
https://github.com/scalarhq/go-fluent-ffmpeg

ffmpeg fluent-ffmpeg go go-fluent-ffmpeg

Last synced: 2 days ago
JSON representation

A Go implementation of fluent-ffmpeg

Awesome Lists containing this project

README

        

# Go Fluent FFmpeg [![GoDoc](https://pkg.go.dev/badge/github.com/modfy/fluent-ffmpeg)](https://pkg.go.dev/github.com/modfy/fluent-ffmpeg)

A Go version of [node-fluent-ffmpeg](https://github.com/fluent-ffmpeg/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:

```go
// 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:

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

You could use `context` to set the timeout:

```go
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.
```go
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](https://golang.org/pkg/os/exec/#Cmd) struct, with which you can have better control over the running process. For example, you can conditionally kill the FFmpeg command:

```go
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:
```go
data := fluentffmpeg.Probe("./video.avi")
```

## Credits

This repo was inspired by [node-fluent-ffmpeg](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg) and was built upon the work done by [@bitcodr](https://github.com/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