8
8
9
9
TEST_DIR = os .path .dirname (__file__ )
10
10
SAMPLE_DATA_DIR = os .path .join (TEST_DIR , 'sample_data' )
11
- TEST_INPUT_FILE = os .path .join (SAMPLE_DATA_DIR , 'dummy .mp4' )
11
+ TEST_INPUT_FILE1 = os .path .join (SAMPLE_DATA_DIR , 'in1 .mp4' )
12
12
TEST_OVERLAY_FILE = os .path .join (SAMPLE_DATA_DIR , 'overlay.png' )
13
- TEST_OUTPUT_FILE = os .path .join (SAMPLE_DATA_DIR , 'dummy2.mp4' )
13
+ TEST_OUTPUT_FILE1 = os .path .join (SAMPLE_DATA_DIR , 'out1.mp4' )
14
+ TEST_OUTPUT_FILE2 = os .path .join (SAMPLE_DATA_DIR , 'out2.mp4' )
14
15
15
16
16
17
subprocess .check_call (['ffmpeg' , '-version' ])
@@ -94,7 +95,7 @@ def test_get_args_simple():
94
95
95
96
def _get_complex_filter_example ():
96
97
split = (ffmpeg
97
- .input (TEST_INPUT_FILE )
98
+ .input (TEST_INPUT_FILE1 )
98
99
.vflip ()
99
100
.split ()
100
101
)
@@ -109,15 +110,15 @@ def _get_complex_filter_example():
109
110
)
110
111
.overlay (overlay_file .hflip ())
111
112
.drawbox (50 , 50 , 120 , 120 , color = 'red' , thickness = 5 )
112
- .output (TEST_OUTPUT_FILE )
113
+ .output (TEST_OUTPUT_FILE1 )
113
114
.overwrite_output ()
114
115
)
115
116
116
117
117
118
def test_get_args_complex_filter ():
118
119
out = _get_complex_filter_example ()
119
120
args = ffmpeg .get_args (out )
120
- assert args == ['-i' , TEST_INPUT_FILE ,
121
+ assert args == ['-i' , TEST_INPUT_FILE1 ,
121
122
'-i' , TEST_OVERLAY_FILE ,
122
123
'-filter_complex' ,
123
124
'[0]vflip[s0];' \
@@ -128,7 +129,7 @@ def test_get_args_complex_filter():
128
129
'[1]hflip[s6];' \
129
130
'[s5][s6]overlay=eof_action=repeat[s7];' \
130
131
'[s7]drawbox=50:50:120:120:red:t=5[s8]' ,
131
- '-map' , '[s8]' , os . path . join ( SAMPLE_DATA_DIR , 'dummy2.mp4' ) ,
132
+ '-map' , '[s8]' , TEST_OUTPUT_FILE1 ,
132
133
'-y'
133
134
]
134
135
@@ -139,31 +140,38 @@ def test_get_args_complex_filter():
139
140
140
141
141
142
def test_run ():
142
- node = _get_complex_filter_example ()
143
- ffmpeg .run (node )
143
+ stream = _get_complex_filter_example ()
144
+ ffmpeg .run (stream )
145
+
146
+
147
+ def test_run_multi_output ():
148
+ in_ = ffmpeg .input (TEST_INPUT_FILE1 )
149
+ out1 = in_ .output (TEST_OUTPUT_FILE1 )
150
+ out2 = in_ .output (TEST_OUTPUT_FILE2 )
151
+ ffmpeg .run ([out1 , out2 ], overwrite_output = True )
144
152
145
153
146
154
def test_run_dummy_cmd ():
147
- node = _get_complex_filter_example ()
148
- ffmpeg .run (node , cmd = 'true' )
155
+ stream = _get_complex_filter_example ()
156
+ ffmpeg .run (stream , cmd = 'true' )
149
157
150
158
151
159
def test_run_dummy_cmd_list ():
152
- node = _get_complex_filter_example ()
153
- ffmpeg .run (node , cmd = ['true' , 'ignored' ])
160
+ stream = _get_complex_filter_example ()
161
+ ffmpeg .run (stream , cmd = ['true' , 'ignored' ])
154
162
155
163
156
164
def test_run_failing_cmd ():
157
- node = _get_complex_filter_example ()
165
+ stream = _get_complex_filter_example ()
158
166
with pytest .raises (subprocess .CalledProcessError ):
159
- ffmpeg .run (node , cmd = 'false' )
167
+ ffmpeg .run (stream , cmd = 'false' )
160
168
161
169
162
170
def test_custom_filter ():
163
- node = ffmpeg .input ('dummy.mp4' )
164
- node = ffmpeg .filter_ (node , 'custom_filter' , 'a' , 'b' , kwarg1 = 'c' )
165
- node = ffmpeg .output (node , 'dummy2.mp4' )
166
- assert node .get_args () == [
171
+ stream = ffmpeg .input ('dummy.mp4' )
172
+ stream = ffmpeg .filter_ (stream , 'custom_filter' , 'a' , 'b' , kwarg1 = 'c' )
173
+ stream = ffmpeg .output (stream , 'dummy2.mp4' )
174
+ assert stream .get_args () == [
167
175
'-i' , 'dummy.mp4' ,
168
176
'-filter_complex' , '[0]custom_filter=a:b:kwarg1=c[s0]' ,
169
177
'-map' , '[s0]' ,
@@ -172,19 +180,51 @@ def test_custom_filter():
172
180
173
181
174
182
def test_custom_filter_fluent ():
175
- node = (ffmpeg
183
+ stream = (ffmpeg
176
184
.input ('dummy.mp4' )
177
185
.filter_ ('custom_filter' , 'a' , 'b' , kwarg1 = 'c' )
178
186
.output ('dummy2.mp4' )
179
187
)
180
- assert node .get_args () == [
188
+ assert stream .get_args () == [
181
189
'-i' , 'dummy.mp4' ,
182
190
'-filter_complex' , '[0]custom_filter=a:b:kwarg1=c[s0]' ,
183
191
'-map' , '[s0]' ,
184
192
'dummy2.mp4'
185
193
]
186
194
187
195
196
+ def test_merge_outputs ():
197
+ in_ = ffmpeg .input ('in.mp4' )
198
+ out1 = in_ .output ('out1.mp4' )
199
+ out2 = in_ .output ('out2.mp4' )
200
+ assert ffmpeg .merge_outputs (out1 , out2 ).get_args () == [
201
+ '-i' , 'in.mp4' , 'out1.mp4' , 'out2.mp4'
202
+ ]
203
+ assert ffmpeg .get_args ([out1 , out2 ]) == [
204
+ '-i' , 'in.mp4' , 'out2.mp4' , 'out1.mp4'
205
+ ]
206
+
207
+
208
+ def test_multi_passthrough ():
209
+ out1 = ffmpeg .input ('in1.mp4' ).output ('out1.mp4' )
210
+ out2 = ffmpeg .input ('in2.mp4' ).output ('out2.mp4' )
211
+ out = ffmpeg .merge_outputs (out1 , out2 )
212
+ assert ffmpeg .get_args (out ) == [
213
+ '-i' , 'in1.mp4' ,
214
+ '-i' , 'in2.mp4' ,
215
+ 'out1.mp4' ,
216
+ '-map' , '[1]' , # FIXME: this should not be here (see #23)
217
+ 'out2.mp4'
218
+ ]
219
+ assert ffmpeg .get_args ([out1 , out2 ]) == [
220
+ '-i' , 'in2.mp4' ,
221
+ '-i' , 'in1.mp4' ,
222
+ 'out2.mp4' ,
223
+ '-map' , '[1]' , # FIXME: this should not be here (see #23)
224
+ 'out1.mp4'
225
+ ]
226
+
227
+
188
228
def test_pipe ():
189
229
width = 32
190
230
height = 32
0 commit comments