@remotion/media-parser 4.0.292 → 4.0.294
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/containers/iso-base-media/are-samples-complete.d.ts +6 -0
- package/dist/containers/iso-base-media/are-samples-complete.js +11 -0
- package/dist/containers/iso-base-media/collect-sample-positions-from-moof-boxes.d.ts +2 -3
- package/dist/containers/iso-base-media/collect-sample-positions-from-moof-boxes.js +1 -3
- package/dist/containers/iso-base-media/find-track-to-seek.js +9 -2
- package/dist/containers/iso-base-media/get-keyframes.js +6 -2
- package/dist/containers/iso-base-media/get-sample-positions-from-track.d.ts +2 -3
- package/dist/containers/iso-base-media/get-sample-positions-from-track.js +4 -4
- package/dist/containers/iso-base-media/get-seeking-byte-from-fragmented-mp4.js +6 -1
- package/dist/containers/iso-base-media/mdat/mdat.js +18 -1
- package/dist/containers/iso-base-media/process-box.js +7 -7
- package/dist/containers/iso-base-media/seeking-hints.js +1 -1
- package/dist/containers/iso-base-media/traversal.d.ts +2 -1
- package/dist/containers/iso-base-media/traversal.js +8 -4
- package/dist/emit-available-info.js +26 -26
- package/dist/esm/index.mjs +160 -88
- package/dist/esm/node.mjs +7 -4
- package/dist/esm/universal.mjs +29 -37
- package/dist/esm/web.mjs +22 -33
- package/dist/esm/worker-server-entry.mjs +166 -91
- package/dist/esm/worker-web-entry.mjs +159 -87
- package/dist/get-duration.js +15 -3
- package/dist/has-all-info.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/readers/fetch/get-body-and-reader.js +3 -1
- package/dist/readers/from-node.js +7 -3
- package/dist/readers/from-web-file.js +20 -32
- package/dist/readers/reader.d.ts +1 -1
- package/dist/seek-backwards.js +1 -0
- package/dist/seek-forwards.js +1 -0
- package/dist/state/iso-base-media/cached-sample-positions.d.ts +5 -2
- package/dist/state/iso-base-media/cached-sample-positions.js +17 -7
- package/dist/state/iso-base-media/iso-state.d.ts +1 -1
- package/dist/state/iso-base-media/last-moof-box.d.ts +2 -0
- package/dist/state/iso-base-media/last-moof-box.js +21 -0
- package/dist/state/iso-base-media/precomputed-moof.d.ts +1 -0
- package/dist/state/iso-base-media/precomputed-moof.js +1 -0
- package/dist/state/parser-state.d.ts +1 -1
- package/dist/state/parser-state.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/dist/esm/index.mjs
CHANGED
|
@@ -2064,7 +2064,8 @@ var toMoofBox = (box) => {
|
|
|
2064
2064
|
}
|
|
2065
2065
|
return {
|
|
2066
2066
|
offset: box.offset,
|
|
2067
|
-
trafBoxes: box.children.filter((c) => c.type === "regular-box" && c.boxType === "traf")
|
|
2067
|
+
trafBoxes: box.children.filter((c) => c.type === "regular-box" && c.boxType === "traf"),
|
|
2068
|
+
size: box.boxSize
|
|
2068
2069
|
};
|
|
2069
2070
|
};
|
|
2070
2071
|
var deduplicateMoofBoxesByOffset = (moofBoxes) => {
|
|
@@ -2238,13 +2239,16 @@ var getTrunBoxes = (segment) => {
|
|
|
2238
2239
|
const trunBoxes = segment.children.filter((c) => c.type === "trun-box");
|
|
2239
2240
|
return trunBoxes;
|
|
2240
2241
|
};
|
|
2242
|
+
var getTfraBoxesFromMfraBoxChildren = (mfraBoxChildren) => {
|
|
2243
|
+
const tfraBoxes = mfraBoxChildren.filter((b) => b.type === "tfra-box");
|
|
2244
|
+
return tfraBoxes;
|
|
2245
|
+
};
|
|
2241
2246
|
var getTfraBoxes = (structure) => {
|
|
2242
|
-
const mfraBox = structure.
|
|
2247
|
+
const mfraBox = structure.find((b) => b.type === "regular-box" && b.boxType === "mfra");
|
|
2243
2248
|
if (!mfraBox) {
|
|
2244
2249
|
return [];
|
|
2245
2250
|
}
|
|
2246
|
-
|
|
2247
|
-
return tfraBoxes;
|
|
2251
|
+
return getTfraBoxesFromMfraBoxChildren(mfraBox.children);
|
|
2248
2252
|
};
|
|
2249
2253
|
|
|
2250
2254
|
// src/containers/riff/traversal.ts
|
|
@@ -5088,13 +5092,13 @@ var processBox = async ({
|
|
|
5088
5092
|
if (boxType === "ftyp") {
|
|
5089
5093
|
return {
|
|
5090
5094
|
type: "box",
|
|
5091
|
-
box:
|
|
5095
|
+
box: parseFtyp({ iterator, size: boxSize, offset: fileOffset })
|
|
5092
5096
|
};
|
|
5093
5097
|
}
|
|
5094
5098
|
if (boxType === "colr") {
|
|
5095
5099
|
return {
|
|
5096
5100
|
type: "box",
|
|
5097
|
-
box:
|
|
5101
|
+
box: parseColorParameterBox({
|
|
5098
5102
|
iterator,
|
|
5099
5103
|
size: boxSize
|
|
5100
5104
|
})
|
|
@@ -5103,25 +5107,25 @@ var processBox = async ({
|
|
|
5103
5107
|
if (boxType === "mvhd") {
|
|
5104
5108
|
return {
|
|
5105
5109
|
type: "box",
|
|
5106
|
-
box:
|
|
5110
|
+
box: parseMvhd({ iterator, offset: fileOffset, size: boxSize })
|
|
5107
5111
|
};
|
|
5108
5112
|
}
|
|
5109
5113
|
if (boxType === "tkhd") {
|
|
5110
5114
|
return {
|
|
5111
5115
|
type: "box",
|
|
5112
|
-
box:
|
|
5116
|
+
box: parseTkhd({ iterator, offset: fileOffset, size: boxSize })
|
|
5113
5117
|
};
|
|
5114
5118
|
}
|
|
5115
5119
|
if (boxType === "trun") {
|
|
5116
5120
|
return {
|
|
5117
5121
|
type: "box",
|
|
5118
|
-
box:
|
|
5122
|
+
box: parseTrun({ iterator, offset: fileOffset, size: boxSize })
|
|
5119
5123
|
};
|
|
5120
5124
|
}
|
|
5121
5125
|
if (boxType === "tfdt") {
|
|
5122
5126
|
return {
|
|
5123
5127
|
type: "box",
|
|
5124
|
-
box:
|
|
5128
|
+
box: parseTfdt({ iterator, size: boxSize, offset: fileOffset })
|
|
5125
5129
|
};
|
|
5126
5130
|
}
|
|
5127
5131
|
if (boxType === "stsd") {
|
|
@@ -5370,7 +5374,7 @@ var processBox = async ({
|
|
|
5370
5374
|
};
|
|
5371
5375
|
}
|
|
5372
5376
|
if (boxType === "moof") {
|
|
5373
|
-
onlyIfMoovAtomExpected?.isoState?.mfra.triggerLoad();
|
|
5377
|
+
await onlyIfMoovAtomExpected?.isoState?.mfra.triggerLoad();
|
|
5374
5378
|
}
|
|
5375
5379
|
if (boxType === "mdia" || boxType === "minf" || boxType === "stbl" || boxType === "udta" || boxType === "moof" || boxType === "dims" || boxType === "meta" || boxType === "wave" || boxType === "traf" || boxType === "mfra" || boxType === "stsb") {
|
|
5376
5380
|
const children = await getIsoBaseMediaChildren({
|
|
@@ -6776,6 +6780,17 @@ var getDurationFromFlac = (parserState) => {
|
|
|
6776
6780
|
return streaminfo.totalSamples / streaminfo.sampleRate;
|
|
6777
6781
|
};
|
|
6778
6782
|
|
|
6783
|
+
// src/containers/iso-base-media/are-samples-complete.ts
|
|
6784
|
+
var areSamplesComplete = ({
|
|
6785
|
+
moofBoxes,
|
|
6786
|
+
tfraBoxes
|
|
6787
|
+
}) => {
|
|
6788
|
+
if (moofBoxes.length === 0) {
|
|
6789
|
+
return true;
|
|
6790
|
+
}
|
|
6791
|
+
return tfraBoxes.length > 0 && tfraBoxes.every((t) => t.entries.length === moofBoxes.length);
|
|
6792
|
+
};
|
|
6793
|
+
|
|
6779
6794
|
// src/samples-from-moof.ts
|
|
6780
6795
|
var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
6781
6796
|
if (trafSegment.type !== "regular-box" || trafSegment.boxType !== "traf") {
|
|
@@ -6849,10 +6864,9 @@ var getSamplesFromMoof = ({
|
|
|
6849
6864
|
// src/containers/iso-base-media/collect-sample-positions-from-moof-boxes.ts
|
|
6850
6865
|
var collectSamplePositionsFromMoofBoxes = ({
|
|
6851
6866
|
moofBoxes,
|
|
6852
|
-
|
|
6853
|
-
|
|
6867
|
+
tkhdBox,
|
|
6868
|
+
isComplete
|
|
6854
6869
|
}) => {
|
|
6855
|
-
const isComplete = tfraBoxes.length > 0 && tfraBoxes.every((t) => t.entries.length === moofBoxes.length);
|
|
6856
6870
|
const samplePositions = moofBoxes.map((m, index) => {
|
|
6857
6871
|
const isLastFragment = index === moofBoxes.length - 1 && isComplete;
|
|
6858
6872
|
return {
|
|
@@ -7032,21 +7046,21 @@ var collectSamplePositionsFromTrak = (trakBox) => {
|
|
|
7032
7046
|
var getSamplePositionsFromTrack = ({
|
|
7033
7047
|
trakBox,
|
|
7034
7048
|
moofBoxes,
|
|
7035
|
-
|
|
7049
|
+
moofComplete
|
|
7036
7050
|
}) => {
|
|
7037
7051
|
const tkhdBox = getTkhdBox(trakBox);
|
|
7038
7052
|
if (!tkhdBox) {
|
|
7039
7053
|
throw new Error("Expected tkhd box in trak box");
|
|
7040
7054
|
}
|
|
7041
7055
|
if (moofBoxes.length > 0) {
|
|
7042
|
-
const {
|
|
7056
|
+
const { samplePositions } = collectSamplePositionsFromMoofBoxes({
|
|
7043
7057
|
moofBoxes,
|
|
7044
|
-
|
|
7045
|
-
|
|
7058
|
+
tkhdBox,
|
|
7059
|
+
isComplete: moofComplete
|
|
7046
7060
|
});
|
|
7047
7061
|
return {
|
|
7048
7062
|
samplePositions: samplePositions.map((s) => s.samples).flat(1),
|
|
7049
|
-
isComplete
|
|
7063
|
+
isComplete: moofComplete
|
|
7050
7064
|
};
|
|
7051
7065
|
}
|
|
7052
7066
|
return {
|
|
@@ -7249,6 +7263,20 @@ var getDurationFromWav = (state) => {
|
|
|
7249
7263
|
return durationInSeconds;
|
|
7250
7264
|
};
|
|
7251
7265
|
|
|
7266
|
+
// src/state/iso-base-media/precomputed-tfra.ts
|
|
7267
|
+
var precomputedTfraState = () => {
|
|
7268
|
+
let tfraBoxes = [];
|
|
7269
|
+
return {
|
|
7270
|
+
getTfraBoxes: () => tfraBoxes,
|
|
7271
|
+
setTfraBoxes: (boxes) => {
|
|
7272
|
+
tfraBoxes = boxes;
|
|
7273
|
+
}
|
|
7274
|
+
};
|
|
7275
|
+
};
|
|
7276
|
+
var deduplicateTfraBoxesByOffset = (tfraBoxes) => {
|
|
7277
|
+
return tfraBoxes.filter((m, i, arr) => i === arr.findIndex((t) => t.offset === m.offset));
|
|
7278
|
+
};
|
|
7279
|
+
|
|
7252
7280
|
// src/get-duration.ts
|
|
7253
7281
|
var getDurationFromMatroska = (segments) => {
|
|
7254
7282
|
const mainSegment = segments.find((s) => s.type === "Segment");
|
|
@@ -7286,7 +7314,14 @@ var getDurationFromIsoBaseMedia = (parserState) => {
|
|
|
7286
7314
|
return null;
|
|
7287
7315
|
}
|
|
7288
7316
|
const moofBoxes = getMoofBoxes(structure.boxes);
|
|
7289
|
-
const
|
|
7317
|
+
const mfra = parserState.iso.mfra.getIfAlreadyLoaded();
|
|
7318
|
+
const tfraBoxes = deduplicateTfraBoxesByOffset([
|
|
7319
|
+
...mfra ? getTfraBoxesFromMfraBoxChildren(mfra) : [],
|
|
7320
|
+
...getTfraBoxes(structure.boxes)
|
|
7321
|
+
]);
|
|
7322
|
+
if (!areSamplesComplete({ moofBoxes, tfraBoxes })) {
|
|
7323
|
+
return null;
|
|
7324
|
+
}
|
|
7290
7325
|
const mvhdBox = getMvhdBox(moovBox);
|
|
7291
7326
|
if (!mvhdBox) {
|
|
7292
7327
|
return null;
|
|
@@ -7308,7 +7343,7 @@ var getDurationFromIsoBaseMedia = (parserState) => {
|
|
|
7308
7343
|
const { samplePositions, isComplete } = getSamplePositionsFromTrack({
|
|
7309
7344
|
trakBox: t.trakBox,
|
|
7310
7345
|
moofBoxes,
|
|
7311
|
-
tfraBoxes
|
|
7346
|
+
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes })
|
|
7312
7347
|
});
|
|
7313
7348
|
if (!isComplete) {
|
|
7314
7349
|
return null;
|
|
@@ -7365,7 +7400,10 @@ var hasDuration = (parserState) => {
|
|
|
7365
7400
|
};
|
|
7366
7401
|
var hasSlowDuration = (parserState) => {
|
|
7367
7402
|
try {
|
|
7368
|
-
|
|
7403
|
+
if (!hasDuration(parserState)) {
|
|
7404
|
+
return false;
|
|
7405
|
+
}
|
|
7406
|
+
return getDuration(parserState) !== null;
|
|
7369
7407
|
} catch {
|
|
7370
7408
|
return false;
|
|
7371
7409
|
}
|
|
@@ -7393,13 +7431,16 @@ var getKeyframesFromIsoBaseMedia = (state) => {
|
|
|
7393
7431
|
});
|
|
7394
7432
|
const structure = state.structure.getIsoStructure();
|
|
7395
7433
|
const moofBoxes = getMoofBoxes(structure.boxes);
|
|
7396
|
-
const tfraBoxes = getTfraBoxes(structure);
|
|
7434
|
+
const tfraBoxes = getTfraBoxes(structure.boxes);
|
|
7397
7435
|
const allSamples = videoTracks.map((t) => {
|
|
7398
7436
|
const { timescale: ts } = t;
|
|
7399
7437
|
const { samplePositions, isComplete } = getSamplePositionsFromTrack({
|
|
7400
7438
|
trakBox: t.trakBox,
|
|
7401
7439
|
moofBoxes,
|
|
7402
|
-
|
|
7440
|
+
moofComplete: areSamplesComplete({
|
|
7441
|
+
moofBoxes,
|
|
7442
|
+
tfraBoxes
|
|
7443
|
+
})
|
|
7403
7444
|
});
|
|
7404
7445
|
if (!isComplete) {
|
|
7405
7446
|
return [];
|
|
@@ -7852,7 +7893,10 @@ var findAnyTrackWithSamplePositions = (allTracks, struc) => {
|
|
|
7852
7893
|
const { samplePositions } = getSamplePositionsFromTrack({
|
|
7853
7894
|
trakBox: track.trakBox,
|
|
7854
7895
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
7855
|
-
|
|
7896
|
+
moofComplete: areSamplesComplete({
|
|
7897
|
+
moofBoxes: getMoofBoxes(struc.boxes),
|
|
7898
|
+
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
7899
|
+
})
|
|
7856
7900
|
});
|
|
7857
7901
|
if (samplePositions.length === 0) {
|
|
7858
7902
|
continue;
|
|
@@ -7871,7 +7915,10 @@ var findTrackToSeek = (allTracks, structure) => {
|
|
|
7871
7915
|
const { samplePositions } = getSamplePositionsFromTrack({
|
|
7872
7916
|
trakBox: firstVideoTrack.trakBox,
|
|
7873
7917
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
7874
|
-
|
|
7918
|
+
moofComplete: areSamplesComplete({
|
|
7919
|
+
moofBoxes: getMoofBoxes(struc.boxes),
|
|
7920
|
+
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
7921
|
+
})
|
|
7875
7922
|
});
|
|
7876
7923
|
if (samplePositions.length === 0) {
|
|
7877
7924
|
return findAnyTrackWithSamplePositions(allTracks, struc);
|
|
@@ -8011,10 +8058,14 @@ var getSeekingByteFromFragmentedMp4 = async ({
|
|
|
8011
8058
|
if (!tkhdBox) {
|
|
8012
8059
|
throw new Error("Expected tkhd box in trak box");
|
|
8013
8060
|
}
|
|
8061
|
+
const isComplete = areSamplesComplete({
|
|
8062
|
+
moofBoxes: info.moofBoxes,
|
|
8063
|
+
tfraBoxes: info.tfraBoxes
|
|
8064
|
+
});
|
|
8014
8065
|
const { samplePositions: samplePositionsArray } = collectSamplePositionsFromMoofBoxes({
|
|
8015
8066
|
moofBoxes: info.moofBoxes,
|
|
8016
|
-
|
|
8017
|
-
|
|
8067
|
+
tkhdBox,
|
|
8068
|
+
isComplete
|
|
8018
8069
|
});
|
|
8019
8070
|
Log.trace(logLevel, "Fragmented MP4 - Checking if we have seeking info for this time range");
|
|
8020
8071
|
for (const positions of samplePositionsArray) {
|
|
@@ -8938,20 +8989,6 @@ var setSeekingHintsForFlac = ({
|
|
|
8938
8989
|
state.flac.audioSamples.setFromSeekingHints(hints.audioSampleMap);
|
|
8939
8990
|
};
|
|
8940
8991
|
|
|
8941
|
-
// src/state/iso-base-media/precomputed-tfra.ts
|
|
8942
|
-
var precomputedTfraState = () => {
|
|
8943
|
-
let tfraBoxes = [];
|
|
8944
|
-
return {
|
|
8945
|
-
getTfraBoxes: () => tfraBoxes,
|
|
8946
|
-
setTfraBoxes: (boxes) => {
|
|
8947
|
-
tfraBoxes = boxes;
|
|
8948
|
-
}
|
|
8949
|
-
};
|
|
8950
|
-
};
|
|
8951
|
-
var deduplicateTfraBoxesByOffset = (tfraBoxes) => {
|
|
8952
|
-
return tfraBoxes.filter((m, i, arr) => i === arr.findIndex((t) => t.offset === m.offset));
|
|
8953
|
-
};
|
|
8954
|
-
|
|
8955
8992
|
// src/containers/iso-base-media/seeking-hints.ts
|
|
8956
8993
|
var getSeekingHintsFromMp4 = ({
|
|
8957
8994
|
structureState,
|
|
@@ -8972,7 +9009,7 @@ var getSeekingHintsFromMp4 = ({
|
|
|
8972
9009
|
]);
|
|
8973
9010
|
const tfraBoxes = deduplicateTfraBoxesByOffset([
|
|
8974
9011
|
...isoState.tfra.getTfraBoxes(),
|
|
8975
|
-
...getTfraBoxes(structure)
|
|
9012
|
+
...getTfraBoxes(structure.boxes)
|
|
8976
9013
|
]);
|
|
8977
9014
|
if (!moovAtom) {
|
|
8978
9015
|
return null;
|
|
@@ -9231,6 +9268,7 @@ var seekBackwards = async ({
|
|
|
9231
9268
|
}
|
|
9232
9269
|
const time = Date.now();
|
|
9233
9270
|
Log.verbose(logLevel, `Seeking in video from position ${iterator.counter.getOffset()} -> ${seekTo}. Re-reading because this portion is not available.`);
|
|
9271
|
+
await currentReader.getCurrent().abort();
|
|
9234
9272
|
const { reader: newReader } = await readerInterface.read({
|
|
9235
9273
|
src,
|
|
9236
9274
|
range: seekTo,
|
|
@@ -9325,6 +9363,7 @@ var seekForward = async ({
|
|
|
9325
9363
|
}
|
|
9326
9364
|
const time = Date.now();
|
|
9327
9365
|
Log.verbose(logLevel, `Skipping over video data from position ${iterator.counter.getOffset()} -> ${seekTo}. Re-reading because this portion is not available`);
|
|
9366
|
+
await currentReader.getCurrent().abort();
|
|
9328
9367
|
const { reader: newReader } = await readerInterface.read({
|
|
9329
9368
|
src,
|
|
9330
9369
|
range: seekTo,
|
|
@@ -9705,7 +9744,7 @@ var emitAvailableInfo = async ({
|
|
|
9705
9744
|
}
|
|
9706
9745
|
if (key === "slowFps") {
|
|
9707
9746
|
if (hasInfo.slowFps && !emittedFields.slowFps) {
|
|
9708
|
-
const slowFps = state.samplesObserved.getFps();
|
|
9747
|
+
const slowFps = getFps(state) ?? state.samplesObserved.getFps();
|
|
9709
9748
|
await callbackFunctions.onSlowFps?.(slowFps);
|
|
9710
9749
|
if (fieldsInReturnValue.slowFps) {
|
|
9711
9750
|
returnValue.slowFps = slowFps;
|
|
@@ -10001,7 +10040,8 @@ var getAvailableInfo = ({
|
|
|
10001
10040
|
return Boolean(structure && hasDuration(state));
|
|
10002
10041
|
}
|
|
10003
10042
|
if (key === "slowDurationInSeconds") {
|
|
10004
|
-
|
|
10043
|
+
const res = Boolean(structure && hasSlowDuration(state));
|
|
10044
|
+
return res;
|
|
10005
10045
|
}
|
|
10006
10046
|
if (key === "dimensions" || key === "rotation" || key === "unrotatedDimensions") {
|
|
10007
10047
|
return Boolean(structure && hasDimensions(state));
|
|
@@ -10669,18 +10709,31 @@ var parseFlac = ({
|
|
|
10669
10709
|
};
|
|
10670
10710
|
|
|
10671
10711
|
// src/state/iso-base-media/cached-sample-positions.ts
|
|
10672
|
-
var calculateFlatSamples = (
|
|
10712
|
+
var calculateFlatSamples = ({
|
|
10713
|
+
state,
|
|
10714
|
+
mediaSectionStart
|
|
10715
|
+
}) => {
|
|
10673
10716
|
const tracks2 = getTracks(state, true);
|
|
10674
10717
|
const allTracks = [
|
|
10675
10718
|
...tracks2.videoTracks,
|
|
10676
10719
|
...tracks2.audioTracks,
|
|
10677
10720
|
...tracks2.otherTracks
|
|
10678
10721
|
];
|
|
10722
|
+
const moofBoxes = getMoofBoxes(state.structure.getIsoStructure().boxes);
|
|
10723
|
+
const tfraBoxes = deduplicateTfraBoxesByOffset([
|
|
10724
|
+
...state.iso.tfra.getTfraBoxes(),
|
|
10725
|
+
...getTfraBoxes(state.structure.getIsoStructure().boxes)
|
|
10726
|
+
]);
|
|
10727
|
+
const moofComplete = areSamplesComplete({ moofBoxes, tfraBoxes });
|
|
10728
|
+
const relevantMoofBox = moofBoxes.find((moofBox) => moofBox.offset + moofBox.size + 8 === mediaSectionStart);
|
|
10729
|
+
if (moofBoxes.length > 0 && !relevantMoofBox) {
|
|
10730
|
+
throw new Error("No relevant moof box found");
|
|
10731
|
+
}
|
|
10679
10732
|
const flatSamples = allTracks.map((track) => {
|
|
10680
10733
|
const { samplePositions } = getSamplePositionsFromTrack({
|
|
10681
10734
|
trakBox: track.trakBox,
|
|
10682
|
-
moofBoxes:
|
|
10683
|
-
|
|
10735
|
+
moofBoxes: relevantMoofBox ? [relevantMoofBox] : [],
|
|
10736
|
+
moofComplete
|
|
10684
10737
|
});
|
|
10685
10738
|
return samplePositions.map((samplePosition) => {
|
|
10686
10739
|
return {
|
|
@@ -10696,10 +10749,7 @@ var cachedSamplePositionsState = () => {
|
|
|
10696
10749
|
const jumpMarksForMdatStart = {};
|
|
10697
10750
|
return {
|
|
10698
10751
|
getSamples: (mdatStart) => {
|
|
10699
|
-
|
|
10700
|
-
return cachedForMdatStart[mdatStart];
|
|
10701
|
-
}
|
|
10702
|
-
return null;
|
|
10752
|
+
return cachedForMdatStart[mdatStart] ?? null;
|
|
10703
10753
|
},
|
|
10704
10754
|
setSamples: (mdatStart, samples) => {
|
|
10705
10755
|
cachedForMdatStart[mdatStart] = samples;
|
|
@@ -10713,6 +10763,24 @@ var cachedSamplePositionsState = () => {
|
|
|
10713
10763
|
};
|
|
10714
10764
|
};
|
|
10715
10765
|
|
|
10766
|
+
// src/state/iso-base-media/last-moof-box.ts
|
|
10767
|
+
var getLastMoofBox = (boxes) => {
|
|
10768
|
+
if (boxes) {
|
|
10769
|
+
const tfras = boxes.filter((b) => b.type === "tfra-box");
|
|
10770
|
+
const lastMoofOffsets = tfras.map((f) => {
|
|
10771
|
+
if (f.entries.length <= 1) {
|
|
10772
|
+
return null;
|
|
10773
|
+
}
|
|
10774
|
+
return f.entries[f.entries.length - 1].moofOffset;
|
|
10775
|
+
});
|
|
10776
|
+
if (lastMoofOffsets.length > 0) {
|
|
10777
|
+
const maxOffset = Math.max(...lastMoofOffsets.filter(truthy));
|
|
10778
|
+
return maxOffset;
|
|
10779
|
+
}
|
|
10780
|
+
return null;
|
|
10781
|
+
}
|
|
10782
|
+
};
|
|
10783
|
+
|
|
10716
10784
|
// src/state/can-skip-tracks.ts
|
|
10717
10785
|
var needsTracksForField = ({
|
|
10718
10786
|
field,
|
|
@@ -11109,6 +11177,14 @@ var parseMdatSection = async (state) => {
|
|
|
11109
11177
|
}
|
|
11110
11178
|
const endOfMdat = mediaSection.size + mediaSection.start;
|
|
11111
11179
|
if (maySkipVideoData({ state })) {
|
|
11180
|
+
const mfra = state.iso.mfra.getIfAlreadyLoaded();
|
|
11181
|
+
if (mfra) {
|
|
11182
|
+
const lastMoof = getLastMoofBox(mfra);
|
|
11183
|
+
if (lastMoof && lastMoof > endOfMdat) {
|
|
11184
|
+
Log.verbose(state.logLevel, "Skipping to last moof", lastMoof, "end of mdat", endOfMdat);
|
|
11185
|
+
return makeSkip(lastMoof);
|
|
11186
|
+
}
|
|
11187
|
+
}
|
|
11112
11188
|
return makeSkip(endOfMdat);
|
|
11113
11189
|
}
|
|
11114
11190
|
const alreadyHasMoov = getHasTracks(state, true);
|
|
@@ -11126,7 +11202,10 @@ var parseMdatSection = async (state) => {
|
|
|
11126
11202
|
return parseMdatSection(state);
|
|
11127
11203
|
}
|
|
11128
11204
|
if (!state.iso.flatSamples.getSamples(mediaSection.start)) {
|
|
11129
|
-
const flattedSamples = calculateFlatSamples(
|
|
11205
|
+
const flattedSamples = calculateFlatSamples({
|
|
11206
|
+
state,
|
|
11207
|
+
mediaSectionStart: mediaSection.start
|
|
11208
|
+
});
|
|
11130
11209
|
const calcedJumpMarks = calculateJumpMarks(flattedSamples, endOfMdat);
|
|
11131
11210
|
state.iso.flatSamples.setJumpMarks(mediaSection.start, calcedJumpMarks);
|
|
11132
11211
|
state.iso.flatSamples.setSamples(mediaSection.start, flattedSamples.flat(1));
|
|
@@ -11143,9 +11222,11 @@ var parseMdatSection = async (state) => {
|
|
|
11143
11222
|
iterator.discard(nextSample_.samplePosition.offset - iterator.counter.getOffset());
|
|
11144
11223
|
return null;
|
|
11145
11224
|
}
|
|
11225
|
+
Log.verbose(state.logLevel, "Could not find sample at offset", iterator.counter.getOffset(), "skipping to end of mdat");
|
|
11146
11226
|
return makeSkip(endOfMdat);
|
|
11147
11227
|
}
|
|
11148
11228
|
if (samplesWithIndex.samplePosition.offset + samplesWithIndex.samplePosition.size > state.contentLength) {
|
|
11229
|
+
Log.verbose(state.logLevel, "Sample is beyond the end of the file. Don't process it.", samplesWithIndex.samplePosition.offset + samplesWithIndex.samplePosition.size, endOfMdat);
|
|
11149
11230
|
return makeSkip(endOfMdat);
|
|
11150
11231
|
}
|
|
11151
11232
|
if (iterator.bytesRemaining() < samplesWithIndex.samplePosition.size) {
|
|
@@ -11199,6 +11280,7 @@ var parseMdatSection = async (state) => {
|
|
|
11199
11280
|
}
|
|
11200
11281
|
const jump = jumpMarks.find((j) => j.afterSampleWithOffset === offset);
|
|
11201
11282
|
if (jump) {
|
|
11283
|
+
Log.verbose(state.logLevel, "Found jump mark", jump.jumpToOffset, "skipping to jump mark");
|
|
11202
11284
|
return makeSkip(jump.jumpToOffset);
|
|
11203
11285
|
}
|
|
11204
11286
|
return null;
|
|
@@ -11650,8 +11732,9 @@ var getLengthAndReader = async ({
|
|
|
11650
11732
|
contentLength: encoded.byteLength,
|
|
11651
11733
|
reader: {
|
|
11652
11734
|
reader: stream.getReader(),
|
|
11653
|
-
abort() {
|
|
11735
|
+
abort: () => {
|
|
11654
11736
|
ownController.abort();
|
|
11737
|
+
return Promise.resolve();
|
|
11655
11738
|
}
|
|
11656
11739
|
},
|
|
11657
11740
|
needsContentRange: false
|
|
@@ -11666,6 +11749,7 @@ var getLengthAndReader = async ({
|
|
|
11666
11749
|
reader,
|
|
11667
11750
|
abort: () => {
|
|
11668
11751
|
ownController.abort();
|
|
11752
|
+
return Promise.resolve();
|
|
11669
11753
|
}
|
|
11670
11754
|
},
|
|
11671
11755
|
contentLength,
|
|
@@ -11886,42 +11970,29 @@ var webFileReadContent = ({ src, range: range2, controller }) => {
|
|
|
11886
11970
|
if (typeof src === "string" || src instanceof URL) {
|
|
11887
11971
|
throw new Error("`inputTypeFileReader` only supports `File` objects");
|
|
11888
11972
|
}
|
|
11889
|
-
const part = range2 === null ? src : typeof range2 === "number" ? src.slice(range2) : src.slice(range2[0], range2[1]);
|
|
11890
|
-
const
|
|
11891
|
-
|
|
11892
|
-
const ownController = new AbortController;
|
|
11893
|
-
if (ownController) {
|
|
11894
|
-
ownController.signal.addEventListener("abort", () => {
|
|
11895
|
-
reader.abort();
|
|
11896
|
-
}, { once: true });
|
|
11897
|
-
}
|
|
11973
|
+
const part = range2 === null ? src : typeof range2 === "number" ? src.slice(range2) : src.slice(range2[0], range2[1] + 1);
|
|
11974
|
+
const stream = part.stream();
|
|
11975
|
+
const streamReader = stream.getReader();
|
|
11898
11976
|
if (controller) {
|
|
11899
11977
|
controller._internals.signal.addEventListener("abort", () => {
|
|
11900
|
-
|
|
11978
|
+
streamReader.cancel();
|
|
11901
11979
|
}, { once: true });
|
|
11902
11980
|
}
|
|
11903
|
-
return
|
|
11904
|
-
reader
|
|
11905
|
-
|
|
11906
|
-
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
11914
|
-
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
11918
|
-
contentType: src.type,
|
|
11919
|
-
needsContentRange: true
|
|
11920
|
-
});
|
|
11921
|
-
};
|
|
11922
|
-
reader.onerror = () => {
|
|
11923
|
-
reject(reader.error);
|
|
11924
|
-
};
|
|
11981
|
+
return Promise.resolve({
|
|
11982
|
+
reader: {
|
|
11983
|
+
reader: streamReader,
|
|
11984
|
+
async abort() {
|
|
11985
|
+
try {
|
|
11986
|
+
await streamReader.cancel();
|
|
11987
|
+
} catch {}
|
|
11988
|
+
return Promise.resolve();
|
|
11989
|
+
}
|
|
11990
|
+
},
|
|
11991
|
+
contentLength: src.size,
|
|
11992
|
+
name: src instanceof File ? src.name : src.toString(),
|
|
11993
|
+
supportsContentRange: true,
|
|
11994
|
+
contentType: src.type,
|
|
11995
|
+
needsContentRange: true
|
|
11925
11996
|
});
|
|
11926
11997
|
};
|
|
11927
11998
|
var webFileReadWholeAsText = () => {
|
|
@@ -16572,6 +16643,7 @@ var makeParserState = ({
|
|
|
16572
16643
|
fields: fieldsInReturnValue,
|
|
16573
16644
|
callbacks
|
|
16574
16645
|
});
|
|
16646
|
+
const mediaSection = mediaSectionState();
|
|
16575
16647
|
return {
|
|
16576
16648
|
riff: riffSpecificState({
|
|
16577
16649
|
controller,
|
|
@@ -16629,7 +16701,7 @@ var makeParserState = ({
|
|
|
16629
16701
|
samplesObserved,
|
|
16630
16702
|
contentLength,
|
|
16631
16703
|
images,
|
|
16632
|
-
mediaSection
|
|
16704
|
+
mediaSection,
|
|
16633
16705
|
logLevel,
|
|
16634
16706
|
iterator,
|
|
16635
16707
|
controller,
|
|
@@ -16905,7 +16977,7 @@ var downloadAndParseMedia = async (options) => {
|
|
|
16905
16977
|
return returnValue;
|
|
16906
16978
|
};
|
|
16907
16979
|
// src/version.ts
|
|
16908
|
-
var VERSION = "4.0.
|
|
16980
|
+
var VERSION = "4.0.294";
|
|
16909
16981
|
|
|
16910
16982
|
// src/index.ts
|
|
16911
16983
|
var MediaParserInternals = {
|
package/dist/esm/node.mjs
CHANGED
|
@@ -8,8 +8,7 @@ var nodeReadContent = ({ src, range, controller }) => {
|
|
|
8
8
|
const ownController = new AbortController;
|
|
9
9
|
const stream = createReadStream(src, {
|
|
10
10
|
start: range === null ? 0 : typeof range === "number" ? range : range[0],
|
|
11
|
-
end: range === null ? Infinity : typeof range === "number" ? Infinity : range[1]
|
|
12
|
-
signal: ownController.signal
|
|
11
|
+
end: range === null ? Infinity : typeof range === "number" ? Infinity : range[1]
|
|
13
12
|
});
|
|
14
13
|
controller._internals.signal.addEventListener("abort", () => {
|
|
15
14
|
ownController.abort();
|
|
@@ -44,8 +43,12 @@ var nodeReadContent = ({ src, range, controller }) => {
|
|
|
44
43
|
return Promise.resolve({
|
|
45
44
|
reader: {
|
|
46
45
|
reader,
|
|
47
|
-
abort: () => {
|
|
48
|
-
|
|
46
|
+
abort: async () => {
|
|
47
|
+
try {
|
|
48
|
+
stream.destroy();
|
|
49
|
+
ownController.abort();
|
|
50
|
+
await reader.cancel();
|
|
51
|
+
} catch {}
|
|
49
52
|
}
|
|
50
53
|
},
|
|
51
54
|
contentLength: stats.size,
|
package/dist/esm/universal.mjs
CHANGED
|
@@ -75,8 +75,9 @@ var getLengthAndReader = async ({
|
|
|
75
75
|
contentLength: encoded.byteLength,
|
|
76
76
|
reader: {
|
|
77
77
|
reader: stream.getReader(),
|
|
78
|
-
abort() {
|
|
78
|
+
abort: () => {
|
|
79
79
|
ownController.abort();
|
|
80
|
+
return Promise.resolve();
|
|
80
81
|
}
|
|
81
82
|
},
|
|
82
83
|
needsContentRange: false
|
|
@@ -91,6 +92,7 @@ var getLengthAndReader = async ({
|
|
|
91
92
|
reader,
|
|
92
93
|
abort: () => {
|
|
93
94
|
ownController.abort();
|
|
95
|
+
return Promise.resolve();
|
|
94
96
|
}
|
|
95
97
|
},
|
|
96
98
|
contentLength,
|
|
@@ -316,8 +318,7 @@ var nodeReadContent = ({ src, range, controller }) => {
|
|
|
316
318
|
const ownController = new AbortController;
|
|
317
319
|
const stream = createReadStream(src, {
|
|
318
320
|
start: range === null ? 0 : typeof range === "number" ? range : range[0],
|
|
319
|
-
end: range === null ? Infinity : typeof range === "number" ? Infinity : range[1]
|
|
320
|
-
signal: ownController.signal
|
|
321
|
+
end: range === null ? Infinity : typeof range === "number" ? Infinity : range[1]
|
|
321
322
|
});
|
|
322
323
|
controller._internals.signal.addEventListener("abort", () => {
|
|
323
324
|
ownController.abort();
|
|
@@ -352,8 +353,12 @@ var nodeReadContent = ({ src, range, controller }) => {
|
|
|
352
353
|
return Promise.resolve({
|
|
353
354
|
reader: {
|
|
354
355
|
reader,
|
|
355
|
-
abort: () => {
|
|
356
|
-
|
|
356
|
+
abort: async () => {
|
|
357
|
+
try {
|
|
358
|
+
stream.destroy();
|
|
359
|
+
ownController.abort();
|
|
360
|
+
await reader.cancel();
|
|
361
|
+
} catch {}
|
|
357
362
|
}
|
|
358
363
|
},
|
|
359
364
|
contentLength: stats.size,
|
|
@@ -386,42 +391,29 @@ var webFileReadContent = ({ src, range, controller }) => {
|
|
|
386
391
|
if (typeof src === "string" || src instanceof URL) {
|
|
387
392
|
throw new Error("`inputTypeFileReader` only supports `File` objects");
|
|
388
393
|
}
|
|
389
|
-
const part = range === null ? src : typeof range === "number" ? src.slice(range) : src.slice(range[0], range[1]);
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
const ownController = new AbortController;
|
|
393
|
-
if (ownController) {
|
|
394
|
-
ownController.signal.addEventListener("abort", () => {
|
|
395
|
-
reader.abort();
|
|
396
|
-
}, { once: true });
|
|
397
|
-
}
|
|
394
|
+
const part = range === null ? src : typeof range === "number" ? src.slice(range) : src.slice(range[0], range[1] + 1);
|
|
395
|
+
const stream = part.stream();
|
|
396
|
+
const streamReader = stream.getReader();
|
|
398
397
|
if (controller) {
|
|
399
398
|
controller._internals.signal.addEventListener("abort", () => {
|
|
400
|
-
|
|
399
|
+
streamReader.cancel();
|
|
401
400
|
}, { once: true });
|
|
402
401
|
}
|
|
403
|
-
return
|
|
404
|
-
reader
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
contentType: src.type,
|
|
419
|
-
needsContentRange: true
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
reader.onerror = () => {
|
|
423
|
-
reject(reader.error);
|
|
424
|
-
};
|
|
402
|
+
return Promise.resolve({
|
|
403
|
+
reader: {
|
|
404
|
+
reader: streamReader,
|
|
405
|
+
async abort() {
|
|
406
|
+
try {
|
|
407
|
+
await streamReader.cancel();
|
|
408
|
+
} catch {}
|
|
409
|
+
return Promise.resolve();
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
contentLength: src.size,
|
|
413
|
+
name: src instanceof File ? src.name : src.toString(),
|
|
414
|
+
supportsContentRange: true,
|
|
415
|
+
contentType: src.type,
|
|
416
|
+
needsContentRange: true
|
|
425
417
|
});
|
|
426
418
|
};
|
|
427
419
|
var webFileReadWholeAsText = () => {
|