-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_utils_parser.py
More file actions
102 lines (91 loc) · 3.02 KB
/
test_utils_parser.py
File metadata and controls
102 lines (91 loc) · 3.02 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
from ffmpegio.utils import parser
from ffmpegio import FilterGraph
def test_ffmpeg():
out = parser.parse("ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi")
assert out == {
"global_options": {},
"inputs": [("input.avi", {})],
"outputs": [("output.avi", {"b:v": "64k", "bufsize": "64k"})],
}
s = r"ffmpeg -i input.ts -filter_complex \
'[#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay' \
-sn -map '#0x2dc' -map a output.mkv"
assert parser.parse(s) == {
"global_options": {
"filter_complex": "[#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay"
},
"inputs": [("input.ts", {})],
"outputs": [("output.mkv", {"sn": None, "map": ["#0x2dc", "a"]})],
}
s = "ffmpeg -i /tmp/a.wav -map 0:a -b:a 64k /tmp/a.mp2 -map 0:a -b:a 128k /tmp/b.mp2"
p = parser.parse(s)
assert p == {
"global_options": {},
"inputs": [("/tmp/a.wav", {})],
"outputs": [
("/tmp/a.mp2", {"map": "0:a", "b:a": "64k"}),
("/tmp/b.mp2", {"map": "0:a", "b:a": "128k"}),
],
}
def test_parse_options():
s = r"-filter_complex \
'[#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay' \
-sn -map '#0x2dc'"
parser.parse_options(s) == {
"filter_complex": "\n",
"#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay": "\n",
"sn": None,
"map": "#0x2dc",
}
s = "-i /tmp/a.wav -map 0:a -map 1:a -map 1:v -b:a 64k"
p = parser.parse_options(s)
assert p == {"i": "/tmp/a.wav", "map": ["0:a", "1:a", "1:v"], "b:a": "64k"}
def test_compose():
assert (
parser.compose(
{
"global_options": None,
"inputs": [("input.avi", {})],
"outputs": [("output.avi", {"b:v": "64k", "bufsize": "64k"})],
}
)
== ["-i", "input.avi", "-b:v", "64k", "-bufsize", "64k", "output.avi"]
)
assert parser.compose(
{
"global_options": {
"filter_complex": FilterGraph(
"[#0x2ef] setpts=PTS+1/TB [sub] ; [#0x2d0] [sub] overlay"
)
},
"inputs": [("input.ts", {})],
"outputs": [("output.mkv", {"sn": None, "map": ["#0x2dc", "a"]})],
},
command="ffmpeg",
) == [
"ffmpeg",
"-filter_complex",
"[#0x2ef]setpts=PTS+1/TB[sub];[#0x2d0][sub]overlay",
"-i",
"input.ts",
"-sn",
"-map",
"#0x2dc",
"-map",
"a",
"output.mkv",
]
assert (
parser.compose(
dict(
inputs=[("/tmp/a.wav", {})],
outputs=[
("/tmp/a test.mp2", {"map": "0:a", "b:a": "64k"}),
("/tmp/b.mp2", {"map": "0:a", "b:a": "128k"}),
],
),
command="ffmpeg",
shell_command=True,
)
== "ffmpeg -i /tmp/a.wav -map 0:a -b:a 64k '/tmp/a test.mp2' -map 0:a -b:a 128k /tmp/b.mp2"
)