vidformer 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vidformer
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A Python library for creating and viewing videos with vidformer.
5
5
  Author-email: Dominik Winecki <dominikwinecki@gmail.com>
6
6
  Requires-Python: >=3.8
@@ -13,3 +13,10 @@ Requires-Dist: numpy
13
13
 
14
14
  # vidformer-py
15
15
 
16
+ ## Publish
17
+
18
+ ```bash
19
+ export FLIT_USERNAME='__token__' FLIT_PASSWORD='<token>'
20
+ flit publish
21
+ ```
22
+
@@ -0,0 +1,4 @@
1
+ vidformer.py,sha256=KcSMT_q66O-r0xtGujhHl0e6YMAyAovhzpsnR_ftgwY,23911
2
+ vidformer-0.2.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
3
+ vidformer-0.2.0.dist-info/METADATA,sha256=QJ8XqcazkCcn_ufPkTQzX3rQ9yTzb4_SOf_npWpnjHQ,523
4
+ vidformer-0.2.0.dist-info/RECORD,,
vidformer.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """A Python library for creating and viewing videos with vidformer."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.2.0"
4
4
 
5
5
  import subprocess
6
6
  from fractions import Fraction
@@ -13,6 +13,8 @@ import sys
13
13
  import multiprocessing
14
14
  import uuid
15
15
  import threading
16
+ import gzip
17
+ import base64
16
18
 
17
19
  import requests
18
20
  import msgpack
@@ -80,10 +82,10 @@ class Spec:
80
82
 
81
83
  from IPython.display import HTML
82
84
 
83
- spec_pth = f"spec-{str(uuid.uuid4())}.json"
84
- with open(spec_pth, "w") as outfile:
85
- spec, sources, filters = self._to_json_spec()
86
- outfile.write(json.dumps(spec))
85
+ spec, sources, filters = self._to_json_spec()
86
+ spec_json_bytes = json.dumps(spec).encode("utf-8")
87
+ spec_obj_json_gzip = gzip.compress(spec_json_bytes, compresslevel=1)
88
+ spec_obj_json_gzip_b64 = base64.b64encode(spec_obj_json_gzip).decode("utf-8")
87
89
 
88
90
  sources = [
89
91
  {
@@ -103,14 +105,11 @@ class Spec:
103
105
  }
104
106
  arrays = []
105
107
 
106
- print("Sending to server")
107
- resp = server._new(spec_pth, sources, filters, arrays, self._fmt)
108
+ print(f"Sending to server. Spec is {len(spec_obj_json_gzip_b64)} bytes")
109
+ resp = server._new(spec_obj_json_gzip_b64, sources, filters, arrays, self._fmt)
108
110
  hls_video_url = resp["stream_url"]
109
111
  namespace = resp["namespace"]
110
112
 
111
- if not keep_spec:
112
- os.remove(spec_pth)
113
-
114
113
  hls_js_url = server.hls_js_url()
115
114
 
116
115
  # We add a namespace to the video element to avoid conflicts with other videos
@@ -140,13 +139,19 @@ class Spec:
140
139
  """
141
140
  return HTML(data=html_code)
142
141
 
143
- def save(self, server, pth, keep_spec=False):
142
+ def save(self, server, pth, keep_spec=False, encoder=None, encoder_opts=None):
144
143
  """Save the video to a file."""
145
144
 
146
- spec_pth = f"spec-{str(uuid.uuid4())}.json"
147
- with open(spec_pth, "w") as outfile:
148
- spec, sources, filters = self._to_json_spec()
149
- outfile.write(json.dumps(spec))
145
+ assert encoder is None or type(encoder) == str
146
+ assert encoder_opts is None or type(encoder_opts) == dict
147
+ if encoder_opts is not None:
148
+ for k, v in encoder_opts:
149
+ assert type(k) == str and type(v) == str
150
+
151
+ spec, sources, filters = self._to_json_spec()
152
+ spec_json_bytes = json.dumps(spec).encode("utf-8")
153
+ spec_obj_json_gzip = gzip.compress(spec_json_bytes, compresslevel=1)
154
+ spec_obj_json_gzip_b64 = base64.b64encode(spec_obj_json_gzip).decode("utf-8")
150
155
 
151
156
  sources = [
152
157
  {
@@ -166,10 +171,16 @@ class Spec:
166
171
  }
167
172
  arrays = []
168
173
 
169
- resp = server._export(pth, spec_pth, sources, filters, arrays, self._fmt)
170
-
171
- if not keep_spec:
172
- os.remove(spec_pth)
174
+ resp = server._export(
175
+ pth,
176
+ spec_obj_json_gzip_b64,
177
+ sources,
178
+ filters,
179
+ arrays,
180
+ self._fmt,
181
+ encoder,
182
+ encoder_opts,
183
+ )
173
184
 
174
185
  return resp
175
186
 
@@ -245,7 +256,7 @@ class Spec:
245
256
  out["dve2_create_spec"] = end_t - start_t
246
257
 
247
258
  start = time.time()
248
- resp = server._export(pth, sources, filters, arrays, self._fmt)
259
+ resp = server._export(pth, sources, filters, arrays, self._fmt, None, None)
249
260
  end = time.time()
250
261
  out["dve2_exec"] = end - start
251
262
  return out
@@ -310,9 +321,9 @@ class YrdenServer:
310
321
 
311
322
  return r.json()
312
323
 
313
- def _export(self, pth, spec_pth, sources, filters, arrays, fmt):
324
+ def _export(self, pth, spec, sources, filters, arrays, fmt, encoder, encoder_opts):
314
325
  req = {
315
- "spec": spec_pth,
326
+ "spec": spec,
316
327
  "sources": sources,
317
328
  "filters": filters,
318
329
  "arrays": arrays,
@@ -320,6 +331,8 @@ class YrdenServer:
320
331
  "height": fmt["height"],
321
332
  "pix_fmt": fmt["pix_fmt"],
322
333
  "output_path": pth,
334
+ "encoder": encoder,
335
+ "encoder_opts": encoder_opts,
323
336
  }
324
337
 
325
338
  r = requests.post(f"http://{self._domain}:{self._port}/export", json=req)
@@ -1,4 +0,0 @@
1
- vidformer.py,sha256=bLGZ4zQVkU6etFj0jWuJM8h0sJqcZXwkqA0VfdtCyk0,23257
2
- vidformer-0.1.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
3
- vidformer-0.1.0.dist-info/METADATA,sha256=2YNtgTcee8N9LM8lzMvNFLndbcNy88Fqk6mwFYhz8pQ,427
4
- vidformer-0.1.0.dist-info/RECORD,,