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
|
# ffmpeg
|
||||||
friendly ffmpeg sdk for go.
|
|
||||||
|
|
||||||
|
friendly ffmpeg wrap for go.
|
||||||
|
|
||||||
- ffmpeg
|
- ffmpeg
|
||||||
- 多路输入
|
- 多路输入
|
||||||
@@ -19,8 +19,8 @@ friendly ffmpeg sdk for go.
|
|||||||
- -movflags(默认faststart)
|
- -movflags(默认faststart)
|
||||||
- 输出文件
|
- 输出文件
|
||||||
|
|
||||||
|
|
||||||
### 支持的滤镜
|
### 支持的滤镜
|
||||||
|
|
||||||
- 视频属性video:
|
- 视频属性video:
|
||||||
- 缩放clip:可以设置width和height,不设置默认-2(自适应偶数长度)
|
- 缩放clip:可以设置width和height,不设置默认-2(自适应偶数长度)
|
||||||
- 音频属性audio:
|
- 音频属性audio:
|
||||||
@@ -34,4 +34,4 @@ friendly ffmpeg sdk for go.
|
|||||||
- 指定开始时间和持续时长,持续时长不指定的话默认到视频结束
|
- 指定开始时间和持续时长,持续时长不指定的话默认到视频结束
|
||||||
- 添加元信息metadata:
|
- 添加元信息metadata:
|
||||||
- 指定一组key-value
|
- 指定一组key-value
|
||||||
- key仅支持部分字符串,可用的字符串可以看ffmpeg
|
- key仅支持部分字符串,可用的字符串可以看ffmpeg
|
||||||
|
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
|
package ffcut
|
||||||
|
|
||||||
|
import "github.com/fxkt-tech/liv/internal/sugar"
|
||||||
|
|
||||||
type FFcut struct {
|
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
|
return ff
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ff *FFprobe) DryRun() {
|
func (ff *FFprobe) dryRun() {
|
||||||
var ps []string
|
var ps []string
|
||||||
ps = append(ps, ff.bin)
|
ps = append(ps, ff.bin)
|
||||||
ps = append(ps, ff.Params()...)
|
ps = append(ps, ff.Params()...)
|
||||||
@@ -82,10 +82,10 @@ func (ff *FFprobe) DryRun() {
|
|||||||
|
|
||||||
func (ff *FFprobe) Run(ctx context.Context) error {
|
func (ff *FFprobe) Run(ctx context.Context) error {
|
||||||
if ff.debug {
|
if ff.debug {
|
||||||
ff.DryRun()
|
ff.dryRun()
|
||||||
} else {
|
} else {
|
||||||
if ff.dry {
|
if ff.dry {
|
||||||
ff.DryRun()
|
ff.dryRun()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,14 @@ func (ff *FFprobe) Run(ctx context.Context) error {
|
|||||||
return nil
|
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) {
|
func (ff *FFprobe) RunRetRaw(ctx context.Context) ([]byte, error) {
|
||||||
cc := exec.CommandContext(ctx, ff.bin, ff.Params()...)
|
cc := exec.CommandContext(ctx, ff.bin, ff.Params()...)
|
||||||
ff.Sentence = cc.String()
|
ff.Sentence = cc.String()
|
||||||
|
@@ -9,6 +9,26 @@ import (
|
|||||||
"github.com/fxkt-tech/liv/ffprobe"
|
"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) {
|
func TestProbeRunRaw(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user