-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_utils_filter.py
More file actions
170 lines (142 loc) · 5.27 KB
/
test_utils_filter.py
File metadata and controls
170 lines (142 loc) · 5.27 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
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
import logging
from ffmpegio.caps import filters
logging.basicConfig(level=logging.INFO)
from ffmpegio.utils import filter as filter_utils
from pprint import pprint
import pytest
def test_parse_filter():
f = "loudnorm"
assert filter_utils.parse_filter(f) == ("loudnorm",)
f = "loudnorm "
assert filter_utils.parse_filter(f) == ("loudnorm",)
with pytest.raises(ValueError):
f = "loudnorm,"
filter_utils.parse_filter(f) == ("loudnorm",)
f = "loudnorm=print_format=summary:linear=true"
print(filter_utils.parse_filter(f))
with pytest.raises(ValueError):
f = "loudnorm=print_format=summary:linear=true:"
filter_utils.parse_filter(f)
with pytest.raises(ValueError):
f = "loudnorm=print_format=summary:linear=true,"
filter_utils.parse_filter(f)
f = "scale=iw/2:-1"
print(filter_utils.parse_filter(f))
f = r"select='eq(pict_type,I)'"
print(filter_utils.parse_filter(f))
f = r"drawtext=fontfile=/usr/share/fonts/truetype/DroidSans.ttf: timecode=09\:57\:00\:00: r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1"
print(filter_utils.parse_filter(f))
def test_compose_filter():
f = "loudnorm"
print(filter_utils.compose_filter("loudnorm"))
f = "loudnorm=print_format=summary:linear=true"
print(
filter_utils.compose_filter(
"loudnorm", dict(print_format="summary", linear=True)
)
)
f = "scale=iw/2:-1"
print(filter_utils.compose_filter("scale", "iw/2", -1))
f = r"select='eq(pict_type\,I)'"
print(filter_utils.compose_filter("select", "eq(pict_type,I)"))
f = r"drawtext=fontfile=/usr/share/fonts/truetype/DroidSans.ttf: timecode='09\:57\:00\:00': r=25: \
x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1"
print(
filter_utils.compose_filter(
"drawtext",
dict(
fontfile="/usr/share/fonts/truetype/DroidSans.ttf",
timecode="09:57:00:00",
r=25,
x="(w-tw)/2",
y="h-(2*lh)",
fontcolor="white",
box=1,
boxcolor="0x00000000@1",
),
)
)
def test_compose_graph():
f = "yadif=0:0:0,scale=iw/2:-1"
pprint(filter_utils.compose_graph([[("yadif", 0, 0, 0), ("scale", "iw/2", -1)]]))
f = "[1:v]negate[a]; \
[2:v]hflip[b]; \
[3:v]edgedetect[c]; \
[0:v][a]hstack=inputs=2[top]; \
[b][c]hstack=inputs=2[bottom]; \
[top][bottom]vstack=inputs=2[out]"
pprint(
filter_utils.compose_graph(
[
[("negate",)], # chain #0
[("hflip",)], # chain #1
[("edgedetect",)], # chain #2
[("hstack", {"inputs": 2})], # chain #3
[("hstack", {"inputs": 2})], # chain #4
[("vstack", {"inputs": 2})], # chain #5
],
{
"1:v": [(0, 0, 0), None], # feeds to negate
"2:v": [(1, 0, 0), None], # feeds to hflip
"3:v": [(2, 0, 0), None], # feeds to edgedetect
"0:v": [(3, 0, 0), None], # feeds to the 1st input of 1st hstack
"out": [None, (5, 0, 0)], # feeds from vstack output
0: [(3, 0, 1), (0, 0, 0)], # 1st hstack gets its 2nd input from negate
1: [(4, 0, 0), (1, 0, 0)], # 2nd hstack gets its 1st input from hflip
2: [(4, 0, 1), (2, 0, 0)], # 2nd hstack its 2nd input <- edgedetect
3: [(5, 0, 0), (3, 0, 0)], # vstack gets its 1st input from 1st hstack
4: [(5, 0, 1), (4, 0, 0)], # vstack gets its 2nd input from 2nd hstack
},
)
)
f = "[0:v]pad=iw*2:ih*2[a]; \
[1:v]negate[b]; \
[2:v]hflip[c]; \
[3:v]edgedetect[d]; \
[a][b]overlay=w[x]; \
[x][c]overlay=0:h[y]; \
[y][d]overlay=w:h[out]"
pprint(
filter_utils.compose_graph(
[
[("pad", "iw*2", "ih*2")],
[("negate",)],
[("hflip",)],
[("edgedetect",)],
[("overlay", "w")],
[("overlay", "0", "h")],
[("overlay", "w", "h")],
],
{
"0:v": [(0, 0, 0), None],
"1:v": [(1, 0, 0), None],
"2:v": [(2, 0, 0), None],
"3:v": [(3, 0, 0), None],
"out": [None, (6, 0, 0)],
0: [(4, 0, 0), (0, 0, 0)],
1: [(4, 0, 1), (1, 0, 0)],
2: [(5, 0, 0), (4, 0, 0)],
3: [(5, 0, 1), (2, 0, 0)],
4: [(6, 0, 0), (5, 0, 0)],
5: [(6, 0, 1), (3, 0, 0)],
},
)
)
f = "[0:v]hflip,setpts=PTS-STARTPTS[a];[1:v]setpts=PTS-STARTPTS[b];[a][b]overlay"
pprint(
filter_utils.compose_graph(
[
[("hflip",), ("setpts", "PTS-STARTPTS")],
[("setpts", "PTS-STARTPTS")],
[("overlay",)],
],
{
"0:v": [(0, 0, 0), None],
"1:v": [(1, 0, 0), None],
0: [(2, 0, 0), (0, 1, 0)],
1: [(2, 0, 1), (1, 0, 0)],
},
)
)
if __name__ == "__main__":
from pprint import pprint