@remotion/media-parser 4.0.312 → 4.0.313
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/base-media-box.d.ts +3 -2
- package/dist/containers/iso-base-media/collect-sample-positions-from-moof-boxes.d.ts +3 -1
- package/dist/containers/iso-base-media/collect-sample-positions-from-moof-boxes.js +2 -1
- package/dist/containers/iso-base-media/find-track-to-seek.js +2 -0
- package/dist/containers/iso-base-media/get-keyframes.js +1 -0
- package/dist/containers/iso-base-media/get-sample-positions-from-track.d.ts +3 -1
- package/dist/containers/iso-base-media/get-sample-positions-from-track.js +2 -1
- package/dist/containers/iso-base-media/get-seeking-byte-from-fragmented-mp4.js +1 -0
- package/dist/containers/iso-base-media/moov/mvhd.d.ts +30 -0
- package/dist/containers/iso-base-media/moov/mvhd.js +65 -0
- package/dist/containers/iso-base-media/moov/trex.d.ts +16 -0
- package/dist/containers/iso-base-media/moov/trex.js +27 -0
- package/dist/containers/iso-base-media/process-box.js +10 -1
- package/dist/containers/iso-base-media/tkhd.d.ts +1 -1
- package/dist/containers/iso-base-media/traversal.d.ts +4 -1
- package/dist/containers/iso-base-media/traversal.js +18 -1
- package/dist/esm/index.mjs +102 -26
- package/dist/esm/worker-server-entry.mjs +101 -25
- package/dist/esm/worker-web-entry.mjs +101 -25
- package/dist/get-duration.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/iterator/buffer-iterator.d.ts +1 -1
- package/dist/iterator/buffer-manager.d.ts +1 -1
- package/dist/iterator/buffer-manager.js +19 -5
- package/dist/samples-from-moof.d.ts +3 -1
- package/dist/samples-from-moof.js +15 -12
- package/dist/state/iso-base-media/cached-sample-positions.js +1 -0
- package/dist/state/iso-base-media/lazy-mfra-load.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -1068,6 +1068,21 @@ var getTrunBoxes = (segment) => {
|
|
|
1068
1068
|
const trunBoxes = segment.children.filter((c) => c.type === "trun-box");
|
|
1069
1069
|
return trunBoxes;
|
|
1070
1070
|
};
|
|
1071
|
+
var getMvexBox = (moovAtom) => {
|
|
1072
|
+
const mvexBox = moovAtom.children.find((s) => s.type === "regular-box" && s.boxType === "mvex");
|
|
1073
|
+
if (!mvexBox || mvexBox.type !== "regular-box") {
|
|
1074
|
+
return null;
|
|
1075
|
+
}
|
|
1076
|
+
return mvexBox;
|
|
1077
|
+
};
|
|
1078
|
+
var getTrexBoxes = (moovAtom) => {
|
|
1079
|
+
const mvexBox = getMvexBox(moovAtom);
|
|
1080
|
+
if (!mvexBox) {
|
|
1081
|
+
return [];
|
|
1082
|
+
}
|
|
1083
|
+
const trexBoxes = mvexBox.children.filter((c) => c.type === "trex-box");
|
|
1084
|
+
return trexBoxes;
|
|
1085
|
+
};
|
|
1071
1086
|
var getTfraBoxesFromMfraBoxChildren = (mfraBoxChildren) => {
|
|
1072
1087
|
const tfraBoxes = mfraBoxChildren.filter((b) => b.type === "tfra-box");
|
|
1073
1088
|
return tfraBoxes;
|
|
@@ -2440,14 +2455,28 @@ var detectFileType = (data) => {
|
|
|
2440
2455
|
};
|
|
2441
2456
|
|
|
2442
2457
|
// src/iterator/buffer-manager.ts
|
|
2458
|
+
var makeBufferWithMaxBytes = (initialData, maxBytes) => {
|
|
2459
|
+
const maxByteLength = Math.min(maxBytes, 2 ** 31);
|
|
2460
|
+
try {
|
|
2461
|
+
const buf = new ArrayBuffer(initialData.byteLength, {
|
|
2462
|
+
maxByteLength
|
|
2463
|
+
});
|
|
2464
|
+
return buf;
|
|
2465
|
+
} catch (e) {
|
|
2466
|
+
if (e instanceof RangeError && maxBytes > 2 ** 27) {
|
|
2467
|
+
return new ArrayBuffer(initialData.byteLength, {
|
|
2468
|
+
maxByteLength: 2 ** 27
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
throw e;
|
|
2472
|
+
}
|
|
2473
|
+
};
|
|
2443
2474
|
var bufferManager = ({
|
|
2444
2475
|
initialData,
|
|
2445
2476
|
maxBytes,
|
|
2446
2477
|
counter
|
|
2447
2478
|
}) => {
|
|
2448
|
-
const buf =
|
|
2449
|
-
maxByteLength: maxBytes === null ? initialData.byteLength : Math.min(maxBytes, 2 ** 31)
|
|
2450
|
-
});
|
|
2479
|
+
const buf = makeBufferWithMaxBytes(initialData, maxBytes);
|
|
2451
2480
|
if (!buf.resize) {
|
|
2452
2481
|
throw new Error("`ArrayBuffer.resize` is not supported in this Runtime. On the server: Use at least Node.js 20 or Bun. In the browser: Chrome 111, Edge 111, Safari 16.4, Firefox 128, Opera 111");
|
|
2453
2482
|
}
|
|
@@ -4827,14 +4856,15 @@ var areSamplesComplete = ({
|
|
|
4827
4856
|
};
|
|
4828
4857
|
|
|
4829
4858
|
// src/samples-from-moof.ts
|
|
4830
|
-
var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
4859
|
+
var getSamplesFromTraf = (trafSegment, moofOffset, trexBoxes) => {
|
|
4831
4860
|
if (trafSegment.type !== "regular-box" || trafSegment.boxType !== "traf") {
|
|
4832
4861
|
throw new Error("Expected traf-box");
|
|
4833
4862
|
}
|
|
4834
4863
|
const tfhdBox = getTfhdBox(trafSegment);
|
|
4835
|
-
const
|
|
4836
|
-
const
|
|
4837
|
-
const
|
|
4864
|
+
const trexBox = trexBoxes.find((t) => t.trackId === tfhdBox?.trackId) ?? null;
|
|
4865
|
+
const defaultTrackSampleDuration = tfhdBox?.defaultSampleDuration || trexBox?.defaultSampleDuration || null;
|
|
4866
|
+
const defaultTrackSampleSize = tfhdBox?.defaultSampleSize || trexBox?.defaultSampleSize || null;
|
|
4867
|
+
const defaultTrackSampleFlags = tfhdBox?.defaultSampleFlags ?? trexBox?.defaultSampleFlags ?? null;
|
|
4838
4868
|
const tfdtBox = getTfdtBox(trafSegment);
|
|
4839
4869
|
const trunBoxes = getTrunBoxes(trafSegment);
|
|
4840
4870
|
let time = 0;
|
|
@@ -4849,16 +4879,16 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
|
4849
4879
|
}
|
|
4850
4880
|
for (const sample of trunBox.samples) {
|
|
4851
4881
|
i++;
|
|
4852
|
-
const duration2 = sample.sampleDuration
|
|
4882
|
+
const duration2 = sample.sampleDuration || defaultTrackSampleDuration;
|
|
4853
4883
|
if (duration2 === null) {
|
|
4854
4884
|
throw new Error("Expected duration");
|
|
4855
4885
|
}
|
|
4856
|
-
const size = sample.sampleSize ??
|
|
4886
|
+
const size = sample.sampleSize ?? defaultTrackSampleSize;
|
|
4857
4887
|
if (size === null) {
|
|
4858
4888
|
throw new Error("Expected size");
|
|
4859
4889
|
}
|
|
4860
4890
|
const isFirstSample = i === 0;
|
|
4861
|
-
const sampleFlags = sample.sampleFlags ? sample.sampleFlags : isFirstSample && trunBox.firstSampleFlags !== null ? trunBox.firstSampleFlags :
|
|
4891
|
+
const sampleFlags = sample.sampleFlags ? sample.sampleFlags : isFirstSample && trunBox.firstSampleFlags !== null ? trunBox.firstSampleFlags : defaultTrackSampleFlags;
|
|
4862
4892
|
if (sampleFlags === null) {
|
|
4863
4893
|
throw new Error("Expected sample flags");
|
|
4864
4894
|
}
|
|
@@ -4884,14 +4914,15 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
|
4884
4914
|
};
|
|
4885
4915
|
var getSamplesFromMoof = ({
|
|
4886
4916
|
moofBox,
|
|
4887
|
-
trackId
|
|
4917
|
+
trackId,
|
|
4918
|
+
trexBoxes
|
|
4888
4919
|
}) => {
|
|
4889
4920
|
const mapped = moofBox.trafBoxes.map((traf) => {
|
|
4890
4921
|
const tfhdBox = getTfhdBox(traf);
|
|
4891
4922
|
if (!tfhdBox || tfhdBox.trackId !== trackId) {
|
|
4892
4923
|
return [];
|
|
4893
4924
|
}
|
|
4894
|
-
return getSamplesFromTraf(traf, moofBox.offset);
|
|
4925
|
+
return getSamplesFromTraf(traf, moofBox.offset, trexBoxes);
|
|
4895
4926
|
});
|
|
4896
4927
|
return mapped.flat(1);
|
|
4897
4928
|
};
|
|
@@ -4900,7 +4931,8 @@ var getSamplesFromMoof = ({
|
|
|
4900
4931
|
var collectSamplePositionsFromMoofBoxes = ({
|
|
4901
4932
|
moofBoxes,
|
|
4902
4933
|
tkhdBox,
|
|
4903
|
-
isComplete
|
|
4934
|
+
isComplete,
|
|
4935
|
+
trexBoxes
|
|
4904
4936
|
}) => {
|
|
4905
4937
|
const samplePositions = moofBoxes.map((m, index) => {
|
|
4906
4938
|
const isLastFragment = index === moofBoxes.length - 1 && isComplete;
|
|
@@ -4908,7 +4940,8 @@ var collectSamplePositionsFromMoofBoxes = ({
|
|
|
4908
4940
|
isLastFragment,
|
|
4909
4941
|
samples: getSamplesFromMoof({
|
|
4910
4942
|
moofBox: m,
|
|
4911
|
-
trackId: tkhdBox.trackId
|
|
4943
|
+
trackId: tkhdBox.trackId,
|
|
4944
|
+
trexBoxes
|
|
4912
4945
|
})
|
|
4913
4946
|
};
|
|
4914
4947
|
});
|
|
@@ -5081,7 +5114,8 @@ var collectSamplePositionsFromTrak = (trakBox) => {
|
|
|
5081
5114
|
var getSamplePositionsFromTrack = ({
|
|
5082
5115
|
trakBox,
|
|
5083
5116
|
moofBoxes,
|
|
5084
|
-
moofComplete
|
|
5117
|
+
moofComplete,
|
|
5118
|
+
trexBoxes
|
|
5085
5119
|
}) => {
|
|
5086
5120
|
const tkhdBox = getTkhdBox(trakBox);
|
|
5087
5121
|
if (!tkhdBox) {
|
|
@@ -5091,7 +5125,8 @@ var getSamplePositionsFromTrack = ({
|
|
|
5091
5125
|
const { samplePositions } = collectSamplePositionsFromMoofBoxes({
|
|
5092
5126
|
moofBoxes,
|
|
5093
5127
|
tkhdBox,
|
|
5094
|
-
isComplete: moofComplete
|
|
5128
|
+
isComplete: moofComplete,
|
|
5129
|
+
trexBoxes
|
|
5095
5130
|
});
|
|
5096
5131
|
return {
|
|
5097
5132
|
samplePositions: samplePositions.map((s) => s.samples).flat(1),
|
|
@@ -5377,7 +5412,8 @@ var getDurationFromIsoBaseMedia = (parserState) => {
|
|
|
5377
5412
|
const { samplePositions, isComplete } = getSamplePositionsFromTrack({
|
|
5378
5413
|
trakBox,
|
|
5379
5414
|
moofBoxes,
|
|
5380
|
-
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes })
|
|
5415
|
+
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes }),
|
|
5416
|
+
trexBoxes: getTrexBoxes(moovBox)
|
|
5381
5417
|
});
|
|
5382
5418
|
if (!isComplete) {
|
|
5383
5419
|
return null;
|
|
@@ -5483,7 +5519,8 @@ var getKeyframesFromIsoBaseMedia = (state) => {
|
|
|
5483
5519
|
moofComplete: areSamplesComplete({
|
|
5484
5520
|
moofBoxes,
|
|
5485
5521
|
tfraBoxes
|
|
5486
|
-
})
|
|
5522
|
+
}),
|
|
5523
|
+
trexBoxes: getTrexBoxes(moov)
|
|
5487
5524
|
});
|
|
5488
5525
|
if (!isComplete) {
|
|
5489
5526
|
return [];
|
|
@@ -5949,7 +5986,8 @@ var findAnyTrackWithSamplePositions = (allTracks, struc) => {
|
|
|
5949
5986
|
moofComplete: areSamplesComplete({
|
|
5950
5987
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
5951
5988
|
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
5952
|
-
})
|
|
5989
|
+
}),
|
|
5990
|
+
trexBoxes: getTrexBoxes(moov)
|
|
5953
5991
|
});
|
|
5954
5992
|
if (samplePositions.length === 0) {
|
|
5955
5993
|
continue;
|
|
@@ -5979,7 +6017,8 @@ var findTrackToSeek = (allTracks, structure) => {
|
|
|
5979
6017
|
moofComplete: areSamplesComplete({
|
|
5980
6018
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
5981
6019
|
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
5982
|
-
})
|
|
6020
|
+
}),
|
|
6021
|
+
trexBoxes: getTrexBoxes(moov)
|
|
5983
6022
|
});
|
|
5984
6023
|
if (samplePositions.length === 0) {
|
|
5985
6024
|
return findAnyTrackWithSamplePositions(allTracks, struc);
|
|
@@ -6141,7 +6180,8 @@ var getSeekingByteFromFragmentedMp4 = async ({
|
|
|
6141
6180
|
const { samplePositions: samplePositionsArray } = collectSamplePositionsFromMoofBoxes({
|
|
6142
6181
|
moofBoxes: info.moofBoxes,
|
|
6143
6182
|
tkhdBox,
|
|
6144
|
-
isComplete
|
|
6183
|
+
isComplete,
|
|
6184
|
+
trexBoxes: getTrexBoxes(moov)
|
|
6145
6185
|
});
|
|
6146
6186
|
Log.trace(logLevel, "Fragmented MP4 - Checking if we have seeking info for this time range");
|
|
6147
6187
|
for (const positions of samplePositionsArray) {
|
|
@@ -9293,7 +9333,8 @@ var calculateFlatSamples = ({
|
|
|
9293
9333
|
const { samplePositions } = getSamplePositionsFromTrack({
|
|
9294
9334
|
trakBox,
|
|
9295
9335
|
moofBoxes: relevantMoofBox ? [relevantMoofBox] : [],
|
|
9296
|
-
moofComplete
|
|
9336
|
+
moofComplete,
|
|
9337
|
+
trexBoxes: getTrexBoxes(moov)
|
|
9297
9338
|
});
|
|
9298
9339
|
return samplePositions.map((samplePosition) => {
|
|
9299
9340
|
return {
|
|
@@ -10009,7 +10050,7 @@ var toUnixTimestamp = (value) => {
|
|
|
10009
10050
|
return Math.floor(value + baseDate.getTime() / 1000) * 1000;
|
|
10010
10051
|
};
|
|
10011
10052
|
|
|
10012
|
-
// src/containers/iso-base-media/mvhd.ts
|
|
10053
|
+
// src/containers/iso-base-media/moov/mvhd.ts
|
|
10013
10054
|
var parseMvhd = ({
|
|
10014
10055
|
iterator,
|
|
10015
10056
|
offset,
|
|
@@ -10065,6 +10106,34 @@ var parseMvhd = ({
|
|
|
10065
10106
|
};
|
|
10066
10107
|
};
|
|
10067
10108
|
|
|
10109
|
+
// src/containers/iso-base-media/moov/trex.ts
|
|
10110
|
+
var parseTrex = ({
|
|
10111
|
+
iterator,
|
|
10112
|
+
offset,
|
|
10113
|
+
size
|
|
10114
|
+
}) => {
|
|
10115
|
+
const box = iterator.startBox(size - 8);
|
|
10116
|
+
const version = iterator.getUint8();
|
|
10117
|
+
iterator.discard(3);
|
|
10118
|
+
const trackId = iterator.getUint32();
|
|
10119
|
+
const defaultSampleDescriptionIndex = iterator.getUint32();
|
|
10120
|
+
const defaultSampleDuration = iterator.getUint32();
|
|
10121
|
+
const defaultSampleSize = iterator.getUint32();
|
|
10122
|
+
const defaultSampleFlags = iterator.getUint32();
|
|
10123
|
+
box.expectNoMoreBytes();
|
|
10124
|
+
return {
|
|
10125
|
+
type: "trex-box",
|
|
10126
|
+
boxSize: size,
|
|
10127
|
+
offset,
|
|
10128
|
+
trackId,
|
|
10129
|
+
version,
|
|
10130
|
+
defaultSampleDescriptionIndex,
|
|
10131
|
+
defaultSampleDuration,
|
|
10132
|
+
defaultSampleSize,
|
|
10133
|
+
defaultSampleFlags
|
|
10134
|
+
};
|
|
10135
|
+
};
|
|
10136
|
+
|
|
10068
10137
|
// src/containers/iso-base-media/stsd/av1c.ts
|
|
10069
10138
|
var parseAv1C = ({
|
|
10070
10139
|
data,
|
|
@@ -11437,10 +11506,16 @@ var processBox = async ({
|
|
|
11437
11506
|
})
|
|
11438
11507
|
};
|
|
11439
11508
|
}
|
|
11509
|
+
if (boxType === "trex") {
|
|
11510
|
+
return {
|
|
11511
|
+
type: "box",
|
|
11512
|
+
box: await parseTrex({ iterator, offset: fileOffset, size: boxSize })
|
|
11513
|
+
};
|
|
11514
|
+
}
|
|
11440
11515
|
if (boxType === "moof") {
|
|
11441
11516
|
await onlyIfMoovAtomExpected?.isoState?.mfra.triggerLoad();
|
|
11442
11517
|
}
|
|
11443
|
-
if (boxType === "mdia" || boxType === "minf" || boxType === "stbl" || boxType === "udta" || boxType === "moof" || boxType === "dims" || boxType === "meta" || boxType === "wave" || boxType === "traf" || boxType === "mfra" || boxType === "edts" || boxType === "stsb") {
|
|
11518
|
+
if (boxType === "mdia" || boxType === "minf" || boxType === "stbl" || boxType === "udta" || boxType === "moof" || boxType === "dims" || boxType === "meta" || boxType === "wave" || boxType === "traf" || boxType === "mfra" || boxType === "edts" || boxType === "mvex" || boxType === "stsb") {
|
|
11444
11519
|
const children = await getIsoBaseMediaChildren({
|
|
11445
11520
|
iterator,
|
|
11446
11521
|
size: boxSize - 8,
|
|
@@ -11460,6 +11535,7 @@ var processBox = async ({
|
|
|
11460
11535
|
};
|
|
11461
11536
|
}
|
|
11462
11537
|
iterator.discard(boxSize - 8);
|
|
11538
|
+
Log.verbose(logLevel, "Unknown ISO Base Media Box:", boxType);
|
|
11463
11539
|
return {
|
|
11464
11540
|
type: "box",
|
|
11465
11541
|
box: {
|
|
@@ -16254,7 +16330,7 @@ var lazyMfraLoad = ({
|
|
|
16254
16330
|
logLevel,
|
|
16255
16331
|
prefetchCache
|
|
16256
16332
|
}).then((boxes) => {
|
|
16257
|
-
Log.verbose(logLevel, "Lazily found mfra atom.");
|
|
16333
|
+
Log.verbose(logLevel, boxes ? "Lazily found mfra atom." : "No mfra atom found.");
|
|
16258
16334
|
result = boxes;
|
|
16259
16335
|
return boxes;
|
|
16260
16336
|
});
|
|
@@ -965,6 +965,21 @@ var getTrunBoxes = (segment) => {
|
|
|
965
965
|
const trunBoxes = segment.children.filter((c) => c.type === "trun-box");
|
|
966
966
|
return trunBoxes;
|
|
967
967
|
};
|
|
968
|
+
var getMvexBox = (moovAtom) => {
|
|
969
|
+
const mvexBox = moovAtom.children.find((s) => s.type === "regular-box" && s.boxType === "mvex");
|
|
970
|
+
if (!mvexBox || mvexBox.type !== "regular-box") {
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
return mvexBox;
|
|
974
|
+
};
|
|
975
|
+
var getTrexBoxes = (moovAtom) => {
|
|
976
|
+
const mvexBox = getMvexBox(moovAtom);
|
|
977
|
+
if (!mvexBox) {
|
|
978
|
+
return [];
|
|
979
|
+
}
|
|
980
|
+
const trexBoxes = mvexBox.children.filter((c) => c.type === "trex-box");
|
|
981
|
+
return trexBoxes;
|
|
982
|
+
};
|
|
968
983
|
var getTfraBoxesFromMfraBoxChildren = (mfraBoxChildren) => {
|
|
969
984
|
const tfraBoxes = mfraBoxChildren.filter((b) => b.type === "tfra-box");
|
|
970
985
|
return tfraBoxes;
|
|
@@ -2337,14 +2352,28 @@ var detectFileType = (data) => {
|
|
|
2337
2352
|
};
|
|
2338
2353
|
|
|
2339
2354
|
// src/iterator/buffer-manager.ts
|
|
2355
|
+
var makeBufferWithMaxBytes = (initialData, maxBytes) => {
|
|
2356
|
+
const maxByteLength = Math.min(maxBytes, 2 ** 31);
|
|
2357
|
+
try {
|
|
2358
|
+
const buf = new ArrayBuffer(initialData.byteLength, {
|
|
2359
|
+
maxByteLength
|
|
2360
|
+
});
|
|
2361
|
+
return buf;
|
|
2362
|
+
} catch (e) {
|
|
2363
|
+
if (e instanceof RangeError && maxBytes > 2 ** 27) {
|
|
2364
|
+
return new ArrayBuffer(initialData.byteLength, {
|
|
2365
|
+
maxByteLength: 2 ** 27
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
throw e;
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2340
2371
|
var bufferManager = ({
|
|
2341
2372
|
initialData,
|
|
2342
2373
|
maxBytes,
|
|
2343
2374
|
counter
|
|
2344
2375
|
}) => {
|
|
2345
|
-
const buf =
|
|
2346
|
-
maxByteLength: maxBytes === null ? initialData.byteLength : Math.min(maxBytes, 2 ** 31)
|
|
2347
|
-
});
|
|
2376
|
+
const buf = makeBufferWithMaxBytes(initialData, maxBytes);
|
|
2348
2377
|
if (!buf.resize) {
|
|
2349
2378
|
throw new Error("`ArrayBuffer.resize` is not supported in this Runtime. On the server: Use at least Node.js 20 or Bun. In the browser: Chrome 111, Edge 111, Safari 16.4, Firefox 128, Opera 111");
|
|
2350
2379
|
}
|
|
@@ -4724,14 +4753,15 @@ var areSamplesComplete = ({
|
|
|
4724
4753
|
};
|
|
4725
4754
|
|
|
4726
4755
|
// src/samples-from-moof.ts
|
|
4727
|
-
var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
4756
|
+
var getSamplesFromTraf = (trafSegment, moofOffset, trexBoxes) => {
|
|
4728
4757
|
if (trafSegment.type !== "regular-box" || trafSegment.boxType !== "traf") {
|
|
4729
4758
|
throw new Error("Expected traf-box");
|
|
4730
4759
|
}
|
|
4731
4760
|
const tfhdBox = getTfhdBox(trafSegment);
|
|
4732
|
-
const
|
|
4733
|
-
const
|
|
4734
|
-
const
|
|
4761
|
+
const trexBox = trexBoxes.find((t) => t.trackId === tfhdBox?.trackId) ?? null;
|
|
4762
|
+
const defaultTrackSampleDuration = tfhdBox?.defaultSampleDuration || trexBox?.defaultSampleDuration || null;
|
|
4763
|
+
const defaultTrackSampleSize = tfhdBox?.defaultSampleSize || trexBox?.defaultSampleSize || null;
|
|
4764
|
+
const defaultTrackSampleFlags = tfhdBox?.defaultSampleFlags ?? trexBox?.defaultSampleFlags ?? null;
|
|
4735
4765
|
const tfdtBox = getTfdtBox(trafSegment);
|
|
4736
4766
|
const trunBoxes = getTrunBoxes(trafSegment);
|
|
4737
4767
|
let time = 0;
|
|
@@ -4746,16 +4776,16 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
|
4746
4776
|
}
|
|
4747
4777
|
for (const sample of trunBox.samples) {
|
|
4748
4778
|
i++;
|
|
4749
|
-
const duration2 = sample.sampleDuration
|
|
4779
|
+
const duration2 = sample.sampleDuration || defaultTrackSampleDuration;
|
|
4750
4780
|
if (duration2 === null) {
|
|
4751
4781
|
throw new Error("Expected duration");
|
|
4752
4782
|
}
|
|
4753
|
-
const size = sample.sampleSize ??
|
|
4783
|
+
const size = sample.sampleSize ?? defaultTrackSampleSize;
|
|
4754
4784
|
if (size === null) {
|
|
4755
4785
|
throw new Error("Expected size");
|
|
4756
4786
|
}
|
|
4757
4787
|
const isFirstSample = i === 0;
|
|
4758
|
-
const sampleFlags = sample.sampleFlags ? sample.sampleFlags : isFirstSample && trunBox.firstSampleFlags !== null ? trunBox.firstSampleFlags :
|
|
4788
|
+
const sampleFlags = sample.sampleFlags ? sample.sampleFlags : isFirstSample && trunBox.firstSampleFlags !== null ? trunBox.firstSampleFlags : defaultTrackSampleFlags;
|
|
4759
4789
|
if (sampleFlags === null) {
|
|
4760
4790
|
throw new Error("Expected sample flags");
|
|
4761
4791
|
}
|
|
@@ -4781,14 +4811,15 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
|
4781
4811
|
};
|
|
4782
4812
|
var getSamplesFromMoof = ({
|
|
4783
4813
|
moofBox,
|
|
4784
|
-
trackId
|
|
4814
|
+
trackId,
|
|
4815
|
+
trexBoxes
|
|
4785
4816
|
}) => {
|
|
4786
4817
|
const mapped = moofBox.trafBoxes.map((traf) => {
|
|
4787
4818
|
const tfhdBox = getTfhdBox(traf);
|
|
4788
4819
|
if (!tfhdBox || tfhdBox.trackId !== trackId) {
|
|
4789
4820
|
return [];
|
|
4790
4821
|
}
|
|
4791
|
-
return getSamplesFromTraf(traf, moofBox.offset);
|
|
4822
|
+
return getSamplesFromTraf(traf, moofBox.offset, trexBoxes);
|
|
4792
4823
|
});
|
|
4793
4824
|
return mapped.flat(1);
|
|
4794
4825
|
};
|
|
@@ -4797,7 +4828,8 @@ var getSamplesFromMoof = ({
|
|
|
4797
4828
|
var collectSamplePositionsFromMoofBoxes = ({
|
|
4798
4829
|
moofBoxes,
|
|
4799
4830
|
tkhdBox,
|
|
4800
|
-
isComplete
|
|
4831
|
+
isComplete,
|
|
4832
|
+
trexBoxes
|
|
4801
4833
|
}) => {
|
|
4802
4834
|
const samplePositions = moofBoxes.map((m, index) => {
|
|
4803
4835
|
const isLastFragment = index === moofBoxes.length - 1 && isComplete;
|
|
@@ -4805,7 +4837,8 @@ var collectSamplePositionsFromMoofBoxes = ({
|
|
|
4805
4837
|
isLastFragment,
|
|
4806
4838
|
samples: getSamplesFromMoof({
|
|
4807
4839
|
moofBox: m,
|
|
4808
|
-
trackId: tkhdBox.trackId
|
|
4840
|
+
trackId: tkhdBox.trackId,
|
|
4841
|
+
trexBoxes
|
|
4809
4842
|
})
|
|
4810
4843
|
};
|
|
4811
4844
|
});
|
|
@@ -4978,7 +5011,8 @@ var collectSamplePositionsFromTrak = (trakBox) => {
|
|
|
4978
5011
|
var getSamplePositionsFromTrack = ({
|
|
4979
5012
|
trakBox,
|
|
4980
5013
|
moofBoxes,
|
|
4981
|
-
moofComplete
|
|
5014
|
+
moofComplete,
|
|
5015
|
+
trexBoxes
|
|
4982
5016
|
}) => {
|
|
4983
5017
|
const tkhdBox = getTkhdBox(trakBox);
|
|
4984
5018
|
if (!tkhdBox) {
|
|
@@ -4988,7 +5022,8 @@ var getSamplePositionsFromTrack = ({
|
|
|
4988
5022
|
const { samplePositions } = collectSamplePositionsFromMoofBoxes({
|
|
4989
5023
|
moofBoxes,
|
|
4990
5024
|
tkhdBox,
|
|
4991
|
-
isComplete: moofComplete
|
|
5025
|
+
isComplete: moofComplete,
|
|
5026
|
+
trexBoxes
|
|
4992
5027
|
});
|
|
4993
5028
|
return {
|
|
4994
5029
|
samplePositions: samplePositions.map((s) => s.samples).flat(1),
|
|
@@ -5274,7 +5309,8 @@ var getDurationFromIsoBaseMedia = (parserState) => {
|
|
|
5274
5309
|
const { samplePositions, isComplete } = getSamplePositionsFromTrack({
|
|
5275
5310
|
trakBox,
|
|
5276
5311
|
moofBoxes,
|
|
5277
|
-
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes })
|
|
5312
|
+
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes }),
|
|
5313
|
+
trexBoxes: getTrexBoxes(moovBox)
|
|
5278
5314
|
});
|
|
5279
5315
|
if (!isComplete) {
|
|
5280
5316
|
return null;
|
|
@@ -5380,7 +5416,8 @@ var getKeyframesFromIsoBaseMedia = (state) => {
|
|
|
5380
5416
|
moofComplete: areSamplesComplete({
|
|
5381
5417
|
moofBoxes,
|
|
5382
5418
|
tfraBoxes
|
|
5383
|
-
})
|
|
5419
|
+
}),
|
|
5420
|
+
trexBoxes: getTrexBoxes(moov)
|
|
5384
5421
|
});
|
|
5385
5422
|
if (!isComplete) {
|
|
5386
5423
|
return [];
|
|
@@ -5846,7 +5883,8 @@ var findAnyTrackWithSamplePositions = (allTracks, struc) => {
|
|
|
5846
5883
|
moofComplete: areSamplesComplete({
|
|
5847
5884
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
5848
5885
|
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
5849
|
-
})
|
|
5886
|
+
}),
|
|
5887
|
+
trexBoxes: getTrexBoxes(moov)
|
|
5850
5888
|
});
|
|
5851
5889
|
if (samplePositions.length === 0) {
|
|
5852
5890
|
continue;
|
|
@@ -5876,7 +5914,8 @@ var findTrackToSeek = (allTracks, structure) => {
|
|
|
5876
5914
|
moofComplete: areSamplesComplete({
|
|
5877
5915
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
5878
5916
|
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
5879
|
-
})
|
|
5917
|
+
}),
|
|
5918
|
+
trexBoxes: getTrexBoxes(moov)
|
|
5880
5919
|
});
|
|
5881
5920
|
if (samplePositions.length === 0) {
|
|
5882
5921
|
return findAnyTrackWithSamplePositions(allTracks, struc);
|
|
@@ -6038,7 +6077,8 @@ var getSeekingByteFromFragmentedMp4 = async ({
|
|
|
6038
6077
|
const { samplePositions: samplePositionsArray } = collectSamplePositionsFromMoofBoxes({
|
|
6039
6078
|
moofBoxes: info.moofBoxes,
|
|
6040
6079
|
tkhdBox,
|
|
6041
|
-
isComplete
|
|
6080
|
+
isComplete,
|
|
6081
|
+
trexBoxes: getTrexBoxes(moov)
|
|
6042
6082
|
});
|
|
6043
6083
|
Log.trace(logLevel, "Fragmented MP4 - Checking if we have seeking info for this time range");
|
|
6044
6084
|
for (const positions of samplePositionsArray) {
|
|
@@ -9190,7 +9230,8 @@ var calculateFlatSamples = ({
|
|
|
9190
9230
|
const { samplePositions } = getSamplePositionsFromTrack({
|
|
9191
9231
|
trakBox,
|
|
9192
9232
|
moofBoxes: relevantMoofBox ? [relevantMoofBox] : [],
|
|
9193
|
-
moofComplete
|
|
9233
|
+
moofComplete,
|
|
9234
|
+
trexBoxes: getTrexBoxes(moov)
|
|
9194
9235
|
});
|
|
9195
9236
|
return samplePositions.map((samplePosition) => {
|
|
9196
9237
|
return {
|
|
@@ -9906,7 +9947,7 @@ var toUnixTimestamp = (value) => {
|
|
|
9906
9947
|
return Math.floor(value + baseDate.getTime() / 1000) * 1000;
|
|
9907
9948
|
};
|
|
9908
9949
|
|
|
9909
|
-
// src/containers/iso-base-media/mvhd.ts
|
|
9950
|
+
// src/containers/iso-base-media/moov/mvhd.ts
|
|
9910
9951
|
var parseMvhd = ({
|
|
9911
9952
|
iterator,
|
|
9912
9953
|
offset,
|
|
@@ -9962,6 +10003,34 @@ var parseMvhd = ({
|
|
|
9962
10003
|
};
|
|
9963
10004
|
};
|
|
9964
10005
|
|
|
10006
|
+
// src/containers/iso-base-media/moov/trex.ts
|
|
10007
|
+
var parseTrex = ({
|
|
10008
|
+
iterator,
|
|
10009
|
+
offset,
|
|
10010
|
+
size
|
|
10011
|
+
}) => {
|
|
10012
|
+
const box = iterator.startBox(size - 8);
|
|
10013
|
+
const version = iterator.getUint8();
|
|
10014
|
+
iterator.discard(3);
|
|
10015
|
+
const trackId = iterator.getUint32();
|
|
10016
|
+
const defaultSampleDescriptionIndex = iterator.getUint32();
|
|
10017
|
+
const defaultSampleDuration = iterator.getUint32();
|
|
10018
|
+
const defaultSampleSize = iterator.getUint32();
|
|
10019
|
+
const defaultSampleFlags = iterator.getUint32();
|
|
10020
|
+
box.expectNoMoreBytes();
|
|
10021
|
+
return {
|
|
10022
|
+
type: "trex-box",
|
|
10023
|
+
boxSize: size,
|
|
10024
|
+
offset,
|
|
10025
|
+
trackId,
|
|
10026
|
+
version,
|
|
10027
|
+
defaultSampleDescriptionIndex,
|
|
10028
|
+
defaultSampleDuration,
|
|
10029
|
+
defaultSampleSize,
|
|
10030
|
+
defaultSampleFlags
|
|
10031
|
+
};
|
|
10032
|
+
};
|
|
10033
|
+
|
|
9965
10034
|
// src/containers/iso-base-media/stsd/av1c.ts
|
|
9966
10035
|
var parseAv1C = ({
|
|
9967
10036
|
data,
|
|
@@ -11334,10 +11403,16 @@ var processBox = async ({
|
|
|
11334
11403
|
})
|
|
11335
11404
|
};
|
|
11336
11405
|
}
|
|
11406
|
+
if (boxType === "trex") {
|
|
11407
|
+
return {
|
|
11408
|
+
type: "box",
|
|
11409
|
+
box: await parseTrex({ iterator, offset: fileOffset, size: boxSize })
|
|
11410
|
+
};
|
|
11411
|
+
}
|
|
11337
11412
|
if (boxType === "moof") {
|
|
11338
11413
|
await onlyIfMoovAtomExpected?.isoState?.mfra.triggerLoad();
|
|
11339
11414
|
}
|
|
11340
|
-
if (boxType === "mdia" || boxType === "minf" || boxType === "stbl" || boxType === "udta" || boxType === "moof" || boxType === "dims" || boxType === "meta" || boxType === "wave" || boxType === "traf" || boxType === "mfra" || boxType === "edts" || boxType === "stsb") {
|
|
11415
|
+
if (boxType === "mdia" || boxType === "minf" || boxType === "stbl" || boxType === "udta" || boxType === "moof" || boxType === "dims" || boxType === "meta" || boxType === "wave" || boxType === "traf" || boxType === "mfra" || boxType === "edts" || boxType === "mvex" || boxType === "stsb") {
|
|
11341
11416
|
const children = await getIsoBaseMediaChildren({
|
|
11342
11417
|
iterator,
|
|
11343
11418
|
size: boxSize - 8,
|
|
@@ -11357,6 +11432,7 @@ var processBox = async ({
|
|
|
11357
11432
|
};
|
|
11358
11433
|
}
|
|
11359
11434
|
iterator.discard(boxSize - 8);
|
|
11435
|
+
Log.verbose(logLevel, "Unknown ISO Base Media Box:", boxType);
|
|
11360
11436
|
return {
|
|
11361
11437
|
type: "box",
|
|
11362
11438
|
box: {
|
|
@@ -16123,7 +16199,7 @@ var lazyMfraLoad = ({
|
|
|
16123
16199
|
logLevel,
|
|
16124
16200
|
prefetchCache
|
|
16125
16201
|
}).then((boxes) => {
|
|
16126
|
-
Log.verbose(logLevel, "Lazily found mfra atom.");
|
|
16202
|
+
Log.verbose(logLevel, boxes ? "Lazily found mfra atom." : "No mfra atom found.");
|
|
16127
16203
|
result = boxes;
|
|
16128
16204
|
return boxes;
|
|
16129
16205
|
});
|
package/dist/get-duration.js
CHANGED
|
@@ -82,6 +82,7 @@ const getDurationFromIsoBaseMedia = (parserState) => {
|
|
|
82
82
|
trakBox,
|
|
83
83
|
moofBoxes,
|
|
84
84
|
moofComplete: (0, are_samples_complete_1.areSamplesComplete)({ moofBoxes, tfraBoxes }),
|
|
85
|
+
trexBoxes: (0, traversal_1.getTrexBoxes)(moovBox),
|
|
85
86
|
});
|
|
86
87
|
if (!isComplete) {
|
|
87
88
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -669,7 +669,7 @@ export declare const MediaParserInternals: {
|
|
|
669
669
|
offset: number;
|
|
670
670
|
size: number;
|
|
671
671
|
}) => import("./containers/iso-base-media/tkhd").TkhdBox;
|
|
672
|
-
getArrayBufferIterator: (initialData: Uint8Array, maxBytes: number
|
|
672
|
+
getArrayBufferIterator: (initialData: Uint8Array, maxBytes: number) => {
|
|
673
673
|
startReadingBits: () => void;
|
|
674
674
|
stopReadingBits: () => void;
|
|
675
675
|
skipTo: (offset: number) => void;
|
|
@@ -1265,7 +1265,7 @@ export declare const MediaParserInternals: {
|
|
|
1265
1265
|
iterator: import("./iterator/buffer-iterator").BufferIterator;
|
|
1266
1266
|
offset: number;
|
|
1267
1267
|
size: number;
|
|
1268
|
-
}) => import("./containers/iso-base-media/mvhd").MvhdBox;
|
|
1268
|
+
}) => import("./containers/iso-base-media/moov/mvhd").MvhdBox;
|
|
1269
1269
|
internalParseMedia: import("./options").InternalParseMedia;
|
|
1270
1270
|
fieldsNeedSamplesMap: Record<keyof import("./fields").AllOptions<import("./fields").ParseMediaFields>, boolean>;
|
|
1271
1271
|
};
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WEBCODECS_TIMESCALE = exports.VERSION = exports.mediaParserController = exports.defaultSelectM3uStreamFn = exports.defaultSelectM3uAssociatedPlaylists = exports.MediaParserInternals = exports.downloadAndParseMedia = exports.MediaParserAbortError = exports.IsAPdfError = exports.IsAnUnsupportedFileTypeError = exports.IsAnImageError = exports.hasBeenAborted = exports.parseMedia = void 0;
|
|
4
4
|
const aac_codecprivate_1 = require("./aac-codecprivate");
|
|
5
5
|
const ftyp_1 = require("./containers/iso-base-media/ftyp");
|
|
6
|
-
const mvhd_1 = require("./containers/iso-base-media/mvhd");
|
|
6
|
+
const mvhd_1 = require("./containers/iso-base-media/moov/mvhd");
|
|
7
7
|
const samples_1 = require("./containers/iso-base-media/stsd/samples");
|
|
8
8
|
const stsd_1 = require("./containers/iso-base-media/stsd/stsd");
|
|
9
9
|
const tkhd_1 = require("./containers/iso-base-media/tkhd");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes: number
|
|
1
|
+
export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes: number) => {
|
|
2
2
|
startReadingBits: () => void;
|
|
3
3
|
stopReadingBits: () => void;
|
|
4
4
|
skipTo: (offset: number) => void;
|
|
@@ -2,7 +2,7 @@ import type { ParseMediaMode } from '../options';
|
|
|
2
2
|
import type { OffsetCounter } from './offset-counter';
|
|
3
3
|
export declare const bufferManager: ({ initialData, maxBytes, counter, }: {
|
|
4
4
|
initialData: Uint8Array;
|
|
5
|
-
maxBytes: number
|
|
5
|
+
maxBytes: number;
|
|
6
6
|
counter: OffsetCounter;
|
|
7
7
|
}) => {
|
|
8
8
|
view: DataView<ArrayBuffer>;
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bufferManager = void 0;
|
|
4
|
+
const makeBufferWithMaxBytes = (initialData, maxBytes) => {
|
|
5
|
+
const maxByteLength = Math.min(maxBytes, 2 ** 31);
|
|
6
|
+
try {
|
|
7
|
+
const buf = new ArrayBuffer(initialData.byteLength, {
|
|
8
|
+
maxByteLength,
|
|
9
|
+
});
|
|
10
|
+
return buf;
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
// Cloudflare Workers have a limit of 128MB max array buffer size
|
|
14
|
+
if (e instanceof RangeError && maxBytes > 2 ** 27) {
|
|
15
|
+
return new ArrayBuffer(initialData.byteLength, {
|
|
16
|
+
maxByteLength: 2 ** 27,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
4
22
|
const bufferManager = ({ initialData, maxBytes, counter, }) => {
|
|
5
|
-
const buf =
|
|
6
|
-
maxByteLength: maxBytes === null
|
|
7
|
-
? initialData.byteLength
|
|
8
|
-
: Math.min(maxBytes, 2 ** 31),
|
|
9
|
-
});
|
|
23
|
+
const buf = makeBufferWithMaxBytes(initialData, maxBytes);
|
|
10
24
|
if (!buf.resize) {
|
|
11
25
|
throw new Error('`ArrayBuffer.resize` is not supported in this Runtime. On the server: Use at least Node.js 20 or Bun. In the browser: Chrome 111, Edge 111, Safari 16.4, Firefox 128, Opera 111');
|
|
12
26
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { TrexBox } from './containers/iso-base-media/moov/trex';
|
|
1
2
|
import type { SamplePosition } from './get-sample-positions';
|
|
2
3
|
import type { MoofBox } from './state/iso-base-media/precomputed-moof';
|
|
3
|
-
export declare const getSamplesFromMoof: ({ moofBox, trackId, }: {
|
|
4
|
+
export declare const getSamplesFromMoof: ({ moofBox, trackId, trexBoxes, }: {
|
|
4
5
|
moofBox: MoofBox;
|
|
5
6
|
trackId: number;
|
|
7
|
+
trexBoxes: TrexBox[];
|
|
6
8
|
}) => SamplePosition[];
|