Skip to content

Commit 511fc3c

Browse files
committed
updated tests
1 parent 92c2050 commit 511fc3c

3 files changed

Lines changed: 45 additions & 57 deletions

File tree

tests/test_configure.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pprint import pprint
33

44
from ffmpegio import configure
5+
from ffmpegio import filtergraph as fgb
6+
from ffmpegio.utils import analyze_complex_filtergraphs
57

68
vid_url = "tests/assets/testvideo-1m.mp4"
79
img_url = "tests/assets/ffmpeg-logo.png"
@@ -180,39 +182,39 @@ def test_process_url_inputs(url, opts, defopts, ret):
180182
("inputs", "input_info", "filters_complex", "ret"),
181183
[
182184
(
183-
[(mul_url, None)],
185+
[(mul_url, {})],
184186
[{"src_type": "url"}],
185187
None,
186188
{
187-
f"0:{i}": {
189+
f"0:{mtype[0]}:{j}": {
188190
"media_type": mtype,
189191
"input_file_id": 0,
190192
"input_stream_id": i,
191193
}
192-
for i, mtype in mul_streams
194+
for (i, mtype), j in zip(mul_streams, [0, 0, 1, 1])
193195
},
194196
),
195197
(
196198
[(vid_url, None), (aud_url, {})],
197199
[{"src_type": "url"}, {"src_type": "url"}],
198200
None,
199201
{
200-
"0:0": {
202+
"0:v:0": {
201203
"media_type": "video",
202204
"input_file_id": 0,
203205
"input_stream_id": 0,
204206
},
205-
"1:0": {
207+
"1:a:0": {
206208
"media_type": "audio",
207209
"input_file_id": 1,
208210
"input_stream_id": 0,
209211
},
210212
},
211213
),
212214
(
213-
[(mul_url, None)],
215+
[(mul_url, {})],
214216
[{"src_type": "url"}],
215-
["split=n=2"],
217+
["split=outputs=2"],
216218
{"[out0]": {"media_type": "video"}, "[out1]": {"media_type": "video"}},
217219
),
218220
],
@@ -221,8 +223,11 @@ def test_auto_map(inputs, input_info, filters_complex, ret):
221223
args = configure.empty()
222224
args["inputs"].extend(inputs)
223225
if filters_complex is not None:
226+
filters_complex, fg_info = analyze_complex_filtergraphs(
227+
fgb.as_filtergraph(filters_complex), args["inputs"], input_info
228+
)
224229
args["global_options"] = {"filter_complex": filters_complex}
225-
out = configure.auto_map(args, input_info)
230+
out = configure.auto_map(args, input_info, filters_complex and fg_info)
226231
assert out == {
227232
spec: {"dst_type": "pipe", "user_map": None, **info}
228233
for spec, info in ret.items()
@@ -259,7 +264,7 @@ def ffmpeg_url_inputs_vid_aud():
259264
[
260265
("ffmpeg_url_inputs_mul", None, ["v"]),
261266
("ffmpeg_url_inputs_vid_aud", None, ["0:v:0", "1:a:0"]),
262-
("ffmpeg_url_inputs_mul", ["split=n=2"], ["[out0]", "[out1]", "a:0"]),
267+
("ffmpeg_url_inputs_mul", ["split=2"], ["[out0]", "[out1]", "a:0"]),
263268
],
264269
)
265270
def test_resolve_raw_output_streams(
@@ -268,7 +273,12 @@ def test_resolve_raw_output_streams(
268273

269274
args, input_info = request.getfixturevalue(ffmpeg_url_inputs)
270275

271-
if filters_complex is not None:
276+
if filters_complex is None:
277+
fg_info = None
278+
else:
279+
filters_complex, fg_info = analyze_complex_filtergraphs(
280+
fgb.as_filtergraph(filters_complex), args["inputs"], input_info
281+
)
272282
args["global_options"] = {"filter_complex": filters_complex}
273-
out = configure.resolve_raw_output_streams(args, input_info, streams)
283+
out = configure.resolve_raw_output_streams(args, input_info, fg_info, streams)
274284
pprint(out)

tests/test_media.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
from tempfile import TemporaryDirectory
22
from os import path
33
from pprint import pprint
4+
import pytest
45

56
import ffmpegio as ff
67

8+
url = "tests/assets/testmulti-1m.mp4"
9+
url1 = "tests/assets/testvideo-1m.mp4"
10+
url2 = "tests/assets/testaudio-1m.mp3"
711

8-
def test_media_read():
9-
url = "tests/assets/testmulti-1m.mp4"
10-
url1 = "tests/assets/testvideo-1m.mp4"
11-
url2 = "tests/assets/testaudio-1m.mp3"
12-
rates, data = ff.media.read(url, t=1, show_log=True)
13-
rates, data = ff.media.read(url, map=("v:0", "v:1", "a:1", "a:0"), t=1, show_log=True)
14-
rates, data = ff.media.read(url1, url2, t=1, show_log=True)
15-
rates, data = ff.media.read(url2, url, map=("1:v:0", (0, "a:0")), t=1, show_log=True)
1612

13+
@pytest.mark.parametrize(
14+
"urls,kwargs",
15+
[
16+
((url,), dict(t=1, show_log=True)),
17+
((url,), dict(map=("v:0", "v:1", "a:1", "a:0"), t=1, show_log=True)),
18+
((url1, url2), dict(t=1, show_log=True)),
19+
((url2, url), dict(map=("1:v:0", (0, "a:0")), t=1, show_log=True)),
20+
],
21+
)
22+
def test_media_read(urls, kwargs):
23+
rates, data = ff.media.read(*urls, **kwargs)
24+
print(rates)
25+
print([(k, x["shape"], x["dtype"]) for k, x in data.items()])
26+
27+
28+
def test_media_read_filter_complex():
29+
urls = (url2, url) # aud + mul
30+
kwargs = dict(t=1, show_log=True, filter_complex='[0:a]aformat=f=dbl:r=8000:cl=mono;[1:v:1]setpts=0.5*PTS')
31+
# kwargs = dict(map=(['[vout]','[aout]']), t=1, show_log=True, filter_complex='[0:a]aformat=f=dbl:r=8000:cl=mono[aout];[1:v:1]setpts=0.5*PTS[vout]')
32+
rates, data = ff.media.read(*urls, **kwargs)
1733
print(rates)
1834
print([(k, x["shape"], x["dtype"]) for k, x in data.items()])
1935

tests/test_threading.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,3 @@ def test_copyfileobj():
4343

4444
assert data == data_out
4545

46-
47-
if __name__ == "__main__":
48-
49-
url = "tests/assets/testmulti-1m.mp4"
50-
url1 = "tests/assets/testvideo-1m.mp4"
51-
url2 = "tests/assets/testaudio-1m.mp3"
52-
53-
from pprint import pprint
54-
55-
from ffmpegio import ffmpeg, configure
56-
import io
57-
58-
args = {
59-
"inputs": [(url1, None), (url2, None)],
60-
"outputs": [
61-
(
62-
"-",
63-
{
64-
"vframes": 16,
65-
},
66-
)
67-
],
68-
}
69-
use_ya = configure.finalize_media_read_opts(args)
70-
pprint(args)
71-
72-
# create a short example with both audio & video
73-
f = io.BytesIO(ffmpegprocess.run(args).stdout)
74-
75-
reader = threading.AviReaderThread()
76-
reader.start(f, use_ya)
77-
try:
78-
reader.wait()
79-
print(f"thread is running {reader.is_alive()}")
80-
pprint(reader.streams)
81-
pprint(reader.rates)
82-
except:
83-
reader.join()

0 commit comments

Comments
 (0)