@editframe/elements 0.12.0-beta.12 → 0.12.0-beta.15
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/elements/{src/elements/EFMedia.js → EFMedia.js} +2 -2
- package/package.json +2 -2
- package/dist/assets/src/EncodedAsset.js +0 -560
- package/dist/assets/src/MP4File.js +0 -223
- package/dist/assets/src/memoize.js +0 -14
- /package/dist/{elements/src/EF_FRAMEGEN.js → EF_FRAMEGEN.js} +0 -0
- /package/dist/{elements/src/EF_INTERACTIVE.js → EF_INTERACTIVE.js} +0 -0
- /package/dist/{elements/src/EF_RENDERING.js → EF_RENDERING.js} +0 -0
- /package/dist/elements/{src/elements/CrossUpdateController.js → CrossUpdateController.js} +0 -0
- /package/dist/elements/{src/elements/EFAudio.js → EFAudio.js} +0 -0
- /package/dist/elements/{src/elements/EFCaptions.js → EFCaptions.js} +0 -0
- /package/dist/elements/{src/elements/EFImage.js → EFImage.js} +0 -0
- /package/dist/elements/{src/elements/EFSourceMixin.js → EFSourceMixin.js} +0 -0
- /package/dist/elements/{src/elements/EFTemporal.js → EFTemporal.js} +0 -0
- /package/dist/elements/{src/elements/EFTimegroup.js → EFTimegroup.js} +0 -0
- /package/dist/elements/{src/elements/EFVideo.js → EFVideo.js} +0 -0
- /package/dist/elements/{src/elements/EFWaveform.js → EFWaveform.js} +0 -0
- /package/dist/elements/{src/elements/FetchMixin.js → FetchMixin.js} +0 -0
- /package/dist/elements/{src/elements/TimegroupController.js → TimegroupController.js} +0 -0
- /package/dist/elements/{src/elements/durationConverter.js → durationConverter.js} +0 -0
- /package/dist/elements/{src/elements/parseTimeToMs.js → parseTimeToMs.js} +0 -0
- /package/dist/{elements/src/gui → gui}/ContextMixin.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFFilmstrip.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFPreview.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFScrubber.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFTimeDisplay.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFToggleLoop.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFTogglePlay.js +0 -0
- /package/dist/{elements/src/gui → gui}/EFWorkbench.js +0 -0
- /package/dist/{elements/src/gui → gui}/TWMixin.css.js +0 -0
- /package/dist/{elements/src/gui → gui}/TWMixin.js +0 -0
- /package/dist/{elements/src/gui → gui}/apiHostContext.js +0 -0
- /package/dist/{elements/src/gui → gui}/efContext.js +0 -0
- /package/dist/{elements/src/gui → gui}/fetchContext.js +0 -0
- /package/dist/{elements/src/gui → gui}/focusContext.js +0 -0
- /package/dist/{elements/src/gui → gui}/focusedElementContext.js +0 -0
- /package/dist/{elements/src/gui → gui}/playingContext.js +0 -0
- /package/dist/{elements/src/index.js → index.js} +0 -0
- /package/dist/{elements/src/msToTimeCode.js → msToTimeCode.js} +0 -0
|
@@ -4,8 +4,8 @@ import { deepArrayEquals } from "@lit/task/deep-equals.js";
|
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
import { css, LitElement } from "lit";
|
|
6
6
|
import { property, state } from "lit/decorators.js";
|
|
7
|
-
import { VideoAsset } from "
|
|
8
|
-
import { MP4File } from "
|
|
7
|
+
import { VideoAsset } from "@editframe/assets/EncodedAsset.js";
|
|
8
|
+
import { MP4File } from "@editframe/assets/MP4File.js";
|
|
9
9
|
import { EF_INTERACTIVE } from "../EF_INTERACTIVE.js";
|
|
10
10
|
import { EF_RENDERING } from "../EF_RENDERING.js";
|
|
11
11
|
import { apiHostContext } from "../gui/apiHostContext.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editframe/elements",
|
|
3
|
-
"version": "0.12.0-beta.
|
|
3
|
+
"version": "0.12.0-beta.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"author": "",
|
|
21
21
|
"license": "UNLICENSED",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@editframe/assets": "0.12.0-beta.
|
|
23
|
+
"@editframe/assets": "0.12.0-beta.15",
|
|
24
24
|
"@lit/context": "^1.1.2",
|
|
25
25
|
"@lit/task": "^1.0.1",
|
|
26
26
|
"d3": "^7.9.0",
|
|
@@ -1,560 +0,0 @@
|
|
|
1
|
-
import * as MP4Box from "mp4box";
|
|
2
|
-
import debug from "debug";
|
|
3
|
-
import { memoize } from "./memoize.js";
|
|
4
|
-
import { MP4File } from "./MP4File.js";
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
8
|
-
var result = __getOwnPropDesc(target, key);
|
|
9
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
10
|
-
if (decorator = decorators[i])
|
|
11
|
-
result = decorator(target, key, result) || result;
|
|
12
|
-
if (result) __defProp(target, key, result);
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
const log = debug("ef:av");
|
|
16
|
-
const BUFFER_SIZE = 10;
|
|
17
|
-
class AssetNotAvailableLocally extends Error {
|
|
18
|
-
}
|
|
19
|
-
class FileAsset {
|
|
20
|
-
constructor(localName, file) {
|
|
21
|
-
this.localName = localName;
|
|
22
|
-
this.file = file;
|
|
23
|
-
}
|
|
24
|
-
async arrayBuffer() {
|
|
25
|
-
return this.file.arrayBuffer();
|
|
26
|
-
}
|
|
27
|
-
get byteSize() {
|
|
28
|
-
return this.file.size;
|
|
29
|
-
}
|
|
30
|
-
get fileExtension() {
|
|
31
|
-
return this.file.name.split(".").pop();
|
|
32
|
-
}
|
|
33
|
-
slice(start, end) {
|
|
34
|
-
return this.file.slice(start, end);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
class ISOFileAsset extends FileAsset {
|
|
38
|
-
constructor(localName, file, mp4boxFile) {
|
|
39
|
-
super(localName, file);
|
|
40
|
-
this.localName = localName;
|
|
41
|
-
this.file = file;
|
|
42
|
-
this.mp4boxFile = mp4boxFile;
|
|
43
|
-
}
|
|
44
|
-
get fileInfo() {
|
|
45
|
-
return this.mp4boxFile.getInfo();
|
|
46
|
-
}
|
|
47
|
-
get containerFormat() {
|
|
48
|
-
return "mp4";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
__decorateClass([
|
|
52
|
-
memoize
|
|
53
|
-
], ISOFileAsset.prototype, "fileInfo");
|
|
54
|
-
const _VideoAsset = class _VideoAsset2 extends ISOFileAsset {
|
|
55
|
-
constructor(localName, mp4boxFile, file) {
|
|
56
|
-
super(localName, file, mp4boxFile);
|
|
57
|
-
this.decodedFrames = [];
|
|
58
|
-
this.requestedSampleNumber = 0;
|
|
59
|
-
this.outCursor = 0;
|
|
60
|
-
this.sampleCursor = 0;
|
|
61
|
-
this.eventListeners = {};
|
|
62
|
-
this.latestSeekCts = 0;
|
|
63
|
-
this.videoDecoder = new VideoDecoder({
|
|
64
|
-
error: (e) => {
|
|
65
|
-
console.error("Video Decoder Error", e);
|
|
66
|
-
},
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
68
|
-
output: async (decodedFrame) => {
|
|
69
|
-
const clone = decodedFrame.clone();
|
|
70
|
-
log("🖼️ frame cts=", decodedFrame.timestamp);
|
|
71
|
-
this.decodedFrames.push(clone);
|
|
72
|
-
this.pruneBuffer();
|
|
73
|
-
decodedFrame.close();
|
|
74
|
-
this.outCursor = this.samples.findIndex(
|
|
75
|
-
(sample) => sample.cts === decodedFrame.timestamp
|
|
76
|
-
);
|
|
77
|
-
log(`cursor=${this.sampleCursor} outCursor=${this.outCursor}`);
|
|
78
|
-
this.emit("frame", clone);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
this.configureDecoder();
|
|
82
|
-
}
|
|
83
|
-
static async createFromReadableStream(id, stream, file) {
|
|
84
|
-
let fileStart = 0;
|
|
85
|
-
const inputFile = new MP4File();
|
|
86
|
-
const reader = stream.getReader();
|
|
87
|
-
const processChunk = ({
|
|
88
|
-
done,
|
|
89
|
-
value
|
|
90
|
-
}) => {
|
|
91
|
-
if (done) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (!value) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const mp4buffer = value.buffer;
|
|
98
|
-
mp4buffer.fileStart = fileStart;
|
|
99
|
-
const isLast = file.size === fileStart + value.byteLength;
|
|
100
|
-
inputFile.appendBuffer(mp4buffer, isLast);
|
|
101
|
-
fileStart += value.byteLength;
|
|
102
|
-
return reader.read().then(processChunk);
|
|
103
|
-
};
|
|
104
|
-
await reader.read().then(processChunk);
|
|
105
|
-
return new _VideoAsset2(id, inputFile, file);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* **Only use this function in tests to reset a VideoAsset to its initial state.**
|
|
109
|
-
*
|
|
110
|
-
* @deprecated
|
|
111
|
-
*/
|
|
112
|
-
async TEST_ONLY_RESET() {
|
|
113
|
-
await this.videoDecoder.flush();
|
|
114
|
-
this.configureDecoder();
|
|
115
|
-
this.requestedSampleNumber = 0;
|
|
116
|
-
this.outCursor = 0;
|
|
117
|
-
this.sampleCursor = 0;
|
|
118
|
-
for (const frame of this.decodedFrames) {
|
|
119
|
-
frame.close();
|
|
120
|
-
}
|
|
121
|
-
this.decodedFrames = [];
|
|
122
|
-
this.lastDecodedSample = void 0;
|
|
123
|
-
this.lastSoughtFrame?.close();
|
|
124
|
-
this.lastSoughtFrame = void 0;
|
|
125
|
-
}
|
|
126
|
-
addEventListener(type, callback) {
|
|
127
|
-
this.eventListeners[type] ||= /* @__PURE__ */ new Set();
|
|
128
|
-
this.eventListeners[type]?.add(callback);
|
|
129
|
-
}
|
|
130
|
-
removeEventListener(type, callback) {
|
|
131
|
-
this.eventListeners[type]?.delete(callback);
|
|
132
|
-
}
|
|
133
|
-
emit(type, ...args) {
|
|
134
|
-
for (const listener of this.eventListeners[type] ?? []) {
|
|
135
|
-
listener(...args);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
get videoCodec() {
|
|
139
|
-
if (!this.defaultVideoTrack) {
|
|
140
|
-
throw new Error("No default video track found");
|
|
141
|
-
}
|
|
142
|
-
return this.defaultVideoTrack?.codec;
|
|
143
|
-
}
|
|
144
|
-
get fragmentInfo() {
|
|
145
|
-
const fragments = [];
|
|
146
|
-
const [first, ...samples] = this.samples;
|
|
147
|
-
if (!first) {
|
|
148
|
-
return fragments;
|
|
149
|
-
}
|
|
150
|
-
let currentFragment = {
|
|
151
|
-
offset: first.offset,
|
|
152
|
-
size: first.size,
|
|
153
|
-
start_ms: first.cts,
|
|
154
|
-
duration_ms: 0
|
|
155
|
-
};
|
|
156
|
-
for (const sample of samples) {
|
|
157
|
-
if (sample.is_sync) {
|
|
158
|
-
if (currentFragment) {
|
|
159
|
-
currentFragment.duration_ms = sample.cts - currentFragment.start_ms;
|
|
160
|
-
fragments.push(currentFragment);
|
|
161
|
-
}
|
|
162
|
-
currentFragment = {
|
|
163
|
-
offset: sample.offset,
|
|
164
|
-
size: sample.size,
|
|
165
|
-
start_ms: sample.cts,
|
|
166
|
-
duration_ms: 0
|
|
167
|
-
};
|
|
168
|
-
} else {
|
|
169
|
-
currentFragment.size += sample.size;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return fragments;
|
|
173
|
-
}
|
|
174
|
-
pruneBuffer() {
|
|
175
|
-
if (this.decodedFrames.length > BUFFER_SIZE) {
|
|
176
|
-
this.decodedFrames.shift()?.close();
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
get editsOffset() {
|
|
180
|
-
if (!this.defaultVideoTrack?.edits) {
|
|
181
|
-
return 0;
|
|
182
|
-
}
|
|
183
|
-
return this.defaultVideoTrack.edits.reduce((acc, edit) => {
|
|
184
|
-
return acc + edit.media_time;
|
|
185
|
-
}, 0);
|
|
186
|
-
}
|
|
187
|
-
async waitUntilVideoQueueDrained() {
|
|
188
|
-
if (this.videoDecoder.decodeQueueSize === 0) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
await new Promise((resolve) => {
|
|
192
|
-
this.videoDecoder.addEventListener(
|
|
193
|
-
"dequeue",
|
|
194
|
-
() => {
|
|
195
|
-
resolve();
|
|
196
|
-
},
|
|
197
|
-
{ once: true }
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
await this.waitUntilVideoQueueDrained();
|
|
201
|
-
}
|
|
202
|
-
get canDecodeNextSample() {
|
|
203
|
-
return this.sampleCursor < this.samples.length;
|
|
204
|
-
}
|
|
205
|
-
async decodeNextSample() {
|
|
206
|
-
if (!this.canDecodeNextSample) {
|
|
207
|
-
throw new Error("No more samples to decode");
|
|
208
|
-
}
|
|
209
|
-
await this.decodeSlice(this.sampleCursor, this.sampleCursor);
|
|
210
|
-
this.sampleCursor++;
|
|
211
|
-
}
|
|
212
|
-
async decodeSlice(start, end) {
|
|
213
|
-
const samples = this.samples.slice(start, end + 1);
|
|
214
|
-
const firstSample = samples[0];
|
|
215
|
-
const lastSample = samples[samples.length - 1];
|
|
216
|
-
if (!firstSample || !lastSample) {
|
|
217
|
-
throw new Error("Samples not found");
|
|
218
|
-
}
|
|
219
|
-
const sliceStart = firstSample.offset;
|
|
220
|
-
const sliceEnd = lastSample.offset + lastSample.size;
|
|
221
|
-
const buffer = await this.file.slice(sliceStart, sliceEnd).arrayBuffer();
|
|
222
|
-
const firstSampleOffset = firstSample.offset;
|
|
223
|
-
for (let i = start; i <= end; i++) {
|
|
224
|
-
await this.waitUntilVideoQueueDrained();
|
|
225
|
-
const sample = this.getSample(i);
|
|
226
|
-
log("Decoding sample #", i, `cts=${sample.cts}`);
|
|
227
|
-
const sampleStart = sample.offset - firstSampleOffset;
|
|
228
|
-
const sampleEnd = sample.offset + sample.size - firstSampleOffset;
|
|
229
|
-
const chunk = new EncodedVideoChunk({
|
|
230
|
-
data: buffer.slice(sampleStart, sampleEnd),
|
|
231
|
-
timestamp: sample.cts,
|
|
232
|
-
duration: sample.duration,
|
|
233
|
-
type: sample.is_sync ? "key" : "delta"
|
|
234
|
-
});
|
|
235
|
-
this.videoDecoder.decode(chunk);
|
|
236
|
-
const nextSample = this.defaultVideoTrak?.samples?.[i + 1];
|
|
237
|
-
if (nextSample === void 0) {
|
|
238
|
-
log("ENDFLUSH");
|
|
239
|
-
await this.videoDecoder.flush();
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
get decoderConfiguration() {
|
|
244
|
-
if (!this.defaultVideoTrack) {
|
|
245
|
-
throw new Error("No default video track found");
|
|
246
|
-
}
|
|
247
|
-
let description = new Uint8Array();
|
|
248
|
-
const trak = this.mp4boxFile.getTrackById(this.defaultVideoTrack.id);
|
|
249
|
-
for (const entry of trak.mdia.minf.stbl.stsd.entries) {
|
|
250
|
-
if (entry.avcC ?? entry.hvcC) {
|
|
251
|
-
const stream = new MP4Box.DataStream(
|
|
252
|
-
void 0,
|
|
253
|
-
0,
|
|
254
|
-
MP4Box.DataStream.BIG_ENDIAN
|
|
255
|
-
);
|
|
256
|
-
if (entry.avcC) {
|
|
257
|
-
entry.avcC.write(stream);
|
|
258
|
-
} else {
|
|
259
|
-
entry.hvcC.write(stream);
|
|
260
|
-
}
|
|
261
|
-
description = new Uint8Array(stream.buffer, 8);
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
codec: this.defaultVideoTrack.codec,
|
|
267
|
-
codedWidth: this.defaultVideoTrack.track_width,
|
|
268
|
-
codedHeight: this.defaultVideoTrack.track_height,
|
|
269
|
-
optimizeForLatency: true,
|
|
270
|
-
description
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Configures the video decoder with the appropriate codec, dimensions, and hardware acceleration settings.
|
|
275
|
-
* If the decoder is already configured, it will be reset before being reconfigured.
|
|
276
|
-
*/
|
|
277
|
-
configureDecoder() {
|
|
278
|
-
if (this.videoDecoder.state === "configured") {
|
|
279
|
-
this.videoDecoder.reset();
|
|
280
|
-
}
|
|
281
|
-
log("Attempting to configure decoder", this.decoderConfiguration);
|
|
282
|
-
this.videoDecoder.configure(this.decoderConfiguration);
|
|
283
|
-
}
|
|
284
|
-
// Default to -1 to throw error if called without an index
|
|
285
|
-
getSample(index = -1) {
|
|
286
|
-
const sample = this.samples?.[index];
|
|
287
|
-
if (!sample) {
|
|
288
|
-
throw new Error(`Sample not found at index ${index}`);
|
|
289
|
-
}
|
|
290
|
-
return sample;
|
|
291
|
-
}
|
|
292
|
-
get timescale() {
|
|
293
|
-
if (!this.defaultVideoTrack) {
|
|
294
|
-
throw new Error("No default video track found");
|
|
295
|
-
}
|
|
296
|
-
return this.defaultVideoTrack.timescale;
|
|
297
|
-
}
|
|
298
|
-
get samples() {
|
|
299
|
-
if (!this.defaultVideoTrak.samples) {
|
|
300
|
-
throw new Error("No video samples found");
|
|
301
|
-
}
|
|
302
|
-
return this.defaultVideoTrak.samples;
|
|
303
|
-
}
|
|
304
|
-
get displayOrderedSamples() {
|
|
305
|
-
return Array.from(this.samples).sort((a, b) => {
|
|
306
|
-
return a.cts - b.cts;
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
getSampleClosetToTime(seconds) {
|
|
310
|
-
const targetTime = Math.round(seconds * this.timescale + this.editsOffset);
|
|
311
|
-
const sampleIndex = this.displayOrderedSamples.findIndex(
|
|
312
|
-
(sample) => sample.cts >= targetTime
|
|
313
|
-
);
|
|
314
|
-
if (sampleIndex === -1) {
|
|
315
|
-
return this.displayOrderedSamples[this.displayOrderedSamples.length - 1];
|
|
316
|
-
}
|
|
317
|
-
return this.displayOrderedSamples[sampleIndex];
|
|
318
|
-
}
|
|
319
|
-
seekingWillEmitNewFrame(seconds) {
|
|
320
|
-
if (!this.lastSoughtFrame) {
|
|
321
|
-
return true;
|
|
322
|
-
}
|
|
323
|
-
if (this.seekingWillGoBackwards(seconds)) {
|
|
324
|
-
return true;
|
|
325
|
-
}
|
|
326
|
-
const nextCts = this.getSampleClosetToTime(seconds).cts;
|
|
327
|
-
return nextCts > this.lastSoughtFrame.timestamp;
|
|
328
|
-
}
|
|
329
|
-
seekingWillSkipPictureGroup(seconds) {
|
|
330
|
-
let start = this.sampleCursor;
|
|
331
|
-
const end = this.getSampleClosetToTime(seconds).number;
|
|
332
|
-
let syncFrameCrossings = 0;
|
|
333
|
-
while (start <= end) {
|
|
334
|
-
const sample = this.getSample(start);
|
|
335
|
-
if (sample.is_sync) {
|
|
336
|
-
if (syncFrameCrossings > 1) {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
syncFrameCrossings++;
|
|
340
|
-
}
|
|
341
|
-
start++;
|
|
342
|
-
}
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
seekingWillGoBackwards(seconds) {
|
|
346
|
-
const targetSample = this.getSampleClosetToTime(seconds);
|
|
347
|
-
const targetIndex = this.displayOrderedSamples.indexOf(targetSample);
|
|
348
|
-
const targetInCache = this.decodedFrames.find(
|
|
349
|
-
(frame) => frame.timestamp === targetSample.cts
|
|
350
|
-
);
|
|
351
|
-
const atEnd = this.sampleCursor === this.samples.length - 1;
|
|
352
|
-
log(
|
|
353
|
-
"this.outCursor <= targetSample.number",
|
|
354
|
-
this.outCursor <= targetSample.number
|
|
355
|
-
);
|
|
356
|
-
log("this.outCursor <= targetIndex", this.outCursor <= targetIndex);
|
|
357
|
-
if (atEnd) {
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
if (targetInCache) {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
log("========");
|
|
364
|
-
log("sampleCursor", this.sampleCursor);
|
|
365
|
-
log(" outCursor", this.outCursor);
|
|
366
|
-
log(" target", targetSample.number);
|
|
367
|
-
log(" targetIndex", targetIndex);
|
|
368
|
-
log(" inCache", !!targetInCache);
|
|
369
|
-
log(" atEnd", atEnd);
|
|
370
|
-
return this.outCursor > targetIndex;
|
|
371
|
-
}
|
|
372
|
-
async seekToTime(seconds) {
|
|
373
|
-
const sample = this.getSampleClosetToTime(seconds);
|
|
374
|
-
const cts = sample.cts;
|
|
375
|
-
this.latestSeekCts = cts;
|
|
376
|
-
const alreadyDecodedFrame = this.decodedFrames.find(
|
|
377
|
-
(f) => f.timestamp === cts
|
|
378
|
-
);
|
|
379
|
-
if (alreadyDecodedFrame) {
|
|
380
|
-
return alreadyDecodedFrame;
|
|
381
|
-
}
|
|
382
|
-
if (this.seekingWillSkipPictureGroup(seconds)) {
|
|
383
|
-
await this.videoDecoder.flush();
|
|
384
|
-
let syncSampleNumber = sample.number;
|
|
385
|
-
while (!this.getSample(syncSampleNumber).is_sync) {
|
|
386
|
-
syncSampleNumber--;
|
|
387
|
-
if (syncSampleNumber < 0) {
|
|
388
|
-
throw new Error("No sync sample found when traversing backwards");
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
this.sampleCursor = syncSampleNumber;
|
|
392
|
-
}
|
|
393
|
-
if (this.seekingWillGoBackwards(seconds)) {
|
|
394
|
-
log("BACKWARDS FLUSH");
|
|
395
|
-
await this.videoDecoder.flush();
|
|
396
|
-
for (const frame2 of this.decodedFrames) {
|
|
397
|
-
frame2.close();
|
|
398
|
-
}
|
|
399
|
-
this.decodedFrames = [];
|
|
400
|
-
let syncSampleNumber = sample.number;
|
|
401
|
-
while (!this.getSample(syncSampleNumber).is_sync) {
|
|
402
|
-
syncSampleNumber--;
|
|
403
|
-
if (syncSampleNumber < 0) {
|
|
404
|
-
throw new Error("No sync sample found when traversing backwards");
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
this.sampleCursor = syncSampleNumber;
|
|
408
|
-
}
|
|
409
|
-
let frame;
|
|
410
|
-
const maybeFrame = (_frame) => {
|
|
411
|
-
if (frame) {
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
log("Maybe frame", _frame.timestamp, cts);
|
|
415
|
-
if (_frame.timestamp === cts) {
|
|
416
|
-
this.removeEventListener("frame", maybeFrame);
|
|
417
|
-
frame = _frame;
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
this.addEventListener("frame", maybeFrame);
|
|
421
|
-
while (frame === void 0 && this.canDecodeNextSample) {
|
|
422
|
-
await this.decodeNextSample();
|
|
423
|
-
}
|
|
424
|
-
this.removeEventListener("frame", maybeFrame);
|
|
425
|
-
if (frame) {
|
|
426
|
-
if (this.lastSoughtFrame && !this.decodedFrames.includes(this.lastSoughtFrame)) {
|
|
427
|
-
try {
|
|
428
|
-
this.lastSoughtFrame.close();
|
|
429
|
-
} catch (error) {
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
this.lastSoughtFrame = frame;
|
|
433
|
-
}
|
|
434
|
-
return frame;
|
|
435
|
-
}
|
|
436
|
-
get defaultVideoTrack() {
|
|
437
|
-
return this.fileInfo.videoTracks[0];
|
|
438
|
-
}
|
|
439
|
-
get defaultVideoTrak() {
|
|
440
|
-
return this.mp4boxFile.getTrackById(this.defaultVideoTrack?.id ?? -1);
|
|
441
|
-
}
|
|
442
|
-
get duration() {
|
|
443
|
-
return this.fileInfo.duration / this.fileInfo.timescale;
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
__decorateClass([
|
|
447
|
-
memoize
|
|
448
|
-
], _VideoAsset.prototype, "editsOffset");
|
|
449
|
-
__decorateClass([
|
|
450
|
-
memoize
|
|
451
|
-
], _VideoAsset.prototype, "timescale");
|
|
452
|
-
__decorateClass([
|
|
453
|
-
memoize
|
|
454
|
-
], _VideoAsset.prototype, "samples");
|
|
455
|
-
__decorateClass([
|
|
456
|
-
memoize
|
|
457
|
-
], _VideoAsset.prototype, "displayOrderedSamples");
|
|
458
|
-
__decorateClass([
|
|
459
|
-
memoize
|
|
460
|
-
], _VideoAsset.prototype, "defaultVideoTrack");
|
|
461
|
-
__decorateClass([
|
|
462
|
-
memoize
|
|
463
|
-
], _VideoAsset.prototype, "defaultVideoTrak");
|
|
464
|
-
__decorateClass([
|
|
465
|
-
memoize
|
|
466
|
-
], _VideoAsset.prototype, "duration");
|
|
467
|
-
let VideoAsset = _VideoAsset;
|
|
468
|
-
const _AudioAsset = class _AudioAsset2 extends ISOFileAsset {
|
|
469
|
-
static async createFromReadableStream(id, stream, file) {
|
|
470
|
-
let fileStart = 0;
|
|
471
|
-
const inputFile = new MP4File();
|
|
472
|
-
const reader = stream.getReader();
|
|
473
|
-
const processChunk = ({
|
|
474
|
-
done,
|
|
475
|
-
value
|
|
476
|
-
}) => {
|
|
477
|
-
if (done) {
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
if (!value) {
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
const mp4buffer = value.buffer;
|
|
484
|
-
mp4buffer.fileStart = fileStart;
|
|
485
|
-
fileStart += value.byteLength;
|
|
486
|
-
inputFile.appendBuffer(mp4buffer);
|
|
487
|
-
return reader.read().then(processChunk);
|
|
488
|
-
};
|
|
489
|
-
await reader.read().then(processChunk);
|
|
490
|
-
return new _AudioAsset2(id, file, inputFile);
|
|
491
|
-
}
|
|
492
|
-
get defaultAudioTrack() {
|
|
493
|
-
return this.fileInfo.audioTracks[0];
|
|
494
|
-
}
|
|
495
|
-
get defaultAudioTrak() {
|
|
496
|
-
return this.mp4boxFile.getTrackById(this.defaultAudioTrack?.id ?? -1);
|
|
497
|
-
}
|
|
498
|
-
get audioCodec() {
|
|
499
|
-
if (!this.defaultAudioTrack) {
|
|
500
|
-
throw new Error("No default audio track found");
|
|
501
|
-
}
|
|
502
|
-
return this.defaultAudioTrack.codec;
|
|
503
|
-
}
|
|
504
|
-
get samplerate() {
|
|
505
|
-
if (!this.defaultAudioTrack) {
|
|
506
|
-
throw new Error("No default audio track found");
|
|
507
|
-
}
|
|
508
|
-
return this.defaultAudioTrack.audio.sample_rate;
|
|
509
|
-
}
|
|
510
|
-
get channelCount() {
|
|
511
|
-
if (!this.defaultAudioTrack) {
|
|
512
|
-
throw new Error("No default audio track found");
|
|
513
|
-
}
|
|
514
|
-
return this.defaultAudioTrack.audio.channel_count;
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
__decorateClass([
|
|
518
|
-
memoize
|
|
519
|
-
], _AudioAsset.prototype, "defaultAudioTrack");
|
|
520
|
-
__decorateClass([
|
|
521
|
-
memoize
|
|
522
|
-
], _AudioAsset.prototype, "defaultAudioTrak");
|
|
523
|
-
__decorateClass([
|
|
524
|
-
memoize
|
|
525
|
-
], _AudioAsset.prototype, "audioCodec");
|
|
526
|
-
__decorateClass([
|
|
527
|
-
memoize
|
|
528
|
-
], _AudioAsset.prototype, "samplerate");
|
|
529
|
-
__decorateClass([
|
|
530
|
-
memoize
|
|
531
|
-
], _AudioAsset.prototype, "channelCount");
|
|
532
|
-
const _ImageAsset = class _ImageAsset2 extends FileAsset {
|
|
533
|
-
static async createFromReadableStream(id, file) {
|
|
534
|
-
if (file.size === 0) {
|
|
535
|
-
throw new AssetNotAvailableLocally();
|
|
536
|
-
}
|
|
537
|
-
return new _ImageAsset2(id, file);
|
|
538
|
-
}
|
|
539
|
-
get objectUrl() {
|
|
540
|
-
return URL.createObjectURL(this.file);
|
|
541
|
-
}
|
|
542
|
-
get format() {
|
|
543
|
-
return this.fileExtension;
|
|
544
|
-
}
|
|
545
|
-
get type() {
|
|
546
|
-
return `image/${this.format}`;
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
__decorateClass([
|
|
550
|
-
memoize
|
|
551
|
-
], _ImageAsset.prototype, "objectUrl");
|
|
552
|
-
__decorateClass([
|
|
553
|
-
memoize
|
|
554
|
-
], _ImageAsset.prototype, "format");
|
|
555
|
-
export {
|
|
556
|
-
AssetNotAvailableLocally,
|
|
557
|
-
FileAsset,
|
|
558
|
-
ISOFileAsset,
|
|
559
|
-
VideoAsset
|
|
560
|
-
};
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import * as MP4Box from "mp4box";
|
|
2
|
-
import debug from "debug";
|
|
3
|
-
const log = debug("ef:av:mp4file");
|
|
4
|
-
class MP4File extends MP4Box.ISOFile {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.readyPromise = new Promise((resolve, reject) => {
|
|
8
|
-
this.onReady = () => resolve();
|
|
9
|
-
this.onError = reject;
|
|
10
|
-
});
|
|
11
|
-
this.waitingForSamples = [];
|
|
12
|
-
this._hasSeenLastSamples = false;
|
|
13
|
-
this._arrayBufferFileStart = 0;
|
|
14
|
-
}
|
|
15
|
-
setSegmentOptions(id, user, options) {
|
|
16
|
-
const trak = this.getTrackById(id);
|
|
17
|
-
if (trak) {
|
|
18
|
-
trak.nextSample = 0;
|
|
19
|
-
this.fragmentedTracks.push({
|
|
20
|
-
id,
|
|
21
|
-
user,
|
|
22
|
-
trak,
|
|
23
|
-
segmentStream: null,
|
|
24
|
-
nb_samples: "nbSamples" in options && options.nbSamples || 1e3,
|
|
25
|
-
rapAlignement: ("rapAlignement" in options && options.rapAlignement) ?? true
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Fragments all tracks in a file into separate array buffers.
|
|
31
|
-
*/
|
|
32
|
-
async fragmentAllTracks() {
|
|
33
|
-
const trackBuffers = {};
|
|
34
|
-
for await (const segment of this.fragmentIterator()) {
|
|
35
|
-
(trackBuffers[segment.track] ??= []).push(segment.data);
|
|
36
|
-
}
|
|
37
|
-
return trackBuffers;
|
|
38
|
-
}
|
|
39
|
-
async *fragmentIterator() {
|
|
40
|
-
await this.readyPromise;
|
|
41
|
-
const trackInfo = {};
|
|
42
|
-
for (const videoTrack of this.getInfo().videoTracks) {
|
|
43
|
-
trackInfo[videoTrack.id] = { index: 0 };
|
|
44
|
-
this.setSegmentOptions(videoTrack.id, null, {
|
|
45
|
-
rapAlignement: true
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
for (const audioTrack of this.getInfo().audioTracks) {
|
|
49
|
-
trackInfo[audioTrack.id] = { index: 0 };
|
|
50
|
-
const sampleRate = audioTrack.audio.sample_rate;
|
|
51
|
-
const probablePacketSize = 1024;
|
|
52
|
-
const probableFourSecondsOfSamples = Math.ceil(
|
|
53
|
-
sampleRate / probablePacketSize * 4
|
|
54
|
-
);
|
|
55
|
-
this.setSegmentOptions(audioTrack.id, null, {
|
|
56
|
-
nbSamples: probableFourSecondsOfSamples
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const initSegments = this.initializeSegmentation();
|
|
60
|
-
for (const initSegment of initSegments) {
|
|
61
|
-
yield {
|
|
62
|
-
track: initSegment.id,
|
|
63
|
-
segment: "init",
|
|
64
|
-
data: initSegment.buffer
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const fragmentStartSamples = {};
|
|
68
|
-
let finishedReading = false;
|
|
69
|
-
do {
|
|
70
|
-
for (const fragTrak of this.fragmentedTracks) {
|
|
71
|
-
const trak = fragTrak.trak;
|
|
72
|
-
if (trak.nextSample === void 0) {
|
|
73
|
-
throw new Error("trak.nextSample is undefined");
|
|
74
|
-
}
|
|
75
|
-
if (trak.samples === void 0) {
|
|
76
|
-
throw new Error("trak.samples is undefined");
|
|
77
|
-
}
|
|
78
|
-
log("trak.nextSample", fragTrak.id, trak.nextSample);
|
|
79
|
-
log("trak.samples.length", fragTrak.id, trak.samples.length);
|
|
80
|
-
while (trak.nextSample < trak.samples.length) {
|
|
81
|
-
let result = void 0;
|
|
82
|
-
const fragTrakNextSample = trak.samples[trak.nextSample];
|
|
83
|
-
if (fragTrakNextSample) {
|
|
84
|
-
fragmentStartSamples[fragTrak.id] ||= fragTrakNextSample;
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
result = this.createFragment(
|
|
88
|
-
fragTrak.id,
|
|
89
|
-
trak.nextSample,
|
|
90
|
-
fragTrak.segmentStream
|
|
91
|
-
);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error("Failed to createFragment", error);
|
|
94
|
-
}
|
|
95
|
-
if (result) {
|
|
96
|
-
fragTrak.segmentStream = result;
|
|
97
|
-
trak.nextSample++;
|
|
98
|
-
} else {
|
|
99
|
-
finishedReading = await this.waitForMoreSamples();
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
const nextSample = trak.samples[trak.nextSample];
|
|
103
|
-
const emitSegment = (
|
|
104
|
-
// if rapAlignement is true, we emit a fragment when we have a rap sample coming up next
|
|
105
|
-
fragTrak.rapAlignement === true && nextSample?.is_sync || // if rapAlignement is false, we emit a fragment when we have the required number of samples
|
|
106
|
-
!fragTrak.rapAlignement && trak.nextSample % fragTrak.nb_samples === 0 || // // if this is the last sample, we emit the fragment
|
|
107
|
-
// finished ||
|
|
108
|
-
// if we have more samples than the number of samples requested, we emit the fragment
|
|
109
|
-
trak.nextSample >= trak.samples.length
|
|
110
|
-
);
|
|
111
|
-
if (emitSegment) {
|
|
112
|
-
const trackInfoForFrag = trackInfo[fragTrak.id];
|
|
113
|
-
if (!trackInfoForFrag) {
|
|
114
|
-
throw new Error("trackInfoForFrag is undefined");
|
|
115
|
-
}
|
|
116
|
-
const startSample = fragmentStartSamples[fragTrak.id];
|
|
117
|
-
const endSample = trak.samples[trak.nextSample - 1];
|
|
118
|
-
if (!startSample || !endSample) {
|
|
119
|
-
throw new Error("startSample or endSample is undefined");
|
|
120
|
-
}
|
|
121
|
-
log(
|
|
122
|
-
`Yielding fragment #${trackInfoForFrag.index} for track=${fragTrak.id}`,
|
|
123
|
-
`startTime=${startSample.cts}`,
|
|
124
|
-
`endTime=${endSample.cts + endSample.duration}`
|
|
125
|
-
);
|
|
126
|
-
yield {
|
|
127
|
-
track: fragTrak.id,
|
|
128
|
-
segment: trackInfoForFrag.index,
|
|
129
|
-
data: fragTrak.segmentStream.buffer,
|
|
130
|
-
cts: startSample.cts,
|
|
131
|
-
dts: startSample.dts,
|
|
132
|
-
duration: endSample.cts - startSample.cts + endSample.duration
|
|
133
|
-
};
|
|
134
|
-
trackInfoForFrag.index += 1;
|
|
135
|
-
fragTrak.segmentStream = null;
|
|
136
|
-
delete fragmentStartSamples[fragTrak.id];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
finishedReading = await this.waitForMoreSamples();
|
|
141
|
-
} while (!finishedReading);
|
|
142
|
-
for (const fragTrak of this.fragmentedTracks) {
|
|
143
|
-
const trak = fragTrak.trak;
|
|
144
|
-
if (trak.nextSample === void 0) {
|
|
145
|
-
throw new Error("trak.nextSample is undefined");
|
|
146
|
-
}
|
|
147
|
-
if (trak.samples === void 0) {
|
|
148
|
-
throw new Error("trak.samples is undefined");
|
|
149
|
-
}
|
|
150
|
-
while (trak.nextSample < trak.samples.length) {
|
|
151
|
-
let result = void 0;
|
|
152
|
-
try {
|
|
153
|
-
result = this.createFragment(
|
|
154
|
-
fragTrak.id,
|
|
155
|
-
trak.nextSample,
|
|
156
|
-
fragTrak.segmentStream
|
|
157
|
-
);
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.error("Failed to createFragment", error);
|
|
160
|
-
}
|
|
161
|
-
if (result) {
|
|
162
|
-
fragTrak.segmentStream = result;
|
|
163
|
-
trak.nextSample++;
|
|
164
|
-
} else {
|
|
165
|
-
finishedReading = await this.waitForMoreSamples();
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
const nextSample = trak.samples[trak.nextSample];
|
|
169
|
-
const emitSegment = (
|
|
170
|
-
// if rapAlignement is true, we emit a fragment when we have a rap sample coming up next
|
|
171
|
-
fragTrak.rapAlignement === true && nextSample?.is_sync || // if rapAlignement is false, we emit a fragment when we have the required number of samples
|
|
172
|
-
!fragTrak.rapAlignement && trak.nextSample % fragTrak.nb_samples === 0 || // if we have more samples than the number of samples requested, we emit the fragment
|
|
173
|
-
trak.nextSample >= trak.samples.length
|
|
174
|
-
);
|
|
175
|
-
if (emitSegment) {
|
|
176
|
-
const trackInfoForFrag = trackInfo[fragTrak.id];
|
|
177
|
-
if (!trackInfoForFrag) {
|
|
178
|
-
throw new Error("trackInfoForFrag is undefined");
|
|
179
|
-
}
|
|
180
|
-
const startSample = fragmentStartSamples[fragTrak.id];
|
|
181
|
-
const endSample = trak.samples[trak.nextSample - 1];
|
|
182
|
-
if (!startSample || !endSample) {
|
|
183
|
-
throw new Error("startSample or endSample is undefined");
|
|
184
|
-
}
|
|
185
|
-
log(
|
|
186
|
-
`Yielding fragment #${trackInfoForFrag.index} for track=${fragTrak.id}`,
|
|
187
|
-
`startTime=${startSample.cts}`,
|
|
188
|
-
`endTime=${endSample.cts + endSample.duration}`
|
|
189
|
-
);
|
|
190
|
-
yield {
|
|
191
|
-
track: fragTrak.id,
|
|
192
|
-
segment: trackInfoForFrag.index,
|
|
193
|
-
data: fragTrak.segmentStream.buffer,
|
|
194
|
-
cts: startSample.cts,
|
|
195
|
-
dts: startSample.dts,
|
|
196
|
-
duration: endSample.cts - startSample.cts + endSample.duration
|
|
197
|
-
};
|
|
198
|
-
trackInfoForFrag.index += 1;
|
|
199
|
-
fragTrak.segmentStream = null;
|
|
200
|
-
delete fragmentStartSamples[fragTrak.id];
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
waitForMoreSamples() {
|
|
206
|
-
if (this._hasSeenLastSamples) {
|
|
207
|
-
return Promise.resolve(true);
|
|
208
|
-
}
|
|
209
|
-
return new Promise((resolve) => {
|
|
210
|
-
this.waitingForSamples.push(resolve);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
processSamples(last) {
|
|
214
|
-
this._hasSeenLastSamples = last;
|
|
215
|
-
for (const observer of this.waitingForSamples) {
|
|
216
|
-
observer(last);
|
|
217
|
-
}
|
|
218
|
-
this.waitingForSamples = [];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
export {
|
|
222
|
-
MP4File
|
|
223
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const memoize = (_target, _propertyKey, descriptor) => {
|
|
2
|
-
const get = descriptor.get;
|
|
3
|
-
if (!get) return;
|
|
4
|
-
const memoized = /* @__PURE__ */ new WeakMap();
|
|
5
|
-
descriptor.get = function() {
|
|
6
|
-
if (!memoized.has(this)) {
|
|
7
|
-
memoized.set(this, get.call(this));
|
|
8
|
-
}
|
|
9
|
-
return memoized.get(this);
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
memoize
|
|
14
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|