add examples

This commit is contained in:
sorcererxw
2022-04-19 18:41:01 +08:00
parent 8c657227c0
commit 01e0e50dd5
19 changed files with 134 additions and 27 deletions

View File

@@ -1,22 +1,14 @@
# ffstatic
Embed ffmpeg and ffprobe static binaries into your go
program and use them without preinstalled binaries.
Embed ffmpeg and ffprobe static binaries into your go program and use them without preinstalled binaries.
This project is inspired
by [ffmpeg-static](https://github.com/eugeneware/ffmpeg-static)
.
This project is inspired by [ffmpeg-static](https://github.com/eugeneware/ffmpeg-static).
## How it works
We use go embed to embed the ffmpeg/ffprobe binaries as
bytes in go program. The real ffmpeg/ffprobe executable
files would be created in system temp directory when you run
the program.
We use go embed to embed the ffmpeg/ffprobe binaries as bytes in go program. The real ffmpeg/ffprobe executable files would be created in system temp directory when you run the program.
With this package, you can use ffmpeg/ffprobe without
preinstalling. It would be very helpful to run program on
serverless platform (ie. lambda\Vercel).
With this package, you can use ffmpeg/ffprobe without preinstalling. It would be very helpful to run program on serverless platform (ie. lambda/Vercel).
## Installation
@@ -24,49 +16,82 @@ Choose the version matched with your environment.
- Darwin
- amd64
```sh
go get -u github.com/go-ffstatic/darwin-amd64
```
- arm64
```sh
go get -u github.com/go-ffstatic/darwin-arm64
```
- Linux
- amd64
```sh
go get -u github.com/go-ffstatic/linux-amd64
```
- arm64
```sh
go get -u github.com/go-ffstatic/linux-arm64
```
- arm
```sh
go get -u github.com/go-ffstatic/linux-arm
```
- 386
```sh
go get -u github.com/go-ffstatic/linux-386
```
- Windows
- amd64
```sh
go get -u github.com/go-ffstatic/windows-amd64
```
- 386
```sh
go get -u github.com/go-ffstatic/windows-386
```
- FreeBSD
- amd64
```sh
go get -u github.com/go-ffstatic/freebsd-amd64
```
## How to use
## Basic Usage
## Cross compiling
You can use `os/exec` to execute ffmpeg/ffprobe directly. I also recommend to use a ffmpeg wrapper, for example:
- [xfrr/goffmpeg](https://github.com/xfrr/goffmpeg)
- [floostack/transcoder](https://github.com/floostack/transcoder)
- [u2takey/ffmpeg-go](https://github.com/u2takey/ffmpeg-go)
- [AlexEidt/Vidio](https://github.com/AlexEidt/Vidio)
Check [examples/basic](./examples/basic) for more details.
## Cross-platform
If you want to run your program on multi platforms (dev on darwin, deploy on linux, etc.), you need using `go:build` constrain to cross compile.
Check [examples/cross-plaform](./examples/cross-plaform) for more details.
## License
MIT
MIT

8
examples/basic/go.mod Normal file
View File

@@ -0,0 +1,8 @@
module github.com/go-ffstatic/ffstatic/examples/basic
go 1.18
require (
github.com/floostack/transcoder v1.1.1 // indirect
github.com/go-ffstatic/darwin-amd64 v0.0.0-20220419071301-3be09c46cfa9 // indirect
)

4
examples/basic/go.sum Normal file
View File

@@ -0,0 +1,4 @@
github.com/floostack/transcoder v1.1.1 h1:ApvdTZGt4r1N8dcT1PEl4jxX5OBHaOMY42kmCKNbYCE=
github.com/floostack/transcoder v1.1.1/go.mod h1:lT+f8NEGaHP6AVeYLicas0EI0+TforD+DRuLziJg6bY=
github.com/go-ffstatic/darwin-amd64 v0.0.0-20220419071301-3be09c46cfa9 h1:7m3vIAZFNmqJg1IpdvYnZKVi67pf6PjCrwZiP/mFSZQ=
github.com/go-ffstatic/darwin-amd64 v0.0.0-20220419071301-3be09c46cfa9/go.mod h1:8dBlJ3xj3C3oGoLAE2u7c3Dl5Spk9cbiQs9IJWaHb54=

19
examples/basic/main.go Normal file
View File

@@ -0,0 +1,19 @@
package main
import (
"github.com/floostack/transcoder/ffmpeg"
ffstatic_darwin_amd64 "github.com/go-ffstatic/darwin-amd64"
)
func main() {
ff := ffmpeg.New(&ffmpeg.Config{
FfmpegBinPath: ffstatic_darwin_amd64.FFmpegPath(),
FfprobeBinPath: ffstatic_darwin_amd64.FFprobePath(),
})
ch, err := ff.Input("./input.avi").Output("./output.mp4").Start(ffmpeg.Options{})
if err != nil {
panic(err)
}
for range ch {
}
}

View File

@@ -0,0 +1,10 @@
//go:build darwin
package main
import (
ff "github.com/go-ffstatic/darwin-amd64"
)
var ffmpegPath = ff.FFmpegPath()
var ffprobePath = ff.FFprobePath()

View File

@@ -0,0 +1,9 @@
module github.com/go-ffstatic/ffstatic/examples/cross-platform
go 1.18
require (
github.com/floostack/transcoder v1.1.1
github.com/go-ffstatic/darwin-amd64 v0.0.0-20220419102624-c00b1b8ed833
github.com/go-ffstatic/linux-amd64 v0.0.0-20220419102626-3eb73541e19c
)

View File

@@ -0,0 +1,6 @@
github.com/floostack/transcoder v1.1.1 h1:ApvdTZGt4r1N8dcT1PEl4jxX5OBHaOMY42kmCKNbYCE=
github.com/floostack/transcoder v1.1.1/go.mod h1:lT+f8NEGaHP6AVeYLicas0EI0+TforD+DRuLziJg6bY=
github.com/go-ffstatic/darwin-amd64 v0.0.0-20220419102624-c00b1b8ed833 h1:4aiRoGBPjvS26oU28sqa1H2Cv+6mLeLw14yTqnP1ijI=
github.com/go-ffstatic/darwin-amd64 v0.0.0-20220419102624-c00b1b8ed833/go.mod h1:8dBlJ3xj3C3oGoLAE2u7c3Dl5Spk9cbiQs9IJWaHb54=
github.com/go-ffstatic/linux-amd64 v0.0.0-20220419102626-3eb73541e19c h1:dOZdf/kSqBKoj8d/JeiCa5xuBx0g9w+Q3syEa9+QQkE=
github.com/go-ffstatic/linux-amd64 v0.0.0-20220419102626-3eb73541e19c/go.mod h1:IBog11RNX7YKzt2nE5Qc0zuscWQYj5TfqY/QxTUOOpQ=

View File

@@ -0,0 +1,10 @@
//go:build linux
package main
import (
ff "github.com/go-ffstatic/linux-amd64"
)
var ffmpegPath = ff.FFmpegPath()
var ffprobePath = ff.FFprobePath()

View File

@@ -0,0 +1,18 @@
package main
import (
"github.com/floostack/transcoder/ffmpeg"
)
func main() {
ff := ffmpeg.New(&ffmpeg.Config{
FfmpegBinPath: ffmpegPath,
FfprobeBinPath: ffprobePath,
})
ch, err := ff.Input("./input.avi").Output("./output.mp4").Start(ffmpeg.Options{})
if err != nil {
panic(err)
}
for range ch {
}
}

View File

@@ -1,6 +1,4 @@
//generated by github.com/go-ffstatic/ffstatic
//go:build {{.system}} && {{.arch}}
// +build {{.system}},{{.arch}}
// generated by github.com/go-ffstatic/ffstatic
package ffstatic_{{.system}}_{{.arch}}