This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_global.go
173 lines (155 loc) · 5.88 KB
/
options_global.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package ffmpeg
import (
"fmt"
"strconv"
"strings"
"time"
)
// FLAG SPEC ARGS AFFECTS IMPL
// cpuflags false [flags] [global] [ ]
// opencl_options false [options] [global] [X]
// y false [] [global] [X]
// n false [] [global] [X]
// filter_threads false [nb_threads] [global] [X]
// stats false [] [global] [ ]
// progress false [url] [global] [ ]
// debug_ts false [] [global] [ ]
// qphist false [] [global] [ ]
// benchmark false [] [global] [ ]
// benchmark_all false [] [global] [ ]
// timelimit false [duration] [global] [X]
// dump false [] [global] [ ]
// hex false [] [global] [ ]
// filter_complex false [filtergraph] [global] [ ]
// filter_complex_threads false [nb_threads] [global] [X]
// lavfi false [filtergraph] [global] [ ]
// filter_complex_script false [filename] [global] [X]
// override_ffserver false [] [global] [ ]
// sdp_file false [file] [global] [ ]
// abort_on false [flags] [global] [ ]
// xerror false [] [global] [ ]
// GlobalOption configures how ffmpeg runs overall
type GlobalOption func() ([]string, error)
// GlobalOptions represents a slice of GlobalOption to be applied
type GlobalOptions []GlobalOption
// Flags generates the ffmpeg flags to be applied
func (g GlobalOptions) Flags() []string {
// TODO: capture potential errors and return *mutlierror.Error
var f []string
for _, opt := range g {
gf, _ := opt()
f = append(f, gf...)
}
return f
}
// WithLogLevel sets the logging level used by ffmpeg
func WithLogLevel(l LogLevel) GlobalOption {
return func() ([]string, error) {
return []string{"-loglevel", l.String()}, nil
}
}
// LogLevel ...
type LogLevel int
// Log level definitions
const (
LogLevelQuiet LogLevel = iota - 1 // Show nothing at all; be silent.
LogLevelPanic LogLevel = iota // Only show fatal errors which could lead the process to crash, such as an assertion failure. This is not currently used for anything.
LogLevelFatal // Only show fatal errors. These are errors after which the process absolutely cannot continue.
LogLevelError // Show all errors, including ones which can be recovered from.
LogLevelWarning // Show all warnings and errors. Any message related to possibly incorrect or unexpected events will be shown.
LogLevelInfo // Show informative messages during processing. This is in addition to warnings and errors. This is the default value.
LogLevelVerbose // Same as "info", except more verbose.
LogLevelDebug // Show everything, including debugging information.
LogLevelTrace
)
func (l LogLevel) String() string {
switch l {
case LogLevelPanic:
return "panic"
case LogLevelFatal:
return "fatal"
case LogLevelError:
return "error"
case LogLevelWarning:
return "warning"
case LogLevelInfo:
return "info"
case LogLevelVerbose:
return "verbose"
case LogLevelDebug:
return "debug"
case LogLevelTrace:
return "trace"
default:
return "quiet"
}
}
// WithOpenCLOptions sets OpenCL environment options
//
// This option is only available when FFmpeg has been compiled with "--enable-opencl"
func WithOpenCLOptions(opts map[string]string) GlobalOption {
create := func(opts map[string]string) string {
var f []string
for key, value := range opts {
f = append(f, fmt.Sprintf("%s=%s", key, value))
}
return strings.Join(f, ":")
}
return func() ([]string, error) {
return []string{"-opencl_options", create(opts)}, nil
}
}
// WithOverwrite sets whether to overwrite output files without asking
//
// If set to false the command will exit immediately if a specified output file already exists
func WithOverwrite(ovr bool) GlobalOption {
return func() ([]string, error) {
var tmp []string
if ovr {
tmp = append(tmp, "-y")
} else {
tmp = append(tmp, "-n")
}
return tmp, nil
}
}
// WithNumFilterThreads defines how many threads are used to process a filter pipeline
//
// Each pipeline will produce a thread pool with this many threads
// available for parallel processing. The default is the number of
// available CPUs.
func WithNumFilterThreads(num int) GlobalOption {
return func() ([]string, error) {
return []string{"-filter_threads", strconv.Itoa(num)}, nil
}
}
// WithTimelimit sets the timelimit duration on ffmpeg.
//
// Exit after ffmpeg has been running for duration seconds.
func WithTimelimit(dur time.Duration) GlobalOption {
create := func(dur time.Duration) string {
matches := regexpDuration.FindAllStringSubmatch(dur.String(), -1)
hour, _ := strconv.ParseInt(matches[0][2], 10, 32)
minute, _ := strconv.ParseInt(matches[0][4], 10, 32)
seconds, _ := strconv.ParseFloat(matches[0][6], 32)
return fmt.Sprintf("%02d:%02d:%f", hour, minute, seconds)
}
return func() ([]string, error) {
return []string{"-timelimit", create(dur)}, nil
}
}
// WithNumFilterComplexThreads defines how many threads are used to process a filter_complex graph
//
// Similar to WithNumFilterThreads but used for "-filter_complex"
// graphs only. The default is the number of available CPUs.
func WithNumFilterComplexThreads(num int) GlobalOption {
return func() ([]string, error) {
return []string{"-filter_complex_threads", strconv.Itoa(num)}, nil
}
}
// WithFilterComplexScript ...
func WithFilterComplexScript(filename string) GlobalOption {
return func() ([]string, error) {
return []string{"-filter_complex_script", filename}, nil
}
}