@remotion/media-parser 4.0.312 → 4.0.314
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
|
@@ -7,7 +7,8 @@ import type { HdlrBox } from './meta/hdlr';
|
|
|
7
7
|
import type { IlstBox } from './meta/ilst';
|
|
8
8
|
import type { TfraBox } from './mfra/tfra';
|
|
9
9
|
import type { MoovBox } from './moov/moov';
|
|
10
|
-
import type { MvhdBox } from './mvhd';
|
|
10
|
+
import type { MvhdBox } from './moov/mvhd';
|
|
11
|
+
import type { TrexBox } from './moov/trex';
|
|
11
12
|
import type { Av1CBox } from './stsd/av1c';
|
|
12
13
|
import type { AvccBox } from './stsd/avcc';
|
|
13
14
|
import type { ColorParameterBox } from './stsd/colr';
|
|
@@ -35,4 +36,4 @@ export interface RegularBox extends BaseBox {
|
|
|
35
36
|
offset: number;
|
|
36
37
|
type: 'regular-box';
|
|
37
38
|
}
|
|
38
|
-
export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | ElstBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | IlstBox | EsdsBox | StszBox | StcoBox | StscBox | AvccBox | HvccBox | VoidBox | StssBox | PaspBox | CttsBox | Av1CBox | TrunBox | HdlrBox | ColorParameterBox | TfdtBox | TfhdBox | TfraBox;
|
|
39
|
+
export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | ElstBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | IlstBox | EsdsBox | StszBox | StcoBox | StscBox | AvccBox | HvccBox | VoidBox | StssBox | PaspBox | CttsBox | Av1CBox | TrunBox | HdlrBox | ColorParameterBox | TfdtBox | TfhdBox | TfraBox | TrexBox;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { MoofBox } from '../../state/iso-base-media/precomputed-moof';
|
|
2
|
+
import type { TrexBox } from './moov/trex';
|
|
2
3
|
import type { TkhdBox } from './tkhd';
|
|
3
|
-
export declare const collectSamplePositionsFromMoofBoxes: ({ moofBoxes, tkhdBox, isComplete, }: {
|
|
4
|
+
export declare const collectSamplePositionsFromMoofBoxes: ({ moofBoxes, tkhdBox, isComplete, trexBoxes, }: {
|
|
4
5
|
moofBoxes: MoofBox[];
|
|
5
6
|
tkhdBox: TkhdBox;
|
|
6
7
|
isComplete: boolean;
|
|
8
|
+
trexBoxes: TrexBox[];
|
|
7
9
|
}) => {
|
|
8
10
|
samplePositions: {
|
|
9
11
|
isLastFragment: boolean;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.collectSamplePositionsFromMoofBoxes = void 0;
|
|
4
4
|
const samples_from_moof_1 = require("../../samples-from-moof");
|
|
5
|
-
const collectSamplePositionsFromMoofBoxes = ({ moofBoxes, tkhdBox, isComplete, }) => {
|
|
5
|
+
const collectSamplePositionsFromMoofBoxes = ({ moofBoxes, tkhdBox, isComplete, trexBoxes, }) => {
|
|
6
6
|
const samplePositions = moofBoxes.map((m, index) => {
|
|
7
7
|
const isLastFragment = index === moofBoxes.length - 1 && isComplete;
|
|
8
8
|
return {
|
|
@@ -10,6 +10,7 @@ const collectSamplePositionsFromMoofBoxes = ({ moofBoxes, tkhdBox, isComplete, }
|
|
|
10
10
|
samples: (0, samples_from_moof_1.getSamplesFromMoof)({
|
|
11
11
|
moofBox: m,
|
|
12
12
|
trackId: tkhdBox.trackId,
|
|
13
|
+
trexBoxes,
|
|
13
14
|
}),
|
|
14
15
|
};
|
|
15
16
|
});
|
|
@@ -22,6 +22,7 @@ const findAnyTrackWithSamplePositions = (allTracks, struc) => {
|
|
|
22
22
|
moofBoxes: (0, traversal_1.getMoofBoxes)(struc.boxes),
|
|
23
23
|
tfraBoxes: (0, traversal_1.getTfraBoxes)(struc.boxes),
|
|
24
24
|
}),
|
|
25
|
+
trexBoxes: (0, traversal_1.getTrexBoxes)(moov),
|
|
25
26
|
});
|
|
26
27
|
if (samplePositions.length === 0) {
|
|
27
28
|
continue;
|
|
@@ -53,6 +54,7 @@ const findTrackToSeek = (allTracks, structure) => {
|
|
|
53
54
|
moofBoxes: (0, traversal_1.getMoofBoxes)(struc.boxes),
|
|
54
55
|
tfraBoxes: (0, traversal_1.getTfraBoxes)(struc.boxes),
|
|
55
56
|
}),
|
|
57
|
+
trexBoxes: (0, traversal_1.getTrexBoxes)(moov),
|
|
56
58
|
});
|
|
57
59
|
if (samplePositions.length === 0) {
|
|
58
60
|
return (0, exports.findAnyTrackWithSamplePositions)(allTracks, struc);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { SamplePosition } from '../../get-sample-positions';
|
|
2
2
|
import type { MoofBox } from '../../state/iso-base-media/precomputed-moof';
|
|
3
|
+
import type { TrexBox } from './moov/trex';
|
|
3
4
|
import type { TrakBox } from './trak/trak';
|
|
4
|
-
export declare const getSamplePositionsFromTrack: ({ trakBox, moofBoxes, moofComplete, }: {
|
|
5
|
+
export declare const getSamplePositionsFromTrack: ({ trakBox, moofBoxes, moofComplete, trexBoxes, }: {
|
|
5
6
|
trakBox: TrakBox;
|
|
6
7
|
moofBoxes: MoofBox[];
|
|
7
8
|
moofComplete: boolean;
|
|
9
|
+
trexBoxes: TrexBox[];
|
|
8
10
|
}) => {
|
|
9
11
|
samplePositions: SamplePosition[];
|
|
10
12
|
isComplete: boolean;
|
|
@@ -4,7 +4,7 @@ exports.getSamplePositionsFromTrack = void 0;
|
|
|
4
4
|
const collect_sample_positions_from_moof_boxes_1 = require("./collect-sample-positions-from-moof-boxes");
|
|
5
5
|
const collect_sample_positions_from_trak_1 = require("./collect-sample-positions-from-trak");
|
|
6
6
|
const traversal_1 = require("./traversal");
|
|
7
|
-
const getSamplePositionsFromTrack = ({ trakBox, moofBoxes, moofComplete, }) => {
|
|
7
|
+
const getSamplePositionsFromTrack = ({ trakBox, moofBoxes, moofComplete, trexBoxes, }) => {
|
|
8
8
|
const tkhdBox = (0, traversal_1.getTkhdBox)(trakBox);
|
|
9
9
|
if (!tkhdBox) {
|
|
10
10
|
throw new Error('Expected tkhd box in trak box');
|
|
@@ -14,6 +14,7 @@ const getSamplePositionsFromTrack = ({ trakBox, moofBoxes, moofComplete, }) => {
|
|
|
14
14
|
moofBoxes,
|
|
15
15
|
tkhdBox,
|
|
16
16
|
isComplete: moofComplete,
|
|
17
|
+
trexBoxes,
|
|
17
18
|
});
|
|
18
19
|
return {
|
|
19
20
|
samplePositions: samplePositions.map((s) => s.samples).flat(1),
|
|
@@ -41,6 +41,7 @@ const getSeekingByteFromFragmentedMp4 = async ({ info, time, logLevel, currentPo
|
|
|
41
41
|
moofBoxes: info.moofBoxes,
|
|
42
42
|
tkhdBox,
|
|
43
43
|
isComplete,
|
|
44
|
+
trexBoxes: (0, traversal_1.getTrexBoxes)(moov),
|
|
44
45
|
});
|
|
45
46
|
log_1.Log.trace(logLevel, 'Fragmented MP4 - Checking if we have seeking info for this time range');
|
|
46
47
|
for (const positions of samplePositionsArray) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../../iterator/buffer-iterator';
|
|
2
|
+
import type { BaseBox } from '../base-type';
|
|
3
|
+
export type ThreeDMatrix = [
|
|
4
|
+
number,
|
|
5
|
+
number,
|
|
6
|
+
number,
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number,
|
|
11
|
+
number,
|
|
12
|
+
number
|
|
13
|
+
];
|
|
14
|
+
export interface MvhdBox extends BaseBox {
|
|
15
|
+
durationInUnits: number;
|
|
16
|
+
durationInSeconds: number;
|
|
17
|
+
creationTime: number | null;
|
|
18
|
+
modificationTime: number | null;
|
|
19
|
+
timeScale: number;
|
|
20
|
+
rate: number;
|
|
21
|
+
volume: number;
|
|
22
|
+
matrix: ThreeDMatrix;
|
|
23
|
+
nextTrackId: number;
|
|
24
|
+
type: 'mvhd-box';
|
|
25
|
+
}
|
|
26
|
+
export declare const parseMvhd: ({ iterator, offset, size, }: {
|
|
27
|
+
iterator: BufferIterator;
|
|
28
|
+
offset: number;
|
|
29
|
+
size: number;
|
|
30
|
+
}) => MvhdBox;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMvhd = void 0;
|
|
4
|
+
const buffer_iterator_1 = require("../../../iterator/buffer-iterator");
|
|
5
|
+
const to_date_1 = require("../to-date");
|
|
6
|
+
const parseMvhd = ({ iterator, offset, size, }) => {
|
|
7
|
+
const version = iterator.getUint8();
|
|
8
|
+
// Flags, we discard them
|
|
9
|
+
iterator.discard(3);
|
|
10
|
+
const creationTime = version === 1 ? iterator.getUint64() : iterator.getUint32();
|
|
11
|
+
const modificationTime = version === 1 ? iterator.getUint64() : iterator.getUint32();
|
|
12
|
+
const timeScale = iterator.getUint32();
|
|
13
|
+
const durationInUnits = version === 1 ? iterator.getUint64() : iterator.getUint32();
|
|
14
|
+
const durationInSeconds = Number(durationInUnits) / timeScale;
|
|
15
|
+
const rateArray = iterator.getSlice(4);
|
|
16
|
+
const rateView = (0, buffer_iterator_1.getArrayBufferIterator)(rateArray, rateArray.length);
|
|
17
|
+
const rate = rateView.getInt8() * 10 +
|
|
18
|
+
rateView.getInt8() +
|
|
19
|
+
rateView.getInt8() * 0.1 +
|
|
20
|
+
rateView.getInt8() * 0.01;
|
|
21
|
+
const volumeArray = iterator.getSlice(2);
|
|
22
|
+
const volumeView = (0, buffer_iterator_1.getArrayBufferIterator)(volumeArray, volumeArray.length);
|
|
23
|
+
const volume = volumeView.getInt8() + volumeView.getInt8() * 0.1;
|
|
24
|
+
// reserved 16bit
|
|
25
|
+
iterator.discard(2);
|
|
26
|
+
// reserved 32bit x2
|
|
27
|
+
iterator.discard(4);
|
|
28
|
+
iterator.discard(4);
|
|
29
|
+
// matrix
|
|
30
|
+
const matrix = [
|
|
31
|
+
iterator.getFixedPointSigned1616Number(),
|
|
32
|
+
iterator.getFixedPointSigned1616Number(),
|
|
33
|
+
iterator.getFixedPointSigned230Number(),
|
|
34
|
+
iterator.getFixedPointSigned1616Number(),
|
|
35
|
+
iterator.getFixedPointSigned1616Number(),
|
|
36
|
+
iterator.getFixedPointSigned230Number(),
|
|
37
|
+
iterator.getFixedPointSigned1616Number(),
|
|
38
|
+
iterator.getFixedPointSigned1616Number(),
|
|
39
|
+
iterator.getFixedPointSigned230Number(),
|
|
40
|
+
];
|
|
41
|
+
// pre-defined
|
|
42
|
+
iterator.discard(4 * 6);
|
|
43
|
+
// next track id
|
|
44
|
+
const nextTrackId = iterator.getUint32();
|
|
45
|
+
volumeView.destroy();
|
|
46
|
+
const bytesRemaining = size - (iterator.counter.getOffset() - offset);
|
|
47
|
+
if (bytesRemaining !== 0) {
|
|
48
|
+
throw new Error('expected 0 bytes ' + bytesRemaining);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
creationTime: (0, to_date_1.toUnixTimestamp)(Number(creationTime)),
|
|
52
|
+
modificationTime: (0, to_date_1.toUnixTimestamp)(Number(modificationTime)),
|
|
53
|
+
timeScale,
|
|
54
|
+
durationInUnits: Number(durationInUnits),
|
|
55
|
+
durationInSeconds,
|
|
56
|
+
rate,
|
|
57
|
+
volume,
|
|
58
|
+
matrix: matrix,
|
|
59
|
+
nextTrackId,
|
|
60
|
+
type: 'mvhd-box',
|
|
61
|
+
boxSize: size,
|
|
62
|
+
offset,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.parseMvhd = parseMvhd;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../../iterator/buffer-iterator';
|
|
2
|
+
import type { BaseBox } from '../base-type';
|
|
3
|
+
export interface TrexBox extends BaseBox {
|
|
4
|
+
type: 'trex-box';
|
|
5
|
+
version: number;
|
|
6
|
+
trackId: number;
|
|
7
|
+
defaultSampleDescriptionIndex: number;
|
|
8
|
+
defaultSampleDuration: number;
|
|
9
|
+
defaultSampleSize: number;
|
|
10
|
+
defaultSampleFlags: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const parseTrex: ({ iterator, offset, size, }: {
|
|
13
|
+
iterator: BufferIterator;
|
|
14
|
+
offset: number;
|
|
15
|
+
size: number;
|
|
16
|
+
}) => TrexBox;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTrex = void 0;
|
|
4
|
+
const parseTrex = ({ iterator, offset, size, }) => {
|
|
5
|
+
const box = iterator.startBox(size - 8);
|
|
6
|
+
const version = iterator.getUint8();
|
|
7
|
+
// Flags, we discard them
|
|
8
|
+
iterator.discard(3);
|
|
9
|
+
const trackId = iterator.getUint32();
|
|
10
|
+
const defaultSampleDescriptionIndex = iterator.getUint32();
|
|
11
|
+
const defaultSampleDuration = iterator.getUint32();
|
|
12
|
+
const defaultSampleSize = iterator.getUint32();
|
|
13
|
+
const defaultSampleFlags = iterator.getUint32();
|
|
14
|
+
box.expectNoMoreBytes();
|
|
15
|
+
return {
|
|
16
|
+
type: 'trex-box',
|
|
17
|
+
boxSize: size,
|
|
18
|
+
offset,
|
|
19
|
+
trackId,
|
|
20
|
+
version,
|
|
21
|
+
defaultSampleDescriptionIndex,
|
|
22
|
+
defaultSampleDuration,
|
|
23
|
+
defaultSampleSize,
|
|
24
|
+
defaultSampleFlags,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.parseTrex = parseTrex;
|
|
@@ -15,7 +15,8 @@ const hdlr_1 = require("./meta/hdlr");
|
|
|
15
15
|
const ilst_1 = require("./meta/ilst");
|
|
16
16
|
const tfra_1 = require("./mfra/tfra");
|
|
17
17
|
const moov_1 = require("./moov/moov");
|
|
18
|
-
const mvhd_1 = require("./mvhd");
|
|
18
|
+
const mvhd_1 = require("./moov/mvhd");
|
|
19
|
+
const trex_1 = require("./moov/trex");
|
|
19
20
|
const av1c_1 = require("./stsd/av1c");
|
|
20
21
|
const avcc_1 = require("./stsd/avcc");
|
|
21
22
|
const colr_1 = require("./stsd/colr");
|
|
@@ -390,6 +391,12 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
|
|
|
390
391
|
}),
|
|
391
392
|
};
|
|
392
393
|
}
|
|
394
|
+
if (boxType === 'trex') {
|
|
395
|
+
return {
|
|
396
|
+
type: 'box',
|
|
397
|
+
box: await (0, trex_1.parseTrex)({ iterator, offset: fileOffset, size: boxSize }),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
393
400
|
if (boxType === 'moof') {
|
|
394
401
|
await ((_b = onlyIfMoovAtomExpected === null || onlyIfMoovAtomExpected === void 0 ? void 0 : onlyIfMoovAtomExpected.isoState) === null || _b === void 0 ? void 0 : _b.mfra.triggerLoad());
|
|
395
402
|
}
|
|
@@ -404,6 +411,7 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
|
|
|
404
411
|
boxType === 'traf' ||
|
|
405
412
|
boxType === 'mfra' ||
|
|
406
413
|
boxType === 'edts' ||
|
|
414
|
+
boxType === 'mvex' ||
|
|
407
415
|
boxType === 'stsb') {
|
|
408
416
|
const children = await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
409
417
|
iterator,
|
|
@@ -424,6 +432,7 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
|
|
|
424
432
|
};
|
|
425
433
|
}
|
|
426
434
|
iterator.discard(boxSize - 8);
|
|
435
|
+
log_1.Log.verbose(logLevel, 'Unknown ISO Base Media Box:', boxType);
|
|
427
436
|
return {
|
|
428
437
|
type: 'box',
|
|
429
438
|
box: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../iterator/buffer-iterator';
|
|
2
2
|
import type { BaseBox } from './base-type';
|
|
3
|
-
import type { ThreeDMatrix } from './mvhd';
|
|
3
|
+
import type { ThreeDMatrix } from './moov/mvhd';
|
|
4
4
|
export interface TkhdBox extends BaseBox {
|
|
5
5
|
type: 'tkhd-box';
|
|
6
6
|
alternateGroup: number;
|
|
@@ -8,7 +8,8 @@ import type { FtypBox } from './ftyp';
|
|
|
8
8
|
import type { MdhdBox } from './mdhd';
|
|
9
9
|
import type { TfraBox } from './mfra/tfra';
|
|
10
10
|
import type { MoovBox } from './moov/moov';
|
|
11
|
-
import type { MvhdBox } from './mvhd';
|
|
11
|
+
import type { MvhdBox } from './moov/mvhd';
|
|
12
|
+
import type { TrexBox } from './moov/trex';
|
|
12
13
|
import type { CttsBox } from './stsd/ctts';
|
|
13
14
|
import type { StcoBox } from './stsd/stco';
|
|
14
15
|
import type { StscBox } from './stsd/stsc';
|
|
@@ -47,6 +48,8 @@ export declare const getStssBox: (trakBox: TrakBox) => StssBox | null;
|
|
|
47
48
|
export declare const getTfdtBox: (segment: IsoBaseMediaBox) => TfdtBox | null;
|
|
48
49
|
export declare const getTfhdBox: (segment: IsoBaseMediaBox) => TfhdBox | null;
|
|
49
50
|
export declare const getTrunBoxes: (segment: IsoBaseMediaBox) => TrunBox[];
|
|
51
|
+
export declare const getMvexBox: (moovAtom: MoovBox) => RegularBox | null;
|
|
52
|
+
export declare const getTrexBoxes: (moovAtom: MoovBox) => TrexBox[];
|
|
50
53
|
export declare const getTfraBoxesFromMfraBoxChildren: (mfraBoxChildren: IsoBaseMediaBox[]) => TfraBox[];
|
|
51
54
|
export declare const getTfraBoxes: (structure: IsoBaseMediaBox[]) => TfraBox[];
|
|
52
55
|
export declare const getTrakBoxByTrackId: (moovBox: MoovBox, trackId: number) => TrakBox | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getElstBox = exports.getTrakBoxByTrackId = exports.getTfraBoxes = exports.getTfraBoxesFromMfraBoxChildren = exports.getTrunBoxes = exports.getTfhdBox = exports.getTfdtBox = exports.getStssBox = exports.getStscBox = exports.getStszBox = exports.getCttsBox = exports.getSttsBox = exports.getStcoBox = exports.getVideoDescriptors = exports.getStsdBox = exports.getStblBox = exports.getMdhdBox = exports.getMdiaBox = exports.getTkhdBox = exports.getTraks = exports.getMvhdBox = exports.getMoofBoxes = exports.getMoovBoxFromState = exports.getMoovFromFromIsoStructure = exports.getFtypBox = void 0;
|
|
3
|
+
exports.getElstBox = exports.getTrakBoxByTrackId = exports.getTfraBoxes = exports.getTfraBoxesFromMfraBoxChildren = exports.getTrexBoxes = exports.getMvexBox = exports.getTrunBoxes = exports.getTfhdBox = exports.getTfdtBox = exports.getStssBox = exports.getStscBox = exports.getStszBox = exports.getCttsBox = exports.getSttsBox = exports.getStcoBox = exports.getVideoDescriptors = exports.getStsdBox = exports.getStblBox = exports.getMdhdBox = exports.getMdiaBox = exports.getTkhdBox = exports.getTraks = exports.getMvhdBox = exports.getMoofBoxes = exports.getMoovBoxFromState = exports.getMoovFromFromIsoStructure = exports.getFtypBox = void 0;
|
|
4
4
|
const precomputed_moof_1 = require("../../state/iso-base-media/precomputed-moof");
|
|
5
5
|
const getFtypBox = (segments) => {
|
|
6
6
|
const ftypBox = segments.find((s) => s.type === 'ftyp-box');
|
|
@@ -198,6 +198,23 @@ const getTrunBoxes = (segment) => {
|
|
|
198
198
|
return trunBoxes;
|
|
199
199
|
};
|
|
200
200
|
exports.getTrunBoxes = getTrunBoxes;
|
|
201
|
+
const getMvexBox = (moovAtom) => {
|
|
202
|
+
const mvexBox = moovAtom.children.find((s) => s.type === 'regular-box' && s.boxType === 'mvex');
|
|
203
|
+
if (!mvexBox || mvexBox.type !== 'regular-box') {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return mvexBox;
|
|
207
|
+
};
|
|
208
|
+
exports.getMvexBox = getMvexBox;
|
|
209
|
+
const getTrexBoxes = (moovAtom) => {
|
|
210
|
+
const mvexBox = (0, exports.getMvexBox)(moovAtom);
|
|
211
|
+
if (!mvexBox) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
const trexBoxes = mvexBox.children.filter((c) => c.type === 'trex-box');
|
|
215
|
+
return trexBoxes;
|
|
216
|
+
};
|
|
217
|
+
exports.getTrexBoxes = getTrexBoxes;
|
|
201
218
|
const getTfraBoxesFromMfraBoxChildren = (mfraBoxChildren) => {
|
|
202
219
|
const tfraBoxes = mfraBoxChildren.filter((b) => b.type === 'tfra-box');
|
|
203
220
|
return tfraBoxes;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1164,14 +1164,28 @@ var Log = {
|
|
|
1164
1164
|
};
|
|
1165
1165
|
|
|
1166
1166
|
// src/iterator/buffer-manager.ts
|
|
1167
|
+
var makeBufferWithMaxBytes = (initialData, maxBytes) => {
|
|
1168
|
+
const maxByteLength = Math.min(maxBytes, 2 ** 31);
|
|
1169
|
+
try {
|
|
1170
|
+
const buf = new ArrayBuffer(initialData.byteLength, {
|
|
1171
|
+
maxByteLength
|
|
1172
|
+
});
|
|
1173
|
+
return buf;
|
|
1174
|
+
} catch (e) {
|
|
1175
|
+
if (e instanceof RangeError && maxBytes > 2 ** 27) {
|
|
1176
|
+
return new ArrayBuffer(initialData.byteLength, {
|
|
1177
|
+
maxByteLength: 2 ** 27
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
throw e;
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1167
1183
|
var bufferManager = ({
|
|
1168
1184
|
initialData,
|
|
1169
1185
|
maxBytes,
|
|
1170
1186
|
counter
|
|
1171
1187
|
}) => {
|
|
1172
|
-
const buf =
|
|
1173
|
-
maxByteLength: maxBytes === null ? initialData.byteLength : Math.min(maxBytes, 2 ** 31)
|
|
1174
|
-
});
|
|
1188
|
+
const buf = makeBufferWithMaxBytes(initialData, maxBytes);
|
|
1175
1189
|
if (!buf.resize) {
|
|
1176
1190
|
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");
|
|
1177
1191
|
}
|
|
@@ -1721,7 +1735,7 @@ var toUnixTimestamp = (value) => {
|
|
|
1721
1735
|
return Math.floor(value + baseDate.getTime() / 1000) * 1000;
|
|
1722
1736
|
};
|
|
1723
1737
|
|
|
1724
|
-
// src/containers/iso-base-media/mvhd.ts
|
|
1738
|
+
// src/containers/iso-base-media/moov/mvhd.ts
|
|
1725
1739
|
var parseMvhd = ({
|
|
1726
1740
|
iterator,
|
|
1727
1741
|
offset,
|
|
@@ -2287,6 +2301,21 @@ var getTrunBoxes = (segment) => {
|
|
|
2287
2301
|
const trunBoxes = segment.children.filter((c) => c.type === "trun-box");
|
|
2288
2302
|
return trunBoxes;
|
|
2289
2303
|
};
|
|
2304
|
+
var getMvexBox = (moovAtom) => {
|
|
2305
|
+
const mvexBox = moovAtom.children.find((s) => s.type === "regular-box" && s.boxType === "mvex");
|
|
2306
|
+
if (!mvexBox || mvexBox.type !== "regular-box") {
|
|
2307
|
+
return null;
|
|
2308
|
+
}
|
|
2309
|
+
return mvexBox;
|
|
2310
|
+
};
|
|
2311
|
+
var getTrexBoxes = (moovAtom) => {
|
|
2312
|
+
const mvexBox = getMvexBox(moovAtom);
|
|
2313
|
+
if (!mvexBox) {
|
|
2314
|
+
return [];
|
|
2315
|
+
}
|
|
2316
|
+
const trexBoxes = mvexBox.children.filter((c) => c.type === "trex-box");
|
|
2317
|
+
return trexBoxes;
|
|
2318
|
+
};
|
|
2290
2319
|
var getTfraBoxesFromMfraBoxChildren = (mfraBoxChildren) => {
|
|
2291
2320
|
const tfraBoxes = mfraBoxChildren.filter((b) => b.type === "tfra-box");
|
|
2292
2321
|
return tfraBoxes;
|
|
@@ -4498,6 +4527,34 @@ var parseMoov = async ({
|
|
|
4498
4527
|
};
|
|
4499
4528
|
};
|
|
4500
4529
|
|
|
4530
|
+
// src/containers/iso-base-media/moov/trex.ts
|
|
4531
|
+
var parseTrex = ({
|
|
4532
|
+
iterator,
|
|
4533
|
+
offset,
|
|
4534
|
+
size
|
|
4535
|
+
}) => {
|
|
4536
|
+
const box = iterator.startBox(size - 8);
|
|
4537
|
+
const version = iterator.getUint8();
|
|
4538
|
+
iterator.discard(3);
|
|
4539
|
+
const trackId = iterator.getUint32();
|
|
4540
|
+
const defaultSampleDescriptionIndex = iterator.getUint32();
|
|
4541
|
+
const defaultSampleDuration = iterator.getUint32();
|
|
4542
|
+
const defaultSampleSize = iterator.getUint32();
|
|
4543
|
+
const defaultSampleFlags = iterator.getUint32();
|
|
4544
|
+
box.expectNoMoreBytes();
|
|
4545
|
+
return {
|
|
4546
|
+
type: "trex-box",
|
|
4547
|
+
boxSize: size,
|
|
4548
|
+
offset,
|
|
4549
|
+
trackId,
|
|
4550
|
+
version,
|
|
4551
|
+
defaultSampleDescriptionIndex,
|
|
4552
|
+
defaultSampleDuration,
|
|
4553
|
+
defaultSampleSize,
|
|
4554
|
+
defaultSampleFlags
|
|
4555
|
+
};
|
|
4556
|
+
};
|
|
4557
|
+
|
|
4501
4558
|
// src/containers/iso-base-media/stsd/av1c.ts
|
|
4502
4559
|
var parseAv1C = ({
|
|
4503
4560
|
data,
|
|
@@ -5583,10 +5640,16 @@ var processBox = async ({
|
|
|
5583
5640
|
})
|
|
5584
5641
|
};
|
|
5585
5642
|
}
|
|
5643
|
+
if (boxType === "trex") {
|
|
5644
|
+
return {
|
|
5645
|
+
type: "box",
|
|
5646
|
+
box: await parseTrex({ iterator, offset: fileOffset, size: boxSize })
|
|
5647
|
+
};
|
|
5648
|
+
}
|
|
5586
5649
|
if (boxType === "moof") {
|
|
5587
5650
|
await onlyIfMoovAtomExpected?.isoState?.mfra.triggerLoad();
|
|
5588
5651
|
}
|
|
5589
|
-
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") {
|
|
5652
|
+
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") {
|
|
5590
5653
|
const children = await getIsoBaseMediaChildren({
|
|
5591
5654
|
iterator,
|
|
5592
5655
|
size: boxSize - 8,
|
|
@@ -5606,6 +5669,7 @@ var processBox = async ({
|
|
|
5606
5669
|
};
|
|
5607
5670
|
}
|
|
5608
5671
|
iterator.discard(boxSize - 8);
|
|
5672
|
+
Log.verbose(logLevel, "Unknown ISO Base Media Box:", boxType);
|
|
5609
5673
|
return {
|
|
5610
5674
|
type: "box",
|
|
5611
5675
|
box: {
|
|
@@ -7085,14 +7149,15 @@ var areSamplesComplete = ({
|
|
|
7085
7149
|
};
|
|
7086
7150
|
|
|
7087
7151
|
// src/samples-from-moof.ts
|
|
7088
|
-
var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
7152
|
+
var getSamplesFromTraf = (trafSegment, moofOffset, trexBoxes) => {
|
|
7089
7153
|
if (trafSegment.type !== "regular-box" || trafSegment.boxType !== "traf") {
|
|
7090
7154
|
throw new Error("Expected traf-box");
|
|
7091
7155
|
}
|
|
7092
7156
|
const tfhdBox = getTfhdBox(trafSegment);
|
|
7093
|
-
const
|
|
7094
|
-
const
|
|
7095
|
-
const
|
|
7157
|
+
const trexBox = trexBoxes.find((t) => t.trackId === tfhdBox?.trackId) ?? null;
|
|
7158
|
+
const defaultTrackSampleDuration = tfhdBox?.defaultSampleDuration || trexBox?.defaultSampleDuration || null;
|
|
7159
|
+
const defaultTrackSampleSize = tfhdBox?.defaultSampleSize || trexBox?.defaultSampleSize || null;
|
|
7160
|
+
const defaultTrackSampleFlags = tfhdBox?.defaultSampleFlags ?? trexBox?.defaultSampleFlags ?? null;
|
|
7096
7161
|
const tfdtBox = getTfdtBox(trafSegment);
|
|
7097
7162
|
const trunBoxes = getTrunBoxes(trafSegment);
|
|
7098
7163
|
let time = 0;
|
|
@@ -7107,16 +7172,16 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
|
7107
7172
|
}
|
|
7108
7173
|
for (const sample of trunBox.samples) {
|
|
7109
7174
|
i++;
|
|
7110
|
-
const duration2 = sample.sampleDuration
|
|
7175
|
+
const duration2 = sample.sampleDuration || defaultTrackSampleDuration;
|
|
7111
7176
|
if (duration2 === null) {
|
|
7112
7177
|
throw new Error("Expected duration");
|
|
7113
7178
|
}
|
|
7114
|
-
const size = sample.sampleSize ??
|
|
7179
|
+
const size = sample.sampleSize ?? defaultTrackSampleSize;
|
|
7115
7180
|
if (size === null) {
|
|
7116
7181
|
throw new Error("Expected size");
|
|
7117
7182
|
}
|
|
7118
7183
|
const isFirstSample = i === 0;
|
|
7119
|
-
const sampleFlags = sample.sampleFlags ? sample.sampleFlags : isFirstSample && trunBox.firstSampleFlags !== null ? trunBox.firstSampleFlags :
|
|
7184
|
+
const sampleFlags = sample.sampleFlags ? sample.sampleFlags : isFirstSample && trunBox.firstSampleFlags !== null ? trunBox.firstSampleFlags : defaultTrackSampleFlags;
|
|
7120
7185
|
if (sampleFlags === null) {
|
|
7121
7186
|
throw new Error("Expected sample flags");
|
|
7122
7187
|
}
|
|
@@ -7142,14 +7207,15 @@ var getSamplesFromTraf = (trafSegment, moofOffset) => {
|
|
|
7142
7207
|
};
|
|
7143
7208
|
var getSamplesFromMoof = ({
|
|
7144
7209
|
moofBox,
|
|
7145
|
-
trackId
|
|
7210
|
+
trackId,
|
|
7211
|
+
trexBoxes
|
|
7146
7212
|
}) => {
|
|
7147
7213
|
const mapped = moofBox.trafBoxes.map((traf) => {
|
|
7148
7214
|
const tfhdBox = getTfhdBox(traf);
|
|
7149
7215
|
if (!tfhdBox || tfhdBox.trackId !== trackId) {
|
|
7150
7216
|
return [];
|
|
7151
7217
|
}
|
|
7152
|
-
return getSamplesFromTraf(traf, moofBox.offset);
|
|
7218
|
+
return getSamplesFromTraf(traf, moofBox.offset, trexBoxes);
|
|
7153
7219
|
});
|
|
7154
7220
|
return mapped.flat(1);
|
|
7155
7221
|
};
|
|
@@ -7158,7 +7224,8 @@ var getSamplesFromMoof = ({
|
|
|
7158
7224
|
var collectSamplePositionsFromMoofBoxes = ({
|
|
7159
7225
|
moofBoxes,
|
|
7160
7226
|
tkhdBox,
|
|
7161
|
-
isComplete
|
|
7227
|
+
isComplete,
|
|
7228
|
+
trexBoxes
|
|
7162
7229
|
}) => {
|
|
7163
7230
|
const samplePositions = moofBoxes.map((m, index) => {
|
|
7164
7231
|
const isLastFragment = index === moofBoxes.length - 1 && isComplete;
|
|
@@ -7166,7 +7233,8 @@ var collectSamplePositionsFromMoofBoxes = ({
|
|
|
7166
7233
|
isLastFragment,
|
|
7167
7234
|
samples: getSamplesFromMoof({
|
|
7168
7235
|
moofBox: m,
|
|
7169
|
-
trackId: tkhdBox.trackId
|
|
7236
|
+
trackId: tkhdBox.trackId,
|
|
7237
|
+
trexBoxes
|
|
7170
7238
|
})
|
|
7171
7239
|
};
|
|
7172
7240
|
});
|
|
@@ -7339,7 +7407,8 @@ var collectSamplePositionsFromTrak = (trakBox) => {
|
|
|
7339
7407
|
var getSamplePositionsFromTrack = ({
|
|
7340
7408
|
trakBox,
|
|
7341
7409
|
moofBoxes,
|
|
7342
|
-
moofComplete
|
|
7410
|
+
moofComplete,
|
|
7411
|
+
trexBoxes
|
|
7343
7412
|
}) => {
|
|
7344
7413
|
const tkhdBox = getTkhdBox(trakBox);
|
|
7345
7414
|
if (!tkhdBox) {
|
|
@@ -7349,7 +7418,8 @@ var getSamplePositionsFromTrack = ({
|
|
|
7349
7418
|
const { samplePositions } = collectSamplePositionsFromMoofBoxes({
|
|
7350
7419
|
moofBoxes,
|
|
7351
7420
|
tkhdBox,
|
|
7352
|
-
isComplete: moofComplete
|
|
7421
|
+
isComplete: moofComplete,
|
|
7422
|
+
trexBoxes
|
|
7353
7423
|
});
|
|
7354
7424
|
return {
|
|
7355
7425
|
samplePositions: samplePositions.map((s) => s.samples).flat(1),
|
|
@@ -7635,7 +7705,8 @@ var getDurationFromIsoBaseMedia = (parserState) => {
|
|
|
7635
7705
|
const { samplePositions, isComplete } = getSamplePositionsFromTrack({
|
|
7636
7706
|
trakBox,
|
|
7637
7707
|
moofBoxes,
|
|
7638
|
-
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes })
|
|
7708
|
+
moofComplete: areSamplesComplete({ moofBoxes, tfraBoxes }),
|
|
7709
|
+
trexBoxes: getTrexBoxes(moovBox)
|
|
7639
7710
|
});
|
|
7640
7711
|
if (!isComplete) {
|
|
7641
7712
|
return null;
|
|
@@ -7741,7 +7812,8 @@ var getKeyframesFromIsoBaseMedia = (state) => {
|
|
|
7741
7812
|
moofComplete: areSamplesComplete({
|
|
7742
7813
|
moofBoxes,
|
|
7743
7814
|
tfraBoxes
|
|
7744
|
-
})
|
|
7815
|
+
}),
|
|
7816
|
+
trexBoxes: getTrexBoxes(moov)
|
|
7745
7817
|
});
|
|
7746
7818
|
if (!isComplete) {
|
|
7747
7819
|
return [];
|
|
@@ -8207,7 +8279,8 @@ var findAnyTrackWithSamplePositions = (allTracks, struc) => {
|
|
|
8207
8279
|
moofComplete: areSamplesComplete({
|
|
8208
8280
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
8209
8281
|
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
8210
|
-
})
|
|
8282
|
+
}),
|
|
8283
|
+
trexBoxes: getTrexBoxes(moov)
|
|
8211
8284
|
});
|
|
8212
8285
|
if (samplePositions.length === 0) {
|
|
8213
8286
|
continue;
|
|
@@ -8237,7 +8310,8 @@ var findTrackToSeek = (allTracks, structure) => {
|
|
|
8237
8310
|
moofComplete: areSamplesComplete({
|
|
8238
8311
|
moofBoxes: getMoofBoxes(struc.boxes),
|
|
8239
8312
|
tfraBoxes: getTfraBoxes(struc.boxes)
|
|
8240
|
-
})
|
|
8313
|
+
}),
|
|
8314
|
+
trexBoxes: getTrexBoxes(moov)
|
|
8241
8315
|
});
|
|
8242
8316
|
if (samplePositions.length === 0) {
|
|
8243
8317
|
return findAnyTrackWithSamplePositions(allTracks, struc);
|
|
@@ -8399,7 +8473,8 @@ var getSeekingByteFromFragmentedMp4 = async ({
|
|
|
8399
8473
|
const { samplePositions: samplePositionsArray } = collectSamplePositionsFromMoofBoxes({
|
|
8400
8474
|
moofBoxes: info.moofBoxes,
|
|
8401
8475
|
tkhdBox,
|
|
8402
|
-
isComplete
|
|
8476
|
+
isComplete,
|
|
8477
|
+
trexBoxes: getTrexBoxes(moov)
|
|
8403
8478
|
});
|
|
8404
8479
|
Log.trace(logLevel, "Fragmented MP4 - Checking if we have seeking info for this time range");
|
|
8405
8480
|
for (const positions of samplePositionsArray) {
|
|
@@ -11170,7 +11245,8 @@ var calculateFlatSamples = ({
|
|
|
11170
11245
|
const { samplePositions } = getSamplePositionsFromTrack({
|
|
11171
11246
|
trakBox,
|
|
11172
11247
|
moofBoxes: relevantMoofBox ? [relevantMoofBox] : [],
|
|
11173
|
-
moofComplete
|
|
11248
|
+
moofComplete,
|
|
11249
|
+
trexBoxes: getTrexBoxes(moov)
|
|
11174
11250
|
});
|
|
11175
11251
|
return samplePositions.map((samplePosition) => {
|
|
11176
11252
|
return {
|
|
@@ -16126,7 +16202,7 @@ var lazyMfraLoad = ({
|
|
|
16126
16202
|
logLevel,
|
|
16127
16203
|
prefetchCache
|
|
16128
16204
|
}).then((boxes) => {
|
|
16129
|
-
Log.verbose(logLevel, "Lazily found mfra atom.");
|
|
16205
|
+
Log.verbose(logLevel, boxes ? "Lazily found mfra atom." : "No mfra atom found.");
|
|
16130
16206
|
result = boxes;
|
|
16131
16207
|
return boxes;
|
|
16132
16208
|
});
|
|
@@ -17794,7 +17870,7 @@ var downloadAndParseMedia = async (options) => {
|
|
|
17794
17870
|
return returnValue;
|
|
17795
17871
|
};
|
|
17796
17872
|
// src/version.ts
|
|
17797
|
-
var VERSION = "4.0.
|
|
17873
|
+
var VERSION = "4.0.314";
|
|
17798
17874
|
|
|
17799
17875
|
// src/index.ts
|
|
17800
17876
|
var MediaParserInternals = {
|