-
-
Notifications
You must be signed in to change notification settings - Fork 742
/
splice.go
67 lines (51 loc) · 1.5 KB
/
splice.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
package transcoder
import (
"runtime"
"strings"
"github.com/stashapp/stash/pkg/ffmpeg"
)
type SpliceOptions struct {
OutputPath string
Format ffmpeg.Format
VideoCodec ffmpeg.VideoCodec
VideoArgs ffmpeg.Args
AudioCodec ffmpeg.AudioCodec
AudioArgs ffmpeg.Args
// Verbosity is the logging verbosity. Defaults to LogLevelError if not set.
Verbosity ffmpeg.LogLevel
}
func (o *SpliceOptions) setDefaults() {
if o.Verbosity == "" {
o.Verbosity = ffmpeg.LogLevelError
}
}
// fixWindowsPath replaces \ with / in the given path because the \ isn't recognized as valid on windows ffmpeg
func fixWindowsPath(str string) string {
if runtime.GOOS == "windows" {
return strings.ReplaceAll(str, `\`, "/")
}
return str
}
func Splice(concatFile string, options SpliceOptions) ffmpeg.Args {
options.setDefaults()
var args ffmpeg.Args
args = args.LogLevel(options.Verbosity)
args = args.Format(ffmpeg.FormatConcat)
args = args.Input(fixWindowsPath(concatFile))
args = args.Overwrite()
// if video codec is not provided, then use copy
if options.VideoCodec == "" {
options.VideoCodec = ffmpeg.VideoCodecCopy
}
args = args.VideoCodec(options.VideoCodec)
args = args.AppendArgs(options.VideoArgs)
// if audio codec is not provided, then use copy
if options.AudioCodec == "" {
options.AudioCodec = ffmpeg.AudioCodecCopy
}
args = args.AudioCodec(options.AudioCodec)
args = args.AppendArgs(options.AudioArgs)
args = args.Format(options.Format)
args = args.Output(options.OutputPath)
return args
}