Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/scalarhq/go-fluent-ffmpeg
- Owner: scalarhq
- License: apache-2.0
- Created: 2021-01-30T19:46:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-22T19:50:54.000Z (about 1 year ago)
- Last Synced: 2025-01-20T11:08:40.320Z (10 days ago)
- Topics: ffmpeg, fluent-ffmpeg, go, go-fluent-ffmpeg
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 344
- Watchers: 8
- Forks: 20
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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