opt: ffprobe

This commit is contained in:
Justyer
2024-03-18 00:43:28 +08:00
parent f8375ebe71
commit 7a7590142f
6 changed files with 85 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
# ffmpeg
friendly ffmpeg sdk for go.
friendly ffmpeg wrap for go.
- ffmpeg
- 多路输入
@@ -19,8 +19,8 @@ friendly ffmpeg sdk for go.
- -movflags默认faststart
- 输出文件
### 支持的滤镜
- 视频属性video
- 缩放clip可以设置width和height不设置默认-2自适应偶数长度
- 音频属性audio
@@ -34,4 +34,4 @@ friendly ffmpeg sdk for go.
- 指定开始时间和持续时长,持续时长不指定的话默认到视频结束
- 添加元信息metadata
- 指定一组key-value
- key仅支持部分字符串可用的字符串可以看ffmpeg
- key仅支持部分字符串可用的字符串可以看ffmpeg

28
examples/ffprobe/main.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"context"
"fmt"
"github.com/fxkt-tech/liv/ffprobe"
)
func main() {
ctx := context.Background()
fp, err := ffprobe.New().
Input("").
Extract(ctx)
if err != nil {
fmt.Println(err)
return
}
vStream := fp.GetFirstVideoStream()
if vStream == nil {
fmt.Println("file has no video stream")
return
}
fmt.Println(vStream)
}

View File

@@ -1,5 +1,13 @@
package ffcut
import "github.com/fxkt-tech/liv/internal/sugar"
type FFcut struct {
//
}
func New(opts ...Option) *FFcut {
fc := &FFcut{}
sugar.Range(opts, func(o Option) { o(fc) })
return fc
}

15
ffcut/options.go Normal file
View File

@@ -0,0 +1,15 @@
package ffcut
type Option func(*FFcut)
// func WithDebug(debug bool) Option {
// return func(fm *FFcut) {
// fm.debug = debug
// }
// }
// func WithDry(dry bool) Option {
// return func(f *FFcut) {
// f.dry = dry
// }
// }

View File

@@ -73,7 +73,7 @@ func (ff *FFprobe) Input(input string) *FFprobe {
return ff
}
func (ff *FFprobe) DryRun() {
func (ff *FFprobe) dryRun() {
var ps []string
ps = append(ps, ff.bin)
ps = append(ps, ff.Params()...)
@@ -82,10 +82,10 @@ func (ff *FFprobe) DryRun() {
func (ff *FFprobe) Run(ctx context.Context) error {
if ff.debug {
ff.DryRun()
ff.dryRun()
} else {
if ff.dry {
ff.DryRun()
ff.dryRun()
return nil
}
}
@@ -108,6 +108,14 @@ func (ff *FFprobe) Run(ctx context.Context) error {
return nil
}
func (ff *FFprobe) Extract(ctx context.Context) (*FFprobe, error) {
err := ff.Run(ctx)
if err != nil {
return nil, err
}
return ff, nil
}
func (ff *FFprobe) RunRetRaw(ctx context.Context) ([]byte, error) {
cc := exec.CommandContext(ctx, ff.bin, ff.Params()...)
ff.Sentence = cc.String()

View File

@@ -9,6 +9,26 @@ import (
"github.com/fxkt-tech/liv/ffprobe"
)
func TestExtract(t *testing.T) {
var (
ctx = context.Background()
infile = "in.mp4"
)
fp, err := ffprobe.New().Input(infile).Extract(ctx)
if err != nil {
t.Fatal(err)
}
vStream := fp.GetFirstVideoStream()
if vStream == nil {
t.Fatal("file has no v stream")
}
t.Log(vStream)
}
func TestProbeRunRaw(t *testing.T) {
ctx := context.Background()