Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 24e6bb5

Browse files
committed
update
1 parent 33aa4e6 commit 24e6bb5

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

ffmpeg/ffmpeg.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Transcoder struct {
2323
config *Config
2424
input string
2525
output []string
26-
options [][]string
26+
options []transcoder.Options
2727
metadata transcoder.Metadata
2828
inputPipeReader io.ReadCloser
2929
outputPipeReader io.ReadCloser
@@ -68,16 +68,20 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
6868
// Just append the 1 output file we've got
6969
args = append(args, t.output[0])
7070
} else {
71+
arguments := make([][]string, len(t.options))
72+
for i, o := range t.options {
73+
arguments[i] = o.GetStrArguments()
74+
}
7175
for index, out := range t.output {
7276
// Get executable flags
7377
// If we are at the last output file but still have several options, append them all at once
7478
if index == outputLength-1 && outputLength < optionsLength {
7579
for i := index; i < len(t.options); i++ {
76-
args = append(args, t.options[i]...)
80+
args = append(args, arguments[i]...)
7781
}
7882
// Otherwise just append the current options
7983
} else {
80-
args = append(args, t.options[index]...)
84+
args = append(args, arguments[index]...)
8185
}
8286

8387
// Append output flag
@@ -163,13 +167,13 @@ func (t *Transcoder) OutputPipe(w io.WriteCloser, r io.ReadCloser) transcoder.Tr
163167

164168
// WithOptions Sets the options object
165169
func (t *Transcoder) WithOptions(opts transcoder.Options) transcoder.Transcoder {
166-
t.options = [][]string{opts.GetStrArguments()}
170+
t.options = []transcoder.Options{opts}
167171
return t
168172
}
169173

170174
// WithAdditionalOptions Appends an additional options object
171175
func (t *Transcoder) WithAdditionalOptions(opts transcoder.Options) transcoder.Transcoder {
172-
t.options = append(t.options, opts.GetStrArguments())
176+
t.options = append(t.options, opts)
173177
return t
174178
}
175179

ffmpeg/options.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,39 @@ func (opts Options) GetStrArguments() []string {
7777

7878
for i := 0; i < f.NumField(); i++ {
7979
flag := f.Field(i).Tag.Get("flag")
80-
value := v.Field(i).Interface()
80+
rv := v.Field(i)
81+
value := rv.Interface()
8182

82-
if !v.Field(i).IsNil() {
83+
if !rv.IsNil() {
8384

8485
if _, ok := value.(*bool); ok {
8586
values = append(values, flag)
87+
continue
8688
}
8789

8890
if vs, ok := value.(*string); ok {
8991
values = append(values, flag, *vs)
92+
continue
9093
}
9194

9295
if va, ok := value.([]string); ok {
93-
9496
for i := 0; i < len(va); i++ {
9597
item := va[i]
9698
values = append(values, flag, item)
9799
}
100+
continue
98101
}
99102

100103
if vm, ok := value.(map[string]interface{}); ok {
101104
for k, v := range vm {
102105
values = append(values, k, fmt.Sprintf("%v", v))
103106
}
107+
continue
104108
}
105-
109+
106110
if vi, ok := value.(*int); ok {
107111
values = append(values, flag, fmt.Sprintf("%d", *vi))
112+
continue
108113
}
109114

110115
}

0 commit comments

Comments
 (0)