-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg_test.nu
261 lines (237 loc) · 6.42 KB
/
ffmpeg_test.nu
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
use std [assert];
use ffmpeg.nu *;
use filters.nu *;
#[test]
def can_parse_filters_with_inputs_and_outputs [] {
let got = '[foo]loop=loop=1[bar]' | parse filter;
assert equal $got { input: ['foo'] name: 'loop' params: [{param: 'loop', value: '1'}] output: ['bar'] };
}
#[test]
def can_parse_filters_with_multiple_inputs [] {
let got = '[main][flip] overlay=0:H/2 ' | parse filter;
assert equal $got { input: ['main' 'flip'] name: 'overlay' params: [{param: '', value: '0'} {param: '' value: 'H/2'}] output: [] };
}
#[test]
def can_parse_filters_with_multiple_outputs [] {
let got = 'overlay=0:H/2 [main][flip]' | parse filter;
assert equal $got { input: [] name: 'overlay' params: [{param: '', value: '0'} {param: '' value: 'H/2'}] output: ['main' 'flip'] };
}
#[test]
def can_parse_filters_with_multiple_params [] {
let got = '[foo]loop=loop=2:size=1[bar]' | parse filter;
assert equal $got { input: ['foo'] name: 'loop' params: [{param: 'loop', value: '2'} {param: 'size' value: '1'}] output: ['bar'] };
}
#[test]
def can_parse_filterchain [] {
let got = '[tmp] crop=iw:ih/2:0:0, vflip [flip]' | parse filterchain;
assert equal $got [
{
input: ['tmp']
name: 'crop'
params: [
{param: '' value: 'iw'}
{ param: '' value: 'ih/2'}
{ param: '', value: '0'}
{ param: '', value: '0'}
]
output: []
}
{
input: []
name: 'vflip'
params: []
output: ['flip']
}
];
}
#[test]
def can_parse_filtergraph [] {
let got = 'split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2' | parse filtergraph;
assert equal $got [
[
{input: [], name: 'split', params: [], output: ['main' 'tmp']}
]
[
{input: [tmp], name: 'crop', params: [
{ param: '' value: 'iw' }
{ param: '' value: 'ih/2' }
{ param: '' value: '0' }
{ param: '' value: '0' }
], output: []}
{input: [], name: 'vflip', params: [], output: ['flip']}
]
[
{input: ['main' 'flip'], name: 'overlay', params: [
{ param: '' value: '0' }
{ param: '' value: 'H/2' }
], output: []}
]
];
}
#[test]
def can_convert_filtergraph_to_string [] {
let got = 'split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2' | parse filtergraph | filtergraph to-string;
let want = 'split[main][tmp];[tmp]crop=iw:ih/2:0:0,vflip[flip];[main][flip]overlay=0:H/2';
assert equal $got $want;
}
#[test]
def boolean_params_are_converted_to_1_or_0 [] {
let got = (cmd ['INPUT'] ['OUTPUT'] | crop -k | run -d | get 4);
let want = 'crop=w=iw:x=0:y=0:keep_aspect=1:exact=0';
assert equal $got $want;
}
#[test]
def without_filterchain_chains_are_concated [] {
let got = (cmd ['INPUT'] ['OUTPUT'] | fps 25 | loop 2 1);
assert equal $got {
input: ['INPUT']
filters: [
[
{
input: []
name: 'fps'
params: [
{param: 'fps' value: '25'}
]
output: []
}
#{
# input: []
# name: 'settb'
# params: [
# {param: 'expr' value: '1/25'}
# ]
# output: []
#}
]
[{
input: []
name: 'loop'
params: [
{param: 'loop' value: 2}
{param: 'size' value: 1}
]
output: []
}]
]
output: ['OUTPUT']
args: []
options: { chain_filters: false }
};
}
#[test]
def filterchain_concats_filters [] {
let got = (cmd ['INPUT'] ['OUTPUT'] | filterchain { fps 25 -i ['in'] | loop 2 1 -o ['out']});
assert equal $got {
input: ['INPUT']
filters: [[
{
input: ['in']
name: 'fps'
params: [
{param: 'fps' value: '25'}
]
output: []
}
#{
# input: []
# name: 'settb'
# params: [
# {param: 'expr' value: '1/25'}
# ]
# output: []
#}
{
input: []
name: 'loop'
params: [
{param: 'loop' value: 2}
{param: 'size' value: 1}
]
output: ['out']
}
]]
output: ['OUTPUT']
args: []
options: { chain_filters: false }
};
}
#[test]
def filterchain_appends_current_filter [] {
let got = (cmd ['INPUT'] ['OUTPUT'] | fps 12 | filterchain { fps 25 -i ['in'] | loop 2 1 -o ['out']});
assert equal $got {
input: ['INPUT']
filters: [
[
{
input: []
name: 'fps'
params: [
{param: 'fps' value: '12'}
]
output: []
}
]
[
{
input: ['in']
name: 'fps'
params: [
{param: 'fps' value: '25'}
]
output: []
}
#{
# input: []
# name: 'settb'
# params: [
# {param: 'expr' value: '1/25'}
# ]
# output: []
#}
{
input: []
name: 'loop'
params: [
{param: 'loop' value: 2}
{param: 'size' value: 1}
]
output: ['out']
}
]
]
output: ['OUTPUT']
args: []
options: { chain_filters: false }
};
}
#[test]
def filterchains_can_set_inputs_and_outputs [] {
let got = (cmd ['INPUT'] ['OUTPUT'] | filterchain -i ['in'] -o ['out'] { fps 25 | settb '1/25' });
assert equal $got {
input: ['INPUT']
filters: [
[
{
input: ['in']
name: 'fps'
params: [
{param: 'fps' value: '25'}
]
output: []
}
{
input: []
name: 'settb'
params: [
{param: 'expr' value: '1/25'}
]
output: ['out']
}
]
]
output: ['OUTPUT']
args: []
options: { chain_filters: false }
}
}