forked from u2takey/ffmpeg-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.go
135 lines (113 loc) · 4.25 KB
/
filters.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
package ffmpeg_go
import (
"fmt"
"strconv"
)
func AssertType(hasType, expectType string, action string) {
if hasType != expectType {
panic(fmt.Sprintf("cannot %s on non-%s", action, expectType))
}
}
func FilterMultiOutput(streamSpec []*Stream, filterName string, args Args, kwArgs ...KwArgs) *Node {
return NewFilterNode(filterName, streamSpec, -1, args, MergeKwArgs(kwArgs))
}
func Filter(streamSpec []*Stream, filterName string, args Args, kwArgs ...KwArgs) *Stream {
return FilterMultiOutput(streamSpec, filterName, args, MergeKwArgs(kwArgs)).Stream("", "")
}
func (s *Stream) Filter(filterName string, args Args, kwArgs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "filter")
return Filter([]*Stream{s}, filterName, args, MergeKwArgs(kwArgs))
}
func (s *Stream) Split() *Node {
AssertType(s.Type, "FilterableStream", "split")
return NewFilterNode("split", []*Stream{s}, 1, nil, nil)
}
func (s *Stream) ASplit() *Node {
AssertType(s.Type, "FilterableStream", "asplit")
return NewFilterNode("asplit", []*Stream{s}, 1, nil, nil)
}
func (s *Stream) SetPts(expr string) *Node {
AssertType(s.Type, "FilterableStream", "setpts")
return NewFilterNode("setpts", []*Stream{s}, 1, []string{expr}, nil)
}
func (s *Stream) Trim(kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "trim")
return NewFilterNode("trim", []*Stream{s}, 1, nil, MergeKwArgs(kwargs)).Stream("", "")
}
func (s *Stream) Overlay(overlayParentNode *Stream, eofAction string, kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "overlay")
if eofAction == "" {
eofAction = "repeat"
}
args := MergeKwArgs(kwargs)
args["eof_action"] = eofAction
return NewFilterNode("overlay", []*Stream{s, overlayParentNode}, 2, nil, args).Stream("", "")
}
func (s *Stream) HFlip(kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "hflip")
return NewFilterNode("hflip", []*Stream{s}, 1, nil, MergeKwArgs(kwargs)).Stream("", "")
}
func (s *Stream) VFlip(kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "vflip")
return NewFilterNode("vflip", []*Stream{s}, 1, nil, MergeKwArgs(kwargs)).Stream("", "")
}
func (s *Stream) Crop(x, y, w, h int, kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "crop")
return NewFilterNode("crop", []*Stream{s}, 1, []string{
strconv.Itoa(w), strconv.Itoa(h), strconv.Itoa(x), strconv.Itoa(y),
}, MergeKwArgs(kwargs)).Stream("", "")
}
func (s *Stream) DrawBox(x, y, w, h int, color string, thickness int, kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "drawbox")
args := MergeKwArgs(kwargs)
if thickness != 0 {
args["t"] = thickness
}
return NewFilterNode("drawbox", []*Stream{s}, 1, []string{
strconv.Itoa(x), strconv.Itoa(y), strconv.Itoa(w), strconv.Itoa(h), color,
}, args).Stream("", "")
}
func (s *Stream) Drawtext(text string, x, y int, escape bool, kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "drawtext")
args := MergeKwArgs(kwargs)
if escape {
text = fmt.Sprintf("%q", text)
}
if text != "" {
args["text"] = text
}
if x != 0 {
args["x"] = x
}
if y != 0 {
args["y"] = y
}
return NewFilterNode("drawtext", []*Stream{s}, 1, nil, args).Stream("", "")
}
func Concat(streams []*Stream, kwargs ...KwArgs) *Stream {
args := MergeKwArgs(kwargs)
vsc := args.GetDefault("v", 1).(int)
asc := args.GetDefault("a", 0).(int)
sc := vsc + asc
if len(streams)%sc != 0 {
panic("streams count not valid")
}
args["n"] = len(streams) / sc
return NewFilterNode("concat", streams, -1, nil, args).Stream("", "")
}
func (s *Stream) Concat(streams []*Stream, kwargs ...KwArgs) *Stream {
return Concat(append(streams, s), MergeKwArgs(kwargs))
}
func (s *Stream) ZoomPan(kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "zoompan")
return NewFilterNode("zoompan", []*Stream{s}, 1, nil, MergeKwArgs(kwargs)).Stream("", "")
}
func (s *Stream) Hue(kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "hue")
return NewFilterNode("hue", []*Stream{s}, 1, nil, MergeKwArgs(kwargs)).Stream("", "")
}
// todo fix this
func (s *Stream) ColorChannelMixer(kwargs ...KwArgs) *Stream {
AssertType(s.Type, "FilterableStream", "colorchannelmixer")
return NewFilterNode("colorchannelmixer", []*Stream{s}, 1, nil, MergeKwArgs(kwargs)).Stream("", "")
}