vidformer 0.9.0__py3-none-any.whl → 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vidformer/__init__.py +1397 -3
- vidformer/cv2/__init__.py +858 -1
- vidformer/supervision/__init__.py +529 -0
- {vidformer-0.9.0.dist-info → vidformer-0.10.0.dist-info}/METADATA +7 -5
- vidformer-0.10.0.dist-info/RECORD +6 -0
- vidformer/cv2/vf_cv2.py +0 -810
- vidformer/igni/__init__.py +0 -1
- vidformer/igni/vf_igni.py +0 -285
- vidformer/vf.py +0 -1112
- vidformer-0.9.0.dist-info/RECORD +0 -9
- {vidformer-0.9.0.dist-info → vidformer-0.10.0.dist-info}/WHEEL +0 -0
vidformer/igni/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
from .vf_igni import *
|
vidformer/igni/vf_igni.py
DELETED
@@ -1,285 +0,0 @@
|
|
1
|
-
from .. import vf
|
2
|
-
|
3
|
-
import requests
|
4
|
-
from fractions import Fraction
|
5
|
-
from urllib.parse import urlparse
|
6
|
-
|
7
|
-
|
8
|
-
class IgniServer:
|
9
|
-
def __init__(self, endpoint: str, api_key: str):
|
10
|
-
if not endpoint.startswith("http://") and not endpoint.startswith("https://"):
|
11
|
-
raise Exception("Endpoint must start with http:// or https://")
|
12
|
-
if endpoint.endswith("/"):
|
13
|
-
raise Exception("Endpoint must not end with /")
|
14
|
-
self._endpoint = endpoint
|
15
|
-
|
16
|
-
self._api_key = api_key
|
17
|
-
response = requests.get(
|
18
|
-
f"{self._endpoint}/auth",
|
19
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
20
|
-
)
|
21
|
-
if not response.ok:
|
22
|
-
raise Exception(response.text)
|
23
|
-
response = response.json()
|
24
|
-
assert response["status"] == "ok"
|
25
|
-
|
26
|
-
def get_source(self, id: str):
|
27
|
-
assert type(id) == str
|
28
|
-
response = requests.get(
|
29
|
-
f"{self._endpoint}/source/{id}",
|
30
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
31
|
-
)
|
32
|
-
if not response.ok:
|
33
|
-
raise Exception(response.text)
|
34
|
-
response = response.json()
|
35
|
-
return IgniSource(response["id"], response)
|
36
|
-
|
37
|
-
def list_sources(self):
|
38
|
-
response = requests.get(
|
39
|
-
f"{self._endpoint}/source",
|
40
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
41
|
-
)
|
42
|
-
if not response.ok:
|
43
|
-
raise Exception(response.text)
|
44
|
-
response = response.json()
|
45
|
-
return response
|
46
|
-
|
47
|
-
def delete_source(self, id: str):
|
48
|
-
assert type(id) == str
|
49
|
-
response = requests.delete(
|
50
|
-
f"{self._endpoint}/source/{id}",
|
51
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
52
|
-
)
|
53
|
-
if not response.ok:
|
54
|
-
raise Exception(response.text)
|
55
|
-
response = response.json()
|
56
|
-
assert response["status"] == "ok"
|
57
|
-
|
58
|
-
def search_source(self, name, stream_idx, storage_service, storage_config):
|
59
|
-
assert type(name) == str
|
60
|
-
assert type(stream_idx) == int
|
61
|
-
assert type(storage_service) == str
|
62
|
-
assert type(storage_config) == dict
|
63
|
-
for k, v in storage_config.items():
|
64
|
-
assert type(k) == str
|
65
|
-
assert type(v) == str
|
66
|
-
req = {
|
67
|
-
"name": name,
|
68
|
-
"stream_idx": stream_idx,
|
69
|
-
"storage_service": storage_service,
|
70
|
-
"storage_config": storage_config,
|
71
|
-
}
|
72
|
-
response = requests.post(
|
73
|
-
f"{self._endpoint}/source/search",
|
74
|
-
json=req,
|
75
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
76
|
-
)
|
77
|
-
if not response.ok:
|
78
|
-
raise Exception(response.text)
|
79
|
-
response = response.json()
|
80
|
-
return response
|
81
|
-
|
82
|
-
def create_source(self, name, stream_idx, storage_service, storage_config):
|
83
|
-
assert type(name) == str
|
84
|
-
assert type(stream_idx) == int
|
85
|
-
assert type(storage_service) == str
|
86
|
-
assert type(storage_config) == dict
|
87
|
-
for k, v in storage_config.items():
|
88
|
-
assert type(k) == str
|
89
|
-
assert type(v) == str
|
90
|
-
req = {
|
91
|
-
"name": name,
|
92
|
-
"stream_idx": stream_idx,
|
93
|
-
"storage_service": storage_service,
|
94
|
-
"storage_config": storage_config,
|
95
|
-
}
|
96
|
-
response = requests.post(
|
97
|
-
f"{self._endpoint}/source",
|
98
|
-
json=req,
|
99
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
100
|
-
)
|
101
|
-
if not response.ok:
|
102
|
-
raise Exception(response.text)
|
103
|
-
response = response.json()
|
104
|
-
assert response["status"] == "ok"
|
105
|
-
id = response["id"]
|
106
|
-
return self.get_source(id)
|
107
|
-
|
108
|
-
def source(self, name, stream_idx, storage_service, storage_config):
|
109
|
-
"""Convenience function for accessing sources.
|
110
|
-
|
111
|
-
Tries to find a source with the given name, stream_idx, storage_service, and storage_config.
|
112
|
-
If no source is found, creates a new source with the given parameters.
|
113
|
-
"""
|
114
|
-
|
115
|
-
sources = self.search_source(name, stream_idx, storage_service, storage_config)
|
116
|
-
if len(sources) == 0:
|
117
|
-
return self.create_source(name, stream_idx, storage_service, storage_config)
|
118
|
-
return self.get_source(sources[0])
|
119
|
-
|
120
|
-
def get_spec(self, id: str):
|
121
|
-
assert type(id) == str
|
122
|
-
response = requests.get(
|
123
|
-
f"{self._endpoint}/spec/{id}",
|
124
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
125
|
-
)
|
126
|
-
if not response.ok:
|
127
|
-
raise Exception(response.text)
|
128
|
-
response = response.json()
|
129
|
-
return IgniSpec(response["id"], response)
|
130
|
-
|
131
|
-
def list_specs(self):
|
132
|
-
response = requests.get(
|
133
|
-
f"{self._endpoint}/spec",
|
134
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
135
|
-
)
|
136
|
-
if not response.ok:
|
137
|
-
raise Exception(response.text)
|
138
|
-
response = response.json()
|
139
|
-
return response
|
140
|
-
|
141
|
-
def create_spec(
|
142
|
-
self,
|
143
|
-
width,
|
144
|
-
height,
|
145
|
-
pix_fmt,
|
146
|
-
vod_segment_length,
|
147
|
-
frame_rate,
|
148
|
-
ready_hook=None,
|
149
|
-
steer_hook=None,
|
150
|
-
):
|
151
|
-
assert type(width) == int
|
152
|
-
assert type(height) == int
|
153
|
-
assert type(pix_fmt) == str
|
154
|
-
assert type(vod_segment_length) == Fraction
|
155
|
-
assert type(frame_rate) == Fraction
|
156
|
-
assert type(ready_hook) == str or ready_hook is None
|
157
|
-
assert type(steer_hook) == str or steer_hook is None
|
158
|
-
|
159
|
-
req = {
|
160
|
-
"width": width,
|
161
|
-
"height": height,
|
162
|
-
"pix_fmt": pix_fmt,
|
163
|
-
"vod_segment_length": [
|
164
|
-
vod_segment_length.numerator,
|
165
|
-
vod_segment_length.denominator,
|
166
|
-
],
|
167
|
-
"frame_rate": [frame_rate.numerator, frame_rate.denominator],
|
168
|
-
"ready_hook": ready_hook,
|
169
|
-
"steer_hook": steer_hook,
|
170
|
-
}
|
171
|
-
response = requests.post(
|
172
|
-
f"{self._endpoint}/spec",
|
173
|
-
json=req,
|
174
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
175
|
-
)
|
176
|
-
if not response.ok:
|
177
|
-
raise Exception(response.text)
|
178
|
-
response = response.json()
|
179
|
-
assert response["status"] == "ok"
|
180
|
-
return self.get_spec(response["id"])
|
181
|
-
|
182
|
-
def delete_spec(self, id: str):
|
183
|
-
assert type(id) == str
|
184
|
-
response = requests.delete(
|
185
|
-
f"{self._endpoint}/spec/{id}",
|
186
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
187
|
-
)
|
188
|
-
if not response.ok:
|
189
|
-
raise Exception(response.text)
|
190
|
-
response = response.json()
|
191
|
-
assert response["status"] == "ok"
|
192
|
-
|
193
|
-
def push_spec_part(self, spec_id, pos, frames, terminal):
|
194
|
-
if type(spec_id) == IgniSpec:
|
195
|
-
spec_id = spec_id._id
|
196
|
-
assert type(spec_id) == str
|
197
|
-
assert type(pos) == int
|
198
|
-
assert type(frames) == list
|
199
|
-
assert type(terminal) == bool
|
200
|
-
|
201
|
-
req_frames = []
|
202
|
-
for frame in frames:
|
203
|
-
assert type(frame) == tuple
|
204
|
-
assert len(frame) == 2
|
205
|
-
t = frame[0]
|
206
|
-
f = frame[1]
|
207
|
-
assert type(t) == Fraction
|
208
|
-
assert f is None or type(f) == vf.SourceExpr or type(f) == vf.FilterExpr
|
209
|
-
req_frames.append(
|
210
|
-
[
|
211
|
-
[t.numerator, t.denominator],
|
212
|
-
f._to_json_spec() if f is not None else None,
|
213
|
-
]
|
214
|
-
)
|
215
|
-
|
216
|
-
req = {
|
217
|
-
"pos": pos,
|
218
|
-
"frames": req_frames,
|
219
|
-
"terminal": terminal,
|
220
|
-
}
|
221
|
-
response = requests.post(
|
222
|
-
f"{self._endpoint}/spec/{spec_id}/part",
|
223
|
-
json=req,
|
224
|
-
headers={"Authorization": f"Bearer {self._api_key}"},
|
225
|
-
)
|
226
|
-
if not response.ok:
|
227
|
-
raise Exception(response.text)
|
228
|
-
response = response.json()
|
229
|
-
assert response["status"] == "ok"
|
230
|
-
|
231
|
-
|
232
|
-
class IgniSource:
|
233
|
-
def __init__(self, id, src):
|
234
|
-
self._name = id
|
235
|
-
self._fmt = {
|
236
|
-
"width": src["width"],
|
237
|
-
"height": src["height"],
|
238
|
-
"pix_fmt": src["pix_fmt"],
|
239
|
-
}
|
240
|
-
self._ts = [Fraction(x[0], x[1]) for x in src["ts"]]
|
241
|
-
self.iloc = vf.SourceILoc(self)
|
242
|
-
|
243
|
-
def id(self):
|
244
|
-
return self._name
|
245
|
-
|
246
|
-
def fmt(self):
|
247
|
-
return {**self._fmt}
|
248
|
-
|
249
|
-
def ts(self):
|
250
|
-
return self._ts.copy()
|
251
|
-
|
252
|
-
def __len__(self):
|
253
|
-
return len(self._ts)
|
254
|
-
|
255
|
-
def __getitem__(self, idx):
|
256
|
-
if type(idx) != Fraction:
|
257
|
-
raise Exception("Source index must be a Fraction")
|
258
|
-
return vf.SourceExpr(self, idx, False)
|
259
|
-
|
260
|
-
def __repr__(self):
|
261
|
-
return f"IgniSource({self._name})"
|
262
|
-
|
263
|
-
|
264
|
-
class IgniSpec:
|
265
|
-
def __init__(self, id, src):
|
266
|
-
self._id = id
|
267
|
-
self._fmt = {
|
268
|
-
"width": src["width"],
|
269
|
-
"height": src["height"],
|
270
|
-
"pix_fmt": src["pix_fmt"],
|
271
|
-
}
|
272
|
-
self._vod_endpoint = src["vod_endpoint"]
|
273
|
-
parsed_url = urlparse(self._vod_endpoint)
|
274
|
-
self._hls_js_url = f"{parsed_url.scheme}://{parsed_url.netloc}/hls.js"
|
275
|
-
|
276
|
-
def id(self):
|
277
|
-
return self._id
|
278
|
-
|
279
|
-
def play(self, *args, **kwargs):
|
280
|
-
url = f"{self._vod_endpoint}playlist.m3u8"
|
281
|
-
status_url = f"{self._vod_endpoint}status"
|
282
|
-
hls_js_url = self._hls_js_url
|
283
|
-
return vf._play(
|
284
|
-
self._id, url, hls_js_url, *args, **kwargs, status_url=status_url
|
285
|
-
)
|