caffeinism-utils 0.0.171__tar.gz → 0.0.173__tar.gz
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.
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/PKG-INFO +1 -1
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/pyproject.toml +1 -1
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/aiteration.py +14 -14
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/av/io.py +3 -3
- caffeinism_utils-0.0.173/src/caffeinism_utils/av/utils.py +292 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/README.md +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/__init__.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/asyncio.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/av/__init__.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/av/codecs.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/av/filters.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/http.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/io.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/iteration.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/prefetch.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/utils.py +0 -0
- {caffeinism_utils-0.0.171 → caffeinism_utils-0.0.173}/src/caffeinism_utils/zip.py +0 -0
|
@@ -26,35 +26,35 @@ async def rate_limit_iterator(aiterator, iters_per_second):
|
|
|
26
26
|
|
|
27
27
|
T = TypeVar("T")
|
|
28
28
|
|
|
29
|
-
__CLOSE = object()
|
|
30
29
|
|
|
30
|
+
class BaseStreamQueue(Generic[T]):
|
|
31
|
+
_CLOSE = object()
|
|
31
32
|
|
|
32
|
-
class StreamQueue(Generic[T]):
|
|
33
33
|
def __init__(self):
|
|
34
|
-
self.queue = asyncio.Queue
|
|
34
|
+
self.queue = asyncio.Queue()
|
|
35
|
+
|
|
36
|
+
async def close(self):
|
|
37
|
+
await self.queue.put(self._CLOSE)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class StreamQueue(BaseStreamQueue):
|
|
41
|
+
queue: asyncio.Queue[T]
|
|
35
42
|
|
|
36
43
|
def put(self, data: T) -> None:
|
|
37
44
|
return self.queue.put(data)
|
|
38
45
|
|
|
39
46
|
async def __aiter__(self) -> AsyncGenerator[T]:
|
|
40
|
-
while (it := await self.queue.get()) is not
|
|
47
|
+
while (it := await self.queue.get()) is not self._CLOSE:
|
|
41
48
|
yield it
|
|
42
49
|
|
|
43
|
-
async def close(self):
|
|
44
|
-
await self.queue.put(__CLOSE)
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def __init__(self):
|
|
49
|
-
self.queue = asyncio.Queue[AsyncIterable[T]]()
|
|
51
|
+
class StreamIteratorQueue(BaseStreamQueue):
|
|
52
|
+
queue: asyncio.Queue[AsyncIterable[T]]
|
|
50
53
|
|
|
51
54
|
def put(self, data: AsyncIterable[T]) -> None:
|
|
52
55
|
return self.queue.put(data)
|
|
53
56
|
|
|
54
57
|
async def __aiter__(self) -> AsyncGenerator[T]:
|
|
55
|
-
while (iterator := await self.queue.get()) is not
|
|
58
|
+
while (iterator := await self.queue.get()) is not self._CLOSE:
|
|
56
59
|
async for it in iterator:
|
|
57
60
|
yield it
|
|
58
|
-
|
|
59
|
-
async def close(self):
|
|
60
|
-
await self.queue.put(__CLOSE)
|
|
@@ -6,7 +6,7 @@ from abc import ABC, abstractmethod
|
|
|
6
6
|
from concurrent.futures import Future, ThreadPoolExecutor
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from types import TracebackType
|
|
9
|
-
from typing import Iterable
|
|
9
|
+
from typing import Generator, Iterable
|
|
10
10
|
|
|
11
11
|
import av
|
|
12
12
|
import av.container
|
|
@@ -100,7 +100,7 @@ class BasePyAVReader(PyAVInterface):
|
|
|
100
100
|
self._codec_contexts = {}
|
|
101
101
|
|
|
102
102
|
@abstractmethod
|
|
103
|
-
def __iter__(self):
|
|
103
|
+
def __iter__(self) -> Generator[av.VideoFrame | av.AudioFrame, None, None]:
|
|
104
104
|
raise NotImplementedError
|
|
105
105
|
|
|
106
106
|
def _create_container(self):
|
|
@@ -178,7 +178,7 @@ class PyAVReader(BasePyAVReader):
|
|
|
178
178
|
raise NotImplementedError
|
|
179
179
|
return self._alpha_merger
|
|
180
180
|
|
|
181
|
-
def __iter__(self):
|
|
181
|
+
def __iter__(self) -> Generator[av.VideoFrame | av.AudioFrame, None, None]:
|
|
182
182
|
with self:
|
|
183
183
|
for packet in self.container.demux(self.streams + self.audio_streams):
|
|
184
184
|
for frame in self.codec_contexts[packet.stream].decode(packet):
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import av
|
|
2
|
+
import numba
|
|
3
|
+
|
|
4
|
+
@numba.jit(
|
|
5
|
+
(
|
|
6
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
7
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
8
|
+
numba.int64,
|
|
9
|
+
numba.int64,
|
|
10
|
+
numba.int64,
|
|
11
|
+
numba.int64,
|
|
12
|
+
numba.int64,
|
|
13
|
+
numba.int64,
|
|
14
|
+
numba.int64,
|
|
15
|
+
numba.int64,
|
|
16
|
+
),
|
|
17
|
+
nopython=True,
|
|
18
|
+
nogil=True,
|
|
19
|
+
)
|
|
20
|
+
def _frame_paste_rgba(
|
|
21
|
+
dst_view: memoryview,
|
|
22
|
+
src_view: memoryview,
|
|
23
|
+
x: int,
|
|
24
|
+
y: int,
|
|
25
|
+
dw: int,
|
|
26
|
+
dh: int,
|
|
27
|
+
sw: int,
|
|
28
|
+
sh: int,
|
|
29
|
+
src_stride: int,
|
|
30
|
+
dst_stride: int,
|
|
31
|
+
):
|
|
32
|
+
sx = sy = 0
|
|
33
|
+
|
|
34
|
+
if x < 0:
|
|
35
|
+
sx -= x
|
|
36
|
+
sw += x
|
|
37
|
+
x = 0
|
|
38
|
+
if y < 0:
|
|
39
|
+
sy -= y
|
|
40
|
+
sh += y
|
|
41
|
+
y = 0
|
|
42
|
+
|
|
43
|
+
sw = min(sw, sw - sx, dw - x)
|
|
44
|
+
sh = min(sh, sh - sy, dh - y)
|
|
45
|
+
|
|
46
|
+
if sw <= 0 or sh <= 0:
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
s_base = sy * src_stride + sx * 4
|
|
50
|
+
d_base = y * dst_stride + x * 4
|
|
51
|
+
row_bytes = sw * 4
|
|
52
|
+
|
|
53
|
+
for r in range(sh):
|
|
54
|
+
so = s_base + r * src_stride
|
|
55
|
+
do = d_base + r * dst_stride
|
|
56
|
+
dst_view[do : do + row_bytes] = src_view[so : so + row_bytes]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def frame_paste_rgba(dst: av.VideoFrame, src: av.VideoFrame, x: int, y: int):
|
|
60
|
+
assert src.format.name == "rgba" and dst.format.name == "rgba"
|
|
61
|
+
|
|
62
|
+
dst.make_writable()
|
|
63
|
+
|
|
64
|
+
src_plane = src.planes[0]
|
|
65
|
+
dst_plane = dst.planes[0]
|
|
66
|
+
|
|
67
|
+
_frame_paste_rgba(
|
|
68
|
+
memoryview(dst_plane),
|
|
69
|
+
memoryview(src_plane),
|
|
70
|
+
x,
|
|
71
|
+
y,
|
|
72
|
+
dst.width,
|
|
73
|
+
dst.height,
|
|
74
|
+
src.width,
|
|
75
|
+
src.height,
|
|
76
|
+
src_plane.line_size,
|
|
77
|
+
dst_plane.line_size,
|
|
78
|
+
)
|
|
79
|
+
return dst
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@numba.jit(
|
|
83
|
+
(
|
|
84
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
85
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
86
|
+
numba.int64,
|
|
87
|
+
numba.int64,
|
|
88
|
+
numba.int64,
|
|
89
|
+
numba.int64,
|
|
90
|
+
numba.int64,
|
|
91
|
+
numba.int64,
|
|
92
|
+
numba.int64,
|
|
93
|
+
numba.int64,
|
|
94
|
+
),
|
|
95
|
+
nopython=True,
|
|
96
|
+
nogil=True,
|
|
97
|
+
)
|
|
98
|
+
def _blit_8bit_planar(
|
|
99
|
+
dst_view: memoryview,
|
|
100
|
+
src_view: memoryview,
|
|
101
|
+
dx: int,
|
|
102
|
+
dy: int,
|
|
103
|
+
sx: int,
|
|
104
|
+
sy: int,
|
|
105
|
+
w: int,
|
|
106
|
+
h: int,
|
|
107
|
+
dst_stride: int,
|
|
108
|
+
src_stride: int,
|
|
109
|
+
):
|
|
110
|
+
if w <= 0 or h <= 0:
|
|
111
|
+
return
|
|
112
|
+
row_bytes = w # 1 byte per pixel in 8-bit planar
|
|
113
|
+
s_base = sy * src_stride + sx
|
|
114
|
+
d_base = dy * dst_stride + dx
|
|
115
|
+
for r in range(h):
|
|
116
|
+
so = s_base + r * src_stride
|
|
117
|
+
do = d_base + r * dst_stride
|
|
118
|
+
dst_view[do : do + row_bytes] = src_view[so : so + row_bytes]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@numba.jit(
|
|
122
|
+
(
|
|
123
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
124
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
125
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
126
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
127
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
128
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
129
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
130
|
+
numba.types.MemoryView(numba.uint8, 1, "C"),
|
|
131
|
+
numba.int64,
|
|
132
|
+
numba.int64,
|
|
133
|
+
numba.int64,
|
|
134
|
+
numba.int64,
|
|
135
|
+
numba.int64,
|
|
136
|
+
numba.int64,
|
|
137
|
+
numba.int64,
|
|
138
|
+
numba.int64,
|
|
139
|
+
numba.int64,
|
|
140
|
+
numba.int64,
|
|
141
|
+
numba.int64,
|
|
142
|
+
numba.int64,
|
|
143
|
+
numba.int64,
|
|
144
|
+
numba.int64,
|
|
145
|
+
),
|
|
146
|
+
nopython=True,
|
|
147
|
+
nogil=True,
|
|
148
|
+
)
|
|
149
|
+
def _frame_paste_yuva420p(
|
|
150
|
+
dst_view_y: memoryview,
|
|
151
|
+
dst_view_u: memoryview,
|
|
152
|
+
dst_view_v: memoryview,
|
|
153
|
+
dst_view_a: memoryview,
|
|
154
|
+
src_view_y: memoryview,
|
|
155
|
+
src_view_u: memoryview,
|
|
156
|
+
src_view_v: memoryview,
|
|
157
|
+
src_view_a: memoryview,
|
|
158
|
+
x: int,
|
|
159
|
+
y: int,
|
|
160
|
+
dw: int,
|
|
161
|
+
dh: int,
|
|
162
|
+
sw: int,
|
|
163
|
+
sh: int,
|
|
164
|
+
src_stride_y: int,
|
|
165
|
+
src_stride_u: int,
|
|
166
|
+
src_stride_v: int,
|
|
167
|
+
src_stride_a: int,
|
|
168
|
+
dst_stride_y: int,
|
|
169
|
+
dst_stride_u: int,
|
|
170
|
+
dst_stride_v: int,
|
|
171
|
+
dst_stride_a: int,
|
|
172
|
+
):
|
|
173
|
+
sw0, sh0 = sw, sh
|
|
174
|
+
dw, dh = dw, dh
|
|
175
|
+
|
|
176
|
+
sx = max(0, -x)
|
|
177
|
+
sy = max(0, -y)
|
|
178
|
+
dx = max(0, x)
|
|
179
|
+
dy = max(0, y)
|
|
180
|
+
|
|
181
|
+
w = min(sw0 - sx, dw - dx)
|
|
182
|
+
h = min(sh0 - sy, dh - dy)
|
|
183
|
+
|
|
184
|
+
if w <= 0 or h <= 0:
|
|
185
|
+
return
|
|
186
|
+
|
|
187
|
+
_blit_8bit_planar(
|
|
188
|
+
dst_view_y,
|
|
189
|
+
src_view_y,
|
|
190
|
+
dx,
|
|
191
|
+
dy,
|
|
192
|
+
sx,
|
|
193
|
+
sy,
|
|
194
|
+
w,
|
|
195
|
+
h,
|
|
196
|
+
dst_stride_y,
|
|
197
|
+
src_stride_y,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
_blit_8bit_planar(
|
|
201
|
+
dst_view_a,
|
|
202
|
+
src_view_a,
|
|
203
|
+
dx,
|
|
204
|
+
dy,
|
|
205
|
+
sx,
|
|
206
|
+
sy,
|
|
207
|
+
w,
|
|
208
|
+
h,
|
|
209
|
+
dst_stride_a,
|
|
210
|
+
src_stride_a,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
hsub = 1
|
|
214
|
+
vsub = 1
|
|
215
|
+
|
|
216
|
+
sx_c = sx >> hsub
|
|
217
|
+
sy_c = sy >> vsub
|
|
218
|
+
dx_c = dx >> hsub
|
|
219
|
+
dy_c = dy >> vsub
|
|
220
|
+
|
|
221
|
+
src_cw = (sw0 + (1 << hsub) - 1) >> hsub
|
|
222
|
+
src_ch = (sh0 + (1 << vsub) - 1) >> vsub
|
|
223
|
+
dst_cw = (dw + (1 << hsub) - 1) >> hsub
|
|
224
|
+
dst_ch = (dh + (1 << vsub) - 1) >> vsub
|
|
225
|
+
|
|
226
|
+
w_c = ((sx + w + (1 << hsub) - 1) >> hsub) - (sx >> hsub)
|
|
227
|
+
h_c = ((sy + h + (1 << vsub) - 1) >> vsub) - (sy >> vsub)
|
|
228
|
+
|
|
229
|
+
w_c = min(w_c, src_cw - sx_c, dst_cw - dx_c)
|
|
230
|
+
h_c = min(h_c, src_ch - sy_c, dst_ch - dy_c)
|
|
231
|
+
|
|
232
|
+
if w_c > 0 and h_c > 0:
|
|
233
|
+
_blit_8bit_planar(
|
|
234
|
+
dst_view_u,
|
|
235
|
+
src_view_u,
|
|
236
|
+
dx_c,
|
|
237
|
+
dy_c,
|
|
238
|
+
sx_c,
|
|
239
|
+
sy_c,
|
|
240
|
+
w_c,
|
|
241
|
+
h_c,
|
|
242
|
+
dst_stride_u,
|
|
243
|
+
src_stride_u,
|
|
244
|
+
)
|
|
245
|
+
_blit_8bit_planar(
|
|
246
|
+
dst_view_v,
|
|
247
|
+
src_view_v,
|
|
248
|
+
dx_c,
|
|
249
|
+
dy_c,
|
|
250
|
+
sx_c,
|
|
251
|
+
sy_c,
|
|
252
|
+
w_c,
|
|
253
|
+
h_c,
|
|
254
|
+
dst_stride_v,
|
|
255
|
+
src_stride_v,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def frame_paste_yuva420p(dst: av.VideoFrame, src: av.VideoFrame, x: int, y: int):
|
|
260
|
+
assert src.format.name == "yuva420p" and dst.format.name == "yuva420p"
|
|
261
|
+
|
|
262
|
+
dst.make_writable()
|
|
263
|
+
|
|
264
|
+
src_Y, src_U, src_V, src_A = src.planes
|
|
265
|
+
dst_Y, dst_U, dst_V, dst_A = dst.planes
|
|
266
|
+
|
|
267
|
+
_frame_paste_yuva420p(
|
|
268
|
+
memoryview(dst_Y),
|
|
269
|
+
memoryview(dst_U),
|
|
270
|
+
memoryview(dst_V),
|
|
271
|
+
memoryview(dst_A),
|
|
272
|
+
memoryview(src_Y),
|
|
273
|
+
memoryview(src_U),
|
|
274
|
+
memoryview(src_V),
|
|
275
|
+
memoryview(src_A),
|
|
276
|
+
x,
|
|
277
|
+
y,
|
|
278
|
+
dst.width,
|
|
279
|
+
dst.height,
|
|
280
|
+
src.width,
|
|
281
|
+
src.height,
|
|
282
|
+
src_Y.line_size,
|
|
283
|
+
src_U.line_size,
|
|
284
|
+
src_V.line_size,
|
|
285
|
+
src_A.line_size,
|
|
286
|
+
dst_Y.line_size,
|
|
287
|
+
dst_U.line_size,
|
|
288
|
+
dst_V.line_size,
|
|
289
|
+
dst_A.line_size,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
return dst
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|