mirror of
https://github.com/fxkt-tech/liv
synced 2025-09-27 04:16:00 +08:00
opt: ffprobe
This commit is contained in:
@@ -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:
|
||||
|
28
examples/ffprobe/main.go
Normal file
28
examples/ffprobe/main.go
Normal 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)
|
||||
}
|
@@ -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
15
ffcut/options.go
Normal 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
|
||||
// }
|
||||
// }
|
@@ -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()
|
||||
|
@@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user