@taole/giftstage 0.1.33 → 0.1.34

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.
@@ -1,369 +0,0 @@
1
- let y = null;
2
- function v() {
3
- return y || (y = import("./mp4box.all-Bcqr6y1c.js").catch((e) => {
4
- throw y = null, e;
5
- })), y;
6
- }
7
- const C = 800;
8
- function S(e) {
9
- return e.startsWith("avc1") || e.startsWith("avc3");
10
- }
11
- function I(e) {
12
- const t = new Uint8Array(e);
13
- if (t.byteLength < 8) return e;
14
- const n = t[4], r = t[5], o = t[6], i = t[7];
15
- return n === 97 && r === 118 && o === 99 && i === 67 ? e.slice(8) : e;
16
- }
17
- async function F(e) {
18
- const t = e.avcC;
19
- if (!t) return;
20
- const { DataStream: n } = await v(), r = new n();
21
- t.write(r);
22
- const o = r.byteLength;
23
- if (o <= 0) return;
24
- const i = r.buffer.slice(0, o);
25
- return I(i);
26
- }
27
- async function P(e) {
28
- const { createFile: t } = await v();
29
- return new Promise((n, r) => {
30
- const o = t(), i = e.slice(0);
31
- i.fileStart = 0, o.onError = (d) => {
32
- r(new Error(`mp4box: ${d}`));
33
- }, o.onReady = (d) => {
34
- var a, c, l, f, h, m, g;
35
- const s = (a = d.videoTracks) == null ? void 0 : a[0];
36
- if (!s) {
37
- r(new Error("mp4box: no video track"));
38
- return;
39
- }
40
- if (!S(s.codec)) {
41
- r(new Error(`mp4box: unsupported video codec ${s.codec}`));
42
- return;
43
- }
44
- if (s.nb_samples > C) {
45
- r(new Error(`mp4box: too many samples (${s.nb_samples})`));
46
- return;
47
- }
48
- const p = [];
49
- o.onSamples = (q, B, k) => {
50
- p.push(...k);
51
- }, o.setExtractionOptions(s.id, null, {
52
- nbSamples: Math.max(s.nb_samples, 1)
53
- }), o.start();
54
- const b = s.timescale > 0 ? s.duration / s.timescale : d.duration / (d.timescale || 1);
55
- if (p.length === 0) {
56
- r(new Error("mp4box: extraction produced no samples"));
57
- return;
58
- }
59
- n({
60
- codec: s.codec,
61
- timescale: s.timescale,
62
- durationSec: Number.isFinite(b) ? b : 0,
63
- videoWidth: (f = (l = (c = s.video) == null ? void 0 : c.width) != null ? l : s.track_width) != null ? f : 0,
64
- videoHeight: (g = (m = (h = s.video) == null ? void 0 : h.height) != null ? m : s.track_height) != null ? g : 0,
65
- samples: p
66
- });
67
- }, o.appendBuffer(i), o.flush();
68
- });
69
- }
70
- const x = 25e3;
71
- async function D(e, t, n) {
72
- const r = performance.now();
73
- let o = 0;
74
- for (; e.decodeQueueSize > 0; )
75
- if (await new Promise((i) => queueMicrotask(i)), o++, o % 120 === 0 && await new Promise((i) => setTimeout(i, 0)), performance.now() - r > n) {
76
- console.warn("[GiftStage:WC] decodeQueue drain gave up", {
77
- label: t,
78
- decodeQueueSize: e.decodeQueueSize,
79
- spins: o
80
- });
81
- break;
82
- }
83
- }
84
- async function E(e, t) {
85
- console.info("[GiftStage:WC] VideoDecoder.flush…", t);
86
- try {
87
- await Promise.race([
88
- e.flush(),
89
- new Promise((n, r) => {
90
- setTimeout(
91
- () => r(
92
- new Error(
93
- `VideoDecoder.flush() timed out after ${x}ms (${JSON.stringify(t)})`
94
- )
95
- ),
96
- x
97
- );
98
- })
99
- ]);
100
- } catch (n) {
101
- try {
102
- e.close();
103
- } catch (r) {
104
- }
105
- throw n;
106
- }
107
- }
108
- function _(e, t, n) {
109
- if (e.length === 0) return 0;
110
- const r = e.length;
111
- if (n <= e[0]) return 0;
112
- const o = e[r - 1];
113
- if (n >= t || n >= o) return r - 1;
114
- let i = 0, d = r - 1;
115
- for (; i + 1 < d; ) {
116
- const a = i + d >>> 1;
117
- e[a] <= n ? i = a : d = a;
118
- }
119
- return i;
120
- }
121
- function N(e, t) {
122
- if (t.length === 0) return 1e-6;
123
- const n = t.length, r = n - 1, o = t[r], i = n >= 2 ? t[r] - t[r - 1] : 1 / 30, d = o + i;
124
- let a = e > 0 ? e : d;
125
- if (!(a > 0) && n >= 2) {
126
- const c = (t[n - 1] - t[0]) / (n - 1);
127
- a = t[n - 1] + (c > 0 ? c : 1 / 30);
128
- }
129
- return a > 0 || (a = Math.max(d, 1 / 30)), a;
130
- }
131
- function T(e, t) {
132
- var n, r;
133
- if (e.length === 0) return new Float64Array(0);
134
- const o = e.map((d, a) => a);
135
- o.sort((d, a) => {
136
- var c, l, f, h;
137
- const m = e[d], g = e[a], s = (l = (c = m.cts) != null ? c : m.dts) != null ? l : 0, p = (h = (f = g.cts) != null ? f : g.dts) != null ? h : 0;
138
- return s !== p ? s - p : d - a;
139
- });
140
- const i = new Float64Array(o.length);
141
- for (let d = 0; d < o.length; d++) {
142
- const a = e[o[d]];
143
- i[d] = ((r = (n = a.cts) != null ? n : a.dts) != null ? r : 0) / t;
144
- }
145
- return i;
146
- }
147
- function O(e) {
148
- return [...e].sort((t, n) => {
149
- var r, o, i, d;
150
- const a = ((o = (r = t.dts) != null ? r : t.cts) != null ? o : 0) - ((d = (i = n.dts) != null ? i : n.cts) != null ? d : 0);
151
- return a !== 0 ? a : 0;
152
- });
153
- }
154
- function W(e, t) {
155
- if (e.length === 0) return 0;
156
- const n = t / 1e6;
157
- let r = 0, o = 1 / 0;
158
- for (let i = 0; i < e.length; i++) {
159
- const d = Math.abs(e[i] - n);
160
- d < o && (o = d, r = i);
161
- }
162
- return r;
163
- }
164
- function A(e) {
165
- for (let t = 0; t < e.length; t++)
166
- if (e[t].is_sync) return t;
167
- return 0;
168
- }
169
- async function V(e, t) {
170
- var n;
171
- const r = {
172
- codec: e,
173
- hardwareAcceleration: "prefer-software",
174
- ...t && t.byteLength > 0 ? { description: t } : {}
175
- };
176
- let o = await VideoDecoder.isConfigSupported(r), i = r;
177
- if (!o.supported) {
178
- const d = {
179
- codec: e,
180
- ...t && t.byteLength > 0 ? { description: t } : {}
181
- };
182
- if (o = await VideoDecoder.isConfigSupported(d), !o.supported)
183
- throw new Error(`WebCodecs: unsupported config ${e}`);
184
- i = d;
185
- }
186
- return (n = o.config) != null ? n : i;
187
- }
188
- let u = null;
189
- self.onmessage = (e) => {
190
- const t = e.data;
191
- if (t) {
192
- if (t.type === "init") {
193
- H(t);
194
- return;
195
- }
196
- if (!(!u || t.id !== u.id)) {
197
- if (t.type === "ensure") {
198
- u.targetNeedIdx = Math.max(u.targetNeedIdx, t.needIdx), w(u);
199
- return;
200
- }
201
- if (t.type === "rewind") {
202
- Q(u);
203
- return;
204
- }
205
- t.type === "destroy" && M(u);
206
- }
207
- }
208
- };
209
- function M(e) {
210
- if (e.destroyed = !0, e.decoder && e.decoder.state !== "closed")
211
- try {
212
- e.decoder.close();
213
- } catch (t) {
214
- }
215
- e.decoder = null, u = null;
216
- }
217
- function w(e) {
218
- e.pumpScheduled || e.destroyed || (e.pumpScheduled = !0, queueMicrotask(() => {
219
- e.pumpScheduled = !1, U(e);
220
- }));
221
- }
222
- async function H(e) {
223
- u && M(u);
224
- const t = e.id;
225
- try {
226
- const n = await P(e.buffer);
227
- if (n.samples.length === 0) {
228
- self.postMessage({ type: "error", id: t, message: "mp4box: no samples" });
229
- return;
230
- }
231
- const r = O(n.samples), o = T(n.samples, n.timescale), i = N(n.durationSec, o), d = n.videoWidth || 0, a = n.videoHeight || 0, c = new Float64Array(o.length);
232
- c.set(o), self.postMessage(
233
- {
234
- type: "meta",
235
- id: t,
236
- duration: i,
237
- videoWidth: d,
238
- videoHeight: a,
239
- frameCount: o.length,
240
- timesSec: c
241
- },
242
- { transfer: [c.buffer] }
243
- );
244
- const l = _(o, i, 0), f = Math.min(
245
- o.length - 1,
246
- Math.max(0, l + Math.max(0, e.decodeAheadFrames))
247
- );
248
- u = {
249
- id: t,
250
- destroyed: !1,
251
- decodeOrder: r,
252
- presTimes: o,
253
- timescale: n.timescale,
254
- codec: n.codec,
255
- description: n.samples[0] ? await F(
256
- n.samples[0].description
257
- ) : void 0,
258
- duration: i,
259
- videoWidth: d,
260
- videoHeight: a,
261
- decoder: null,
262
- nextChunk: 0,
263
- chunksFed: 0,
264
- targetNeedIdx: f,
265
- lastPostedMax: -1,
266
- minPosted: Number.POSITIVE_INFINITY,
267
- playbackNeedFloor: l,
268
- eosClosed: !1,
269
- pumpScheduled: !1,
270
- pumping: !1
271
- }, w(u);
272
- } catch (n) {
273
- self.postMessage({
274
- type: "error",
275
- id: t,
276
- message: n instanceof Error ? n.message : String(n)
277
- });
278
- }
279
- }
280
- async function L(e) {
281
- if (e.decoder && e.decoder.state !== "closed") return;
282
- const t = await V(e.codec, e.description), n = new VideoDecoder({
283
- output: (r) => {
284
- if (e.destroyed) {
285
- try {
286
- r.close();
287
- } catch (i) {
288
- }
289
- return;
290
- }
291
- const o = W(e.presTimes, r.timestamp);
292
- e.lastPostedMax = Math.max(e.lastPostedMax, o), e.minPosted = Math.min(e.minPosted, o), self.postMessage({ type: "frame", id: e.id, index: o, frame: r }, { transfer: [r] });
293
- },
294
- error: (r) => {
295
- console.error("[GiftStage:WC] worker VideoDecoder error", r);
296
- }
297
- });
298
- n.configure(t), e.decoder = n;
299
- }
300
- async function Q(e) {
301
- if (e.destroyed) return;
302
- if (e.decoder && e.decoder.state !== "closed")
303
- try {
304
- e.decoder.close();
305
- } catch (n) {
306
- }
307
- e.decoder = null, e.nextChunk = A(e.decodeOrder), e.chunksFed = 0, e.lastPostedMax = -1, e.minPosted = Number.POSITIVE_INFINITY, e.eosClosed = !1;
308
- const t = _(e.presTimes, e.duration, 0);
309
- e.playbackNeedFloor = t, e.targetNeedIdx = Math.max(
310
- e.targetNeedIdx,
311
- Math.min(e.presTimes.length - 1, Math.max(0, t))
312
- ), w(e);
313
- }
314
- function $(e) {
315
- var t, n;
316
- const r = e.decoder, o = e.nextChunk;
317
- if (o >= e.decodeOrder.length) return;
318
- const i = e.decodeOrder[o];
319
- e.nextChunk = o + 1;
320
- const d = i.data;
321
- if (!d || d.byteLength === 0) return;
322
- const a = (n = (t = i.cts) != null ? t : i.dts) != null ? n : 0, c = Math.round(a / e.timescale * 1e6), l = i.duration && e.timescale > 0 ? Math.round(i.duration / e.timescale * 1e6) : void 0, f = new Uint8Array(d.byteLength);
323
- f.set(d);
324
- const h = new EncodedVideoChunk({
325
- type: i.is_sync ? "key" : "delta",
326
- timestamp: c,
327
- duration: l,
328
- data: f
329
- });
330
- r.decode(h), e.chunksFed++;
331
- }
332
- async function z(e) {
333
- if (!e.decoder || e.eosClosed) return;
334
- const t = e.decoder;
335
- await D(t, "before flush", 1e4);
336
- const n = t.decodeQueueSize;
337
- await E(t, {
338
- chunksDecoded: e.chunksFed,
339
- outputsBeforeFlush: e.lastPostedMax + 1,
340
- queueBeforeFlush: n
341
- });
342
- try {
343
- t.close();
344
- } catch (r) {
345
- }
346
- e.decoder = null, e.eosClosed = !0, self.postMessage({ type: "eos", id: e.id });
347
- }
348
- async function U(e) {
349
- if (!e.destroyed && !e.pumping) {
350
- e.pumping = !0;
351
- try {
352
- for (; !e.destroyed; ) {
353
- if (e.eosClosed)
354
- return;
355
- const t = e.nextChunk < e.decodeOrder.length, n = Number.isFinite(e.minPosted) && e.minPosted <= e.playbackNeedFloor, r = e.lastPostedMax < e.targetNeedIdx || !n;
356
- if (!t && !e.eosClosed) {
357
- await z(e);
358
- continue;
359
- }
360
- if (!r && t || !r && !t)
361
- return;
362
- await L(e), $(e), e.chunksFed % 4 === 0 && await new Promise((o) => setTimeout(o, 0));
363
- }
364
- } finally {
365
- e.pumping = !1;
366
- }
367
- }
368
- }
369
- //# sourceMappingURL=webcodecs-mp4.worker-BvV8Fiyc.js.map