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