@video-editor/renderer 0.0.1-beta.22 → 0.0.1-beta.24
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.
- package/dist/index.js +325 -322
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,149 +3,152 @@ import { toRaw as De, isRef as Ne, shallowRef as se, unref as de, ref as ue, com
|
|
|
3
3
|
import { renderTxt2ImgBitmap as Be, MP4Clip as z, Combinator as pe, OffscreenSprite as he } from "@webav/av-cliper";
|
|
4
4
|
import { file as _e } from "opfs-tools";
|
|
5
5
|
import { Application as we, Sprite as F, Texture as A, Graphics as me, Container as We } from "pixi.js";
|
|
6
|
-
async function Ye(
|
|
6
|
+
async function Ye(e) {
|
|
7
7
|
const o = new we();
|
|
8
|
-
return await o.init({ resizeTo: window, backgroundAlpha: 0, ...
|
|
8
|
+
return await o.init({ resizeTo: window, backgroundAlpha: 0, ...e }), o;
|
|
9
9
|
}
|
|
10
|
-
function je(
|
|
11
|
-
const u = o || i,
|
|
12
|
-
if (!u || !
|
|
10
|
+
function je(e, o, a, i, c) {
|
|
11
|
+
const u = o || i, f = a || c;
|
|
12
|
+
if (!u || !f)
|
|
13
13
|
return { width: i, height: c };
|
|
14
|
-
const s = u /
|
|
15
|
-
switch (
|
|
14
|
+
const s = u / f, m = i / c;
|
|
15
|
+
switch (e) {
|
|
16
16
|
case "none":
|
|
17
|
-
return { width: u, height:
|
|
17
|
+
return { width: u, height: f };
|
|
18
18
|
case "cover":
|
|
19
|
-
return s >
|
|
19
|
+
return s > m ? { width: c * s, height: c } : { width: i, height: i / s };
|
|
20
20
|
case "stretch":
|
|
21
21
|
return { width: i, height: c };
|
|
22
22
|
default:
|
|
23
|
-
return s >
|
|
23
|
+
return s > m ? { width: i, height: i / s } : { width: c * s, height: c };
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function Ke(
|
|
27
|
-
const u = "fillMode" in
|
|
26
|
+
function Ke(e, o, a, i, c) {
|
|
27
|
+
const u = "fillMode" in e ? e.fillMode : void 0, { width: f, height: s } = je(
|
|
28
28
|
u,
|
|
29
29
|
i,
|
|
30
30
|
c,
|
|
31
31
|
o,
|
|
32
32
|
a
|
|
33
|
-
),
|
|
33
|
+
), m = "transform" in e ? e.transform : void 0, [M, g] = m?.position ?? [0, 0], [E, I] = m?.scale ?? [1, 1], S = m?.rotation?.[2] ?? 0, w = f * E, v = s * I, y = o / 2 + M * o / 2, C = a / 2 - g * a / 2;
|
|
34
34
|
return {
|
|
35
35
|
width: w,
|
|
36
36
|
height: v,
|
|
37
|
-
centerX:
|
|
38
|
-
centerY:
|
|
39
|
-
rotationRad:
|
|
37
|
+
centerX: y,
|
|
38
|
+
centerY: C,
|
|
39
|
+
rotationRad: S / 180 * Math.PI
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function Xe(
|
|
42
|
+
function Xe(e) {
|
|
43
43
|
const o = /* @__PURE__ */ new Set();
|
|
44
|
-
for (const a of
|
|
44
|
+
for (const a of e.tracks)
|
|
45
45
|
for (const i of a.children)
|
|
46
46
|
i.url && o.add(i.url);
|
|
47
47
|
return o;
|
|
48
48
|
}
|
|
49
|
-
function Ge(
|
|
49
|
+
function Ge(e, o) {
|
|
50
50
|
const a = [];
|
|
51
|
-
return
|
|
52
|
-
i.children.forEach((u,
|
|
53
|
-
u.startTime <= o && o < u.endTime && a.push({ segment: u, trackIndex: c, childIndex:
|
|
51
|
+
return e.tracks.forEach((i, c) => {
|
|
52
|
+
i.children.forEach((u, f) => {
|
|
53
|
+
u.startTime <= o && o < u.endTime && a.push({ segment: u, trackIndex: c, childIndex: f });
|
|
54
54
|
});
|
|
55
|
-
}), a.sort((i, c) =>
|
|
55
|
+
}), a.sort((i, c) => {
|
|
56
|
+
const u = e.tracks[i.trackIndex], f = e.tracks[c.trackIndex], s = u?.trackType === "frames" && u.isMain, m = f?.trackType === "frames" && f.isMain, M = e.tracks.length, g = s ? 0 : M - i.trackIndex, E = m ? 0 : M - c.trackIndex;
|
|
57
|
+
return g !== E ? g - E : i.trackIndex === c.trackIndex ? i.childIndex - c.childIndex : i.trackIndex - c.trackIndex;
|
|
58
|
+
});
|
|
56
59
|
}
|
|
57
|
-
function Je(
|
|
58
|
-
const c = Qe(o), u =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, { once: !0 })) :
|
|
60
|
+
function Je(e, o, a, i) {
|
|
61
|
+
const c = Qe(o), u = e instanceof F && e.texture.width || a, f = e instanceof F && e.texture.height || i, s = Ke(o, a, i, u, f);
|
|
62
|
+
e instanceof F ? (e.anchor.set(0.5), e.width = s.width, e.height = s.height, e.position.set(s.centerX, s.centerY), e.rotation = s.rotationRad, e.texture.source?.addEventListener?.("error", () => {
|
|
63
|
+
e.texture = A.from(He(a, i));
|
|
64
|
+
}, { once: !0 })) : e instanceof me && (e.clear(), e.rect(0, 0, s.width, s.height).fill({ color: ye("url" in o && typeof o.url == "string" ? o.url : o.segmentType), alpha: ve(o) ? c : 0.35 }), e.pivot.set(s.width / 2, s.height / 2), e.position.set(s.centerX, s.centerY), e.rotation = s.rotationRad), e.alpha = c;
|
|
62
65
|
}
|
|
63
|
-
function j(
|
|
66
|
+
function j(e, o) {
|
|
64
67
|
const a = new me();
|
|
65
|
-
return a.rect(0, 0, 10, 10).fill({ color: ye(o ??
|
|
68
|
+
return a.rect(0, 0, 10, 10).fill({ color: ye(o ?? e), alpha: 1 }), a;
|
|
66
69
|
}
|
|
67
|
-
function He(
|
|
68
|
-
const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${
|
|
70
|
+
function He(e, o, a) {
|
|
71
|
+
const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${o}"><rect width="100%" height="100%" fill="#0f172a" fill-opacity="0.8"/></svg>`;
|
|
69
72
|
return `data:image/svg+xml;base64,${btoa(i)}`;
|
|
70
73
|
}
|
|
71
|
-
function ye(
|
|
74
|
+
function ye(e) {
|
|
72
75
|
let o = 0;
|
|
73
|
-
for (let a = 0; a <
|
|
74
|
-
o =
|
|
76
|
+
for (let a = 0; a < e.length; a++)
|
|
77
|
+
o = e.charCodeAt(a) + ((o << 5) - o);
|
|
75
78
|
return o & 16777215;
|
|
76
79
|
}
|
|
77
|
-
function X(
|
|
78
|
-
const o =
|
|
80
|
+
function X(e) {
|
|
81
|
+
const o = e.tracks.flatMap((a) => a.children.map((i) => i.endTime));
|
|
79
82
|
return o.length ? Math.max(...o) : 0;
|
|
80
83
|
}
|
|
81
|
-
function K(
|
|
82
|
-
return Math.min(Math.max(
|
|
84
|
+
function K(e, o, a) {
|
|
85
|
+
return Math.min(Math.max(e, o), a);
|
|
83
86
|
}
|
|
84
|
-
function
|
|
85
|
-
const o = De(
|
|
87
|
+
function fe(e) {
|
|
88
|
+
const o = De(e);
|
|
86
89
|
return JSON.parse(JSON.stringify(o));
|
|
87
90
|
}
|
|
88
|
-
function ve(
|
|
89
|
-
return "opacity" in
|
|
91
|
+
function ve(e) {
|
|
92
|
+
return "opacity" in e;
|
|
90
93
|
}
|
|
91
|
-
function Qe(
|
|
92
|
-
return ve(
|
|
94
|
+
function Qe(e) {
|
|
95
|
+
return ve(e) && typeof e.opacity == "number" ? e.opacity : 1;
|
|
93
96
|
}
|
|
94
97
|
const Ze = 100, O = /* @__PURE__ */ new Map();
|
|
95
98
|
let et = Ze;
|
|
96
|
-
function tt(
|
|
97
|
-
O.delete(
|
|
99
|
+
function tt(e, o) {
|
|
100
|
+
O.delete(e), O.set(e, o);
|
|
98
101
|
}
|
|
99
102
|
function rt() {
|
|
100
103
|
for (; O.size > et; ) {
|
|
101
|
-
const [
|
|
102
|
-
O.delete(
|
|
104
|
+
const [e, o] = O.entries().next().value;
|
|
105
|
+
O.delete(e), o.close?.();
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
|
-
function nt(
|
|
106
|
-
return
|
|
108
|
+
function nt(e) {
|
|
109
|
+
return e.map((o) => o.content).filter(Boolean).join(`
|
|
107
110
|
`);
|
|
108
111
|
}
|
|
109
|
-
function ot(
|
|
110
|
-
const o = Array.isArray(
|
|
112
|
+
function ot(e) {
|
|
113
|
+
const o = Array.isArray(e.fontFamily) ? e.fontFamily.join(", ") : e.fontFamily, a = e.fontSize ?? 32, i = e.fontWeight ?? "normal", c = e.fontStyle ?? "normal", u = e.fill ?? "#ffffff", f = e.align ?? "left", s = [
|
|
111
114
|
`font-size: ${a}px`,
|
|
112
115
|
`font-weight: ${i}`,
|
|
113
116
|
`font-style: ${c}`,
|
|
114
117
|
`color: ${u}`,
|
|
115
|
-
`text-align: ${
|
|
118
|
+
`text-align: ${f}`,
|
|
116
119
|
"white-space: pre-wrap"
|
|
117
120
|
];
|
|
118
|
-
if (o && s.push(`font-family: ${o}`), typeof
|
|
119
|
-
const
|
|
120
|
-
s.push(`text-shadow: ${
|
|
121
|
+
if (o && s.push(`font-family: ${o}`), typeof e.letterSpacing == "number" && s.push(`letter-spacing: ${e.letterSpacing}px`), typeof e.leading == "number" && s.push(`line-height: ${e.leading}px`), e.background?.color && s.push(`background: ${e.background.color}`), e.stroke?.color && typeof e.stroke.width == "number" && s.push(`-webkit-text-stroke: ${e.stroke.width}px ${e.stroke.color}`), e.underline && s.push("text-decoration: underline"), e.dropShadow?.color && typeof e.dropShadow.distance == "number") {
|
|
122
|
+
const m = (e.dropShadow.angle ?? 45) * (Math.PI / 180), M = Math.cos(m) * e.dropShadow.distance, g = Math.sin(m) * e.dropShadow.distance, E = e.dropShadow.blur ?? 0;
|
|
123
|
+
s.push(`text-shadow: ${M}px ${g}px ${E}px ${e.dropShadow.color}`);
|
|
121
124
|
}
|
|
122
125
|
return s.join("; ");
|
|
123
126
|
}
|
|
124
|
-
async function it(
|
|
125
|
-
const a = `${o}::${
|
|
127
|
+
async function it(e, o) {
|
|
128
|
+
const a = `${o}::${e}`, i = O.get(a);
|
|
126
129
|
if (i)
|
|
127
130
|
return tt(a, i), i;
|
|
128
|
-
const c = await Be(
|
|
131
|
+
const c = await Be(e, o);
|
|
129
132
|
return O.set(a, c), rt(), c;
|
|
130
133
|
}
|
|
131
134
|
const at = "/video-editor-res";
|
|
132
|
-
async function ct(
|
|
133
|
-
const o = ze(), a = Ne(
|
|
134
|
-
o.verify(
|
|
135
|
-
), c =
|
|
135
|
+
async function ct(e) {
|
|
136
|
+
const o = ze(), a = Ne(e.protocol) ? e.protocol : se(e.protocol), i = se(
|
|
137
|
+
o.verify(fe(de(a)))
|
|
138
|
+
), c = e.app ?? await Ye(e.appOptions), u = new We();
|
|
136
139
|
c.stage.addChild(u);
|
|
137
|
-
const
|
|
138
|
-
let
|
|
139
|
-
async function
|
|
140
|
-
const n = b, { protocol: r, at: d, layer: l } =
|
|
140
|
+
const f = Ue({ dir: e.resourceDir }), s = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set(), I = e.videoSourceMode ?? "auto", S = /* @__PURE__ */ new Map(), w = ue(0), v = ue(!1), y = qe(() => X(i.value));
|
|
141
|
+
let C, P = 0, b = 0;
|
|
142
|
+
async function R(t) {
|
|
143
|
+
const n = b, { protocol: r, at: d, layer: l } = t, p = Pe(r, d), h = Ge(r, p), T = t.app.renderer.width, k = t.app.renderer.height, $ = [];
|
|
141
144
|
for (const { segment: V } of h) {
|
|
142
145
|
if (n !== b)
|
|
143
146
|
return;
|
|
144
|
-
const N = await
|
|
147
|
+
const N = await t.getDisplay(V);
|
|
145
148
|
if (n !== b)
|
|
146
149
|
return;
|
|
147
150
|
if (N && !N.destroyed) {
|
|
148
|
-
if (Je(N, V,
|
|
151
|
+
if (Je(N, V, T, k), Re(V) && await re(V, p), n !== b)
|
|
149
152
|
return;
|
|
150
153
|
$.push(N);
|
|
151
154
|
}
|
|
@@ -154,9 +157,9 @@ async function ct(t) {
|
|
|
154
157
|
return;
|
|
155
158
|
l.removeChildren();
|
|
156
159
|
const D = $.filter(Boolean);
|
|
157
|
-
D.length && l.addChild(...D), n === b &&
|
|
160
|
+
D.length && l.addChild(...D), n === b && t.app.render();
|
|
158
161
|
}
|
|
159
|
-
const
|
|
162
|
+
const x = st(() => R({
|
|
160
163
|
app: c,
|
|
161
164
|
layer: u,
|
|
162
165
|
protocol: i.value,
|
|
@@ -166,171 +169,171 @@ async function ct(t) {
|
|
|
166
169
|
J.run(() => {
|
|
167
170
|
Y(
|
|
168
171
|
() => de(a),
|
|
169
|
-
(
|
|
172
|
+
(t) => {
|
|
170
173
|
try {
|
|
171
|
-
i.value = o.verify(
|
|
174
|
+
i.value = o.verify(fe(t));
|
|
172
175
|
} catch (n) {
|
|
173
176
|
console.error("[renderer] invalid protocol update", n);
|
|
174
177
|
return;
|
|
175
178
|
}
|
|
176
|
-
b += 1, H(),
|
|
179
|
+
b += 1, H(), e.warmUpResources !== !1 && ge(i.value), Se(i.value), q(), e.manualRender || x();
|
|
177
180
|
},
|
|
178
181
|
{ deep: !0, immediate: !0 }
|
|
179
|
-
),
|
|
180
|
-
q(),
|
|
181
|
-
}), Y(
|
|
182
|
+
), e.manualRender || Y(w, () => {
|
|
183
|
+
q(), x();
|
|
184
|
+
}), Y(y, () => q());
|
|
182
185
|
});
|
|
183
186
|
function q() {
|
|
184
|
-
const
|
|
185
|
-
|
|
187
|
+
const t = y.value;
|
|
188
|
+
t <= 0 ? w.value = 0 : w.value > t ? w.value = t : w.value < 0 && (w.value = 0);
|
|
186
189
|
}
|
|
187
|
-
function ge(
|
|
188
|
-
for (const n of Xe(
|
|
189
|
-
s.has(n) || (s.add(n), ie(n) !== "video" && B(n) &&
|
|
190
|
+
function ge(t) {
|
|
191
|
+
for (const n of Xe(t))
|
|
192
|
+
s.has(n) || (s.add(n), ie(n) !== "video" && B(n) && f.add(n).catch(() => {
|
|
190
193
|
}));
|
|
191
194
|
}
|
|
192
|
-
function Se(
|
|
193
|
-
const n = new Set(
|
|
194
|
-
for (const [r, d] of
|
|
195
|
-
n.has(r) || (d.destroy(),
|
|
196
|
-
for (const [r, d] of
|
|
197
|
-
n.has(r) || (ne(d),
|
|
195
|
+
function Se(t) {
|
|
196
|
+
const n = new Set(t.tracks.flatMap((r) => r.children.map((d) => d.id)));
|
|
197
|
+
for (const [r, d] of m)
|
|
198
|
+
n.has(r) || (d.destroy(), m.delete(r));
|
|
199
|
+
for (const [r, d] of S)
|
|
200
|
+
n.has(r) || (ne(d), S.delete(r));
|
|
198
201
|
}
|
|
199
202
|
function H() {
|
|
200
203
|
u.removeChildren();
|
|
201
|
-
for (const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
for (const
|
|
205
|
-
ne(
|
|
206
|
-
|
|
204
|
+
for (const t of m.values())
|
|
205
|
+
t.destroy();
|
|
206
|
+
m.clear(), M.clear();
|
|
207
|
+
for (const t of S.values())
|
|
208
|
+
ne(t);
|
|
209
|
+
S.clear();
|
|
207
210
|
}
|
|
208
211
|
function Q() {
|
|
209
|
-
v.value || (v.value = !0, P = performance.now(),
|
|
212
|
+
v.value || (v.value = !0, P = performance.now(), C = requestAnimationFrame(Z));
|
|
210
213
|
}
|
|
211
214
|
function L() {
|
|
212
|
-
v.value = !1,
|
|
215
|
+
v.value = !1, C !== void 0 && cancelAnimationFrame(C), C = void 0, e.freezeOnPause !== !1 && Fe();
|
|
213
216
|
}
|
|
214
217
|
function Z() {
|
|
215
|
-
ee(), v.value && (
|
|
218
|
+
ee(), v.value && (C = requestAnimationFrame(Z));
|
|
216
219
|
}
|
|
217
|
-
function ee(
|
|
218
|
-
if (!v.value &&
|
|
220
|
+
function ee(t) {
|
|
221
|
+
if (!v.value && t === void 0)
|
|
219
222
|
return;
|
|
220
|
-
const n = performance.now(), r =
|
|
223
|
+
const n = performance.now(), r = t ?? (P ? n - P : 0);
|
|
221
224
|
P = n, r !== 0 && (w.value = K(
|
|
222
225
|
w.value + r,
|
|
223
226
|
0,
|
|
224
|
-
|
|
225
|
-
),
|
|
227
|
+
y.value || Number.POSITIVE_INFINITY
|
|
228
|
+
), y.value > 0 && w.value >= y.value && L());
|
|
226
229
|
}
|
|
227
|
-
function
|
|
228
|
-
w.value = K(
|
|
230
|
+
function Me(t) {
|
|
231
|
+
w.value = K(t, 0, y.value || Number.POSITIVE_INFINITY);
|
|
229
232
|
}
|
|
230
|
-
async function
|
|
231
|
-
w.value = K(
|
|
233
|
+
async function be(t) {
|
|
234
|
+
w.value = K(t, 0, y.value || Number.POSITIVE_INFINITY), await x();
|
|
232
235
|
}
|
|
233
|
-
async function Te(
|
|
234
|
-
const n =
|
|
236
|
+
async function Te(t) {
|
|
237
|
+
const n = m.get(t.id);
|
|
235
238
|
if (n)
|
|
236
239
|
return n;
|
|
237
|
-
const r =
|
|
240
|
+
const r = M.get(t.id);
|
|
238
241
|
if (r)
|
|
239
242
|
return r;
|
|
240
|
-
const d = xe(
|
|
241
|
-
|
|
243
|
+
const d = xe(t);
|
|
244
|
+
M.set(t.id, d);
|
|
242
245
|
const l = await d;
|
|
243
|
-
return l &&
|
|
244
|
-
}
|
|
245
|
-
async function xe(
|
|
246
|
-
if (
|
|
247
|
-
if (!
|
|
248
|
-
return j(
|
|
249
|
-
if ("type" in
|
|
250
|
-
const r = await
|
|
251
|
-
return r || j(
|
|
246
|
+
return l && m.set(t.id, l), M.delete(t.id), l;
|
|
247
|
+
}
|
|
248
|
+
async function xe(t) {
|
|
249
|
+
if (t.segmentType === "frames" || t.segmentType === "sticker") {
|
|
250
|
+
if (!t.url)
|
|
251
|
+
return j(t.segmentType);
|
|
252
|
+
if ("type" in t && t.type === "video" && ae(t.url)) {
|
|
253
|
+
const r = await Ie(t);
|
|
254
|
+
return r || j(t.segmentType, t.url);
|
|
252
255
|
}
|
|
253
|
-
const n = await
|
|
254
|
-
return n ? new F(n) : j(
|
|
256
|
+
const n = await Ee(t.url);
|
|
257
|
+
return n ? new F(n) : j(t.segmentType, t.url);
|
|
255
258
|
}
|
|
256
|
-
if (
|
|
257
|
-
return await
|
|
258
|
-
|
|
259
|
+
if (t.segmentType === "text")
|
|
260
|
+
return await ke(t);
|
|
261
|
+
t.segmentType === "effect" || t.segmentType;
|
|
259
262
|
}
|
|
260
|
-
async function
|
|
261
|
-
const n = nt(
|
|
263
|
+
async function ke(t) {
|
|
264
|
+
const n = nt(t.texts);
|
|
262
265
|
if (!n)
|
|
263
266
|
return;
|
|
264
|
-
const [r] =
|
|
267
|
+
const [r] = t.texts;
|
|
265
268
|
if (!r)
|
|
266
269
|
return;
|
|
267
270
|
const d = await it(n, ot(r)), l = A.from(d);
|
|
268
271
|
return new F(l);
|
|
269
272
|
}
|
|
270
|
-
async function
|
|
271
|
-
const n =
|
|
273
|
+
async function Ee(t) {
|
|
274
|
+
const n = t.startsWith("data:"), r = /^https?:\/\//.test(t);
|
|
272
275
|
if (!n && !r)
|
|
273
276
|
try {
|
|
274
|
-
await
|
|
275
|
-
const d = await
|
|
277
|
+
await f.add(t);
|
|
278
|
+
const d = await f.get(t);
|
|
276
279
|
if (d instanceof HTMLImageElement)
|
|
277
280
|
return A.from(d);
|
|
278
281
|
} catch {
|
|
279
282
|
}
|
|
280
|
-
return await Ve(
|
|
283
|
+
return await Ve(t);
|
|
281
284
|
}
|
|
282
|
-
async function
|
|
283
|
-
const n =
|
|
285
|
+
async function Ie(t) {
|
|
286
|
+
const n = S.get(t.id);
|
|
284
287
|
if (n)
|
|
285
288
|
return n.sprite;
|
|
286
|
-
const r = W(
|
|
287
|
-
if (r &&
|
|
289
|
+
const r = W(t.url), d = I !== "element", l = I !== "mp4clip";
|
|
290
|
+
if (r && g.has(r)) {
|
|
288
291
|
if (!l)
|
|
289
|
-
throw new Error(`[renderer] MP4Clip unsupported for ${
|
|
290
|
-
const
|
|
291
|
-
console.warn("[renderer] failed to load video via <video>",
|
|
292
|
+
throw new Error(`[renderer] MP4Clip unsupported for ${t.url}`);
|
|
293
|
+
const p = await U(t.url).catch((h) => {
|
|
294
|
+
console.warn("[renderer] failed to load video via <video>", t.url, h);
|
|
292
295
|
});
|
|
293
|
-
return
|
|
296
|
+
return p ? (S.set(t.id, p), p.sprite) : void 0;
|
|
294
297
|
}
|
|
295
298
|
if (d) {
|
|
296
|
-
const
|
|
297
|
-
if (r && te(h) &&
|
|
299
|
+
const p = await oe(t.url).catch((h) => {
|
|
300
|
+
if (r && te(h) && g.add(r), (!r || !E.has(r)) && (r && E.add(r), console.warn("[renderer] failed to load video via MP4Clip", t.url, h)), !l)
|
|
298
301
|
throw h;
|
|
299
302
|
});
|
|
300
|
-
if (
|
|
301
|
-
return
|
|
303
|
+
if (p)
|
|
304
|
+
return S.set(t.id, p), p.sprite;
|
|
302
305
|
}
|
|
303
306
|
if (l) {
|
|
304
|
-
const
|
|
305
|
-
console.warn("[renderer] failed to load video via <video>",
|
|
307
|
+
const p = await U(t.url).catch((h) => {
|
|
308
|
+
console.warn("[renderer] failed to load video via <video>", t.url, h);
|
|
306
309
|
});
|
|
307
|
-
if (
|
|
308
|
-
return
|
|
310
|
+
if (p)
|
|
311
|
+
return S.set(t.id, p), p.sprite;
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
|
-
function te(
|
|
312
|
-
if (!(
|
|
314
|
+
function te(t) {
|
|
315
|
+
if (!(t instanceof Error))
|
|
313
316
|
return !1;
|
|
314
|
-
const n =
|
|
317
|
+
const n = t.message || "";
|
|
315
318
|
return n.includes("stream is done") || n.includes("not emit ready");
|
|
316
319
|
}
|
|
317
|
-
async function re(
|
|
318
|
-
const r =
|
|
320
|
+
async function re(t, n) {
|
|
321
|
+
const r = S.get(t.id);
|
|
319
322
|
if (r)
|
|
320
323
|
try {
|
|
321
|
-
const d =
|
|
324
|
+
const d = t.fromTime ?? 0, l = Math.max(0, n - t.startTime + d), p = Math.floor(l * 1e3);
|
|
322
325
|
if (r.kind === "frozen") {
|
|
323
|
-
const
|
|
324
|
-
if (!
|
|
326
|
+
const T = W(t.url);
|
|
327
|
+
if (!T)
|
|
325
328
|
return;
|
|
326
|
-
const
|
|
327
|
-
return
|
|
329
|
+
const k = await Ce(t.url, T, { sprite: r.sprite, oldTexture: r.texture });
|
|
330
|
+
return k ? (S.set(t.id, k), await re(t, n)) : void 0;
|
|
328
331
|
}
|
|
329
332
|
if (r.kind === "mp4clip") {
|
|
330
|
-
const
|
|
331
|
-
if (
|
|
332
|
-
const
|
|
333
|
-
|
|
333
|
+
const T = await r.clip.tick(p);
|
|
334
|
+
if (T.video) {
|
|
335
|
+
const k = r.canvas.getContext("2d");
|
|
336
|
+
k && (k.drawImage(T.video, 0, 0, r.canvas.width, r.canvas.height), ce(r.texture)), T.video.close();
|
|
334
337
|
}
|
|
335
338
|
return;
|
|
336
339
|
}
|
|
@@ -339,48 +342,48 @@ async function ct(t) {
|
|
|
339
342
|
return;
|
|
340
343
|
await Oe(r, {
|
|
341
344
|
targetSec: h,
|
|
342
|
-
playbackRate:
|
|
345
|
+
playbackRate: t.playRate ?? 1
|
|
343
346
|
});
|
|
344
347
|
} catch (d) {
|
|
345
348
|
console.warn("[renderer] update video frame failed", d);
|
|
346
349
|
}
|
|
347
350
|
}
|
|
348
|
-
async function
|
|
349
|
-
const d =
|
|
350
|
-
if (
|
|
351
|
+
async function Ce(t, n, r) {
|
|
352
|
+
const d = I !== "element", l = I !== "mp4clip";
|
|
353
|
+
if (g.has(n)) {
|
|
351
354
|
if (!l)
|
|
352
|
-
throw new Error(`[renderer] MP4Clip unsupported for ${
|
|
353
|
-
return await U(
|
|
355
|
+
throw new Error(`[renderer] MP4Clip unsupported for ${t}`);
|
|
356
|
+
return await U(t, r).catch(() => {
|
|
354
357
|
});
|
|
355
358
|
}
|
|
356
359
|
if (d) {
|
|
357
|
-
const
|
|
358
|
-
if (te(h) &&
|
|
360
|
+
const p = await oe(t, r).catch((h) => {
|
|
361
|
+
if (te(h) && g.add(n), !l)
|
|
359
362
|
throw h;
|
|
360
363
|
});
|
|
361
|
-
if (
|
|
362
|
-
return
|
|
364
|
+
if (p)
|
|
365
|
+
return p;
|
|
363
366
|
}
|
|
364
367
|
if (l)
|
|
365
|
-
return await U(
|
|
368
|
+
return await U(t, r).catch(() => {
|
|
366
369
|
});
|
|
367
370
|
}
|
|
368
|
-
function
|
|
369
|
-
return
|
|
371
|
+
function Re(t) {
|
|
372
|
+
return t.segmentType === "frames" && t.type === "video" && typeof t.url == "string" && ae(t.url);
|
|
370
373
|
}
|
|
371
|
-
function Pe(
|
|
372
|
-
const r = X(
|
|
374
|
+
function Pe(t, n) {
|
|
375
|
+
const r = X(t);
|
|
373
376
|
if (r <= 0)
|
|
374
377
|
return 0;
|
|
375
378
|
if (n < r)
|
|
376
379
|
return n;
|
|
377
|
-
const d = Math.max(1e3 / Math.max(
|
|
380
|
+
const d = Math.max(1e3 / Math.max(t.fps || 30, 1), 1);
|
|
378
381
|
return Math.max(r - d, 0);
|
|
379
382
|
}
|
|
380
|
-
async function $e(
|
|
381
|
-
const n =
|
|
383
|
+
async function $e(t) {
|
|
384
|
+
const n = e.resourceDir ?? at;
|
|
382
385
|
try {
|
|
383
|
-
const r = W(
|
|
386
|
+
const r = W(t);
|
|
384
387
|
if (!r)
|
|
385
388
|
return;
|
|
386
389
|
const d = _e(`${n}/${r}`, "r");
|
|
@@ -390,13 +393,13 @@ async function ct(t) {
|
|
|
390
393
|
return;
|
|
391
394
|
}
|
|
392
395
|
}
|
|
393
|
-
function B(
|
|
394
|
-
return !(!
|
|
396
|
+
function B(t) {
|
|
397
|
+
return !(!t || t.startsWith("data:") || t.startsWith("blob:"));
|
|
395
398
|
}
|
|
396
399
|
function Fe() {
|
|
397
|
-
for (const [
|
|
400
|
+
for (const [t, n] of S) {
|
|
398
401
|
if (n.kind === "mp4clip") {
|
|
399
|
-
n.clip.destroy(),
|
|
402
|
+
n.clip.destroy(), S.set(t, {
|
|
400
403
|
kind: "frozen",
|
|
401
404
|
canvas: n.canvas,
|
|
402
405
|
texture: n.texture,
|
|
@@ -408,83 +411,83 @@ async function ct(t) {
|
|
|
408
411
|
n.kind === "element" && n.video.pause();
|
|
409
412
|
}
|
|
410
413
|
}
|
|
411
|
-
function ne(
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
+
function ne(t) {
|
|
415
|
+
if (t.kind === "mp4clip") {
|
|
416
|
+
t.clip.destroy();
|
|
414
417
|
return;
|
|
415
418
|
}
|
|
416
|
-
|
|
419
|
+
t.kind !== "frozen" && (t.video.pause(), t.video.removeAttribute("src"), t.video.load());
|
|
417
420
|
}
|
|
418
|
-
function _(
|
|
421
|
+
function _(t, n, r = 1e3) {
|
|
419
422
|
return new Promise((d, l) => {
|
|
420
|
-
const
|
|
421
|
-
|
|
423
|
+
const p = window.setTimeout(() => {
|
|
424
|
+
k(), l(new Error(`Timed out waiting for media event: ${n}`));
|
|
422
425
|
}, r), h = () => {
|
|
423
|
-
|
|
424
|
-
},
|
|
425
|
-
|
|
426
|
-
const $ =
|
|
426
|
+
k(), d();
|
|
427
|
+
}, T = () => {
|
|
428
|
+
k();
|
|
429
|
+
const $ = t.error ? `${t.error.code}` : "unknown";
|
|
427
430
|
l(new Error(`Media error (${$}) while waiting for ${n}`));
|
|
428
|
-
},
|
|
429
|
-
window.clearTimeout(
|
|
431
|
+
}, k = () => {
|
|
432
|
+
window.clearTimeout(p), t.removeEventListener(n, h), t.removeEventListener("error", T);
|
|
430
433
|
};
|
|
431
|
-
|
|
434
|
+
t.addEventListener(n, h, { once: !0 }), t.addEventListener("error", T, { once: !0 });
|
|
432
435
|
});
|
|
433
436
|
}
|
|
434
|
-
async function oe(
|
|
437
|
+
async function oe(t, n) {
|
|
435
438
|
let r;
|
|
436
|
-
B(
|
|
439
|
+
B(t) && (r = await $e(t));
|
|
437
440
|
let d;
|
|
438
441
|
try {
|
|
439
442
|
if (r)
|
|
440
443
|
d = new z(r);
|
|
441
444
|
else {
|
|
442
|
-
const $ = await fetch(
|
|
445
|
+
const $ = await fetch(t);
|
|
443
446
|
if (!$.body)
|
|
444
447
|
return;
|
|
445
|
-
if (B(
|
|
448
|
+
if (B(t)) {
|
|
446
449
|
const [D, V] = $.body.tee();
|
|
447
|
-
|
|
450
|
+
f.add(t, { body: V }).catch(() => {
|
|
448
451
|
}), d = new z(D);
|
|
449
452
|
} else
|
|
450
453
|
d = new z($.body);
|
|
451
454
|
}
|
|
452
455
|
await d.ready;
|
|
453
|
-
const { width: l, height:
|
|
454
|
-
h.width = l || 1, h.height =
|
|
455
|
-
const
|
|
456
|
-
return n?.sprite && (n.sprite.texture =
|
|
456
|
+
const { width: l, height: p } = d.meta, h = document.createElement("canvas");
|
|
457
|
+
h.width = l || 1, h.height = p || 1;
|
|
458
|
+
const T = A.from(h), k = n?.sprite ?? new F(T);
|
|
459
|
+
return n?.sprite && (n.sprite.texture = T, n.oldTexture?.destroy(!0)), { kind: "mp4clip", clip: d, canvas: h, texture: T, sprite: k, meta: { width: l, height: p } };
|
|
457
460
|
} catch (l) {
|
|
458
461
|
throw d?.destroy(), l;
|
|
459
462
|
}
|
|
460
463
|
}
|
|
461
|
-
function ie(
|
|
462
|
-
const r =
|
|
464
|
+
function ie(t) {
|
|
465
|
+
const r = t.split("#")[0].split("?")[0].split("/").pop()?.split(".").pop()?.toLowerCase() ?? "";
|
|
463
466
|
return ["mp4", "m4v", "mov", "webm"].includes(r) ? "video" : ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "avif"].includes(r) ? "image" : ["mp3", "wav", "aac", "m4a", "ogg", "flac"].includes(r) ? "audio" : "unknown";
|
|
464
467
|
}
|
|
465
|
-
function ae(
|
|
466
|
-
const n = ie(
|
|
468
|
+
function ae(t) {
|
|
469
|
+
const n = ie(t);
|
|
467
470
|
return !(n === "image" || n === "audio");
|
|
468
471
|
}
|
|
469
|
-
async function U(
|
|
472
|
+
async function U(t, n) {
|
|
470
473
|
const r = document.createElement("video");
|
|
471
|
-
r.crossOrigin = "anonymous", r.muted = !0, r.playsInline = !0, r.preload = "auto", r.src =
|
|
474
|
+
r.crossOrigin = "anonymous", r.muted = !0, r.playsInline = !0, r.preload = "auto", r.src = t;
|
|
472
475
|
try {
|
|
473
476
|
await _(r, "loadedmetadata", 4e3);
|
|
474
|
-
} catch (
|
|
475
|
-
throw r.pause(), r.removeAttribute("src"), r.load(),
|
|
477
|
+
} catch (k) {
|
|
478
|
+
throw r.pause(), r.removeAttribute("src"), r.load(), k;
|
|
476
479
|
}
|
|
477
|
-
const d = r.videoWidth || 1, l = r.videoHeight || 1,
|
|
478
|
-
|
|
479
|
-
const h = A.from(
|
|
480
|
-
return n?.sprite && (n.sprite.texture = h, n.oldTexture?.destroy(!0)), { kind: "element", video: r, canvas:
|
|
480
|
+
const d = r.videoWidth || 1, l = r.videoHeight || 1, p = document.createElement("canvas");
|
|
481
|
+
p.width = d, p.height = l;
|
|
482
|
+
const h = A.from(p), T = n?.sprite ?? new F(h);
|
|
483
|
+
return n?.sprite && (n.sprite.texture = h, n.oldTexture?.destroy(!0)), { kind: "element", video: r, canvas: p, texture: h, sprite: T, meta: { width: d, height: l } };
|
|
481
484
|
}
|
|
482
|
-
async function Oe(
|
|
483
|
-
const { video: r, canvas: d, texture: l } =
|
|
485
|
+
async function Oe(t, n) {
|
|
486
|
+
const { video: r, canvas: d, texture: l } = t;
|
|
484
487
|
r.playbackRate = Number.isFinite(n.playbackRate) && n.playbackRate > 0 ? n.playbackRate : 1, v.value ? r.play().catch(() => {
|
|
485
488
|
}) : r.pause();
|
|
486
|
-
const
|
|
487
|
-
if (Number.isFinite(
|
|
489
|
+
const p = r.currentTime, h = Math.abs(p - n.targetSec), T = v.value ? 0.25 : 0.03;
|
|
490
|
+
if (Number.isFinite(p) && h > T) {
|
|
488
491
|
try {
|
|
489
492
|
r.currentTime = n.targetSec;
|
|
490
493
|
} catch {
|
|
@@ -495,85 +498,85 @@ async function ct(t) {
|
|
|
495
498
|
if (r.readyState < 2 && (await _(r, "canplay", 250).catch(() => {
|
|
496
499
|
}), r.readyState < 2))
|
|
497
500
|
return;
|
|
498
|
-
const
|
|
499
|
-
|
|
501
|
+
const k = d.getContext("2d");
|
|
502
|
+
k && (k.drawImage(r, 0, 0, d.width, d.height), ce(l));
|
|
500
503
|
}
|
|
501
|
-
function Ve(
|
|
504
|
+
function Ve(t) {
|
|
502
505
|
return new Promise((n) => {
|
|
503
506
|
const r = new Image();
|
|
504
507
|
r.crossOrigin = "anonymous", r.onload = () => n(A.from(r)), r.onerror = () => {
|
|
505
|
-
console.warn("[renderer] failed to load image",
|
|
506
|
-
}, r.src =
|
|
508
|
+
console.warn("[renderer] failed to load image", t), n(void 0);
|
|
509
|
+
}, r.src = t;
|
|
507
510
|
});
|
|
508
511
|
}
|
|
509
|
-
function ce(
|
|
510
|
-
const n =
|
|
512
|
+
function ce(t) {
|
|
513
|
+
const n = t.source;
|
|
511
514
|
if ("update" in n && typeof n.update == "function") {
|
|
512
515
|
n.update();
|
|
513
516
|
return;
|
|
514
517
|
}
|
|
515
|
-
typeof
|
|
518
|
+
typeof t.update == "function" && t.update();
|
|
516
519
|
}
|
|
517
520
|
function Ae() {
|
|
518
|
-
L(), b += 1, J.stop(), H(), u.destroy({ children: !0 }),
|
|
521
|
+
L(), b += 1, J.stop(), H(), u.destroy({ children: !0 }), m.clear(), M.clear(), s.clear(), e.app || c.destroy();
|
|
519
522
|
}
|
|
520
|
-
return
|
|
523
|
+
return e.autoPlay && Q(), {
|
|
521
524
|
app: c,
|
|
522
525
|
layer: u,
|
|
523
526
|
currentTime: w,
|
|
524
|
-
duration:
|
|
527
|
+
duration: y,
|
|
525
528
|
isPlaying: v,
|
|
526
529
|
play: Q,
|
|
527
530
|
pause: L,
|
|
528
531
|
tick: ee,
|
|
529
|
-
seek:
|
|
530
|
-
renderAt:
|
|
532
|
+
seek: Me,
|
|
533
|
+
renderAt: be,
|
|
531
534
|
destroy: Ae
|
|
532
535
|
};
|
|
533
536
|
}
|
|
534
|
-
function st(
|
|
537
|
+
function st(e) {
|
|
535
538
|
let o = !1, a = !1, i = null, c = null;
|
|
536
539
|
return async () => {
|
|
537
540
|
i || (i = new Promise((s) => {
|
|
538
541
|
c = s;
|
|
539
542
|
}));
|
|
540
|
-
const
|
|
543
|
+
const f = i;
|
|
541
544
|
if (a)
|
|
542
|
-
return o = !0,
|
|
545
|
+
return o = !0, f;
|
|
543
546
|
a = !0;
|
|
544
547
|
do
|
|
545
|
-
o = !1, await
|
|
548
|
+
o = !1, await e();
|
|
546
549
|
while (o);
|
|
547
|
-
return a = !1, c?.(), i = null, c = null,
|
|
550
|
+
return a = !1, c?.(), i = null, c = null, f;
|
|
548
551
|
};
|
|
549
552
|
}
|
|
550
|
-
function dt(
|
|
551
|
-
return typeof
|
|
553
|
+
function dt(e) {
|
|
554
|
+
return typeof e == "object" && e !== null && "createReader" in e && "getSize" in e;
|
|
552
555
|
}
|
|
553
|
-
function ut(
|
|
554
|
-
return typeof ReadableStream < "u" &&
|
|
556
|
+
function ut(e) {
|
|
557
|
+
return typeof ReadableStream < "u" && e instanceof ReadableStream;
|
|
555
558
|
}
|
|
556
|
-
function
|
|
557
|
-
return typeof
|
|
559
|
+
function ft(e) {
|
|
560
|
+
return typeof e == "string" || e instanceof Blob || dt(e) || ut(e) ? { source: e } : e;
|
|
558
561
|
}
|
|
559
|
-
async function
|
|
560
|
-
if (typeof
|
|
561
|
-
const o = await fetch(
|
|
562
|
+
async function le(e) {
|
|
563
|
+
if (typeof e == "string") {
|
|
564
|
+
const o = await fetch(e);
|
|
562
565
|
if (!o.body)
|
|
563
566
|
throw new Error("concatVideos: unable to read video stream from url");
|
|
564
567
|
return o.body;
|
|
565
568
|
}
|
|
566
|
-
return
|
|
569
|
+
return e instanceof Blob ? e.stream() : e;
|
|
567
570
|
}
|
|
568
|
-
function
|
|
571
|
+
function lt(e, o) {
|
|
569
572
|
let a = !1;
|
|
570
573
|
const i = () => {
|
|
571
574
|
a || (a = !0, o());
|
|
572
|
-
}, c =
|
|
575
|
+
}, c = e.getReader();
|
|
573
576
|
return new ReadableStream({
|
|
574
577
|
async pull(u) {
|
|
575
|
-
const { done:
|
|
576
|
-
if (
|
|
578
|
+
const { done: f, value: s } = await c.read();
|
|
579
|
+
if (f) {
|
|
577
580
|
i(), u.close();
|
|
578
581
|
return;
|
|
579
582
|
}
|
|
@@ -588,54 +591,54 @@ function ft(t, o) {
|
|
|
588
591
|
}
|
|
589
592
|
});
|
|
590
593
|
}
|
|
591
|
-
async function gt(
|
|
592
|
-
if (
|
|
594
|
+
async function gt(e, o = {}) {
|
|
595
|
+
if (e.length === 0)
|
|
593
596
|
throw new Error("concatVideos: expected at least one source");
|
|
594
597
|
const {
|
|
595
598
|
onProgress: a,
|
|
596
599
|
width: i,
|
|
597
600
|
height: c,
|
|
598
601
|
...u
|
|
599
|
-
} = o,
|
|
600
|
-
await
|
|
601
|
-
const
|
|
602
|
-
if (!
|
|
603
|
-
throw
|
|
604
|
-
const
|
|
602
|
+
} = o, f = e.map(ft), [s, ...m] = f, M = await le(s.source), g = new z(M);
|
|
603
|
+
await g.ready;
|
|
604
|
+
const E = i ?? Math.round(g.meta.width || 0), I = c ?? Math.round(g.meta.height || 0);
|
|
605
|
+
if (!E || !I)
|
|
606
|
+
throw g.destroy(), new Error("concatVideos: output width/height is required");
|
|
607
|
+
const S = new pe({
|
|
605
608
|
...u,
|
|
606
|
-
width:
|
|
607
|
-
height:
|
|
609
|
+
width: E,
|
|
610
|
+
height: I
|
|
608
611
|
});
|
|
609
|
-
a &&
|
|
612
|
+
a && S.on("OutputProgress", a);
|
|
610
613
|
let w = 0;
|
|
611
614
|
const v = async (b) => {
|
|
612
|
-
const
|
|
613
|
-
if (!Number.isFinite(
|
|
615
|
+
const R = b.meta.duration;
|
|
616
|
+
if (!Number.isFinite(R) || R <= 0)
|
|
614
617
|
throw b.destroy(), new Error("concatVideos: invalid clip duration");
|
|
615
|
-
const
|
|
618
|
+
const x = new he(b);
|
|
616
619
|
try {
|
|
617
|
-
await
|
|
620
|
+
await x.ready, x.rect.x = 0, x.rect.y = 0, x.rect.w = E, x.rect.h = I, x.time.offset = w, x.time.duration = R, await S.addSprite(x), w += R;
|
|
618
621
|
} finally {
|
|
619
|
-
|
|
622
|
+
x.destroy();
|
|
620
623
|
}
|
|
621
624
|
};
|
|
622
625
|
try {
|
|
623
|
-
await v(
|
|
624
|
-
for (const b of
|
|
625
|
-
const
|
|
626
|
-
await
|
|
626
|
+
await v(g);
|
|
627
|
+
for (const b of m) {
|
|
628
|
+
const R = await le(b.source), x = new z(R);
|
|
629
|
+
await x.ready, await v(x);
|
|
627
630
|
}
|
|
628
631
|
} catch (b) {
|
|
629
|
-
throw
|
|
632
|
+
throw S.destroy(), b;
|
|
630
633
|
}
|
|
631
|
-
const
|
|
632
|
-
|
|
634
|
+
const y = w, C = S.output({ maxTime: y }), P = () => {
|
|
635
|
+
S.destroy();
|
|
633
636
|
};
|
|
634
637
|
return {
|
|
635
|
-
stream:
|
|
636
|
-
width:
|
|
637
|
-
height:
|
|
638
|
-
durationMs: Math.round(
|
|
638
|
+
stream: lt(C, P),
|
|
639
|
+
width: E,
|
|
640
|
+
height: I,
|
|
641
|
+
durationMs: Math.round(y / 1e3),
|
|
639
642
|
destroy: P
|
|
640
643
|
};
|
|
641
644
|
}
|
|
@@ -677,11 +680,11 @@ class G {
|
|
|
677
680
|
videoSourceMode: c.videoSourceMode ?? "mp4clip"
|
|
678
681
|
});
|
|
679
682
|
this.renderer = u;
|
|
680
|
-
const
|
|
683
|
+
const f = u.duration.value;
|
|
681
684
|
return this.meta = {
|
|
682
685
|
width: i.renderer.width,
|
|
683
686
|
height: i.renderer.height,
|
|
684
|
-
duration: Math.max(0, Math.round(
|
|
687
|
+
duration: Math.max(0, Math.round(f * 1e3))
|
|
685
688
|
}, this.meta;
|
|
686
689
|
}
|
|
687
690
|
async tick(o) {
|
|
@@ -710,15 +713,15 @@ class G {
|
|
|
710
713
|
this.destroyed || (this.destroyed = !0, this.renderer?.destroy(), this.app?.destroy(!0));
|
|
711
714
|
}
|
|
712
715
|
}
|
|
713
|
-
function pt(
|
|
716
|
+
function pt(e, o) {
|
|
714
717
|
let a = !1;
|
|
715
718
|
const i = () => {
|
|
716
719
|
a || (a = !0, o());
|
|
717
|
-
}, c =
|
|
720
|
+
}, c = e.getReader();
|
|
718
721
|
return new ReadableStream({
|
|
719
722
|
async pull(u) {
|
|
720
|
-
const { done:
|
|
721
|
-
if (
|
|
723
|
+
const { done: f, value: s } = await c.read();
|
|
724
|
+
if (f) {
|
|
722
725
|
i(), u.close();
|
|
723
726
|
return;
|
|
724
727
|
}
|
|
@@ -733,56 +736,56 @@ function pt(t, o) {
|
|
|
733
736
|
}
|
|
734
737
|
});
|
|
735
738
|
}
|
|
736
|
-
async function St(
|
|
739
|
+
async function St(e, o = {}) {
|
|
737
740
|
const {
|
|
738
741
|
width: a,
|
|
739
742
|
height: i,
|
|
740
743
|
fps: c,
|
|
741
744
|
onProgress: u,
|
|
742
|
-
clipOptions:
|
|
745
|
+
clipOptions: f,
|
|
743
746
|
audioSprites: s,
|
|
744
|
-
...
|
|
745
|
-
} = o,
|
|
746
|
-
if (!
|
|
747
|
+
...m
|
|
748
|
+
} = o, M = a ?? e.width, g = i ?? e.height;
|
|
749
|
+
if (!M || !g)
|
|
747
750
|
throw new Error("composeProtocol: output width/height is required");
|
|
748
|
-
const
|
|
749
|
-
...
|
|
750
|
-
audio:
|
|
751
|
-
width:
|
|
752
|
-
height:
|
|
753
|
-
fps:
|
|
751
|
+
const E = c ?? e.fps, I = typeof s == "function", S = m.audio ?? (I ? void 0 : !1), w = new pe({
|
|
752
|
+
...m,
|
|
753
|
+
audio: S,
|
|
754
|
+
width: M,
|
|
755
|
+
height: g,
|
|
756
|
+
fps: E
|
|
754
757
|
});
|
|
755
758
|
u && w.on("OutputProgress", u);
|
|
756
|
-
let v,
|
|
759
|
+
let v, y;
|
|
757
760
|
try {
|
|
758
|
-
if (v = new G(
|
|
759
|
-
width:
|
|
760
|
-
height:
|
|
761
|
-
fps:
|
|
762
|
-
...
|
|
761
|
+
if (v = new G(e, {
|
|
762
|
+
width: M,
|
|
763
|
+
height: g,
|
|
764
|
+
fps: E,
|
|
765
|
+
...f,
|
|
763
766
|
rendererOptions: {
|
|
764
767
|
warmUpResources: !1,
|
|
765
|
-
...
|
|
768
|
+
...f?.rendererOptions
|
|
766
769
|
}
|
|
767
|
-
}), await v.ready,
|
|
768
|
-
const
|
|
769
|
-
for (const
|
|
770
|
-
await w.addSprite(
|
|
770
|
+
}), await v.ready, y = new he(v), await y.ready, y.time.offset = 0, y.time.duration = v.meta.duration, y.rect.x = 0, y.rect.y = 0, y.rect.w = v.meta.width, y.rect.h = v.meta.height, await w.addSprite(y, { main: !0 }), s) {
|
|
771
|
+
const R = await s(e);
|
|
772
|
+
for (const x of R)
|
|
773
|
+
await w.addSprite(x);
|
|
771
774
|
}
|
|
772
|
-
} catch (
|
|
773
|
-
throw w.destroy(),
|
|
775
|
+
} catch (R) {
|
|
776
|
+
throw w.destroy(), R;
|
|
774
777
|
}
|
|
775
|
-
const
|
|
776
|
-
if (!
|
|
778
|
+
const C = v?.meta.duration ?? 0;
|
|
779
|
+
if (!C)
|
|
777
780
|
throw new Error("composeProtocol: protocol has no duration");
|
|
778
|
-
const P = w.output({ maxTime:
|
|
779
|
-
|
|
781
|
+
const P = w.output({ maxTime: C }), b = () => {
|
|
782
|
+
y?.destroy(), v?.destroy(), w.destroy();
|
|
780
783
|
};
|
|
781
784
|
return {
|
|
782
785
|
stream: pt(P, b),
|
|
783
|
-
width:
|
|
784
|
-
height:
|
|
785
|
-
durationMs: Math.round(
|
|
786
|
+
width: M,
|
|
787
|
+
height: g,
|
|
788
|
+
durationMs: Math.round(C / 1e3),
|
|
786
789
|
destroy: b
|
|
787
790
|
};
|
|
788
791
|
}
|