@lumen5/framefusion 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,36 @@
1
- var S = (r, s, t) => {
2
- if (!s.has(r))
1
+ var I = (a, i, t) => {
2
+ if (!i.has(a))
3
3
  throw TypeError("Cannot " + t);
4
4
  };
5
- var e = (r, s, t) => (S(r, s, "read from private field"), t ? t.call(r) : s.get(r)), c = (r, s, t) => {
6
- if (s.has(r))
5
+ var e = (a, i, t) => (I(a, i, "read from private field"), t ? t.call(a) : i.get(a)), c = (a, i, t) => {
6
+ if (i.has(a))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
- s instanceof WeakSet ? s.add(r) : s.set(r, t);
9
- }, a = (r, s, t, i) => (S(r, s, "write to private field"), i ? i.call(r, t) : s.set(r, t), t), T = (r, s, t, i) => ({
10
- set _(o) {
11
- a(r, s, o, t);
8
+ i instanceof WeakSet ? i.add(a) : i.set(a, t);
9
+ }, o = (a, i, t, s) => (I(a, i, "write to private field"), s ? s.call(a, t) : i.set(a, t), t), v = (a, i, t, s) => ({
10
+ set _(r) {
11
+ o(a, i, r, t);
12
12
  },
13
13
  get _() {
14
- return e(r, s, i);
15
- }
16
- }), M = (r, s, t) => (S(r, s, "access private method"), t);
17
- import D from "@lumen5/beamcoder";
18
- import q from "path";
19
- import B from "node:https";
20
- import H from "http";
21
- import O from "tmp";
22
- import z from "fs-extra";
23
- class G {
24
- static async create(s) {
14
+ return e(a, i, s);
15
+ }
16
+ }), L = (a, i, t) => (I(a, i, "access private method"), t);
17
+ import b from "@lumen5/beamcoder";
18
+ import H from "path";
19
+ import O from "node:https";
20
+ import z from "http";
21
+ import G from "tmp";
22
+ import X from "fs-extra";
23
+ class K {
24
+ static async create(i) {
25
25
  throw new Error("Not implemented");
26
26
  }
27
27
  async init({
28
- inputFileOrUrl: s,
28
+ inputFileOrUrl: i,
29
29
  outputFile: t,
30
- threadCount: i = 8,
31
- endTime: o,
32
- interpolateFps: h,
33
- interpolateMode: n
30
+ threadCount: s = 8,
31
+ endTime: r,
32
+ interpolateFps: n,
33
+ interpolateMode: h
34
34
  }) {
35
35
  throw new Error("Not implemented");
36
36
  }
@@ -43,29 +43,29 @@ class G {
43
43
  get height() {
44
44
  throw new Error("Not implemented");
45
45
  }
46
- async seekToPTS(s) {
46
+ async seekToPTS(i) {
47
47
  throw new Error("Not implemented");
48
48
  }
49
- async getFrameAtTime(s) {
49
+ async getFrameAtTime(i) {
50
50
  throw new Error("Not implemented");
51
51
  }
52
- async getImageDataAtTime(s) {
52
+ async getImageDataAtTime(i) {
53
53
  throw new Error("Not implemented");
54
54
  }
55
- async getFrameAtPts(s) {
55
+ async getFrameAtPts(i) {
56
56
  throw new Error("Not implemented");
57
57
  }
58
- async seekToTime(s) {
58
+ async seekToTime(i) {
59
59
  throw new Error("Not implemented");
60
60
  }
61
61
  /**
62
62
  * Convert a PTS (based on timebase) to PTS (in seconds)
63
63
  */
64
- ptsToTime(s) {
64
+ ptsToTime(i) {
65
65
  throw new Error("Not implemented");
66
66
  }
67
67
  async readFrames({
68
- onFrameAvailable: s,
68
+ onFrameAvailable: i,
69
69
  flush: t = !0
70
70
  } = {
71
71
  flush: !0,
@@ -77,123 +77,124 @@ class G {
77
77
  throw new Error("Not implemented");
78
78
  }
79
79
  }
80
- class X extends Error {
80
+ class Y extends Error {
81
81
  }
82
- var x, A, N, v;
83
- class K {
84
- constructor(s) {
85
- c(this, x, void 0);
86
- c(this, A, void 0);
82
+ var P, N, F, _;
83
+ class q {
84
+ constructor(i) {
85
+ c(this, P, void 0);
87
86
  c(this, N, void 0);
88
- c(this, v, void 0);
89
- a(this, x, s);
87
+ c(this, F, void 0);
88
+ c(this, _, void 0);
89
+ o(this, P, i);
90
+ const t = H.extname(i);
91
+ o(this, _, G.fileSync({ postfix: t })), o(this, F, e(this, _).name);
90
92
  }
91
93
  /**
92
94
  * returns the filepath of the downloaded file. If the file has not been downloaded yet, it will be undefined
93
95
  */
94
96
  get filepath() {
95
- return e(this, N);
97
+ return e(this, F);
96
98
  }
97
99
  /**
98
100
  * Downloads the file from the given URL. The file will be downloaded to a temporary file.
99
101
  */
100
102
  async download() {
101
- await new Promise((s, t) => {
102
- const i = e(this, x), o = q.extname(i);
103
- a(this, v, O.fileSync({ postfix: o }));
103
+ await new Promise((i, t) => {
104
+ const s = e(this, P);
104
105
  try {
105
- const h = i.startsWith("https://") ? B : H;
106
- a(this, A, h.get(i, (n) => {
107
- const g = n.headers["content-type"];
108
- if (!g.includes("video")) {
109
- const d = new Error(`Source ${i}, returned unsupported content type ${g}`);
110
- t(d);
106
+ const r = s.startsWith("https://") ? O : z;
107
+ o(this, N, r.get(s, (n) => {
108
+ const h = n.headers["content-type"];
109
+ if (!h.includes("video")) {
110
+ const m = new Error(`Source ${s}, returned unsupported content type ${h}`);
111
+ t(m);
111
112
  return;
112
113
  }
113
- const m = z.createWriteStream(e(this, v).name);
114
- n.pipe(m), m.on("finish", () => {
115
- m.close(), a(this, N, e(this, v).name), s();
116
- }), m.on("error", (d) => {
117
- t(d);
114
+ const u = X.createWriteStream(e(this, _).name);
115
+ n.pipe(u), u.on("finish", () => {
116
+ u.close(), o(this, F, e(this, _).name), i();
117
+ }), u.on("error", (m) => {
118
+ t(m);
118
119
  });
119
- })), e(this, A).on("error", (n) => {
120
- n instanceof X || t(n);
120
+ })), e(this, N).on("error", (n) => {
121
+ n instanceof Y || t(n);
121
122
  });
122
- } catch (h) {
123
- t(h);
123
+ } catch (r) {
124
+ t(r);
124
125
  }
125
126
  });
126
127
  }
127
128
  clear() {
128
- e(this, v) && e(this, v).removeCallback(), e(this, x) && a(this, x, void 0), e(this, A) && a(this, A, null), e(this, N) && a(this, N, void 0);
129
+ e(this, _) && e(this, _).removeCallback(), e(this, P) && o(this, P, void 0), e(this, N) && o(this, N, null), e(this, F) && o(this, F, void 0);
129
130
  }
130
131
  }
131
- x = new WeakMap(), A = new WeakMap(), N = new WeakMap(), v = new WeakMap();
132
- const I = 4, Y = ({
133
- demuxer: r,
134
- streamIndex: s,
132
+ P = new WeakMap(), N = new WeakMap(), F = new WeakMap(), _ = new WeakMap();
133
+ const M = 4, Z = ({
134
+ demuxer: a,
135
+ streamIndex: i,
135
136
  threadCount: t
136
137
  }) => {
137
- const i = {
138
- width: r.streams[s].codecpar.width,
139
- height: r.streams[s].codecpar.height,
140
- pix_fmt: r.streams[s].codecpar.format,
138
+ const s = {
139
+ width: a.streams[i].codecpar.width,
140
+ height: a.streams[i].codecpar.height,
141
+ pix_fmt: a.streams[i].codecpar.format,
141
142
  thread_count: t
142
143
  };
143
- return r.streams[s].codecpar.name === "vp8" ? D.decoder({
144
- ...i,
144
+ return a.streams[i].codecpar.name === "vp8" ? b.decoder({
145
+ ...s,
145
146
  name: "libvpx"
146
- }) : r.streams[s].codecpar.name === "vp9" ? D.decoder({
147
- ...i,
147
+ }) : a.streams[i].codecpar.name === "vp9" ? b.decoder({
148
+ ...s,
148
149
  name: "libvpx-vp9"
149
- }) : D.decoder({
150
- ...i,
151
- demuxer: r,
152
- stream_index: s
150
+ }) : b.decoder({
151
+ ...s,
152
+ demuxer: a,
153
+ stream_index: i
153
154
  });
154
- }, Z = async ({
155
- stream: r,
156
- outputPixelFormat: s,
155
+ }, J = async ({
156
+ stream: a,
157
+ outputPixelFormat: i,
157
158
  interpolateFps: t,
158
- interpolateMode: i = "fast"
159
+ interpolateMode: s = "fast"
159
160
  }) => {
160
- if (!r.codecpar.format)
161
+ if (!a.codecpar.format)
161
162
  return null;
162
- let o = [`[in0:v]format=${r.codecpar.format}`];
163
+ let r = [`[in0:v]format=${a.codecpar.format}`];
163
164
  if (t)
164
- if (i === "high-quality")
165
- o = [...o, `minterpolate=fps=${t}`];
166
- else if (i === "fast")
167
- o = [...o, `fps=${t}`];
165
+ if (s === "high-quality")
166
+ r = [...r, `minterpolate=fps=${t}`];
167
+ else if (s === "fast")
168
+ r = [...r, `fps=${t}`];
168
169
  else
169
- throw new Error(`Unexpected interpolation mode: ${i}`);
170
- const h = o.join(", ") + "[out0:v]";
171
- return D.filterer({
170
+ throw new Error(`Unexpected interpolation mode: ${s}`);
171
+ const n = r.join(", ") + "[out0:v]";
172
+ return b.filterer({
172
173
  filterType: "video",
173
174
  inputParams: [
174
175
  {
175
176
  name: "in0:v",
176
- width: r.codecpar.width,
177
- height: r.codecpar.height,
178
- pixelFormat: r.codecpar.format,
179
- timeBase: r.time_base,
180
- pixelAspect: r.sample_aspect_ratio
177
+ width: a.codecpar.width,
178
+ height: a.codecpar.height,
179
+ pixelFormat: a.codecpar.format,
180
+ timeBase: a.time_base,
181
+ pixelAspect: a.sample_aspect_ratio
181
182
  }
182
183
  ],
183
184
  outputParams: [
184
185
  {
185
186
  name: "out0:v",
186
- pixelFormat: s
187
+ pixelFormat: i
187
188
  }
188
189
  ],
189
- filterSpec: h
190
+ filterSpec: n
190
191
  });
191
- }, L = "video", J = "rgba", Q = 5;
192
- var l, p, k, w, _, E, y, R, u, F, P, C, V;
193
- const $ = class extends G {
192
+ }, V = "video", Q = "rgba", U = 5;
193
+ var l, d, C, w, y, E, T, R, p, x, k, S, B;
194
+ const $ = class extends K {
194
195
  constructor() {
195
196
  super(...arguments);
196
- c(this, C);
197
+ c(this, S);
197
198
  /**
198
199
  * The demuxer reads the file and outputs packet streams
199
200
  */
@@ -201,12 +202,12 @@ const $ = class extends G {
201
202
  /**
202
203
  * The decoder reads packets and can output raw frame data
203
204
  */
204
- c(this, p, null);
205
+ c(this, d, null);
205
206
  /**
206
207
  * Packets can be filtered to change colorspace, fps and add various effects. If there are no colorspace changes or
207
208
  * filters, filter might not be necessary.
208
209
  */
209
- c(this, k, null);
210
+ c(this, C, null);
210
211
  /**
211
212
  * This is where we store filtered frames from each previously processed packet.
212
213
  * We keep these in chronological order. We hang on to them for two reasons:
@@ -219,7 +220,7 @@ const $ = class extends G {
219
220
  * This contains the last raw frames we read from the demuxer. We use it as a starting point for each new query. We
220
221
  * do this ensure we don't skip any frames.
221
222
  */
222
- c(this, _, []);
223
+ c(this, y, []);
223
224
  /**
224
225
  * This contains the last packet we read from the demuxer. We use it as a starting point for each new query. We do
225
226
  * this ensure we don't skip any frames.
@@ -229,7 +230,7 @@ const $ = class extends G {
229
230
  * The last target presentation timestamp (PTS) we requested. If we never requested a time(stamp) then this
230
231
  * value is null
231
232
  */
232
- c(this, y, null);
233
+ c(this, T, null);
233
234
  /**
234
235
  * The number of threads to use for decoding
235
236
  */
@@ -237,98 +238,99 @@ const $ = class extends G {
237
238
  /**
238
239
  * The index of the video stream in the demuxer
239
240
  */
240
- c(this, u, 0);
241
+ c(this, p, 0);
241
242
  /**
242
243
  * The number of packets we've read from the demuxer to complete the frame query
243
244
  * @private
244
245
  */
245
- c(this, F, 0);
246
+ c(this, x, 0);
246
247
  /**
247
248
  * The number of times we've recursively read packets from the demuxer to complete the frame query
248
249
  * @private
249
250
  */
250
- c(this, P, 0);
251
+ c(this, k, 0);
251
252
  }
252
253
  /**
253
254
  * Encoder/Decoder construction is async, so it can't be put in a regular constructor.
254
255
  * Use and await this method to generate an extractor.
255
256
  */
256
257
  static async create(t) {
257
- const i = new $();
258
- return await i.init(t), i;
258
+ const s = new $();
259
+ return await s.init(t), s;
259
260
  }
260
261
  async init({
261
262
  inputFileOrUrl: t,
262
- threadCount: i = 8
263
+ threadCount: s = 8
263
264
  }) {
264
- if (a(this, R, i), t.startsWith("http")) {
265
- const o = new K(t);
266
- await o.download(), t = o.filepath;
265
+ if (o(this, R, s), t.startsWith("http")) {
266
+ const r = new q(t);
267
+ await r.download(), t = r.filepath;
267
268
  }
268
- if (t.startsWith("file:") || (t = "file:" + t), a(this, l, await D.demuxer(t)), a(this, u, e(this, l).streams.findIndex((o) => o.codecpar.codec_type === L)), e(this, u) === -1)
269
- throw new Error(`File has no ${L} stream!`);
270
- a(this, k, await Z({
271
- stream: e(this, l).streams[e(this, u)],
272
- outputPixelFormat: J
269
+ if (t.startsWith("file:") || (t = "file:" + t), o(this, l, await b.demuxer(t)), o(this, p, e(this, l).streams.findIndex((r) => r.codecpar.codec_type === V)), e(this, p) === -1)
270
+ throw new Error(`File has no ${V} stream!`);
271
+ o(this, C, await J({
272
+ stream: e(this, l).streams[e(this, p)],
273
+ outputPixelFormat: Q
273
274
  }));
274
275
  }
275
276
  /**
276
277
  * This is the duration of the first video stream in the file expressed in seconds.
277
278
  */
278
279
  get duration() {
279
- return this.ptsToTime(e(this, l).streams[e(this, u)].duration);
280
+ const t = e(this, l).streams[e(this, p)];
281
+ return t.duration !== null ? this.ptsToTime(t.duration) : this.ptsToTime(e(this, l).duration) / 1e3;
280
282
  }
281
283
  /**
282
284
  * Width in pixels
283
285
  */
284
286
  get width() {
285
- return e(this, l).streams[e(this, u)].codecpar.width;
287
+ return e(this, l).streams[e(this, p)].codecpar.width;
286
288
  }
287
289
  /**
288
290
  * Height in pixels
289
291
  */
290
292
  get height() {
291
- return e(this, l).streams[e(this, u)].codecpar.height;
293
+ return e(this, l).streams[e(this, p)].codecpar.height;
292
294
  }
293
295
  /**
294
296
  * Get the beamcoder Frame for a given time in seconds
295
297
  * @param targetTime
296
298
  */
297
299
  async getFrameAtTime(t) {
298
- const i = Math.round(this._timeToPTS(t));
299
- return this._getFrameAtPts(i);
300
+ const s = Math.round(this._timeToPTS(t));
301
+ return this._getFrameAtPts(s);
300
302
  }
301
303
  /**
302
304
  * Get imageData for a given time in seconds
303
305
  * @param targetTime
304
306
  */
305
- async getImageDataAtTime(t, i) {
306
- const o = Math.round(this._timeToPTS(t)), h = await this._getFrameAtPts(o);
307
- if (!h)
307
+ async getImageDataAtTime(t, s) {
308
+ const r = Math.round(this._timeToPTS(t)), n = await this._getFrameAtPts(r);
309
+ if (!n)
308
310
  return null;
309
- let n = i;
310
- return i || (n = new Uint8ClampedArray(h.width * h.height * I)), this._setFrameDataToImageData(h, n), {
311
- data: n,
312
- width: h.width,
313
- height: h.height
311
+ let h = s;
312
+ return s || (h = new Uint8ClampedArray(n.width * n.height * M)), this._setFrameDataToImageData(n, h), {
313
+ data: h,
314
+ width: n.width,
315
+ height: n.height
314
316
  };
315
317
  }
316
318
  /**
317
319
  * Get the presentation timestamp (PTS) for a given time in seconds
318
320
  */
319
321
  _timeToPTS(t) {
320
- const i = e(this, l).streams[e(this, u)].time_base;
321
- return t * i[1] / i[0];
322
+ const s = e(this, l).streams[e(this, p)].time_base;
323
+ return t * s[1] / s[0];
322
324
  }
323
325
  /**
324
326
  * Get the time in seconds from a given presentation timestamp (PTS)
325
327
  */
326
328
  ptsToTime(t) {
327
- const i = e(this, l).streams[e(this, u)].time_base;
328
- return t * i[0] / i[1];
329
+ const s = e(this, l).streams[e(this, p)].time_base;
330
+ return t * s[0] / s[1];
329
331
  }
330
332
  get packetReadCount() {
331
- return e(this, F);
333
+ return e(this, x);
332
334
  }
333
335
  /**
334
336
  * Get the frame at the given presentation timestamp (PTS)
@@ -337,42 +339,42 @@ const $ = class extends G {
337
339
  * the targetPTS. We use it to further move away from the requested PTS to find a frame. The allows use to read
338
340
  * additional packets and find a frame that is closer to the targetPTS.
339
341
  */
340
- async _getFrameAtPts(t, i = 0) {
341
- a(this, F, 0);
342
- const o = 3, h = e(this, w).flat().some((d) => this.ptsToTime(Math.abs(t - d.pts)) < o);
343
- (e(this, y) === null || e(this, y) > t || !h) && (await e(this, l).seek({
342
+ async _getFrameAtPts(t, s = 0) {
343
+ o(this, x, 0);
344
+ const r = 3, n = e(this, w).flat().some((g) => this.ptsToTime(Math.abs(t - g.pts)) < r);
345
+ (e(this, T) === null || e(this, T) > t || !n) && (await e(this, l).seek({
344
346
  stream_index: 0,
345
347
  // even though we specify the stream index, it still seeks all streams
346
- timestamp: t + i,
348
+ timestamp: t + s,
347
349
  any: !1
348
- }), await M(this, C, V).call(this), a(this, E, null), a(this, _, []), a(this, y, t), a(this, w, []));
349
- let n = null, g = -1, m = null;
350
+ }), await L(this, S, B).call(this), o(this, E, null), o(this, y, []), o(this, T, t), o(this, w, []));
351
+ let h = null, u = -1, m = null;
350
352
  if (e(this, w).length > 0) {
351
- const d = e(this, w).flat().find((f) => f.pts <= t);
352
- if (d) {
353
- const f = e(this, w).flat().find((b) => b.pts > d.pts);
354
- if (g = d.pts, m = d, f && f.pts > t || g === t)
355
- return a(this, y, t), m;
353
+ const g = e(this, w).flat().find((f) => f.pts <= t);
354
+ if (g) {
355
+ const f = e(this, w).flat().find((D) => D.pts > g.pts);
356
+ if (u = g.pts, m = g, f && f.pts > t || u === t)
357
+ return o(this, T, t), m;
356
358
  }
357
359
  }
358
- for (!e(this, E) && e(this, _).length === 0 && ({ packet: T(this, E)._, frames: T(this, _)._ } = await this._getNextPacketAndDecodeFrames(), T(this, F)._++); (e(this, E) || e(this, _).length !== 0) && g < t; ) {
359
- if (e(this, _).length !== 0) {
360
- n = (await e(this, k).filter([{ name: "in0:v", frames: e(this, _) }])).flatMap((b) => b.frames);
361
- const f = e(this, F) === 1 && n[0].pts > t ? n[0] : n.reverse().find((b) => b.pts <= t);
360
+ for (!e(this, E) && e(this, y).length === 0 && ({ packet: v(this, E)._, frames: v(this, y)._ } = await this._getNextPacketAndDecodeFrames(), v(this, x)._++); (e(this, E) || e(this, y).length !== 0) && u < t; ) {
361
+ if (e(this, y).length !== 0) {
362
+ h = (await e(this, C).filter([{ name: "in0:v", frames: e(this, y) }])).flatMap((D) => D.frames);
363
+ const f = e(this, x) === 1 && h[0].pts > t ? h[0] : h.reverse().find((D) => D.pts <= t);
362
364
  if (!f)
363
365
  return m;
364
- if (e(this, w).unshift(n), e(this, w).length > 2 && e(this, w).pop(), g = f == null ? void 0 : f.pts, !m || g <= t)
365
- a(this, y, t), m = f;
366
+ if (e(this, w).unshift(h), e(this, w).length > 2 && e(this, w).pop(), u = f == null ? void 0 : f.pts, !m || u <= t)
367
+ o(this, T, t), m = f;
366
368
  else
367
369
  break;
368
370
  }
369
- ({ packet: T(this, E)._, frames: T(this, _)._ } = await this._getNextPacketAndDecodeFrames()), T(this, F)._++;
371
+ ({ packet: v(this, E)._, frames: v(this, y)._ } = await this._getNextPacketAndDecodeFrames()), v(this, x)._++;
370
372
  }
371
373
  if (!m) {
372
- if (Q < e(this, P))
374
+ if (U < e(this, k))
373
375
  throw Error("No matching frame found");
374
- const d = 0.1, f = this._timeToPTS(d);
375
- T(this, P)._++, m = await this._getFrameAtPts(t, i - f), m && a(this, P, 0);
376
+ const g = 0.1, f = this._timeToPTS(g);
377
+ v(this, k)._++, m = await this._getFrameAtPts(t, s - f), m && o(this, k, 0);
376
378
  }
377
379
  return m;
378
380
  }
@@ -383,38 +385,79 @@ const $ = class extends G {
383
385
  */
384
386
  async _getNextPacketAndDecodeFrames() {
385
387
  const t = await this._getNextVideoStreamPacket();
386
- let i = null;
387
- t !== null && e(this, p) ? i = await e(this, p).decode(t) : e(this, p) && (i = await e(this, p).flush(), a(this, p, null));
388
- let o = [];
389
- return i && i.frames.length !== 0 && (o = i.frames), { packet: t, frames: o };
388
+ let s = null;
389
+ t !== null && e(this, d) ? s = await e(this, d).decode(t) : e(this, d) && (s = await e(this, d).flush(), o(this, d, null));
390
+ let r = [];
391
+ return s && s.frames.length !== 0 && (r = s.frames), { packet: t, frames: r };
390
392
  }
391
393
  async _getNextVideoStreamPacket() {
392
394
  let t = await e(this, l).read();
393
- for (; t && t.stream_index !== e(this, u); )
395
+ for (; t && t.stream_index !== e(this, p); )
394
396
  if (t = await e(this, l).read(), t === null)
395
397
  return null;
396
398
  return t;
397
399
  }
398
- _setFrameDataToImageData(t, i) {
399
- const o = t.linesize, h = t.data[0];
400
- for (let n = 0; n < t.height; n++) {
401
- const g = n * o, m = g + t.width * I, d = h.subarray(g, m), f = n * t.width * I;
402
- i.set(d, f);
400
+ _setFrameDataToImageData(t, s) {
401
+ const r = t.linesize, n = t.data[0];
402
+ for (let h = 0; h < t.height; h++) {
403
+ const u = h * r, m = u + t.width * M, g = n.subarray(u, m), f = h * t.width * M;
404
+ s.set(g, f);
403
405
  }
404
406
  }
405
407
  async dispose() {
406
- e(this, p) && (await e(this, p).flush(), a(this, p, null)), e(this, l).forceClose(), a(this, k, null), a(this, w, void 0), a(this, _, []), a(this, E, null), a(this, y, null), a(this, u, 0);
408
+ e(this, d) && (await e(this, d).flush(), o(this, d, null)), e(this, l).forceClose(), o(this, C, null), o(this, w, void 0), o(this, y, []), o(this, E, null), o(this, T, null), o(this, p, 0);
407
409
  }
408
410
  };
409
411
  let W = $;
410
- l = new WeakMap(), p = new WeakMap(), k = new WeakMap(), w = new WeakMap(), _ = new WeakMap(), E = new WeakMap(), y = new WeakMap(), R = new WeakMap(), u = new WeakMap(), F = new WeakMap(), P = new WeakMap(), C = new WeakSet(), V = async function() {
411
- e(this, p) && (await e(this, p).flush(), a(this, p, null)), a(this, p, Y({
412
+ l = new WeakMap(), d = new WeakMap(), C = new WeakMap(), w = new WeakMap(), y = new WeakMap(), E = new WeakMap(), T = new WeakMap(), R = new WeakMap(), p = new WeakMap(), x = new WeakMap(), k = new WeakMap(), S = new WeakSet(), B = async function() {
413
+ e(this, d) && (await e(this, d).flush(), o(this, d, null)), o(this, d, Z({
412
414
  demuxer: e(this, l),
413
- streamIndex: e(this, u),
415
+ streamIndex: e(this, p),
414
416
  threadCount: e(this, R)
415
417
  }));
416
418
  };
419
+ var A;
420
+ class ot {
421
+ constructor() {
422
+ c(this, A, /* @__PURE__ */ new Map());
423
+ }
424
+ get(i) {
425
+ const t = this;
426
+ let s;
427
+ return {
428
+ url: i,
429
+ get filepath() {
430
+ return s;
431
+ },
432
+ async download() {
433
+ let r = e(t, A).get(i);
434
+ if (r)
435
+ r.refCount += 1, r.downloadPromise && await r.downloadPromise;
436
+ else {
437
+ const n = new q(i), h = n.download();
438
+ r = {
439
+ downloader: n,
440
+ refCount: 1,
441
+ downloadPromise: h
442
+ }, e(t, A).set(i, r);
443
+ try {
444
+ await h;
445
+ } finally {
446
+ r.downloadPromise = void 0;
447
+ }
448
+ }
449
+ s = e(t, A).get(i).downloader.filepath;
450
+ },
451
+ destroy() {
452
+ const r = e(t, A).get(i);
453
+ r && (r.refCount -= 1, r.refCount <= 0 && (r.downloader.clear(), e(t, A).delete(i)), s = void 0);
454
+ }
455
+ };
456
+ }
457
+ }
458
+ A = new WeakMap();
417
459
  export {
418
- W as BeamcoderExtractor
460
+ W as BeamcoderExtractor,
461
+ ot as CachedVideoDownloader
419
462
  };
420
463
  //# sourceMappingURL=framefusion.es.js.map