@video-editor/renderer 0.0.1-beta.31 → 0.0.1-beta.33
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 +884 -719
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { createValidator as
|
|
2
|
-
import { toRaw as
|
|
3
|
-
import { AudioClip as
|
|
4
|
-
import { file as
|
|
5
|
-
import { Application as
|
|
6
|
-
async function
|
|
7
|
-
const
|
|
8
|
-
return await
|
|
1
|
+
import { createValidator as Wt, createResourceManager as Yt, getResourceKey as W } from "@video-editor/protocol";
|
|
2
|
+
import { toRaw as Xt, isRef as Jt, shallowRef as vt, unref as Mt, ref as gt, computed as Ht, effectScope as Qt, watch as Z } from "@vue/reactivity";
|
|
3
|
+
import { AudioClip as Tt, renderTxt2ImgBitmap as Zt, MP4Clip as K, Combinator as bt, OffscreenSprite as nt } from "@webav/av-cliper";
|
|
4
|
+
import { file as te } from "opfs-tools";
|
|
5
|
+
import { Application as kt, Sprite as V, Texture as G, Graphics as Ct, Container as ee } from "pixi.js";
|
|
6
|
+
async function oe(e) {
|
|
7
|
+
const t = new kt();
|
|
8
|
+
return await t.init({ resizeTo: window, backgroundAlpha: 0, ...e }), t;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
10
|
+
function ie(e, t, o, i, n) {
|
|
11
|
+
const a = t || i, c = o || n;
|
|
12
|
+
if (!a || !c)
|
|
13
13
|
return { width: i, height: n };
|
|
14
|
-
const
|
|
15
|
-
switch (
|
|
14
|
+
const u = a / c, d = i / n;
|
|
15
|
+
switch (e) {
|
|
16
16
|
case "none":
|
|
17
|
-
return { width:
|
|
17
|
+
return { width: a, height: c };
|
|
18
18
|
case "cover":
|
|
19
|
-
return
|
|
19
|
+
return u > d ? { width: n * u, height: n } : { width: i, height: i / u };
|
|
20
20
|
case "stretch":
|
|
21
21
|
return { width: i, height: n };
|
|
22
22
|
default:
|
|
23
|
-
return
|
|
23
|
+
return u > d ? { width: i, height: i / u } : { width: n * u, height: n };
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
|
|
26
|
+
function re(e, t, o, i, n) {
|
|
27
|
+
const a = "fillMode" in e ? e.fillMode : void 0, { width: c, height: u } = ie(
|
|
28
|
+
a,
|
|
29
29
|
i,
|
|
30
30
|
n,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
),
|
|
31
|
+
t,
|
|
32
|
+
o
|
|
33
|
+
), d = "transform" in e ? e.transform : void 0, [y, h] = d?.position ?? [0, 0], [w, M] = d?.scale ?? [1, 1], p = d?.rotation?.[2] ?? 0, v = c * w, m = u * M, g = t / 2 + y * t / 2, R = o / 2 - h * o / 2;
|
|
34
34
|
return {
|
|
35
35
|
width: v,
|
|
36
|
-
height:
|
|
36
|
+
height: m,
|
|
37
37
|
centerX: g,
|
|
38
38
|
centerY: R,
|
|
39
|
-
rotationRad:
|
|
39
|
+
rotationRad: p / 180 * Math.PI
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
for (const
|
|
45
|
-
for (const i of
|
|
46
|
-
i.url &&
|
|
47
|
-
return
|
|
42
|
+
function ne(e) {
|
|
43
|
+
const t = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const o of e.tracks)
|
|
45
|
+
for (const i of o.children)
|
|
46
|
+
i.url && t.add(i.url);
|
|
47
|
+
return t;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
const
|
|
51
|
-
return
|
|
52
|
-
i.children.forEach((
|
|
53
|
-
|
|
49
|
+
function Rt(e, t) {
|
|
50
|
+
const o = [];
|
|
51
|
+
return e.tracks.forEach((i, n) => {
|
|
52
|
+
i.children.forEach((a, c) => {
|
|
53
|
+
a.startTime <= t && t < a.endTime && o.push({ segment: a, trackIndex: n, childIndex: c });
|
|
54
54
|
});
|
|
55
|
-
}),
|
|
56
|
-
const
|
|
57
|
-
return
|
|
55
|
+
}), o.sort((i, n) => {
|
|
56
|
+
const a = e.tracks[i.trackIndex], c = e.tracks[n.trackIndex], u = a?.trackType === "frames" && a.isMain, d = c?.trackType === "frames" && c.isMain, y = e.tracks.length, h = u ? 0 : y - i.trackIndex, w = d ? 0 : y - n.trackIndex;
|
|
57
|
+
return h !== w ? h - w : i.trackIndex === n.trackIndex ? i.childIndex - n.childIndex : i.trackIndex - n.trackIndex;
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
const n =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, { once: !0 })) :
|
|
60
|
+
function ae(e, t, o, i) {
|
|
61
|
+
const n = ce(t), a = e instanceof V && e.texture.width || o, c = e instanceof V && e.texture.height || i, u = re(t, o, i, a, c);
|
|
62
|
+
e instanceof V ? (e.anchor.set(0.5), e.width = u.width, e.height = u.height, e.position.set(u.centerX, u.centerY), e.rotation = u.rotationRad, e.texture.source?.addEventListener?.("error", () => {
|
|
63
|
+
e.texture = G.from(se(o, i));
|
|
64
|
+
}, { once: !0 })) : e instanceof Ct && (e.clear(), e.rect(0, 0, u.width, u.height).fill({ color: At("url" in t && typeof t.url == "string" ? t.url : t.segmentType), alpha: Et(t) ? n : 0.35 }), e.pivot.set(u.width / 2, u.height / 2), e.position.set(u.centerX, u.centerY), e.rotation = u.rotationRad), e.alpha = n;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
return
|
|
66
|
+
function tt(e, t) {
|
|
67
|
+
const o = new Ct();
|
|
68
|
+
return o.rect(0, 0, 10, 10).fill({ color: At(t ?? e), alpha: 1 }), o;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${
|
|
70
|
+
function se(e, t, o) {
|
|
71
|
+
const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}"><rect width="100%" height="100%" fill="#0f172a" fill-opacity="0.8"/></svg>`;
|
|
72
72
|
return `data:image/svg+xml;base64,${btoa(i)}`;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
let
|
|
76
|
-
for (let
|
|
77
|
-
|
|
78
|
-
return
|
|
74
|
+
function At(e) {
|
|
75
|
+
let t = 0;
|
|
76
|
+
for (let o = 0; o < e.length; o++)
|
|
77
|
+
t = e.charCodeAt(o) + ((t << 5) - t);
|
|
78
|
+
return t & 16777215;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
const
|
|
82
|
-
return
|
|
80
|
+
function it(e) {
|
|
81
|
+
const t = e.tracks.flatMap((o) => o.children.map((i) => i.endTime));
|
|
82
|
+
return t.length ? Math.max(...t) : 0;
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return Math.min(Math.max(
|
|
84
|
+
function et(e, t, o) {
|
|
85
|
+
return Math.min(Math.max(e, t), o);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
return JSON.parse(JSON.stringify(
|
|
87
|
+
function St(e) {
|
|
88
|
+
const t = Xt(e);
|
|
89
|
+
return JSON.parse(JSON.stringify(t));
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
return "opacity" in
|
|
91
|
+
function Et(e) {
|
|
92
|
+
return "opacity" in e;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
94
|
+
function ce(e) {
|
|
95
|
+
return Et(e) && typeof e.opacity == "number" ? e.opacity : 1;
|
|
96
96
|
}
|
|
97
|
-
class
|
|
97
|
+
class ue {
|
|
98
98
|
protocol;
|
|
99
99
|
clips = /* @__PURE__ */ new Map();
|
|
100
100
|
loadingClips = /* @__PURE__ */ new Map();
|
|
@@ -108,91 +108,91 @@ class ot {
|
|
|
108
108
|
useMediaElementForAudio = !0;
|
|
109
109
|
ctx;
|
|
110
110
|
lastTime = 0;
|
|
111
|
-
constructor(
|
|
112
|
-
this.protocol =
|
|
111
|
+
constructor(t) {
|
|
112
|
+
this.protocol = t, this.ctx = new (window.AudioContext || window.webkitAudioContext)();
|
|
113
113
|
}
|
|
114
|
-
setProtocol(
|
|
115
|
-
this.protocol =
|
|
114
|
+
setProtocol(t) {
|
|
115
|
+
this.protocol = t;
|
|
116
116
|
}
|
|
117
|
-
async sync(
|
|
118
|
-
if (!
|
|
119
|
-
this.stopAll(), this.lastTime =
|
|
117
|
+
async sync(t, o) {
|
|
118
|
+
if (!o) {
|
|
119
|
+
this.stopAll(), this.lastTime = t;
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
122
|
this.ctx.state === "suspended" && await this.ctx.resume().catch(() => {
|
|
123
|
-
}), Math.abs(
|
|
124
|
-
const i =
|
|
123
|
+
}), Math.abs(t - this.lastTime) > 1e3 && this.stopAll(), this.lastTime = t;
|
|
124
|
+
const i = Rt(this.protocol, t), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
125
125
|
for (const { segment: c } of i)
|
|
126
126
|
if (c.segmentType === "audio") {
|
|
127
|
-
const
|
|
128
|
-
n.add(
|
|
127
|
+
const u = this.audioKey(c.id);
|
|
128
|
+
n.add(u), this.useMediaElementForAudio ? this.syncAudioElement(c, t) : this.ensureAudioLoop(c, t);
|
|
129
129
|
} else if (c.segmentType === "frames" && "type" in c && c.type === "video") {
|
|
130
|
-
const
|
|
131
|
-
|
|
130
|
+
const u = this.videoKey(c.id);
|
|
131
|
+
a.add(u);
|
|
132
132
|
}
|
|
133
|
-
for (const [c,
|
|
133
|
+
for (const [c, u] of this.audioLoops)
|
|
134
134
|
if (!n.has(c)) {
|
|
135
|
-
|
|
136
|
-
for (const
|
|
135
|
+
u.stop();
|
|
136
|
+
for (const d of u.sources)
|
|
137
137
|
try {
|
|
138
|
-
|
|
138
|
+
d.stop(), d.disconnect();
|
|
139
139
|
} catch {
|
|
140
140
|
}
|
|
141
141
|
this.audioLoops.delete(c), this.audioLoopContexts.delete(c), this.audioGains.delete(c);
|
|
142
142
|
}
|
|
143
|
-
for (const [c,
|
|
143
|
+
for (const [c, u] of this.audioElements)
|
|
144
144
|
if (!n.has(c)) {
|
|
145
145
|
try {
|
|
146
|
-
|
|
146
|
+
u.el.pause(), u.pendingPlay = void 0, u.lastTimelineMs = void 0, u.lastSourceSec = void 0, u.lastSeekTimelineMs = void 0;
|
|
147
147
|
} catch {
|
|
148
148
|
}
|
|
149
|
-
this.findSegmentInProtocol(
|
|
149
|
+
this.findSegmentInProtocol(u.segmentId) || (this.destroyAudioElement(u.el), this.audioElements.delete(c));
|
|
150
150
|
}
|
|
151
|
-
for (const [c,
|
|
152
|
-
if (!
|
|
153
|
-
|
|
154
|
-
for (const
|
|
151
|
+
for (const [c, u] of this.mp4Loops)
|
|
152
|
+
if (!a.has(c)) {
|
|
153
|
+
u.stop();
|
|
154
|
+
for (const d of u.sources)
|
|
155
155
|
try {
|
|
156
|
-
|
|
156
|
+
d.stop(), d.disconnect();
|
|
157
157
|
} catch {
|
|
158
158
|
}
|
|
159
159
|
this.mp4Loops.delete(c), this.mp4States.delete(c), this.mp4Gains.delete(c);
|
|
160
160
|
}
|
|
161
161
|
for (const c of this.mp4States.keys())
|
|
162
|
-
!
|
|
162
|
+
!a.has(c) && !this.mp4Loops.has(c) && (this.mp4States.delete(c), this.mp4Gains.delete(c));
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Play audio frames from MP4 video directly.
|
|
166
166
|
* Called by renderer after it gets audio data from clip.tick()
|
|
167
167
|
*/
|
|
168
|
-
playMp4AudioFrames(
|
|
169
|
-
if (!
|
|
168
|
+
playMp4AudioFrames(t, o, i) {
|
|
169
|
+
if (!o || o.length === 0 || !o[0]?.length)
|
|
170
170
|
return;
|
|
171
|
-
const n = this.videoKey(
|
|
171
|
+
const n = this.videoKey(t), a = this.getSegmentVolume(t), c = this.getOrCreateGain(this.mp4Gains, n, a);
|
|
172
172
|
this.ctx.state === "suspended" && this.ctx.resume().catch(() => {
|
|
173
173
|
});
|
|
174
|
-
let
|
|
175
|
-
|
|
174
|
+
let u = this.mp4States.get(n);
|
|
175
|
+
u || (u = {
|
|
176
176
|
loop: { stop: () => {
|
|
177
177
|
}, sources: [], isStopped: () => !1 },
|
|
178
178
|
startUs: 0,
|
|
179
179
|
startCtxTime: this.ctx.currentTime,
|
|
180
180
|
fps: 30,
|
|
181
181
|
nextStartAt: 0
|
|
182
|
-
}, this.mp4States.set(n,
|
|
182
|
+
}, this.mp4States.set(n, u)), u.nextStartAt = this.playFrames(o, i, u.nextStartAt ?? 0, c, u.loop.sources);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* Reset MP4 audio playback state (call when seeking or pausing)
|
|
186
186
|
*/
|
|
187
|
-
resetMp4Audio(
|
|
188
|
-
const
|
|
187
|
+
resetMp4Audio(t) {
|
|
188
|
+
const o = this.videoKey(t), i = this.mp4States.get(o);
|
|
189
189
|
i && (i.nextStartAt = 0);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
192
|
* Stop and clean up MP4 audio for a video segment
|
|
193
193
|
*/
|
|
194
|
-
stopMp4Audio(
|
|
195
|
-
const
|
|
194
|
+
stopMp4Audio(t) {
|
|
195
|
+
const o = this.videoKey(t), i = this.mp4States.get(o);
|
|
196
196
|
if (i) {
|
|
197
197
|
i.loop.stop();
|
|
198
198
|
for (const n of i.loop.sources)
|
|
@@ -200,32 +200,32 @@ class ot {
|
|
|
200
200
|
n.stop(), n.disconnect();
|
|
201
201
|
} catch {
|
|
202
202
|
}
|
|
203
|
-
this.mp4Loops.delete(
|
|
203
|
+
this.mp4Loops.delete(o), this.mp4States.delete(o), this.mp4Gains.delete(o);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
207
|
* @deprecated Use playMp4AudioFrames instead
|
|
208
208
|
*/
|
|
209
|
-
ensureMp4Audio(
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
if (Math.abs(w - i) < 15e4 &&
|
|
209
|
+
ensureMp4Audio(t, o, i, n) {
|
|
210
|
+
const a = this.videoKey(t), c = this.getSegmentVolume(t), u = this.getOrCreateGain(this.mp4Gains, a, c), d = this.mp4States.get(a);
|
|
211
|
+
if (d) {
|
|
212
|
+
u.gain.value = Math.max(0, c);
|
|
213
|
+
const h = (this.ctx.currentTime - d.startCtxTime) * 1e6, w = d.startUs + h;
|
|
214
|
+
if (Math.abs(w - i) < 15e4 && d.fps === n)
|
|
215
215
|
return;
|
|
216
|
-
|
|
217
|
-
for (const
|
|
216
|
+
d.loop.stop();
|
|
217
|
+
for (const M of d.loop.sources)
|
|
218
218
|
try {
|
|
219
|
-
|
|
219
|
+
M.stop(), M.disconnect();
|
|
220
220
|
} catch {
|
|
221
221
|
}
|
|
222
|
-
this.mp4Loops.delete(
|
|
222
|
+
this.mp4Loops.delete(a), this.mp4States.delete(a);
|
|
223
223
|
}
|
|
224
224
|
this.ctx.state === "suspended" && this.ctx.resume().catch(() => {
|
|
225
225
|
});
|
|
226
|
-
const
|
|
227
|
-
this.mp4Loops.set(
|
|
228
|
-
loop:
|
|
226
|
+
const y = this.startMp4Loop(o, i, n, u);
|
|
227
|
+
this.mp4Loops.set(a, y), this.mp4States.set(a, {
|
|
228
|
+
loop: y,
|
|
229
229
|
startUs: i,
|
|
230
230
|
startCtxTime: this.ctx.currentTime,
|
|
231
231
|
fps: n
|
|
@@ -233,87 +233,87 @@ class ot {
|
|
|
233
233
|
}
|
|
234
234
|
destroy() {
|
|
235
235
|
this.stopAll();
|
|
236
|
-
for (const
|
|
237
|
-
|
|
236
|
+
for (const t of this.clips.values())
|
|
237
|
+
t.clip.destroy();
|
|
238
238
|
this.clips.clear();
|
|
239
|
-
for (const
|
|
240
|
-
this.destroyAudioElement(
|
|
239
|
+
for (const t of this.audioElements.values())
|
|
240
|
+
this.destroyAudioElement(t.el);
|
|
241
241
|
this.audioElements.clear();
|
|
242
242
|
}
|
|
243
243
|
stopAll() {
|
|
244
|
-
for (const
|
|
244
|
+
for (const t of this.audioElements.values())
|
|
245
245
|
try {
|
|
246
|
-
|
|
246
|
+
t.el.pause(), t.pendingPlay = void 0, t.lastTimelineMs = void 0, t.lastSourceSec = void 0, t.lastSeekTimelineMs = void 0;
|
|
247
247
|
} catch {
|
|
248
248
|
}
|
|
249
|
-
for (const
|
|
250
|
-
|
|
251
|
-
for (const
|
|
249
|
+
for (const t of this.audioLoops.values()) {
|
|
250
|
+
t.stop();
|
|
251
|
+
for (const o of t.sources)
|
|
252
252
|
try {
|
|
253
|
-
|
|
253
|
+
o.stop(0), o.disconnect();
|
|
254
254
|
} catch {
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
t.sources.length = 0;
|
|
257
257
|
}
|
|
258
|
-
for (const
|
|
259
|
-
|
|
260
|
-
for (const
|
|
258
|
+
for (const t of this.mp4Loops.values()) {
|
|
259
|
+
t.stop();
|
|
260
|
+
for (const o of t.sources)
|
|
261
261
|
try {
|
|
262
|
-
|
|
262
|
+
o.stop(0), o.disconnect();
|
|
263
263
|
} catch {
|
|
264
264
|
}
|
|
265
|
-
|
|
265
|
+
t.sources.length = 0;
|
|
266
266
|
}
|
|
267
|
-
for (const
|
|
267
|
+
for (const t of this.audioGains.values())
|
|
268
268
|
try {
|
|
269
|
-
|
|
269
|
+
t.disconnect();
|
|
270
270
|
} catch {
|
|
271
271
|
}
|
|
272
|
-
for (const
|
|
272
|
+
for (const t of this.mp4Gains.values())
|
|
273
273
|
try {
|
|
274
|
-
|
|
274
|
+
t.disconnect();
|
|
275
275
|
} catch {
|
|
276
276
|
}
|
|
277
277
|
this.audioLoops.clear(), this.audioLoopContexts.clear(), this.audioGains.clear(), this.mp4Loops.clear(), this.mp4States.clear(), this.mp4Gains.clear();
|
|
278
278
|
}
|
|
279
|
-
async ensureAudioLoop(
|
|
280
|
-
const i = this.audioKey(
|
|
279
|
+
async ensureAudioLoop(t, o) {
|
|
280
|
+
const i = this.audioKey(t.id), n = await this.loadClip(t);
|
|
281
281
|
if (!n)
|
|
282
282
|
return;
|
|
283
|
-
const
|
|
284
|
-
this.applyFadeToGain(
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
283
|
+
const a = t.fromTime ?? 0, c = this.normalizePlayRate(t.playRate), u = o - t.startTime, d = a + u * c, y = this.getOrCreateGain(this.audioGains, i, t.volume);
|
|
284
|
+
this.applyFadeToGain(t, u, y);
|
|
285
|
+
const h = this.audioLoops.get(i);
|
|
286
|
+
if (h && !h.isStopped())
|
|
287
287
|
return;
|
|
288
|
-
|
|
289
|
-
const
|
|
288
|
+
h && (this.audioLoops.delete(i), this.audioLoopContexts.delete(i));
|
|
289
|
+
const M = (t.endTime - t.startTime) * c, p = a + M, v = this.startAudioLoop(n.clip, Math.max(0, d) * 1e3, y, c, p * 1e3);
|
|
290
290
|
this.audioLoops.set(i, v), this.audioLoopContexts.set(i, {
|
|
291
|
-
segment:
|
|
291
|
+
segment: t,
|
|
292
292
|
startedAt: this.ctx.currentTime,
|
|
293
|
-
segmentRelativeMs:
|
|
293
|
+
segmentRelativeMs: u
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
|
-
syncAudioElement(
|
|
297
|
-
const i = this.audioKey(
|
|
296
|
+
syncAudioElement(t, o) {
|
|
297
|
+
const i = this.audioKey(t.id), n = this.getOrCreateAudioElementState(i, t), a = o - t.startTime, c = this.normalizePlayRate(t.playRate), u = t.fromTime ?? 0, d = u + a * c, h = Math.max(0, t.endTime - t.startTime) * c, w = u + h, M = Math.max(0, w) / 1e3, p = Number.isFinite(n.el.duration) ? Math.max(0, n.el.duration) : void 0, v = p === void 0 ? M : Math.min(M, p), m = Math.max(0, Math.min(d / 1e3, v)), g = d / 1e3 >= v - 0.01;
|
|
298
298
|
Math.abs(n.el.playbackRate - c) > 1e-3 && (n.el.playbackRate = c);
|
|
299
|
-
const R = this.computeSegmentVolume(
|
|
299
|
+
const R = this.computeSegmentVolume(t, a);
|
|
300
300
|
Math.abs(n.el.volume - R) > 1e-3 && (n.el.volume = R);
|
|
301
|
-
const
|
|
301
|
+
const P = 0.24, A = 500, E = 300, b = -40, q = n.lastTimelineMs, D = n.lastSourceSec, z = q === void 0 ? 0 : o - q;
|
|
302
302
|
let O = !1;
|
|
303
|
-
if (
|
|
303
|
+
if (q === void 0)
|
|
304
304
|
O = !0;
|
|
305
|
-
else if (
|
|
305
|
+
else if (z < b || z > E)
|
|
306
306
|
O = !0;
|
|
307
|
-
else if (
|
|
308
|
-
const
|
|
309
|
-
|
|
307
|
+
else if (D !== void 0) {
|
|
308
|
+
const F = D + z * c / 1e3, Y = Math.abs(F - m), _ = n.lastSeekTimelineMs === void 0 || o - n.lastSeekTimelineMs >= A;
|
|
309
|
+
Y > P && _ && (O = !0);
|
|
310
310
|
}
|
|
311
|
-
if (O && Math.abs(n.el.currentTime -
|
|
311
|
+
if (O && Math.abs(n.el.currentTime - m) > 0.06)
|
|
312
312
|
try {
|
|
313
|
-
n.el.currentTime =
|
|
313
|
+
n.el.currentTime = m, n.lastSeekTimelineMs = o;
|
|
314
314
|
} catch {
|
|
315
315
|
}
|
|
316
|
-
if (n.lastTimelineMs =
|
|
316
|
+
if (n.lastTimelineMs = o, n.lastSourceSec = m, g) {
|
|
317
317
|
if (!n.el.paused)
|
|
318
318
|
try {
|
|
319
319
|
n.el.pause();
|
|
@@ -323,59 +323,59 @@ class ot {
|
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
325
325
|
if (n.el.paused && !n.pendingPlay) {
|
|
326
|
-
const
|
|
327
|
-
|
|
326
|
+
const F = n.el.play();
|
|
327
|
+
F && typeof F.then == "function" && (n.pendingPlay = F.catch(() => {
|
|
328
328
|
}).finally(() => {
|
|
329
329
|
n.pendingPlay = void 0;
|
|
330
330
|
}));
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
applyFadeToGain(
|
|
334
|
-
i.gain.value = this.computeSegmentVolume(
|
|
333
|
+
applyFadeToGain(t, o, i) {
|
|
334
|
+
i.gain.value = this.computeSegmentVolume(t, o);
|
|
335
335
|
}
|
|
336
|
-
startMp4Loop(
|
|
337
|
-
let
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
336
|
+
startMp4Loop(t, o, i, n) {
|
|
337
|
+
let a = !1, c = o, u = 0, d = !0;
|
|
338
|
+
const y = Math.round(1e3 / Math.max(i || 30, 1) * 1e3), h = this.getClipSampleRate(t), w = [], M = window.setInterval(async () => {
|
|
339
|
+
if (a)
|
|
340
340
|
return;
|
|
341
|
-
const { audio:
|
|
342
|
-
if (c +=
|
|
341
|
+
const { audio: p, state: v } = await t.tick(Math.round(c));
|
|
342
|
+
if (c += y, v === "done")
|
|
343
343
|
return;
|
|
344
|
-
if (
|
|
345
|
-
|
|
344
|
+
if (d) {
|
|
345
|
+
d = !1;
|
|
346
346
|
return;
|
|
347
347
|
}
|
|
348
|
-
(
|
|
348
|
+
(p?.[0]?.length ?? 0) !== 0 && (u = this.playFrames(p, h, u, n, w));
|
|
349
349
|
}, Math.round(1e3 / Math.max(i || 30, 1)));
|
|
350
350
|
return {
|
|
351
351
|
sources: w,
|
|
352
352
|
stop: () => {
|
|
353
|
-
|
|
353
|
+
a = !0, window.clearInterval(M);
|
|
354
354
|
},
|
|
355
|
-
isStopped: () =>
|
|
355
|
+
isStopped: () => a
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
|
-
startAudioLoop(
|
|
359
|
-
let c = !1,
|
|
360
|
-
const
|
|
358
|
+
startAudioLoop(t, o, i, n = 1, a) {
|
|
359
|
+
let c = !1, u = o, d = 0, y = !1;
|
|
360
|
+
const h = this.getClipSampleRate(t), w = [], p = Math.round(1e5 * n), v = async () => {
|
|
361
361
|
if (c)
|
|
362
362
|
return;
|
|
363
|
-
if (
|
|
363
|
+
if (y || (o > 0 && await t.tick(o), y = !0), u += p, a !== void 0 && u > a) {
|
|
364
364
|
c = !0;
|
|
365
365
|
return;
|
|
366
366
|
}
|
|
367
|
-
const { audio:
|
|
367
|
+
const { audio: m, state: g } = await t.tick(u);
|
|
368
368
|
if (c)
|
|
369
369
|
return;
|
|
370
370
|
if (g === "done") {
|
|
371
371
|
c = !0;
|
|
372
372
|
return;
|
|
373
373
|
}
|
|
374
|
-
if ((
|
|
374
|
+
if ((m?.[0]?.length ?? 0) === 0) {
|
|
375
375
|
c = !0;
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
d = this.playFrames(m, h, d, i, w, n), c || setTimeout(() => v(), 0);
|
|
379
379
|
};
|
|
380
380
|
return v(), {
|
|
381
381
|
sources: w,
|
|
@@ -386,714 +386,714 @@ class ot {
|
|
|
386
386
|
isStopped: () => c && w.length === 0
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
playFrames(
|
|
390
|
-
const
|
|
391
|
-
if (
|
|
389
|
+
playFrames(t, o, i, n, a, c = 1) {
|
|
390
|
+
const u = Math.max(t.length, 1), d = t[0]?.length ?? 0;
|
|
391
|
+
if (d === 0)
|
|
392
392
|
return i;
|
|
393
|
-
const
|
|
394
|
-
for (let
|
|
395
|
-
const v =
|
|
396
|
-
|
|
393
|
+
const y = this.ctx.createBuffer(u, d, o);
|
|
394
|
+
for (let p = 0; p < u; p++) {
|
|
395
|
+
const v = t[p] ?? new Float32Array(d);
|
|
396
|
+
y.copyToChannel(new Float32Array(v), p);
|
|
397
397
|
}
|
|
398
|
-
const
|
|
399
|
-
|
|
398
|
+
const h = this.ctx.createBufferSource();
|
|
399
|
+
h.buffer = y;
|
|
400
400
|
const w = Math.max(0.1, c);
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
const
|
|
401
|
+
h.playbackRate.value = w, h.connect(n);
|
|
402
|
+
const M = Math.max(this.ctx.currentTime, i);
|
|
403
|
+
if (h.start(M), a) {
|
|
404
|
+
a.push(h);
|
|
405
|
+
const p = y.duration / w * 1e3;
|
|
406
406
|
setTimeout(() => {
|
|
407
|
-
const v =
|
|
408
|
-
v > -1 &&
|
|
409
|
-
},
|
|
407
|
+
const v = a.indexOf(h);
|
|
408
|
+
v > -1 && a.splice(v, 1);
|
|
409
|
+
}, p + 100);
|
|
410
410
|
}
|
|
411
|
-
return
|
|
411
|
+
return M + y.duration / w;
|
|
412
412
|
}
|
|
413
|
-
getOrCreateGain(
|
|
414
|
-
const n =
|
|
413
|
+
getOrCreateGain(t, o, i) {
|
|
414
|
+
const n = t.get(o);
|
|
415
415
|
if (n)
|
|
416
416
|
return typeof i == "number" && (n.gain.value = this.normalizeVolume(i)), n;
|
|
417
|
-
const
|
|
418
|
-
return
|
|
417
|
+
const a = this.ctx.createGain();
|
|
418
|
+
return a.gain.value = this.normalizeVolume(i), a.connect(this.ctx.destination), t.set(o, a), a;
|
|
419
419
|
}
|
|
420
|
-
getOrCreateAudioElementState(
|
|
421
|
-
const i = this.audioElements.get(
|
|
420
|
+
getOrCreateAudioElementState(t, o) {
|
|
421
|
+
const i = this.audioElements.get(t);
|
|
422
422
|
if (i)
|
|
423
|
-
return i.url !==
|
|
424
|
-
const n = new Audio(
|
|
425
|
-
n.preload = "auto", n.loop = !1, n.volume = this.normalizeVolume(
|
|
426
|
-
const
|
|
427
|
-
segmentId:
|
|
428
|
-
url:
|
|
423
|
+
return i.url !== o.url && (i.el.pause(), i.el.src = o.url, i.el.currentTime = 0, i.url = o.url, i.pendingPlay = void 0, i.lastTimelineMs = void 0, i.lastSourceSec = void 0, i.lastSeekTimelineMs = void 0), i;
|
|
424
|
+
const n = new Audio(o.url);
|
|
425
|
+
n.preload = "auto", n.loop = !1, n.volume = this.normalizeVolume(o.volume), n.playbackRate = this.normalizePlayRate(o.playRate);
|
|
426
|
+
const a = {
|
|
427
|
+
segmentId: o.id,
|
|
428
|
+
url: o.url,
|
|
429
429
|
el: n
|
|
430
430
|
};
|
|
431
|
-
return this.audioElements.set(
|
|
431
|
+
return this.audioElements.set(t, a), a;
|
|
432
432
|
}
|
|
433
|
-
destroyAudioElement(
|
|
433
|
+
destroyAudioElement(t) {
|
|
434
434
|
try {
|
|
435
|
-
|
|
435
|
+
t.pause();
|
|
436
436
|
} catch {
|
|
437
437
|
}
|
|
438
|
-
|
|
438
|
+
t.removeAttribute("src");
|
|
439
439
|
try {
|
|
440
|
-
|
|
440
|
+
t.load();
|
|
441
441
|
} catch {
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
-
normalizePlayRate(
|
|
445
|
-
return typeof
|
|
444
|
+
normalizePlayRate(t) {
|
|
445
|
+
return typeof t != "number" || !Number.isFinite(t) ? 1 : Math.max(0.1, Math.min(100, t));
|
|
446
446
|
}
|
|
447
|
-
normalizeVolume(
|
|
448
|
-
return typeof
|
|
447
|
+
normalizeVolume(t) {
|
|
448
|
+
return typeof t != "number" || !Number.isFinite(t) ? 1 : Math.max(0, Math.min(1, t));
|
|
449
449
|
}
|
|
450
|
-
computeSegmentVolume(
|
|
451
|
-
const i = this.normalizeVolume(
|
|
452
|
-
let
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
return c > 0 &&
|
|
450
|
+
computeSegmentVolume(t, o) {
|
|
451
|
+
const i = this.normalizeVolume(t.volume), n = Math.max(0, t.endTime - t.startTime), a = Math.max(0, t.fadeInDuration ?? 0), c = Math.max(0, t.fadeOutDuration ?? 0);
|
|
452
|
+
let u = 1;
|
|
453
|
+
a > 0 && o < a && (u = Math.max(0, o / a));
|
|
454
|
+
const d = n - o;
|
|
455
|
+
return c > 0 && d < c && (u = Math.min(u, Math.max(0, d / c))), i * u;
|
|
456
456
|
}
|
|
457
|
-
audioKey(
|
|
458
|
-
return `audio:${
|
|
457
|
+
audioKey(t) {
|
|
458
|
+
return `audio:${t}`;
|
|
459
459
|
}
|
|
460
|
-
videoKey(
|
|
461
|
-
return `video:${
|
|
460
|
+
videoKey(t) {
|
|
461
|
+
return `video:${t}`;
|
|
462
462
|
}
|
|
463
|
-
async loadClip(
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
return
|
|
467
|
-
const i = this.loadingClips.get(
|
|
463
|
+
async loadClip(t) {
|
|
464
|
+
const o = this.clips.get(t.id);
|
|
465
|
+
if (o)
|
|
466
|
+
return o;
|
|
467
|
+
const i = this.loadingClips.get(t.id);
|
|
468
468
|
if (i)
|
|
469
469
|
return i;
|
|
470
470
|
const n = (async () => {
|
|
471
471
|
try {
|
|
472
|
-
const
|
|
473
|
-
if (!
|
|
474
|
-
this.loadingClips.delete(
|
|
472
|
+
const a = await fetch(t.url);
|
|
473
|
+
if (!a.body) {
|
|
474
|
+
this.loadingClips.delete(t.id);
|
|
475
475
|
return;
|
|
476
476
|
}
|
|
477
|
-
const c = new
|
|
478
|
-
if (await c.ready, !this.findSegmentInProtocol(
|
|
479
|
-
c.destroy(), this.loadingClips.delete(
|
|
477
|
+
const c = new Tt(a.body), u = { clip: c, ready: c.ready };
|
|
478
|
+
if (await c.ready, !this.findSegmentInProtocol(t.id)) {
|
|
479
|
+
c.destroy(), this.loadingClips.delete(t.id);
|
|
480
480
|
return;
|
|
481
481
|
}
|
|
482
|
-
return this.clips.set(
|
|
483
|
-
} catch (
|
|
484
|
-
console.error(`[AudioManager] Failed to load audio ${
|
|
482
|
+
return this.clips.set(t.id, u), this.loadingClips.delete(t.id), u;
|
|
483
|
+
} catch (a) {
|
|
484
|
+
console.error(`[AudioManager] Failed to load audio ${t.url}`, a), this.loadingClips.delete(t.id);
|
|
485
485
|
return;
|
|
486
486
|
}
|
|
487
487
|
})();
|
|
488
|
-
return this.loadingClips.set(
|
|
488
|
+
return this.loadingClips.set(t.id, n), n;
|
|
489
489
|
}
|
|
490
|
-
findSegmentInProtocol(
|
|
491
|
-
for (const
|
|
492
|
-
for (const i of
|
|
493
|
-
if (i.id ===
|
|
490
|
+
findSegmentInProtocol(t) {
|
|
491
|
+
for (const o of this.protocol.tracks)
|
|
492
|
+
for (const i of o.children)
|
|
493
|
+
if (i.id === t) return !0;
|
|
494
494
|
return !1;
|
|
495
495
|
}
|
|
496
|
-
getSegmentVolume(
|
|
497
|
-
for (const
|
|
498
|
-
for (const i of
|
|
499
|
-
if (i.id !==
|
|
496
|
+
getSegmentVolume(t) {
|
|
497
|
+
for (const o of this.protocol.tracks)
|
|
498
|
+
for (const i of o.children) {
|
|
499
|
+
if (i.id !== t)
|
|
500
500
|
continue;
|
|
501
501
|
const n = i.volume;
|
|
502
502
|
return this.normalizeVolume(n);
|
|
503
503
|
}
|
|
504
504
|
return 1;
|
|
505
505
|
}
|
|
506
|
-
getClipSampleRate(
|
|
507
|
-
const
|
|
508
|
-
if (!
|
|
506
|
+
getClipSampleRate(t) {
|
|
507
|
+
const o = t.meta;
|
|
508
|
+
if (!o)
|
|
509
509
|
return 48e3;
|
|
510
|
-
const i =
|
|
510
|
+
const i = o.audioSampleRate;
|
|
511
511
|
if (typeof i == "number" && i > 0)
|
|
512
512
|
return i;
|
|
513
|
-
const n =
|
|
513
|
+
const n = o.sampleRate;
|
|
514
514
|
return typeof n == "number" && n > 0 ? n : 48e3;
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
-
const
|
|
518
|
-
let
|
|
519
|
-
function
|
|
520
|
-
|
|
517
|
+
const le = 100, $ = /* @__PURE__ */ new Map();
|
|
518
|
+
let de = le;
|
|
519
|
+
function fe(e, t) {
|
|
520
|
+
$.delete(e), $.set(e, t);
|
|
521
521
|
}
|
|
522
|
-
function
|
|
523
|
-
for (;
|
|
524
|
-
const [
|
|
525
|
-
|
|
522
|
+
function he() {
|
|
523
|
+
for (; $.size > de; ) {
|
|
524
|
+
const [e, t] = $.entries().next().value;
|
|
525
|
+
$.delete(e), t.close?.();
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
|
-
function
|
|
529
|
-
return
|
|
528
|
+
function pe(e) {
|
|
529
|
+
return e.map((t) => t.content).filter(Boolean).join(`
|
|
530
530
|
`);
|
|
531
531
|
}
|
|
532
|
-
function
|
|
533
|
-
const
|
|
534
|
-
`font-size: ${
|
|
532
|
+
function me(e) {
|
|
533
|
+
const t = Array.isArray(e.fontFamily) ? e.fontFamily.join(", ") : e.fontFamily, o = e.fontSize ?? 32, i = e.fontWeight ?? "normal", n = e.fontStyle ?? "normal", a = e.fill ?? "#ffffff", c = e.align ?? "left", u = [
|
|
534
|
+
`font-size: ${o}px`,
|
|
535
535
|
`font-weight: ${i}`,
|
|
536
536
|
`font-style: ${n}`,
|
|
537
|
-
`color: ${
|
|
537
|
+
`color: ${a}`,
|
|
538
538
|
`text-align: ${c}`,
|
|
539
539
|
"white-space: pre-wrap"
|
|
540
540
|
];
|
|
541
|
-
if (
|
|
542
|
-
const
|
|
543
|
-
|
|
541
|
+
if (t && u.push(`font-family: ${t}`), typeof e.letterSpacing == "number" && u.push(`letter-spacing: ${e.letterSpacing}px`), typeof e.leading == "number" && u.push(`line-height: ${e.leading}px`), e.background?.color && u.push(`background: ${e.background.color}`), e.stroke?.color && typeof e.stroke.width == "number" && u.push(`-webkit-text-stroke: ${e.stroke.width}px ${e.stroke.color}`), e.underline && u.push("text-decoration: underline"), e.dropShadow?.color && typeof e.dropShadow.distance == "number") {
|
|
542
|
+
const d = (e.dropShadow.angle ?? 45) * (Math.PI / 180), y = Math.cos(d) * e.dropShadow.distance, h = Math.sin(d) * e.dropShadow.distance, w = e.dropShadow.blur ?? 0;
|
|
543
|
+
u.push(`text-shadow: ${y}px ${h}px ${w}px ${e.dropShadow.color}`);
|
|
544
544
|
}
|
|
545
|
-
return
|
|
545
|
+
return u.join("; ");
|
|
546
546
|
}
|
|
547
|
-
async function
|
|
548
|
-
const
|
|
547
|
+
async function ye(e, t) {
|
|
548
|
+
const o = `${t}::${e}`, i = $.get(o);
|
|
549
549
|
if (i)
|
|
550
|
-
return
|
|
551
|
-
const n = await
|
|
552
|
-
return
|
|
550
|
+
return fe(o, i), i;
|
|
551
|
+
const n = await Zt(e, t);
|
|
552
|
+
return $.set(o, n), he(), n;
|
|
553
553
|
}
|
|
554
|
-
const
|
|
555
|
-
async function
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
), n =
|
|
559
|
-
n.stage.addChild(
|
|
560
|
-
const c =
|
|
561
|
-
let
|
|
562
|
-
async function
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
const
|
|
566
|
-
for (const { segment: N } of
|
|
567
|
-
if (
|
|
554
|
+
const we = "/video-editor-res";
|
|
555
|
+
async function ve(e) {
|
|
556
|
+
const t = Wt(), o = Jt(e.protocol) ? e.protocol : vt(e.protocol), i = vt(
|
|
557
|
+
t.verify(St(Mt(o)))
|
|
558
|
+
), n = e.app ?? await oe(e.appOptions), a = new ee();
|
|
559
|
+
n.stage.addChild(a);
|
|
560
|
+
const c = Yt({ dir: e.resourceDir }), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set(), M = e.videoSourceMode ?? "auto", p = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), m = gt(0), g = gt(!1), R = Ht(() => it(i.value)), P = new ue(i.value);
|
|
561
|
+
let A, E = 0, b = 0;
|
|
562
|
+
async function q(r) {
|
|
563
|
+
const l = b, { protocol: s, at: f, layer: S } = r, x = Kt(s, f), T = Rt(s, x), k = r.app.renderer.width, C = r.app.renderer.height;
|
|
564
|
+
P.sync(f, g.value);
|
|
565
|
+
const I = [];
|
|
566
|
+
for (const { segment: N } of T) {
|
|
567
|
+
if (l !== b)
|
|
568
568
|
return;
|
|
569
|
-
const
|
|
570
|
-
if (
|
|
569
|
+
const L = await r.getDisplay(N);
|
|
570
|
+
if (l !== b)
|
|
571
571
|
return;
|
|
572
|
-
if (
|
|
573
|
-
if (
|
|
572
|
+
if (L && !L.destroyed) {
|
|
573
|
+
if (ae(L, N, k, C), Gt(N) && await H(N, x), l !== b)
|
|
574
574
|
return;
|
|
575
|
-
|
|
575
|
+
I.push(L);
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
|
-
if (
|
|
578
|
+
if (l !== b)
|
|
579
579
|
return;
|
|
580
|
-
|
|
581
|
-
const
|
|
582
|
-
|
|
580
|
+
S.removeChildren();
|
|
581
|
+
const U = I.filter(Boolean);
|
|
582
|
+
U.length && S.addChild(...U), l === b && r.app.render();
|
|
583
583
|
}
|
|
584
|
-
const
|
|
584
|
+
const D = Me(() => q({
|
|
585
585
|
app: n,
|
|
586
|
-
layer:
|
|
586
|
+
layer: a,
|
|
587
587
|
protocol: i.value,
|
|
588
|
-
at:
|
|
589
|
-
getDisplay:
|
|
590
|
-
})),
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
() =>
|
|
594
|
-
(
|
|
588
|
+
at: m.value,
|
|
589
|
+
getDisplay: Lt
|
|
590
|
+
})), z = Qt();
|
|
591
|
+
z.run(() => {
|
|
592
|
+
Z(
|
|
593
|
+
() => Mt(o),
|
|
594
|
+
(r) => {
|
|
595
595
|
try {
|
|
596
|
-
i.value =
|
|
597
|
-
} catch (
|
|
598
|
-
console.error("[renderer] invalid protocol update",
|
|
596
|
+
i.value = t.verify(St(r));
|
|
597
|
+
} catch (l) {
|
|
598
|
+
console.error("[renderer] invalid protocol update", l);
|
|
599
599
|
return;
|
|
600
600
|
}
|
|
601
|
-
|
|
601
|
+
P.setProtocol(i.value), b += 1, _(), e.warmUpResources !== !1 && F(i.value), Y(i.value), O(), e.manualRender || D();
|
|
602
602
|
},
|
|
603
603
|
{ deep: !0, immediate: !0 }
|
|
604
|
-
),
|
|
605
|
-
O(),
|
|
606
|
-
}),
|
|
604
|
+
), e.manualRender || Z(m, () => {
|
|
605
|
+
O(), D();
|
|
606
|
+
}), Z(R, () => O());
|
|
607
607
|
});
|
|
608
608
|
function O() {
|
|
609
|
-
const
|
|
610
|
-
|
|
609
|
+
const r = R.value;
|
|
610
|
+
r <= 0 ? m.value = 0 : m.value > r ? m.value = r : m.value < 0 && (m.value = 0);
|
|
611
611
|
}
|
|
612
|
-
function
|
|
613
|
-
for (const
|
|
614
|
-
|
|
612
|
+
function F(r) {
|
|
613
|
+
for (const l of ne(r))
|
|
614
|
+
u.has(l) || (u.add(l), mt(l) !== "video" && ft(l) && c.add(l).catch(() => {
|
|
615
615
|
}));
|
|
616
616
|
}
|
|
617
|
-
function
|
|
618
|
-
const
|
|
619
|
-
for (const
|
|
620
|
-
for (const f of
|
|
621
|
-
|
|
622
|
-
for (const [
|
|
623
|
-
|
|
624
|
-
for (const [
|
|
625
|
-
|
|
626
|
-
}
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
for (const
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
for (const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
function
|
|
637
|
-
g.value || (g.value = !0,
|
|
638
|
-
}
|
|
639
|
-
function
|
|
640
|
-
g.value = !1,
|
|
641
|
-
}
|
|
642
|
-
function
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
function
|
|
646
|
-
if (!g.value &&
|
|
617
|
+
function Y(r) {
|
|
618
|
+
const l = /* @__PURE__ */ new Set();
|
|
619
|
+
for (const s of r.tracks)
|
|
620
|
+
for (const f of s.children)
|
|
621
|
+
l.add(f.id);
|
|
622
|
+
for (const [s, f] of d)
|
|
623
|
+
l.has(s) || (f.destroy(), d.delete(s));
|
|
624
|
+
for (const [s, f] of p)
|
|
625
|
+
l.has(s) || (ht(f), p.delete(s));
|
|
626
|
+
}
|
|
627
|
+
function _() {
|
|
628
|
+
a.removeChildren();
|
|
629
|
+
for (const r of d.values())
|
|
630
|
+
r.destroy();
|
|
631
|
+
d.clear(), y.clear();
|
|
632
|
+
for (const r of p.values())
|
|
633
|
+
ht(r);
|
|
634
|
+
p.clear();
|
|
635
|
+
}
|
|
636
|
+
function ct() {
|
|
637
|
+
g.value || (g.value = !0, E = performance.now(), A = requestAnimationFrame(ut));
|
|
638
|
+
}
|
|
639
|
+
function X() {
|
|
640
|
+
g.value = !1, A !== void 0 && cancelAnimationFrame(A), A = void 0, P.sync(m.value, !1), e.freezeOnPause !== !1 && qt();
|
|
641
|
+
}
|
|
642
|
+
function ut() {
|
|
643
|
+
lt(), g.value && (A = requestAnimationFrame(ut));
|
|
644
|
+
}
|
|
645
|
+
function lt(r) {
|
|
646
|
+
if (!g.value && r === void 0)
|
|
647
647
|
return;
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
648
|
+
const l = performance.now(), s = r ?? (E ? l - E : 0);
|
|
649
|
+
E = l, s !== 0 && (m.value = et(
|
|
650
|
+
m.value + s,
|
|
651
651
|
0,
|
|
652
652
|
R.value || Number.POSITIVE_INFINITY
|
|
653
|
-
), R.value > 0 &&
|
|
654
|
-
}
|
|
655
|
-
function
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
async function
|
|
659
|
-
|
|
660
|
-
}
|
|
661
|
-
async function
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
664
|
-
return
|
|
665
|
-
const
|
|
666
|
-
if (
|
|
667
|
-
return
|
|
668
|
-
const f =
|
|
669
|
-
|
|
670
|
-
const
|
|
671
|
-
return
|
|
672
|
-
}
|
|
673
|
-
async function
|
|
674
|
-
if (
|
|
675
|
-
if (!
|
|
676
|
-
return
|
|
677
|
-
if ("type" in
|
|
678
|
-
const
|
|
679
|
-
return
|
|
653
|
+
), R.value > 0 && m.value >= R.value && X());
|
|
654
|
+
}
|
|
655
|
+
function Ut(r) {
|
|
656
|
+
m.value = et(r, 0, R.value || Number.POSITIVE_INFINITY);
|
|
657
|
+
}
|
|
658
|
+
async function Ot(r) {
|
|
659
|
+
m.value = et(r, 0, R.value || Number.POSITIVE_INFINITY), await D();
|
|
660
|
+
}
|
|
661
|
+
async function Lt(r) {
|
|
662
|
+
const l = d.get(r.id);
|
|
663
|
+
if (l)
|
|
664
|
+
return l;
|
|
665
|
+
const s = y.get(r.id);
|
|
666
|
+
if (s)
|
|
667
|
+
return s;
|
|
668
|
+
const f = Vt(r);
|
|
669
|
+
y.set(r.id, f);
|
|
670
|
+
const S = await f;
|
|
671
|
+
return S && d.set(r.id, S), y.delete(r.id), S;
|
|
672
|
+
}
|
|
673
|
+
async function Vt(r) {
|
|
674
|
+
if (r.segmentType === "frames" || r.segmentType === "sticker") {
|
|
675
|
+
if (!r.url)
|
|
676
|
+
return tt(r.segmentType);
|
|
677
|
+
if ("type" in r && r.type === "video" && yt(r.url)) {
|
|
678
|
+
const s = await zt(r);
|
|
679
|
+
return s || tt(r.segmentType, r.url);
|
|
680
680
|
}
|
|
681
|
-
const
|
|
682
|
-
return
|
|
681
|
+
const l = await Dt(r.url);
|
|
682
|
+
return l ? new V(l) : tt(r.segmentType, r.url);
|
|
683
683
|
}
|
|
684
|
-
if (
|
|
685
|
-
return await
|
|
686
|
-
|
|
684
|
+
if (r.segmentType === "text")
|
|
685
|
+
return await $t(r);
|
|
686
|
+
r.segmentType === "effect" || r.segmentType;
|
|
687
687
|
}
|
|
688
|
-
async function
|
|
689
|
-
const
|
|
690
|
-
if (!
|
|
688
|
+
async function $t(r) {
|
|
689
|
+
const l = pe(r.texts);
|
|
690
|
+
if (!l)
|
|
691
691
|
return;
|
|
692
|
-
const [
|
|
693
|
-
if (!
|
|
692
|
+
const [s] = r.texts;
|
|
693
|
+
if (!s)
|
|
694
694
|
return;
|
|
695
|
-
const f = await
|
|
696
|
-
return new
|
|
695
|
+
const f = await ye(l, me(s)), S = G.from(f);
|
|
696
|
+
return new V(S);
|
|
697
697
|
}
|
|
698
|
-
async function
|
|
699
|
-
const
|
|
700
|
-
if (!
|
|
698
|
+
async function Dt(r) {
|
|
699
|
+
const l = r.startsWith("data:"), s = /^https?:\/\//.test(r);
|
|
700
|
+
if (!l && !s)
|
|
701
701
|
try {
|
|
702
|
-
await c.add(
|
|
703
|
-
const f = await c.get(
|
|
702
|
+
await c.add(r);
|
|
703
|
+
const f = await c.get(r);
|
|
704
704
|
if (f instanceof HTMLImageElement)
|
|
705
705
|
return G.from(f);
|
|
706
706
|
} catch {
|
|
707
707
|
}
|
|
708
|
-
return await
|
|
709
|
-
}
|
|
710
|
-
async function
|
|
711
|
-
const
|
|
712
|
-
if (
|
|
713
|
-
return
|
|
714
|
-
const
|
|
715
|
-
if (
|
|
716
|
-
if (!
|
|
717
|
-
throw new Error(`[renderer] MP4Clip unsupported for ${
|
|
718
|
-
const
|
|
719
|
-
console.warn("[renderer] failed to load video via <video>",
|
|
708
|
+
return await jt(r);
|
|
709
|
+
}
|
|
710
|
+
async function zt(r) {
|
|
711
|
+
const l = p.get(r.id);
|
|
712
|
+
if (l)
|
|
713
|
+
return l.sprite;
|
|
714
|
+
const s = W(r.url), f = M !== "element", S = M !== "mp4clip";
|
|
715
|
+
if (s && h.has(s)) {
|
|
716
|
+
if (!S)
|
|
717
|
+
throw new Error(`[renderer] MP4Clip unsupported for ${r.url}`);
|
|
718
|
+
const x = await B(r.url).catch((T) => {
|
|
719
|
+
console.warn("[renderer] failed to load video via <video>", r.url, T);
|
|
720
720
|
});
|
|
721
|
-
return
|
|
721
|
+
return x ? (p.set(r.id, x), x.sprite) : void 0;
|
|
722
722
|
}
|
|
723
723
|
if (f) {
|
|
724
|
-
const
|
|
725
|
-
if (
|
|
726
|
-
throw
|
|
724
|
+
const x = await pt(r.url).catch((T) => {
|
|
725
|
+
if (s && J(T) && h.add(s), (!s || !w.has(s)) && (s && w.add(s), console.warn("[renderer] failed to load video via MP4Clip", r.url, T)), !S)
|
|
726
|
+
throw T;
|
|
727
727
|
});
|
|
728
|
-
if (
|
|
729
|
-
return console.info("[renderer] video source: mp4clip",
|
|
728
|
+
if (x)
|
|
729
|
+
return console.info("[renderer] video source: mp4clip", r.url), p.set(r.id, x), x.sprite;
|
|
730
730
|
}
|
|
731
|
-
if (
|
|
732
|
-
const
|
|
733
|
-
console.warn("[renderer] failed to load video via <video>",
|
|
731
|
+
if (S) {
|
|
732
|
+
const x = await B(r.url).catch((T) => {
|
|
733
|
+
console.warn("[renderer] failed to load video via <video>", r.url, T);
|
|
734
734
|
});
|
|
735
|
-
if (
|
|
736
|
-
return console.info("[renderer] video source: element",
|
|
735
|
+
if (x)
|
|
736
|
+
return console.info("[renderer] video source: element", r.url), p.set(r.id, x), x.sprite;
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
|
-
function
|
|
740
|
-
if (!(
|
|
739
|
+
function J(r) {
|
|
740
|
+
if (!(r instanceof Error))
|
|
741
741
|
return !1;
|
|
742
|
-
const
|
|
743
|
-
return
|
|
742
|
+
const l = r.message || "";
|
|
743
|
+
return l.includes("stream is done") || l.includes("not emit ready") || l.includes("tick video timeout");
|
|
744
744
|
}
|
|
745
|
-
async function
|
|
746
|
-
const
|
|
747
|
-
if (
|
|
745
|
+
async function H(r, l) {
|
|
746
|
+
const s = p.get(r.id);
|
|
747
|
+
if (s)
|
|
748
748
|
try {
|
|
749
|
-
const f =
|
|
750
|
-
if (
|
|
751
|
-
const
|
|
752
|
-
if (!
|
|
749
|
+
const f = r.fromTime ?? 0, S = Math.max(0, l - r.startTime + f), x = Math.floor(S * 1e3);
|
|
750
|
+
if (s.kind === "frozen") {
|
|
751
|
+
const k = W(r.url);
|
|
752
|
+
if (!k)
|
|
753
753
|
return;
|
|
754
|
-
const C = await
|
|
755
|
-
return C ? (
|
|
754
|
+
const C = await Nt(r.url, k, { sprite: s.sprite, oldTexture: s.texture });
|
|
755
|
+
return C ? (p.set(r.id, C), await H(r, l)) : void 0;
|
|
756
756
|
}
|
|
757
|
-
if (
|
|
757
|
+
if (s.kind === "mp4clip")
|
|
758
758
|
try {
|
|
759
|
-
const
|
|
760
|
-
if (
|
|
761
|
-
const C =
|
|
762
|
-
C && (C.drawImage(
|
|
759
|
+
const k = await s.clip.tick(x);
|
|
760
|
+
if (k.video) {
|
|
761
|
+
const C = s.canvas.getContext("2d");
|
|
762
|
+
C && (C.drawImage(k.video, 0, 0, s.canvas.width, s.canvas.height), wt(s.texture)), k.video.close();
|
|
763
763
|
}
|
|
764
|
-
if (g.value &&
|
|
765
|
-
const C =
|
|
766
|
-
|
|
764
|
+
if (g.value && k.audio && k.audio.length > 0) {
|
|
765
|
+
const C = s.clip.meta?.audioSampleRate ?? 48e3;
|
|
766
|
+
P.playMp4AudioFrames(r.id, k.audio, C);
|
|
767
767
|
}
|
|
768
768
|
return;
|
|
769
|
-
} catch (
|
|
770
|
-
const C =
|
|
771
|
-
if (C &&
|
|
772
|
-
const
|
|
773
|
-
console.warn("[renderer] failed to fallback to <video> after MP4Clip error",
|
|
769
|
+
} catch (k) {
|
|
770
|
+
const C = W(r.url);
|
|
771
|
+
if (C && J(k) && (h.add(C), s.clip.destroy(), M !== "mp4clip")) {
|
|
772
|
+
const I = await B(r.url, { sprite: s.sprite, oldTexture: s.texture }).catch((U) => {
|
|
773
|
+
console.warn("[renderer] failed to fallback to <video> after MP4Clip error", r.url, U);
|
|
774
774
|
});
|
|
775
|
-
if (
|
|
776
|
-
return
|
|
775
|
+
if (I)
|
|
776
|
+
return p.set(r.id, I), await H(r, l);
|
|
777
777
|
}
|
|
778
|
-
C && !w.has(C) && (w.add(C), console.warn("[renderer] MP4Clip tick failed",
|
|
778
|
+
C && !w.has(C) && (w.add(C), console.warn("[renderer] MP4Clip tick failed", r.url, k));
|
|
779
779
|
return;
|
|
780
780
|
}
|
|
781
|
-
const
|
|
782
|
-
if (!Number.isFinite(
|
|
781
|
+
const T = S / 1e3;
|
|
782
|
+
if (!Number.isFinite(T) || s.kind !== "element")
|
|
783
783
|
return;
|
|
784
|
-
await
|
|
785
|
-
targetSec:
|
|
786
|
-
playbackRate:
|
|
787
|
-
volume:
|
|
784
|
+
await Bt(s, {
|
|
785
|
+
targetSec: T,
|
|
786
|
+
playbackRate: r.playRate ?? 1,
|
|
787
|
+
volume: r.volume ?? 1
|
|
788
788
|
});
|
|
789
789
|
} catch (f) {
|
|
790
790
|
console.warn("[renderer] update video frame failed", f);
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
|
-
async function
|
|
794
|
-
const f =
|
|
795
|
-
if (
|
|
796
|
-
if (!
|
|
797
|
-
throw new Error(`[renderer] MP4Clip unsupported for ${
|
|
798
|
-
return await
|
|
793
|
+
async function Nt(r, l, s) {
|
|
794
|
+
const f = M !== "element", S = M !== "mp4clip";
|
|
795
|
+
if (h.has(l)) {
|
|
796
|
+
if (!S)
|
|
797
|
+
throw new Error(`[renderer] MP4Clip unsupported for ${r}`);
|
|
798
|
+
return await B(r, s).catch(() => {
|
|
799
799
|
});
|
|
800
800
|
}
|
|
801
801
|
if (f) {
|
|
802
|
-
const
|
|
803
|
-
if (
|
|
804
|
-
throw
|
|
802
|
+
const x = await pt(r, s).catch((T) => {
|
|
803
|
+
if (J(T) && h.add(l), !S)
|
|
804
|
+
throw T;
|
|
805
805
|
});
|
|
806
|
-
if (
|
|
807
|
-
return
|
|
806
|
+
if (x)
|
|
807
|
+
return x;
|
|
808
808
|
}
|
|
809
|
-
if (
|
|
810
|
-
return await
|
|
809
|
+
if (S)
|
|
810
|
+
return await B(r, s).catch(() => {
|
|
811
811
|
});
|
|
812
812
|
}
|
|
813
|
-
function
|
|
814
|
-
return
|
|
813
|
+
function Gt(r) {
|
|
814
|
+
return r.segmentType === "frames" && r.type === "video" && typeof r.url == "string" && yt(r.url);
|
|
815
815
|
}
|
|
816
|
-
function
|
|
817
|
-
const
|
|
818
|
-
if (
|
|
816
|
+
function Kt(r, l) {
|
|
817
|
+
const s = it(r);
|
|
818
|
+
if (s <= 0)
|
|
819
819
|
return 0;
|
|
820
|
-
if (
|
|
821
|
-
return
|
|
822
|
-
const f = Math.max(1e3 / Math.max(
|
|
823
|
-
return Math.max(
|
|
820
|
+
if (l < s)
|
|
821
|
+
return l;
|
|
822
|
+
const f = Math.max(1e3 / Math.max(r.fps || 30, 1), 1);
|
|
823
|
+
return Math.max(s - f, 0);
|
|
824
824
|
}
|
|
825
|
-
async function
|
|
826
|
-
const
|
|
825
|
+
async function dt(r) {
|
|
826
|
+
const l = e.resourceDir ?? we;
|
|
827
827
|
try {
|
|
828
|
-
const
|
|
829
|
-
if (!
|
|
828
|
+
const s = W(r);
|
|
829
|
+
if (!s)
|
|
830
830
|
return;
|
|
831
|
-
const f =
|
|
831
|
+
const f = te(`${l}/${s}`, "r");
|
|
832
832
|
if (await f.exists())
|
|
833
833
|
return f;
|
|
834
834
|
} catch {
|
|
835
835
|
return;
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
|
-
function
|
|
839
|
-
return !(!
|
|
838
|
+
function ft(r) {
|
|
839
|
+
return !(!r || r.startsWith("data:") || r.startsWith("blob:"));
|
|
840
840
|
}
|
|
841
|
-
function
|
|
842
|
-
for (const [
|
|
843
|
-
if (
|
|
844
|
-
|
|
841
|
+
function qt() {
|
|
842
|
+
for (const [r, l] of p) {
|
|
843
|
+
if (l.kind === "mp4clip") {
|
|
844
|
+
l.clip.destroy(), p.set(r, {
|
|
845
845
|
kind: "frozen",
|
|
846
|
-
canvas:
|
|
847
|
-
texture:
|
|
848
|
-
sprite:
|
|
849
|
-
meta:
|
|
846
|
+
canvas: l.canvas,
|
|
847
|
+
texture: l.texture,
|
|
848
|
+
sprite: l.sprite,
|
|
849
|
+
meta: l.meta
|
|
850
850
|
});
|
|
851
851
|
continue;
|
|
852
852
|
}
|
|
853
|
-
|
|
853
|
+
l.kind === "element" && l.video.pause();
|
|
854
854
|
}
|
|
855
855
|
}
|
|
856
|
-
function
|
|
857
|
-
if (
|
|
858
|
-
|
|
856
|
+
function ht(r) {
|
|
857
|
+
if (r.kind === "mp4clip") {
|
|
858
|
+
r.clip.destroy();
|
|
859
859
|
return;
|
|
860
860
|
}
|
|
861
|
-
if (
|
|
861
|
+
if (r.kind === "frozen")
|
|
862
862
|
return;
|
|
863
|
-
|
|
864
|
-
const
|
|
865
|
-
|
|
866
|
-
}
|
|
867
|
-
function
|
|
868
|
-
return new Promise((f,
|
|
869
|
-
const
|
|
870
|
-
C(),
|
|
871
|
-
},
|
|
863
|
+
r.video.pause();
|
|
864
|
+
const l = v.get(r.video);
|
|
865
|
+
l && (URL.revokeObjectURL(l), v.delete(r.video)), r.video.removeAttribute("src"), r.video.load();
|
|
866
|
+
}
|
|
867
|
+
function Q(r, l, s = 1e3) {
|
|
868
|
+
return new Promise((f, S) => {
|
|
869
|
+
const x = window.setTimeout(() => {
|
|
870
|
+
C(), S(new Error(`Timed out waiting for media event: ${l}`));
|
|
871
|
+
}, s), T = () => {
|
|
872
872
|
C(), f();
|
|
873
|
-
},
|
|
873
|
+
}, k = () => {
|
|
874
874
|
C();
|
|
875
|
-
const
|
|
876
|
-
|
|
875
|
+
const I = r.error ? `${r.error.code}` : "unknown";
|
|
876
|
+
S(new Error(`Media error (${I}) while waiting for ${l}`));
|
|
877
877
|
}, C = () => {
|
|
878
|
-
window.clearTimeout(
|
|
878
|
+
window.clearTimeout(x), r.removeEventListener(l, T), r.removeEventListener("error", k);
|
|
879
879
|
};
|
|
880
|
-
|
|
880
|
+
r.addEventListener(l, T, { once: !0 }), r.addEventListener("error", k, { once: !0 });
|
|
881
881
|
});
|
|
882
882
|
}
|
|
883
|
-
async function
|
|
884
|
-
let
|
|
885
|
-
|
|
886
|
-
}),
|
|
883
|
+
async function pt(r, l) {
|
|
884
|
+
let s;
|
|
885
|
+
ft(r) && (s = await dt(r), s || (await c.add(r).catch(() => {
|
|
886
|
+
}), s = await dt(r)));
|
|
887
887
|
let f;
|
|
888
888
|
try {
|
|
889
|
-
if (
|
|
890
|
-
f = new
|
|
889
|
+
if (s)
|
|
890
|
+
f = new K(s);
|
|
891
891
|
else {
|
|
892
|
-
const
|
|
893
|
-
if (
|
|
894
|
-
f = new
|
|
892
|
+
const I = await fetch(r);
|
|
893
|
+
if (I.body)
|
|
894
|
+
f = new K(I.body);
|
|
895
895
|
else {
|
|
896
|
-
const
|
|
897
|
-
start(
|
|
898
|
-
|
|
896
|
+
const U = await I.arrayBuffer(), N = new ReadableStream({
|
|
897
|
+
start(L) {
|
|
898
|
+
L.enqueue(new Uint8Array(U)), L.close();
|
|
899
899
|
}
|
|
900
900
|
});
|
|
901
|
-
f = new
|
|
901
|
+
f = new K(N);
|
|
902
902
|
}
|
|
903
903
|
}
|
|
904
904
|
await f.ready;
|
|
905
|
-
const { width:
|
|
906
|
-
|
|
907
|
-
const
|
|
908
|
-
return
|
|
909
|
-
} catch (
|
|
910
|
-
throw f?.destroy(),
|
|
905
|
+
const { width: S, height: x } = f.meta, T = document.createElement("canvas");
|
|
906
|
+
T.width = S || 1, T.height = x || 1;
|
|
907
|
+
const k = G.from(T), C = l?.sprite ?? new V(k);
|
|
908
|
+
return l?.sprite && (l.sprite.texture = k, l.oldTexture?.destroy(!0)), { kind: "mp4clip", clip: f, canvas: T, texture: k, sprite: C, meta: { width: S, height: x } };
|
|
909
|
+
} catch (S) {
|
|
910
|
+
throw f?.destroy(), S;
|
|
911
911
|
}
|
|
912
912
|
}
|
|
913
|
-
function
|
|
914
|
-
const
|
|
915
|
-
return ["mp4", "m4v", "mov", "webm"].includes(
|
|
913
|
+
function mt(r) {
|
|
914
|
+
const s = r.split("#")[0].split("?")[0].split("/").pop()?.split(".").pop()?.toLowerCase() ?? "";
|
|
915
|
+
return ["mp4", "m4v", "mov", "webm"].includes(s) ? "video" : ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "avif"].includes(s) ? "image" : ["mp3", "wav", "aac", "m4a", "ogg", "flac"].includes(s) ? "audio" : "unknown";
|
|
916
916
|
}
|
|
917
|
-
function
|
|
918
|
-
const
|
|
919
|
-
return !(
|
|
917
|
+
function yt(r) {
|
|
918
|
+
const l = mt(r);
|
|
919
|
+
return !(l === "image" || l === "audio");
|
|
920
920
|
}
|
|
921
|
-
async function
|
|
922
|
-
const
|
|
923
|
-
|
|
921
|
+
async function B(r, l) {
|
|
922
|
+
const s = document.createElement("video");
|
|
923
|
+
s.crossOrigin = "anonymous", s.muted = !1, s.playsInline = !0, s.preload = "metadata", s.src = r, s.load();
|
|
924
924
|
try {
|
|
925
|
-
await
|
|
925
|
+
await Q(s, "loadedmetadata", 15e3);
|
|
926
926
|
} catch (C) {
|
|
927
|
-
|
|
928
|
-
const
|
|
929
|
-
throw
|
|
927
|
+
s.pause();
|
|
928
|
+
const I = v.get(s);
|
|
929
|
+
throw I && (URL.revokeObjectURL(I), v.delete(s)), s.removeAttribute("src"), s.load(), C;
|
|
930
930
|
}
|
|
931
|
-
const f =
|
|
932
|
-
|
|
933
|
-
const
|
|
934
|
-
return
|
|
935
|
-
}
|
|
936
|
-
async function
|
|
937
|
-
const { video:
|
|
938
|
-
|
|
939
|
-
}) :
|
|
940
|
-
const
|
|
941
|
-
if (Number.isFinite(
|
|
931
|
+
const f = s.videoWidth || 1, S = s.videoHeight || 1, x = document.createElement("canvas");
|
|
932
|
+
x.width = f, x.height = S;
|
|
933
|
+
const T = G.from(x), k = l?.sprite ?? new V(T);
|
|
934
|
+
return l?.sprite && (l.sprite.texture = T, l.oldTexture?.destroy(!0)), { kind: "element", video: s, canvas: x, texture: T, sprite: k, meta: { width: f, height: S } };
|
|
935
|
+
}
|
|
936
|
+
async function Bt(r, l) {
|
|
937
|
+
const { video: s, canvas: f, texture: S } = r;
|
|
938
|
+
s.playbackRate = Number.isFinite(l.playbackRate) && l.playbackRate > 0 ? l.playbackRate : 1, s.volume = Math.max(0, Math.min(1, l.volume ?? 1)), g.value ? s.play().catch(() => {
|
|
939
|
+
}) : s.pause();
|
|
940
|
+
const x = Number.isFinite(s.duration) && s.duration > 0 ? s.duration : null, T = x ? Math.min(l.targetSec, Math.max(x - 0.03, 0)) : l.targetSec, k = s.currentTime, C = Math.abs(k - T), I = g.value ? 0.25 : 0.03;
|
|
941
|
+
if (Number.isFinite(k) && C > I) {
|
|
942
942
|
try {
|
|
943
|
-
|
|
943
|
+
s.currentTime = T;
|
|
944
944
|
} catch {
|
|
945
945
|
}
|
|
946
|
-
await
|
|
946
|
+
await Q(s, "seeked", 250).catch(() => {
|
|
947
947
|
});
|
|
948
948
|
}
|
|
949
|
-
if (
|
|
950
|
-
}),
|
|
949
|
+
if (s.readyState < 2 && (await Q(s, "canplay", 250).catch(() => {
|
|
950
|
+
}), s.readyState < 2))
|
|
951
951
|
return;
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
function
|
|
956
|
-
return new Promise((
|
|
957
|
-
const
|
|
958
|
-
|
|
959
|
-
console.warn("[renderer] failed to load image",
|
|
960
|
-
},
|
|
952
|
+
const U = f.getContext("2d");
|
|
953
|
+
U && (U.drawImage(s, 0, 0, f.width, f.height), wt(S));
|
|
954
|
+
}
|
|
955
|
+
function jt(r) {
|
|
956
|
+
return new Promise((l) => {
|
|
957
|
+
const s = new Image();
|
|
958
|
+
s.crossOrigin = "anonymous", s.onload = () => l(G.from(s)), s.onerror = () => {
|
|
959
|
+
console.warn("[renderer] failed to load image", r), l(void 0);
|
|
960
|
+
}, s.src = r;
|
|
961
961
|
});
|
|
962
962
|
}
|
|
963
|
-
function
|
|
964
|
-
const
|
|
965
|
-
if ("update" in
|
|
966
|
-
|
|
963
|
+
function wt(r) {
|
|
964
|
+
const l = r.source;
|
|
965
|
+
if ("update" in l && typeof l.update == "function") {
|
|
966
|
+
l.update();
|
|
967
967
|
return;
|
|
968
968
|
}
|
|
969
|
-
typeof
|
|
969
|
+
typeof r.update == "function" && r.update();
|
|
970
970
|
}
|
|
971
|
-
function
|
|
972
|
-
|
|
971
|
+
function _t() {
|
|
972
|
+
X(), b += 1, z.stop(), _(), a.destroy({ children: !0 }), d.clear(), y.clear(), u.clear(), e.app || n.destroy(), P.destroy();
|
|
973
973
|
}
|
|
974
|
-
return
|
|
974
|
+
return e.autoPlay && ct(), {
|
|
975
975
|
app: n,
|
|
976
|
-
layer:
|
|
977
|
-
currentTime:
|
|
976
|
+
layer: a,
|
|
977
|
+
currentTime: m,
|
|
978
978
|
duration: R,
|
|
979
979
|
isPlaying: g,
|
|
980
|
-
play:
|
|
981
|
-
pause:
|
|
982
|
-
tick:
|
|
983
|
-
seek:
|
|
984
|
-
renderAt:
|
|
985
|
-
destroy:
|
|
980
|
+
play: ct,
|
|
981
|
+
pause: X,
|
|
982
|
+
tick: lt,
|
|
983
|
+
seek: Ut,
|
|
984
|
+
renderAt: Ot,
|
|
985
|
+
destroy: _t
|
|
986
986
|
};
|
|
987
987
|
}
|
|
988
|
-
function
|
|
989
|
-
let
|
|
988
|
+
function Me(e) {
|
|
989
|
+
let t = !1, o = !1, i = null, n = null;
|
|
990
990
|
return async () => {
|
|
991
|
-
i || (i = new Promise((
|
|
992
|
-
n =
|
|
991
|
+
i || (i = new Promise((u) => {
|
|
992
|
+
n = u;
|
|
993
993
|
}));
|
|
994
994
|
const c = i;
|
|
995
|
-
if (
|
|
996
|
-
return
|
|
997
|
-
|
|
995
|
+
if (o)
|
|
996
|
+
return t = !0, c;
|
|
997
|
+
o = !0;
|
|
998
998
|
do
|
|
999
|
-
|
|
1000
|
-
while (
|
|
1001
|
-
return
|
|
999
|
+
t = !1, await e();
|
|
1000
|
+
while (t);
|
|
1001
|
+
return o = !1, n?.(), i = null, n = null, c;
|
|
1002
1002
|
};
|
|
1003
1003
|
}
|
|
1004
|
-
function
|
|
1005
|
-
return typeof
|
|
1004
|
+
function ge(e) {
|
|
1005
|
+
return typeof e == "object" && e !== null && "createReader" in e && "getSize" in e;
|
|
1006
1006
|
}
|
|
1007
|
-
function
|
|
1008
|
-
return typeof ReadableStream < "u" &&
|
|
1007
|
+
function Se(e) {
|
|
1008
|
+
return typeof ReadableStream < "u" && e instanceof ReadableStream;
|
|
1009
1009
|
}
|
|
1010
|
-
function
|
|
1011
|
-
return typeof
|
|
1010
|
+
function xe(e) {
|
|
1011
|
+
return typeof e == "string" || e instanceof Blob || ge(e) || Se(e) ? { source: e } : e;
|
|
1012
1012
|
}
|
|
1013
|
-
async function
|
|
1014
|
-
if (typeof
|
|
1015
|
-
const
|
|
1016
|
-
if (!
|
|
1013
|
+
async function xt(e) {
|
|
1014
|
+
if (typeof e == "string") {
|
|
1015
|
+
const t = await fetch(e);
|
|
1016
|
+
if (!t.body)
|
|
1017
1017
|
throw new Error("concatVideos: unable to read video stream from url");
|
|
1018
|
-
return
|
|
1018
|
+
return t.body;
|
|
1019
1019
|
}
|
|
1020
|
-
return
|
|
1020
|
+
return e instanceof Blob ? e.stream() : e;
|
|
1021
1021
|
}
|
|
1022
|
-
function
|
|
1023
|
-
let
|
|
1022
|
+
function Te(e, t) {
|
|
1023
|
+
let o = !1;
|
|
1024
1024
|
const i = () => {
|
|
1025
|
-
|
|
1026
|
-
}, n =
|
|
1025
|
+
o || (o = !0, t());
|
|
1026
|
+
}, n = e.getReader();
|
|
1027
1027
|
return new ReadableStream({
|
|
1028
|
-
async pull(
|
|
1029
|
-
const { done: c, value:
|
|
1028
|
+
async pull(a) {
|
|
1029
|
+
const { done: c, value: u } = await n.read();
|
|
1030
1030
|
if (c) {
|
|
1031
|
-
i(),
|
|
1031
|
+
i(), a.close();
|
|
1032
1032
|
return;
|
|
1033
1033
|
}
|
|
1034
|
-
|
|
1034
|
+
a.enqueue(u);
|
|
1035
1035
|
},
|
|
1036
|
-
async cancel(
|
|
1036
|
+
async cancel(a) {
|
|
1037
1037
|
try {
|
|
1038
|
-
await n.cancel(
|
|
1038
|
+
await n.cancel(a);
|
|
1039
1039
|
} finally {
|
|
1040
1040
|
i();
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
1043
|
});
|
|
1044
1044
|
}
|
|
1045
|
-
async function
|
|
1046
|
-
if (
|
|
1045
|
+
async function Ne(e, t = {}) {
|
|
1046
|
+
if (e.length === 0)
|
|
1047
1047
|
throw new Error("concatVideos: expected at least one source");
|
|
1048
1048
|
const {
|
|
1049
|
-
onProgress:
|
|
1049
|
+
onProgress: o,
|
|
1050
1050
|
width: i,
|
|
1051
1051
|
height: n,
|
|
1052
|
-
...
|
|
1053
|
-
} =
|
|
1054
|
-
await
|
|
1055
|
-
const w = i ?? Math.round(
|
|
1056
|
-
if (!w || !
|
|
1057
|
-
throw
|
|
1058
|
-
const
|
|
1059
|
-
...
|
|
1052
|
+
...a
|
|
1053
|
+
} = t, c = e.map(xe), [u, ...d] = c, y = await xt(u.source), h = new K(y);
|
|
1054
|
+
await h.ready;
|
|
1055
|
+
const w = i ?? Math.round(h.meta.width || 0), M = n ?? Math.round(h.meta.height || 0);
|
|
1056
|
+
if (!w || !M)
|
|
1057
|
+
throw h.destroy(), new Error("concatVideos: output width/height is required");
|
|
1058
|
+
const p = new bt({
|
|
1059
|
+
...a,
|
|
1060
1060
|
width: w,
|
|
1061
|
-
height:
|
|
1061
|
+
height: M
|
|
1062
1062
|
});
|
|
1063
|
-
|
|
1063
|
+
o && p.on("OutputProgress", o);
|
|
1064
1064
|
let v = 0;
|
|
1065
|
-
const
|
|
1066
|
-
const
|
|
1067
|
-
if (!Number.isFinite(
|
|
1068
|
-
throw
|
|
1069
|
-
const
|
|
1065
|
+
const m = async (A) => {
|
|
1066
|
+
const E = A.meta.duration;
|
|
1067
|
+
if (!Number.isFinite(E) || E <= 0)
|
|
1068
|
+
throw A.destroy(), new Error("concatVideos: invalid clip duration");
|
|
1069
|
+
const b = new nt(A);
|
|
1070
1070
|
try {
|
|
1071
|
-
await
|
|
1071
|
+
await b.ready, b.rect.x = 0, b.rect.y = 0, b.rect.w = w, b.rect.h = M, b.time.offset = v, b.time.duration = E, await p.addSprite(b), v += E;
|
|
1072
1072
|
} finally {
|
|
1073
|
-
|
|
1073
|
+
b.destroy();
|
|
1074
1074
|
}
|
|
1075
1075
|
};
|
|
1076
1076
|
try {
|
|
1077
|
-
await
|
|
1078
|
-
for (const
|
|
1079
|
-
const
|
|
1080
|
-
await
|
|
1077
|
+
await m(h);
|
|
1078
|
+
for (const A of d) {
|
|
1079
|
+
const E = await xt(A.source), b = new K(E);
|
|
1080
|
+
await b.ready, await m(b);
|
|
1081
1081
|
}
|
|
1082
|
-
} catch (
|
|
1083
|
-
throw
|
|
1082
|
+
} catch (A) {
|
|
1083
|
+
throw p.destroy(), A;
|
|
1084
1084
|
}
|
|
1085
|
-
const g = v, R =
|
|
1086
|
-
|
|
1085
|
+
const g = v, R = p.output({ maxTime: g }), P = () => {
|
|
1086
|
+
p.destroy();
|
|
1087
1087
|
};
|
|
1088
1088
|
return {
|
|
1089
|
-
stream:
|
|
1089
|
+
stream: Te(R, P),
|
|
1090
1090
|
width: w,
|
|
1091
|
-
height:
|
|
1091
|
+
height: M,
|
|
1092
1092
|
durationMs: Math.round(g / 1e3),
|
|
1093
|
-
destroy:
|
|
1093
|
+
destroy: P
|
|
1094
1094
|
};
|
|
1095
1095
|
}
|
|
1096
|
-
class
|
|
1096
|
+
class at {
|
|
1097
1097
|
ready;
|
|
1098
1098
|
meta;
|
|
1099
1099
|
protocol;
|
|
@@ -1101,27 +1101,27 @@ class oe {
|
|
|
1101
1101
|
renderer;
|
|
1102
1102
|
app;
|
|
1103
1103
|
destroyed = !1;
|
|
1104
|
-
constructor(
|
|
1105
|
-
this.protocol =
|
|
1106
|
-
const i =
|
|
1104
|
+
constructor(t, o = {}) {
|
|
1105
|
+
this.protocol = t, this.options = o;
|
|
1106
|
+
const i = o.width ?? t.width, n = o.height ?? t.height, a = it(t);
|
|
1107
1107
|
this.meta = {
|
|
1108
1108
|
width: i,
|
|
1109
1109
|
height: n,
|
|
1110
|
-
duration: Math.max(0, Math.round(
|
|
1110
|
+
duration: Math.max(0, Math.round(a * 1e3))
|
|
1111
1111
|
}, this.ready = this.init();
|
|
1112
1112
|
}
|
|
1113
1113
|
async init() {
|
|
1114
|
-
const
|
|
1115
|
-
if (!
|
|
1114
|
+
const t = this.options.width ?? this.protocol.width, o = this.options.height ?? this.protocol.height;
|
|
1115
|
+
if (!t || !o)
|
|
1116
1116
|
throw new Error("ProtocolVideoClip: output width/height is required");
|
|
1117
|
-
const i = new
|
|
1117
|
+
const i = new kt();
|
|
1118
1118
|
await i.init({
|
|
1119
|
-
width:
|
|
1120
|
-
height:
|
|
1119
|
+
width: t,
|
|
1120
|
+
height: o,
|
|
1121
1121
|
backgroundAlpha: 0,
|
|
1122
1122
|
...this.options.appOptions
|
|
1123
1123
|
}), i.ticker.stop(), this.app = i;
|
|
1124
|
-
const n = this.options.rendererOptions ?? {},
|
|
1124
|
+
const n = this.options.rendererOptions ?? {}, a = await ve({
|
|
1125
1125
|
protocol: this.protocol,
|
|
1126
1126
|
app: i,
|
|
1127
1127
|
...n,
|
|
@@ -1130,120 +1130,285 @@ class oe {
|
|
|
1130
1130
|
manualRender: !0,
|
|
1131
1131
|
videoSourceMode: n.videoSourceMode ?? "mp4clip"
|
|
1132
1132
|
});
|
|
1133
|
-
this.renderer =
|
|
1134
|
-
const c =
|
|
1133
|
+
this.renderer = a;
|
|
1134
|
+
const c = a.duration.value;
|
|
1135
1135
|
return this.meta = {
|
|
1136
1136
|
width: i.renderer.width,
|
|
1137
1137
|
height: i.renderer.height,
|
|
1138
1138
|
duration: Math.max(0, Math.round(c * 1e3))
|
|
1139
1139
|
}, this.meta;
|
|
1140
1140
|
}
|
|
1141
|
-
async tick(
|
|
1142
|
-
const
|
|
1141
|
+
async tick(t) {
|
|
1142
|
+
const o = [];
|
|
1143
1143
|
if (this.destroyed)
|
|
1144
|
-
return { audio:
|
|
1144
|
+
return { audio: o, state: "done" };
|
|
1145
1145
|
if (await this.ready, !this.renderer)
|
|
1146
|
-
return { audio:
|
|
1146
|
+
return { audio: o, state: "done" };
|
|
1147
1147
|
const i = this.meta.duration;
|
|
1148
|
-
if (
|
|
1149
|
-
return { audio:
|
|
1150
|
-
const n = Math.max(0, Math.min(
|
|
1148
|
+
if (t >= i)
|
|
1149
|
+
return { audio: o, state: "done" };
|
|
1150
|
+
const n = Math.max(0, Math.min(t, i));
|
|
1151
1151
|
return await this.renderer.renderAt(n / 1e3), {
|
|
1152
1152
|
video: new VideoFrame(this.renderer.app.canvas, {
|
|
1153
|
-
timestamp:
|
|
1153
|
+
timestamp: t
|
|
1154
1154
|
}),
|
|
1155
|
-
audio:
|
|
1155
|
+
audio: o,
|
|
1156
1156
|
state: "success"
|
|
1157
1157
|
};
|
|
1158
1158
|
}
|
|
1159
1159
|
async clone() {
|
|
1160
|
-
const
|
|
1161
|
-
return await
|
|
1160
|
+
const t = new at(this.protocol, this.options);
|
|
1161
|
+
return await t.ready, t;
|
|
1162
1162
|
}
|
|
1163
1163
|
destroy() {
|
|
1164
1164
|
this.destroyed || (this.destroyed = !0, this.renderer?.destroy(), this.app?.destroy(!0));
|
|
1165
1165
|
}
|
|
1166
1166
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1167
|
+
const It = 12e3;
|
|
1168
|
+
function be(e, t, o) {
|
|
1169
|
+
return new Promise((i, n) => {
|
|
1170
|
+
const a = globalThis.setTimeout(() => {
|
|
1171
|
+
n(new Error(`composeProtocol: ${o} timed out (${t}ms)`));
|
|
1172
|
+
}, t);
|
|
1173
|
+
e.then((c) => {
|
|
1174
|
+
globalThis.clearTimeout(a), i(c);
|
|
1175
|
+
}).catch((c) => {
|
|
1176
|
+
globalThis.clearTimeout(a), n(c);
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
class st {
|
|
1181
|
+
constructor(t, o) {
|
|
1182
|
+
this.sourceClip = t, this.config = o, this.ready = this.sourceClip.ready.then((i) => {
|
|
1183
|
+
const n = Math.round(this.config.segmentDurationUs * this.config.playRate), a = Math.max(0, i.duration - this.config.fromUs);
|
|
1184
|
+
return this.clipMeta = {
|
|
1185
|
+
width: i.width,
|
|
1186
|
+
height: i.height,
|
|
1187
|
+
duration: Math.max(0, Math.min(n, a))
|
|
1188
|
+
}, this.meta;
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
ready;
|
|
1192
|
+
clipMeta = {
|
|
1193
|
+
width: 0,
|
|
1194
|
+
height: 0,
|
|
1195
|
+
duration: 0
|
|
1196
|
+
};
|
|
1197
|
+
get meta() {
|
|
1198
|
+
return { ...this.clipMeta };
|
|
1199
|
+
}
|
|
1200
|
+
async tick(t) {
|
|
1201
|
+
const o = Math.max(0, Math.round(t)), i = Math.round(o / this.config.playRate);
|
|
1202
|
+
if (i >= this.config.segmentDurationUs)
|
|
1203
|
+
return {
|
|
1204
|
+
audio: [],
|
|
1205
|
+
state: "done"
|
|
1206
|
+
};
|
|
1207
|
+
const n = this.config.fromUs + o, a = await this.sourceClip.tick(n);
|
|
1208
|
+
ke(a.video);
|
|
1209
|
+
const c = this.resolveGain(i);
|
|
1210
|
+
return {
|
|
1211
|
+
audio: Ce(a.audio ?? [], c),
|
|
1212
|
+
state: a.state
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
async clone() {
|
|
1216
|
+
const t = await this.sourceClip.clone(), o = new st(t, this.config);
|
|
1217
|
+
return await o.ready, o;
|
|
1218
|
+
}
|
|
1219
|
+
destroy() {
|
|
1220
|
+
this.sourceClip.destroy();
|
|
1221
|
+
}
|
|
1222
|
+
resolveGain(t) {
|
|
1223
|
+
let o = 1;
|
|
1224
|
+
this.config.fadeInUs > 0 && t < this.config.fadeInUs && (o = Math.max(0, t / this.config.fadeInUs));
|
|
1225
|
+
const i = this.config.segmentDurationUs - t;
|
|
1226
|
+
return this.config.fadeOutUs > 0 && i < this.config.fadeOutUs && (o = Math.min(o, Math.max(0, i / this.config.fadeOutUs))), this.config.baseVolume * o;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
function ke(e) {
|
|
1230
|
+
if (!e || typeof e != "object")
|
|
1231
|
+
return;
|
|
1232
|
+
const t = e.close;
|
|
1233
|
+
typeof t == "function" && t.call(e);
|
|
1234
|
+
}
|
|
1235
|
+
function Ce(e, t) {
|
|
1236
|
+
return !e.length || t >= 0.999 ? e : t <= 0 ? e.map((o) => new Float32Array(o.length)) : e.map((o) => {
|
|
1237
|
+
const i = new Float32Array(o.length);
|
|
1238
|
+
for (let n = 0; n < o.length; n++)
|
|
1239
|
+
i[n] = o[n] * t;
|
|
1240
|
+
return i;
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
function j(e) {
|
|
1244
|
+
return Number.isFinite(e) ? Math.max(0, Math.round(e * 1e3)) : 0;
|
|
1245
|
+
}
|
|
1246
|
+
function rt(e) {
|
|
1247
|
+
return typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e));
|
|
1248
|
+
}
|
|
1249
|
+
function Re(e) {
|
|
1250
|
+
return typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0.1, Math.min(100, e));
|
|
1251
|
+
}
|
|
1252
|
+
function Ae(e) {
|
|
1253
|
+
const t = Math.max(0, e.endTime - e.startTime), o = Math.max(0, Math.min(e.fadeInDuration ?? 0, t)), i = Math.max(0, Math.min(e.fadeOutDuration ?? 0, t));
|
|
1254
|
+
return {
|
|
1255
|
+
fromUs: j(e.fromTime ?? 0),
|
|
1256
|
+
segmentDurationUs: j(t),
|
|
1257
|
+
playRate: Re(e.playRate),
|
|
1258
|
+
baseVolume: rt(e.volume),
|
|
1259
|
+
fadeInUs: j(o),
|
|
1260
|
+
fadeOutUs: j(i)
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
function Ee(e) {
|
|
1264
|
+
return e.segmentType === "audio";
|
|
1265
|
+
}
|
|
1266
|
+
function Ie(e) {
|
|
1267
|
+
return e.segmentType === "frames" && e.type === "video";
|
|
1268
|
+
}
|
|
1269
|
+
async function Pt(e, t = It) {
|
|
1270
|
+
const o = new AbortController(), i = globalThis.setTimeout(() => o.abort(), t);
|
|
1271
|
+
try {
|
|
1272
|
+
const n = await fetch(e, { signal: o.signal });
|
|
1273
|
+
if (!n.body)
|
|
1274
|
+
throw new Error(`composeProtocol: unable to read resource stream: ${e}`);
|
|
1275
|
+
return n.body;
|
|
1276
|
+
} catch (n) {
|
|
1277
|
+
throw o.signal.aborted ? new Error(`composeProtocol: loading resource timed out (${t}ms): ${e}`) : n;
|
|
1278
|
+
} finally {
|
|
1279
|
+
globalThis.clearTimeout(i);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
async function Ft(e, t) {
|
|
1283
|
+
const o = Ae(t), i = new st(e, o), n = new nt(i);
|
|
1284
|
+
try {
|
|
1285
|
+
await be(n.ready, It, "prepare audio sprite");
|
|
1286
|
+
} catch (a) {
|
|
1287
|
+
throw n.destroy(), a;
|
|
1288
|
+
}
|
|
1289
|
+
return n.time.offset = j(t.startTime), n.time.duration = o.segmentDurationUs, n.time.playbackRate = o.playRate, n;
|
|
1290
|
+
}
|
|
1291
|
+
async function Pe(e) {
|
|
1292
|
+
const t = await Pt(e.url), o = new Tt(t);
|
|
1293
|
+
return await Ft(o, e);
|
|
1294
|
+
}
|
|
1295
|
+
async function Fe(e) {
|
|
1296
|
+
const t = await Pt(e.url), o = new K(t, { audio: !0 });
|
|
1297
|
+
return await Ft(o, e);
|
|
1298
|
+
}
|
|
1299
|
+
async function Ue(e) {
|
|
1300
|
+
const t = [];
|
|
1301
|
+
for (const n of e.tracks)
|
|
1302
|
+
for (const a of n.children)
|
|
1303
|
+
if (!(a.endTime <= a.startTime)) {
|
|
1304
|
+
if (Ee(a)) {
|
|
1305
|
+
if (rt(a.volume) <= 0)
|
|
1306
|
+
continue;
|
|
1307
|
+
t.push(Pe(a));
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
if (Ie(a)) {
|
|
1311
|
+
if (rt(a.volume) <= 0)
|
|
1312
|
+
continue;
|
|
1313
|
+
t.push(Fe(a));
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
if (!t.length)
|
|
1317
|
+
return [];
|
|
1318
|
+
const o = await Promise.allSettled(t), i = [];
|
|
1319
|
+
for (const n of o) {
|
|
1320
|
+
if (n.status === "fulfilled") {
|
|
1321
|
+
i.push(n.value);
|
|
1322
|
+
continue;
|
|
1323
|
+
}
|
|
1324
|
+
console.warn("[compose] skip audio sprite due to load failure", n.reason);
|
|
1325
|
+
}
|
|
1326
|
+
return i;
|
|
1327
|
+
}
|
|
1328
|
+
function ot(e) {
|
|
1329
|
+
for (const t of e)
|
|
1330
|
+
t.destroy();
|
|
1331
|
+
}
|
|
1332
|
+
function Oe(e, t) {
|
|
1333
|
+
let o = !1;
|
|
1169
1334
|
const i = () => {
|
|
1170
|
-
|
|
1171
|
-
}, n =
|
|
1335
|
+
o || (o = !0, t());
|
|
1336
|
+
}, n = e.getReader();
|
|
1172
1337
|
return new ReadableStream({
|
|
1173
|
-
async pull(
|
|
1174
|
-
const { done: c, value:
|
|
1338
|
+
async pull(a) {
|
|
1339
|
+
const { done: c, value: u } = await n.read();
|
|
1175
1340
|
if (c) {
|
|
1176
|
-
i(),
|
|
1341
|
+
i(), a.close();
|
|
1177
1342
|
return;
|
|
1178
1343
|
}
|
|
1179
|
-
|
|
1344
|
+
a.enqueue(u);
|
|
1180
1345
|
},
|
|
1181
|
-
async cancel(
|
|
1346
|
+
async cancel(a) {
|
|
1182
1347
|
try {
|
|
1183
|
-
await n.cancel(
|
|
1348
|
+
await n.cancel(a);
|
|
1184
1349
|
} finally {
|
|
1185
1350
|
i();
|
|
1186
1351
|
}
|
|
1187
1352
|
}
|
|
1188
1353
|
});
|
|
1189
1354
|
}
|
|
1190
|
-
async function
|
|
1355
|
+
async function Ge(e, t = {}) {
|
|
1191
1356
|
const {
|
|
1192
|
-
width:
|
|
1357
|
+
width: o,
|
|
1193
1358
|
height: i,
|
|
1194
1359
|
fps: n,
|
|
1195
|
-
onProgress:
|
|
1360
|
+
onProgress: a,
|
|
1196
1361
|
clipOptions: c,
|
|
1197
|
-
audioSprites:
|
|
1198
|
-
...
|
|
1199
|
-
} =
|
|
1200
|
-
if (!
|
|
1362
|
+
audioSprites: u,
|
|
1363
|
+
...d
|
|
1364
|
+
} = t, y = o ?? e.width, h = i ?? e.height;
|
|
1365
|
+
if (!y || !h)
|
|
1201
1366
|
throw new Error("composeProtocol: output width/height is required");
|
|
1202
|
-
const w = n ??
|
|
1203
|
-
...
|
|
1204
|
-
audio:
|
|
1205
|
-
width:
|
|
1206
|
-
height:
|
|
1367
|
+
const w = n ?? e.fps, M = d.audio === !1 ? [] : typeof u == "function" ? await u(e) : await Ue(e), p = d.audio ?? (M.length > 0 ? void 0 : !1), v = new bt({
|
|
1368
|
+
...d,
|
|
1369
|
+
audio: p,
|
|
1370
|
+
width: y,
|
|
1371
|
+
height: h,
|
|
1207
1372
|
fps: w
|
|
1208
1373
|
});
|
|
1209
|
-
|
|
1210
|
-
let
|
|
1374
|
+
a && v.on("OutputProgress", a);
|
|
1375
|
+
let m, g;
|
|
1211
1376
|
try {
|
|
1212
|
-
|
|
1213
|
-
width:
|
|
1214
|
-
height:
|
|
1377
|
+
m = new at(e, {
|
|
1378
|
+
width: y,
|
|
1379
|
+
height: h,
|
|
1215
1380
|
fps: w,
|
|
1216
1381
|
...c,
|
|
1217
1382
|
rendererOptions: {
|
|
1218
1383
|
warmUpResources: !1,
|
|
1219
1384
|
...c?.rendererOptions
|
|
1220
1385
|
}
|
|
1221
|
-
}), await
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
} catch (A) {
|
|
1227
|
-
throw v.destroy(), A;
|
|
1386
|
+
}), await m.ready, g = new nt(m), await g.ready, g.time.offset = 0, g.time.duration = m.meta.duration, g.rect.x = 0, g.rect.y = 0, g.rect.w = m.meta.width, g.rect.h = m.meta.height, await v.addSprite(g, { main: !0 });
|
|
1387
|
+
for (const b of M)
|
|
1388
|
+
await v.addSprite(b);
|
|
1389
|
+
} catch (b) {
|
|
1390
|
+
throw ot(M), g?.destroy(), m?.destroy(), v.destroy(), b;
|
|
1228
1391
|
}
|
|
1229
|
-
const R =
|
|
1392
|
+
const R = m?.meta.duration ?? 0;
|
|
1230
1393
|
if (!R)
|
|
1231
|
-
throw new Error("composeProtocol: protocol has no duration");
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1394
|
+
throw ot(M), g?.destroy(), m?.destroy(), v.destroy(), new Error("composeProtocol: protocol has no duration");
|
|
1395
|
+
const P = v.output({ maxTime: R });
|
|
1396
|
+
let A = !1;
|
|
1397
|
+
const E = () => {
|
|
1398
|
+
A || (A = !0, ot(M), g?.destroy(), m?.destroy(), v.destroy());
|
|
1234
1399
|
};
|
|
1235
1400
|
return {
|
|
1236
|
-
stream:
|
|
1237
|
-
width:
|
|
1238
|
-
height:
|
|
1401
|
+
stream: Oe(P, E),
|
|
1402
|
+
width: y,
|
|
1403
|
+
height: h,
|
|
1239
1404
|
durationMs: Math.round(R / 1e3),
|
|
1240
1405
|
destroy: E
|
|
1241
1406
|
};
|
|
1242
1407
|
}
|
|
1243
1408
|
export {
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1409
|
+
at as ProtocolVideoClip,
|
|
1410
|
+
Ge as composeProtocol,
|
|
1411
|
+
Ne as concatVideos,
|
|
1412
|
+
ve as createRenderer
|
|
1248
1413
|
};
|
|
1249
1414
|
//# sourceMappingURL=index.js.map
|