-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
74 lines (63 loc) · 1.65 KB
/
file.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
// Copyright 2015 Dave Gradwell
// Under BSD-style license (see LICENSE file)
package ff
// Interface for either an input file or an output file
type File interface {
Name() string
AddParam(...Param)
Slice() []string
}
// Base structure representing an input file or an output file.
// Not meant to be used directly; use InputFile or OutputFile
type BaseFile struct {
Filename string
Params *ParamSet
}
// Add a parameter to this file
func (f BaseFile) AddParam(param ...Param) {
f.Params.Add(param...)
}
// Returns the filename passed into the constructor
func (f BaseFile) Name() string {
return f.Filename
}
// Represents an input file for ffmpeg/ffprobe
type InputFile struct {
BaseFile
}
// Returns a slice representation of how an input file should be passed to
// ffmpeg/ffprobe
func (f InputFile) Slice() (result []string) {
result = append(result, f.Params.Slice()...)
result = append(result, "-i", f.Filename)
return
}
// Returns a new File for input to ffmpeg/ffprobe
func NewInput(filename string, params *ParamSet) File {
return &InputFile{
BaseFile: BaseFile{
Filename: filename,
Params: params,
},
}
}
// Represents an output file for ffmpeg/ffprobe
type OutputFile struct {
BaseFile
}
// Returns a slice representation of how an output file should be passed to
// ffmpeg/ffprobe
func (f OutputFile) Slice() (result []string) {
result = append(result, f.Params.Slice()...)
result = append(result, f.Filename, "-y")
return
}
// Returns a new File for output from ffmpeg/ffprobe
func NewOutput(filename string, params *ParamSet) File {
return &OutputFile{
BaseFile: BaseFile{
Filename: filename,
Params: params,
},
}
}