forked from interru/ffmpegwrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
346 lines (263 loc) · 9.95 KB
/
test.py
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# -*- coding: utf8 -*-
import unittest
from mock import patch
from ffmpegwrapper import FFmpeg, Input, Output, \
VideoCodec, AudioCodec, VideoFilter
from ffmpegwrapper.parameters import Parameter
class FFmpegTestCase(unittest.TestCase):
def setUp(self):
self.patcher = patch('ffmpegwrapper.ffmpeg.Popen')
popen = self.patcher.start()
self.instance = popen.return_value
read_value = bytearray(b'this is a line\nthis too\n')
poll = lambda: None if read_value else 0
def read(*args):
try:
return bytearray([read_value.pop(0)])
except IndexError:
return b''
self.instance.poll.side_effect = poll
self.instance.stdout.read.side_effect = read
def test_input_interface(self):
input = Input('/old')
self.assertEqual(list(input), ['-i', '/old'])
self.assertEqual(input.file_path, '/old')
parameter = Parameter('-vf', 'x11grab')
input.append(parameter)
self.assertEqual(list(input), ['-vf', 'x11grab', '-i', '/old'])
self.assertEqual(input.pop(), parameter)
input.add_formatparam('-vf', 'x11grab')
self.assertEqual(input.container_list, [parameter])
def test_output_interface(self):
output = Output('/new')
self.assertEqual(list(output), ['/new'])
self.assertEqual(output.file_path, '/new')
parameter = Parameter('-vcodec', 'libx264')
output.append(parameter)
self.assertEqual(list(output), ['-vcodec', 'libx264', '/new'])
self.assertEqual(output.pop(), parameter)
output.add_formatparam('-vcodec', 'libx264')
self.assertEqual(output.container_list, [parameter])
def test_codec_interface(self):
codec = VideoCodec('libx264')
self.assertEqual(list(codec), ['-vcodec', 'libx264'])
codec = AudioCodec('ac3')
self.assertEqual(list(codec), ['-acodec', 'ac3'])
def test_filter_interface(self):
filter = VideoFilter()
filter.blackframe(1, 2).crop(792)
self.assertEqual(list(filter), ['-vf', 'blackframe=1:2,crop=792'])
output = Output('/new', filter)
self.assertEqual(
list(output), ['-vf', 'blackframe=1:2,crop=792', '/new'])
def test_ffmpeg_interface(self):
input = Input('/old')
output = Output('/new')
ffmpeg = FFmpeg('ffmpeg', input, output)
self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '/new'])
with ffmpeg as process:
result = list(process.readlines())
self.assertEqual(result, ['this is a line', 'this too'])
def tearDown(self):
self.patcher.stop()
class VideoFilterTestCase(unittest.TestCase):
def setUp(self):
self.filter = VideoFilter()
def prefix(self, *args):
return ['-vf'] + list(args)
def test_blackframe(self):
self.filter.blackframe(10, 100)
self.assertEqual(list(self.filter),
self.prefix('blackframe=10:100'))
def test_copy(self):
self.filter.copy()
self.assertEqual(list(self.filter),
self.prefix('copy'))
def test_crop(self):
self.filter.crop(100, 100)
self.assertEqual(list(self.filter),
self.prefix('crop=100:100'))
def test_cropdetect(self):
self.filter.cropdetect(10)
self.assertEqual(list(self.filter),
self.prefix('cropdetect=10'))
def test_drawbox(self):
self.filter.drawbox(10, 10, 10, 10, 'red')
self.assertEqual(list(self.filter),
self.prefix('drawbox=10:10:10:10:red'))
def test_drawtext(self):
self.filter.drawtext(fontfile='./font.ttf', text='Title')
self.assertEqual(list(self.filter),
self.prefix('drawtext="fontfile=./font.ttf:text=Title"'))
def test_fade(self):
self.filter.fade(10, 10, 10)
self.assertEqual(list(self.filter),
self.prefix('fade=10:10:10'))
def test_fieldorder(self):
self.filter.fieldorder(1)
self.assertEqual(list(self.filter),
self.prefix('fieldorder=1'))
def test_fifo(self):
self.filter.fifo()
self.assertEqual(list(self.filter),
self.prefix('fifo'))
def test_format(self):
self.filter.format('yuv420p')
self.assertEqual(list(self.filter),
self.prefix('format=yuv420p'))
def test_freior(self):
self.filter.freior('distort0r', 0.5, 0.01)
self.assertEqual(list(self.filter),
self.prefix('frei0r=distort0r:0.5:0.01'))
def test_gradfun(self):
self.filter.gradfun(10, 100)
self.assertEqual(list(self.filter),
self.prefix('gradfun=10:100'))
def test_hflip(self):
self.filter.hflip()
self.assertEqual(list(self.filter),
self.prefix('hflip'))
def test_hqdn3d(self):
self.filter.hqdn3d(2)
self.assertEqual(list(self.filter),
self.prefix('hqdn3d=2'))
def test_mp(self):
self.filter.mp(delogo=None)
self.assertEqual(list(self.filter),
self.prefix('mp="delogo"'))
def test_negate(self):
self.filter.negate()
self.assertEqual(list(self.filter),
self.prefix('negate=1'))
def test_noformat(self):
self.filter.noformat('yuv420p')
self.assertEqual(list(self.filter),
self.prefix('noformat=yuv420p'))
def test_null(self):
self.filter.null()
self.assertEqual(list(self.filter),
self.prefix('null'))
def test_overlay(self):
self.filter.overlay(10, 10)
self.assertEqual(list(self.filter),
self.prefix('overlay=10:10'))
def test_scale(self):
self.filter.scale(792)
self.assertEqual(list(self.filter),
self.prefix('scale=792:-1'))
def test_select(self):
self.filter.select(1)
self.assertEqual(list(self.filter),
self.prefix('select=1'))
def test_setdar(self):
self.filter.setdar(16, 9)
self.assertEqual(list(self.filter),
self.prefix('setdar=16:9'))
def test_setsar(self):
self.filter.setsar(16, 9)
self.assertEqual(list(self.filter),
self.prefix('setsar=16:9'))
def test_slicify(self):
self.filter.slicify(20)
self.assertEqual(list(self.filter),
self.prefix('slicify=20'))
def test_transpose(self):
self.filter.transpose(2)
self.assertEqual(list(self.filter),
self.prefix('transpose=2'))
def test_unsharp(self):
self.filter.unsharp(1, 2, 3, 4, 5, 6)
self.assertEqual(list(self.filter),
self.prefix('unsharp=1:2:3:4:5:6'))
def test_vflip(self):
self.filter.vflip()
self.assertEqual(list(self.filter),
self.prefix('vflip'))
def test_yadif(self):
self.filter.yadif()
self.assertEqual(list(self.filter),
self.prefix('yadif=0:-1'))
class VideoCodecTestCase(unittest.TestCase):
def setUp(self):
self.codec = VideoCodec('libx264')
def prefix(self, *args):
return ['-vcodec', 'libx264'] + list(args)
def test_bitrate(self):
self.codec.bitrate('300k')
self.assertEqual(list(self.codec),
self.prefix('-b', '300k'))
def test_frames(self):
self.codec.frames(100)
self.assertEqual(list(self.codec),
self.prefix('-vframes', '100'))
def test_fps(self):
self.codec.fps(24)
self.assertEqual(list(self.codec),
self.prefix('-r', '24'))
def test_aspect(self):
self.codec.aspect(16, 9)
self.assertEqual(list(self.codec),
self.prefix('-aspect', '16:9'))
def test_bitrate_tolerance(self):
self.codec.bitrate_tolerance(10)
self.assertEqual(list(self.codec),
self.prefix('-bt', '10'))
def test_max_bitrate(self):
self.codec.max_bitrate('100k')
self.assertEqual(list(self.codec),
self.prefix('-maxrate', '100k'))
def test_min_bitrate(self):
self.codec.min_bitrate('50k')
self.assertEqual(list(self.codec),
self.prefix('-minrate', '50k'))
def test_buffer_size(self):
self.codec.buffer_size('20k')
self.assertEqual(list(self.codec),
self.prefix('-bufsize', '20k'))
def test_pass_number(self):
self.codec.pass_number(2)
self.assertEqual(list(self.codec),
self.prefix('-pass', '2'))
def test_language(self):
self.codec.language('DEU')
self.assertEqual(list(self.codec),
self.prefix('-vlang', 'DEU'))
def test_same_quality(self):
self.codec.same_quality()
self.assertEqual(list(self.codec),
self.prefix('-sameq'))
def test_preset(self):
self.codec.preset('max')
self.assertEqual(list(self.codec),
self.prefix('-vpre', 'max'))
class AudioCodecTestCase(unittest.TestCase):
def setUp(self):
self.codec = AudioCodec('AC3')
def prefix(self, *args):
return ['-acodec', 'AC3'] + list(args)
def test_frames(self):
self.codec.frames(100)
self.assertEqual(list(self.codec),
self.prefix('-aframes', '100'))
def test_frequence(self):
self.codec.frequence(48000)
self.assertEqual(list(self.codec),
self.prefix('-ar', '48000'))
def test_bitrate(self):
self.codec.bitrate('320k')
self.assertEqual(list(self.codec),
self.prefix('-ab', '320k'))
def test_quality(self):
self.codec.quality(8)
self.assertEqual(list(self.codec),
self.prefix('-aq', '8'))
def test_language(self):
self.codec.language('DEU')
self.assertEqual(list(self.codec),
self.prefix('-alang', 'DEU'))
def test_preset(self):
self.codec.preset('max')
self.assertEqual(list(self.codec),
self.prefix('-apre', 'max'))
if __name__ == '__main__':
unittest.main()