-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_probe.py
More file actions
127 lines (107 loc) · 3.11 KB
/
test_probe.py
File metadata and controls
127 lines (107 loc) · 3.11 KB
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
import logging
logging.basicConfig(level=logging.DEBUG)
import pytest
from ffmpegio import ffmpeg_info
import ffmpegio.probe as probe
# print(
# probe.inquire(
# "tests/assets/testvideo-5m.mpg",
# show_format=True,
# show_streams=("index", "codec_name"),
# show_programs=False,
# )
# )
def test_probe():
probe.ffprobe("-help")
def test_url_types():
url = "tests/assets/testmulti-1m.mp4"
out = probe.query(url)
del out["filename"]
with open(url, "rb") as f:
# identical outcome if use file object, except for 'filename' field
out1 = probe.query(f)
f.seek(0)
del out1["filename"]
if 'bit_rate' not in out1:
del out['bit_rate']
if 'size' not in out1:
del out['size']
assert out1 == out
# piping in byte content of the file yields a few other differences
probe.query(f.read())
def test_all():
url = "tests/assets/testmulti-1m.mp4"
print(probe.full_details(url, show_streams="v"))
print(probe.format_basic(url))
print(probe.video_streams_basic(url))
print(probe.audio_streams_basic(url))
def test_query():
url = "tests/assets/testmulti-1m.mp4"
assert isinstance(probe.query(url, fields=("duration",)), dict)
assert isinstance(
probe.query(
url, "v", fields=("duration", "r_frame_rate", "avg_frame_rate", "pix_fmt")
),
list,
)
assert isinstance(
probe.query(url, "a:0", fields=("duration", "sample_rate", "sample_fmt")), dict
)
assert all(
st["max_bit_rate"] is None
for st in probe.query(
url, "a", fields=("duration", "max_bit_rate"), keep_optional_fields=True
)
)
assert (
probe.query(
url, "v:0", fields=("duration", "max_bit_rate"), keep_optional_fields=True
)["max_bit_rate"]
is None
)
# full detail
print(probe.query(url))
print(probe.query(url))
def test_frames():
url = "tests/assets/testmulti-1m.mp4"
info = probe.frames(
url,
streams="a:0",
intervals=10,
# intervals='%+#20,30%+#15'
# intervals=[{"end_offset": 20}, {"start": 30, "end_offset": 12}],
)
print(len(info))
print(info[-1])
pts_time = probe.frames(
url,
"key_frame",
"a:0",
intervals=10,
# intervals='%+#20,30%+#15'
# intervals=[{"end_offset": 20}, {"start": 30, "end_offset": 12}],
)
print(pts_time)
pts_time1 = probe.frames(
url,
"key_frame",
"a:0",
intervals=10,
accurate_time=True,
# intervals='%+#20,30%+#15'
# intervals=[{"end_offset": 20}, {"start": 30, "end_offset": 12}],
)
print(pts_time1)
print([t - t1 for t, t1 in zip(pts_time, pts_time1)])
info = probe.frames(
url,
streams="a:0",
intervals=(23.4, 1),
accurate_time=True,
# intervals='%+#20,30%+#15'
# intervals=[{"end_offset": 20}, {"start": 30, "end_offset": 12}],
)
print(info)
if __name__ == "__main__":
test_all()
pass