Skip to content

Commit 7006736

Browse files
committed
update go-fftool
1 parent a7dfcf3 commit 7006736

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Config struct {
5252
processID string
5353
crypto *Crypto
5454
output string
55-
LogOutput chan string
55+
LogOutput bool
5656
VideoFormat string
5757
AudioFormat string
5858
Scale Scale

ffmpeg.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/goextension/log"
77
"github.com/google/uuid"
88
"os"
9+
"strings"
910
"sync"
1011
)
1112

@@ -23,7 +24,7 @@ type MpegOption struct {
2324
}
2425

2526
// RunOptions ...
26-
type RunOptions func(cfg *Config)
27+
type RunOptions func(cfg *Config) *Config
2728

2829
// Name ...
2930
func (ff FFMpeg) Name() string {
@@ -42,7 +43,7 @@ func (ff FFMpeg) Run(ctx context.Context, input string, opts ...RunOptions) (e e
4243

4344
config.processID = pid
4445
for _, opt := range opts {
45-
opt(config)
46+
config = opt(config)
4647
}
4748
if config.processID == "" {
4849
config.processID = pid
@@ -66,12 +67,28 @@ func (ff FFMpeg) Run(ctx context.Context, input string, opts ...RunOptions) (e e
6667
}
6768
args := outputArgs(config, input)
6869

70+
var outLog chan string
71+
if config.LogOutput {
72+
outLog = make(chan string)
73+
}
74+
75+
log.Infow("runmsg", "init", outLog == nil)
76+
6977
wg := &sync.WaitGroup{}
7078
wg.Add(1)
7179
go func() {
7280
defer wg.Done()
73-
e = ff.cmd.RunContext(ctx, args, config.LogOutput)
81+
e = ff.cmd.RunContext(ctx, args, outLog)
7482
}()
83+
84+
if config.LogOutput {
85+
for i2 := range outLog {
86+
ss := strings.Split(i2, "\r")
87+
for _, i3 := range ss {
88+
log.Infow("runmsg", "outLog", strings.TrimSpace(i3))
89+
}
90+
}
91+
}
7592
wg.Wait()
7693
return e
7794
}

ffmpeg_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ func TestFFMpeg_Run(t *testing.T) {
9898
t.Errorf("OptimizeWithFormat() error = %v, wantErr %v", e, tt.wantErr)
9999
return
100100
}
101-
if err := ff.Run(tt.args.ctx, tt.args.input, func(config *Config) {
102-
config = cfg
101+
cfg.LogOutput = true
102+
if err := ff.Run(tt.args.ctx, tt.args.input, func(config *Config) *Config {
103+
return cfg
103104
}); (err != nil) != tt.wantErr {
104105
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
105106
}

0 commit comments

Comments
 (0)