@remotion/media-parser 4.0.241 → 4.0.243
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/add-avc-profile-to-track.js +2 -2
- package/dist/boxes/avc/codec-private.js +2 -2
- package/dist/boxes/avc/create-sps-pps-data.d.ts +2 -0
- package/dist/boxes/avc/create-sps-pps-data.js +28 -0
- package/dist/boxes/iso-base-media/get-keyframes.d.ts +3 -0
- package/dist/boxes/iso-base-media/get-keyframes.js +30 -0
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -3
- package/dist/boxes/iso-base-media/mdat/mdat.js +9 -5
- package/dist/boxes/iso-base-media/moov/moov.d.ts +3 -3
- package/dist/boxes/iso-base-media/moov/moov.js +5 -4
- package/dist/boxes/iso-base-media/process-box.d.ts +9 -9
- package/dist/boxes/iso-base-media/process-box.js +48 -56
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +3 -3
- package/dist/boxes/iso-base-media/stsd/mebx.js +5 -4
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +5 -5
- package/dist/boxes/iso-base-media/stsd/samples.js +19 -16
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +3 -3
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -2
- package/dist/boxes/iso-base-media/trak/trak.d.ts +3 -3
- package/dist/boxes/iso-base-media/trak/trak.js +7 -6
- package/dist/boxes/riff/expect-riff-box.d.ts +3 -3
- package/dist/boxes/riff/expect-riff-box.js +5 -5
- package/dist/boxes/riff/get-tracks-from-avi.js +1 -1
- package/dist/boxes/riff/parse-box.d.ts +7 -7
- package/dist/boxes/riff/parse-box.js +29 -24
- package/dist/boxes/riff/parse-list-box.d.ts +3 -3
- package/dist/boxes/riff/parse-list-box.js +2 -2
- package/dist/boxes/riff/parse-movi.d.ts +5 -5
- package/dist/boxes/riff/parse-movi.js +35 -20
- package/dist/boxes/riff/parse-riff-box.d.ts +3 -3
- package/dist/boxes/riff/parse-riff-box.js +2 -2
- package/dist/boxes/transport-stream/get-tracks.js +1 -1
- package/dist/boxes/transport-stream/handle-aac-packet.d.ts +4 -3
- package/dist/boxes/transport-stream/handle-aac-packet.js +6 -4
- package/dist/boxes/transport-stream/handle-avc-packet.d.ts +4 -3
- package/dist/boxes/transport-stream/handle-avc-packet.js +8 -6
- package/dist/boxes/transport-stream/parse-packet.d.ts +3 -3
- package/dist/boxes/transport-stream/parse-packet.js +2 -2
- package/dist/boxes/transport-stream/parse-stream-packet.d.ts +3 -3
- package/dist/boxes/transport-stream/parse-stream-packet.js +14 -7
- package/dist/boxes/transport-stream/parse-transport-stream.d.ts +5 -6
- package/dist/boxes/transport-stream/parse-transport-stream.js +10 -9
- package/dist/boxes/transport-stream/process-stream-buffers.d.ts +6 -5
- package/dist/boxes/transport-stream/process-stream-buffers.js +18 -8
- package/dist/boxes/webm/ebml.d.ts +1 -1
- package/dist/boxes/webm/get-sample-from-block.d.ts +2 -2
- package/dist/boxes/webm/get-sample-from-block.js +8 -4
- package/dist/boxes/webm/parse-ebml.d.ts +4 -4
- package/dist/boxes/webm/parse-ebml.js +18 -18
- package/dist/boxes/webm/parse-webm-header.d.ts +5 -5
- package/dist/boxes/webm/parse-webm-header.js +6 -5
- package/dist/boxes/webm/segments/parse-children.d.ts +5 -5
- package/dist/boxes/webm/segments/parse-children.js +12 -13
- package/dist/boxes/webm/segments.d.ts +3 -3
- package/dist/boxes/webm/segments.js +13 -13
- package/dist/convert-audio-or-video-sample.js +5 -2
- package/dist/create/matroska/create-matroska-media.js +2 -0
- package/dist/create/progress-tracker.js +2 -2
- package/dist/emit-available-info.d.ts +4 -5
- package/dist/emit-available-info.js +171 -57
- package/dist/esm/index.mjs +899 -501
- package/dist/file-types/detect-file-type.js +4 -2
- package/dist/get-duration.d.ts +1 -0
- package/dist/get-duration.js +14 -1
- package/dist/get-fields-from-callbacks.js +5 -0
- package/dist/get-fps.d.ts +1 -0
- package/dist/get-fps.js +17 -12
- package/dist/get-keyframes.d.ts +5 -0
- package/dist/get-keyframes.js +20 -0
- package/dist/get-tracks.d.ts +7 -1
- package/dist/get-tracks.js +15 -10
- package/dist/has-all-info.d.ts +2 -5
- package/dist/has-all-info.js +23 -4
- package/dist/index.d.ts +2 -1
- package/dist/may-skip-video-data/may-skip-video-data.d.ts +4 -0
- package/dist/may-skip-video-data/may-skip-video-data.js +14 -0
- package/dist/may-skip-video-data/need-samples-for-fields.d.ts +5 -0
- package/dist/may-skip-video-data/need-samples-for-fields.js +33 -0
- package/dist/options.d.ts +32 -0
- package/dist/parse-media.js +12 -40
- package/dist/parse-result.d.ts +2 -4
- package/dist/parse-video.d.ts +5 -5
- package/dist/parse-video.js +24 -10
- package/dist/register-track.d.ts +5 -5
- package/dist/register-track.js +12 -12
- package/dist/state/can-skip-tracks.js +5 -0
- package/dist/state/emitted-fields.d.ts +2 -0
- package/dist/state/emitted-fields.js +31 -0
- package/dist/state/has-tracks-section.d.ts +1 -0
- package/dist/state/keyframes.d.ts +6 -0
- package/dist/state/keyframes.js +15 -0
- package/dist/state/parser-state.d.ts +60 -29
- package/dist/state/parser-state.js +32 -150
- package/dist/state/riff.d.ts +10 -0
- package/dist/state/riff.js +32 -0
- package/dist/state/sample-callbacks.d.ts +31 -0
- package/dist/state/sample-callbacks.js +101 -0
- package/dist/state/slow-duration-fps.d.ts +8 -0
- package/dist/state/slow-duration-fps.js +36 -0
- package/dist/state/structure.d.ts +7 -0
- package/dist/state/structure.js +21 -0
- package/dist/state/tracks-and-samples.d.ts +0 -0
- package/dist/state/tracks-and-samples.js +1 -0
- package/dist/state/webm.d.ts +11 -0
- package/dist/state/webm.js +67 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webcodec-sample-types.d.ts +2 -0
- package/package.json +3 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addAvcProfileToTrack = void 0;
|
|
4
|
-
const codec_private_1 = require("./boxes/avc/codec-private");
|
|
5
4
|
const codec_string_1 = require("./boxes/avc/codec-string");
|
|
5
|
+
const create_sps_pps_data_1 = require("./boxes/avc/create-sps-pps-data");
|
|
6
6
|
const addAvcProfileToTrack = (track, avc1Profile) => {
|
|
7
7
|
if (avc1Profile === null) {
|
|
8
8
|
return track;
|
|
@@ -10,7 +10,7 @@ const addAvcProfileToTrack = (track, avc1Profile) => {
|
|
|
10
10
|
return {
|
|
11
11
|
...track,
|
|
12
12
|
codec: (0, codec_string_1.getCodecStringFromSpsAndPps)(avc1Profile.sps),
|
|
13
|
-
codecPrivate: (0,
|
|
13
|
+
codecPrivate: (0, create_sps_pps_data_1.createSpsPpsData)(avc1Profile),
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
exports.addAvcProfileToTrack = addAvcProfileToTrack;
|
|
@@ -7,9 +7,9 @@ const getAvccBoxContent = (avc1Profile) => {
|
|
|
7
7
|
new Uint8Array([
|
|
8
8
|
// https://gist.github.com/uupaa/8493378ec15f644a3d2b
|
|
9
9
|
1, // version
|
|
10
|
-
avc1Profile.sps.spsData.level,
|
|
11
|
-
avc1Profile.sps.spsData.compatibility,
|
|
12
10
|
avc1Profile.sps.spsData.profile,
|
|
11
|
+
avc1Profile.sps.spsData.compatibility,
|
|
12
|
+
avc1Profile.sps.spsData.level,
|
|
13
13
|
0xff,
|
|
14
14
|
0xe1,
|
|
15
15
|
]),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSpsPpsData = void 0;
|
|
4
|
+
const make_header_1 = require("../webm/make-header");
|
|
5
|
+
const createSpsPpsData = (avc1Profile) => {
|
|
6
|
+
return (0, make_header_1.combineUint8Arrays)([
|
|
7
|
+
new Uint8Array([
|
|
8
|
+
// https://gist.github.com/uupaa/8493378ec15f644a3d2b
|
|
9
|
+
1, // version
|
|
10
|
+
avc1Profile.sps.spsData.profile,
|
|
11
|
+
avc1Profile.sps.spsData.compatibility,
|
|
12
|
+
avc1Profile.sps.spsData.level,
|
|
13
|
+
0xff,
|
|
14
|
+
0xe1,
|
|
15
|
+
]),
|
|
16
|
+
// sequence parameter set length
|
|
17
|
+
(0, make_header_1.serializeUint16)(avc1Profile.sps.sps.length),
|
|
18
|
+
// sequence parameter set
|
|
19
|
+
avc1Profile.sps.sps,
|
|
20
|
+
// num of PPS
|
|
21
|
+
new Uint8Array([0x01]),
|
|
22
|
+
// picture parameter set length
|
|
23
|
+
(0, make_header_1.serializeUint16)(avc1Profile.pps.pps.length),
|
|
24
|
+
// PPS
|
|
25
|
+
avc1Profile.pps.pps,
|
|
26
|
+
]);
|
|
27
|
+
};
|
|
28
|
+
exports.createSpsPpsData = createSpsPpsData;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKeyframesFromIsoBaseMedia = void 0;
|
|
4
|
+
const get_tracks_1 = require("../../get-tracks");
|
|
5
|
+
const get_sample_positions_from_track_1 = require("./get-sample-positions-from-track");
|
|
6
|
+
const traversal_1 = require("./traversal");
|
|
7
|
+
const getKeyframesFromIsoBaseMedia = (structure) => {
|
|
8
|
+
const { videoTracks } = (0, get_tracks_1.getTracksFromIsoBaseMedia)(structure.boxes);
|
|
9
|
+
const moofBox = (0, traversal_1.getMoofBox)(structure.boxes);
|
|
10
|
+
const allSamples = videoTracks.map((t) => {
|
|
11
|
+
const { timescale: ts } = t;
|
|
12
|
+
const samplePositions = (0, get_sample_positions_from_track_1.getSamplePositionsFromTrack)(t.trakBox, moofBox);
|
|
13
|
+
const keyframes = samplePositions
|
|
14
|
+
.filter((k) => {
|
|
15
|
+
return k.isKeyframe;
|
|
16
|
+
})
|
|
17
|
+
.map((k) => {
|
|
18
|
+
return {
|
|
19
|
+
trackId: t.trackId,
|
|
20
|
+
presentationTimeInSeconds: k.cts / ts,
|
|
21
|
+
decodingTimeInSeconds: k.dts / ts,
|
|
22
|
+
positionInBytes: k.offset,
|
|
23
|
+
sizeInBytes: k.size,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return keyframes;
|
|
27
|
+
});
|
|
28
|
+
return allSamples.flat();
|
|
29
|
+
};
|
|
30
|
+
exports.getKeyframesFromIsoBaseMedia = getKeyframesFromIsoBaseMedia;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
2
|
import type { IsoBaseMediaBox } from '../../../parse-result';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserState } from '../../../state/parser-state';
|
|
4
4
|
type MdatStatus = {
|
|
5
5
|
status: 'samples-buffered';
|
|
6
6
|
} | {
|
|
@@ -13,12 +13,12 @@ export type MdatBox = {
|
|
|
13
13
|
boxSize: number;
|
|
14
14
|
fileOffset: number;
|
|
15
15
|
} & MdatStatus;
|
|
16
|
-
export declare const parseMdat: ({ data, size, fileOffset, existingBoxes,
|
|
16
|
+
export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, state, signal, maySkipSampleProcessing, }: {
|
|
17
17
|
data: BufferIterator;
|
|
18
18
|
size: number;
|
|
19
19
|
fileOffset: number;
|
|
20
20
|
existingBoxes: IsoBaseMediaBox[];
|
|
21
|
-
|
|
21
|
+
state: ParserState;
|
|
22
22
|
signal: AbortSignal | null;
|
|
23
23
|
maySkipSampleProcessing: boolean;
|
|
24
24
|
}) => Promise<MdatBox>;
|
|
@@ -5,11 +5,11 @@ const convert_audio_or_video_sample_1 = require("../../../convert-audio-or-video
|
|
|
5
5
|
const get_tracks_1 = require("../../../get-tracks");
|
|
6
6
|
const get_sample_positions_from_track_1 = require("../get-sample-positions-from-track");
|
|
7
7
|
const traversal_1 = require("../traversal");
|
|
8
|
-
const parseMdat = async ({ data, size, fileOffset, existingBoxes,
|
|
8
|
+
const parseMdat = async ({ data, size, fileOffset, existingBoxes, state, signal, maySkipSampleProcessing, }) => {
|
|
9
9
|
const alreadyHas = (0, get_tracks_1.hasTracks)({
|
|
10
10
|
type: 'iso-base-media',
|
|
11
11
|
boxes: existingBoxes,
|
|
12
|
-
},
|
|
12
|
+
}, state);
|
|
13
13
|
if (!alreadyHas) {
|
|
14
14
|
if (maySkipSampleProcessing) {
|
|
15
15
|
data.discard(size - (data.counter.getOffset() - fileOffset));
|
|
@@ -29,7 +29,7 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
|
|
|
29
29
|
fileOffset,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
const tracks = (0, get_tracks_1.getTracks)({ type: 'iso-base-media', boxes: existingBoxes },
|
|
32
|
+
const tracks = (0, get_tracks_1.getTracks)({ type: 'iso-base-media', boxes: existingBoxes }, state);
|
|
33
33
|
const allTracks = [
|
|
34
34
|
...tracks.videoTracks,
|
|
35
35
|
...tracks.audioTracks,
|
|
@@ -79,7 +79,7 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
|
|
|
79
79
|
const bytes = data.getSlice(samplesWithIndex.samplePosition.size);
|
|
80
80
|
const { cts, dts, duration } = samplesWithIndex.samplePosition;
|
|
81
81
|
if (samplesWithIndex.track.type === 'audio') {
|
|
82
|
-
await
|
|
82
|
+
await state.callbacks.onAudioSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
|
|
83
83
|
data: bytes,
|
|
84
84
|
timestamp: cts,
|
|
85
85
|
duration,
|
|
@@ -87,10 +87,12 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
|
|
|
87
87
|
dts,
|
|
88
88
|
trackId: samplesWithIndex.track.trackId,
|
|
89
89
|
type: samplesWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
|
|
90
|
+
offset: samplesWithIndex.samplePosition.offset,
|
|
91
|
+
timescale: samplesWithIndex.track.timescale,
|
|
90
92
|
}, samplesWithIndex.track.timescale));
|
|
91
93
|
}
|
|
92
94
|
if (samplesWithIndex.track.type === 'video') {
|
|
93
|
-
await
|
|
95
|
+
await state.callbacks.onVideoSample(samplesWithIndex.track.trackId, (0, convert_audio_or_video_sample_1.convertAudioOrVideoSampleToWebCodecsTimestamps)({
|
|
94
96
|
data: bytes,
|
|
95
97
|
timestamp: cts,
|
|
96
98
|
duration,
|
|
@@ -98,6 +100,8 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
|
|
|
98
100
|
dts,
|
|
99
101
|
trackId: samplesWithIndex.track.trackId,
|
|
100
102
|
type: samplesWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
|
|
103
|
+
offset: samplesWithIndex.samplePosition.offset,
|
|
104
|
+
timescale: samplesWithIndex.track.timescale,
|
|
101
105
|
}, samplesWithIndex.track.timescale));
|
|
102
106
|
}
|
|
103
107
|
const remaining = size - (data.counter.getOffset() - fileOffset);
|
|
@@ -2,17 +2,17 @@ import type { BufferIterator } from '../../../buffer-iterator';
|
|
|
2
2
|
import type { LogLevel } from '../../../log';
|
|
3
3
|
import type { Options, ParseMediaFields } from '../../../options';
|
|
4
4
|
import type { AnySegment } from '../../../parse-result';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ParserState } from '../../../state/parser-state';
|
|
6
6
|
import type { BaseBox } from '../base-type';
|
|
7
7
|
export interface MoovBox extends BaseBox {
|
|
8
8
|
type: 'moov-box';
|
|
9
9
|
children: AnySegment[];
|
|
10
10
|
}
|
|
11
|
-
export declare const parseMoov: ({ iterator, offset, size,
|
|
11
|
+
export declare const parseMoov: ({ iterator, offset, size, state, signal, logLevel, fields, }: {
|
|
12
12
|
iterator: BufferIterator;
|
|
13
13
|
offset: number;
|
|
14
14
|
size: number;
|
|
15
|
-
|
|
15
|
+
state: ParserState;
|
|
16
16
|
signal: AbortSignal | null;
|
|
17
17
|
logLevel: LogLevel;
|
|
18
18
|
fields: Options<ParseMediaFields>;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMoov = void 0;
|
|
4
4
|
const process_box_1 = require("../process-box");
|
|
5
|
-
const parseMoov = async ({ iterator, offset, size,
|
|
5
|
+
const parseMoov = async ({ iterator, offset, size, state, signal, logLevel, fields, }) => {
|
|
6
|
+
const boxes = [];
|
|
6
7
|
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
7
8
|
iterator,
|
|
8
9
|
maxBytes: size - (iterator.counter.getOffset() - offset),
|
|
9
10
|
allowIncompleteBoxes: false,
|
|
10
|
-
initialBoxes:
|
|
11
|
-
|
|
11
|
+
initialBoxes: boxes,
|
|
12
|
+
state,
|
|
12
13
|
continueMdat: false,
|
|
13
14
|
signal,
|
|
14
15
|
logLevel,
|
|
@@ -21,7 +22,7 @@ const parseMoov = async ({ iterator, offset, size, options, signal, logLevel, fi
|
|
|
21
22
|
offset,
|
|
22
23
|
boxSize: size,
|
|
23
24
|
type: 'moov-box',
|
|
24
|
-
children:
|
|
25
|
+
children: boxes,
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
exports.parseMoov = parseMoov;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { LogLevel } from '../../log';
|
|
3
3
|
import type { Options, ParseMediaFields } from '../../options';
|
|
4
|
-
import type { IsoBaseMediaBox,
|
|
4
|
+
import type { IsoBaseMediaBox, ParseResult } from '../../parse-result';
|
|
5
5
|
import type { BoxAndNext, PartialMdatBox } from '../../parse-video';
|
|
6
|
-
import type {
|
|
7
|
-
export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes,
|
|
6
|
+
import type { ParserState } from '../../state/parser-state';
|
|
7
|
+
export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, state, signal, }: {
|
|
8
8
|
iterator: BufferIterator;
|
|
9
9
|
boxSize: number;
|
|
10
10
|
fileOffset: number;
|
|
11
11
|
parsedBoxes: IsoBaseMediaBox[];
|
|
12
|
-
|
|
12
|
+
state: ParserState;
|
|
13
13
|
signal: AbortSignal | null;
|
|
14
14
|
}) => Promise<BoxAndNext>;
|
|
15
|
-
export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes,
|
|
15
|
+
export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, state, signal, logLevel, fields, }: {
|
|
16
16
|
iterator: BufferIterator;
|
|
17
17
|
allowIncompleteBoxes: boolean;
|
|
18
18
|
parsedBoxes: IsoBaseMediaBox[];
|
|
19
|
-
|
|
19
|
+
state: ParserState;
|
|
20
20
|
signal: AbortSignal | null;
|
|
21
21
|
logLevel: LogLevel;
|
|
22
22
|
fields: Options<ParseMediaFields>;
|
|
23
23
|
}) => Promise<BoxAndNext>;
|
|
24
|
-
export declare const parseIsoBaseMediaBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes,
|
|
24
|
+
export declare const parseIsoBaseMediaBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, state, continueMdat, signal, logLevel, fields, }: {
|
|
25
25
|
iterator: BufferIterator;
|
|
26
26
|
maxBytes: number;
|
|
27
27
|
allowIncompleteBoxes: boolean;
|
|
28
28
|
initialBoxes: IsoBaseMediaBox[];
|
|
29
|
-
|
|
29
|
+
state: ParserState;
|
|
30
30
|
continueMdat: false | PartialMdatBox;
|
|
31
31
|
signal: AbortSignal | null;
|
|
32
32
|
logLevel: LogLevel;
|
|
33
33
|
fields: Options<ParseMediaFields>;
|
|
34
|
-
}) => Promise<ParseResult
|
|
34
|
+
}) => Promise<ParseResult>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseIsoBaseMediaBoxes = exports.processBox = exports.parseMdatPartially = void 0;
|
|
4
4
|
const get_tracks_1 = require("../../get-tracks");
|
|
5
5
|
const has_all_info_1 = require("../../has-all-info");
|
|
6
|
+
const may_skip_video_data_1 = require("../../may-skip-video-data/may-skip-video-data");
|
|
6
7
|
const register_track_1 = require("../../register-track");
|
|
7
8
|
const esds_1 = require("./esds/esds");
|
|
8
9
|
const ftyp_1 = require("./ftyp");
|
|
@@ -33,7 +34,7 @@ const tkhd_1 = require("./tkhd");
|
|
|
33
34
|
const trak_1 = require("./trak/trak");
|
|
34
35
|
const traversal_1 = require("./traversal");
|
|
35
36
|
const trun_1 = require("./trun");
|
|
36
|
-
const getChildren = async ({ boxType, iterator, bytesRemainingInBox,
|
|
37
|
+
const getChildren = async ({ boxType, iterator, bytesRemainingInBox, state, signal, logLevel, fields, }) => {
|
|
37
38
|
const parseChildren = boxType === 'mdia' ||
|
|
38
39
|
boxType === 'minf' ||
|
|
39
40
|
boxType === 'stbl' ||
|
|
@@ -45,13 +46,14 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
|
|
|
45
46
|
boxType === 'traf' ||
|
|
46
47
|
boxType === 'stsb';
|
|
47
48
|
if (parseChildren) {
|
|
49
|
+
const boxes = [];
|
|
48
50
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
49
51
|
const parsed = await (0, exports.parseIsoBaseMediaBoxes)({
|
|
50
52
|
iterator,
|
|
51
53
|
maxBytes: bytesRemainingInBox,
|
|
52
54
|
allowIncompleteBoxes: false,
|
|
53
|
-
initialBoxes:
|
|
54
|
-
|
|
55
|
+
initialBoxes: boxes,
|
|
56
|
+
state,
|
|
55
57
|
continueMdat: false,
|
|
56
58
|
signal,
|
|
57
59
|
logLevel,
|
|
@@ -60,7 +62,7 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
|
|
|
60
62
|
if (parsed.status === 'incomplete') {
|
|
61
63
|
throw new Error('Incomplete boxes are not allowed');
|
|
62
64
|
}
|
|
63
|
-
return
|
|
65
|
+
return boxes;
|
|
64
66
|
}
|
|
65
67
|
if (bytesRemainingInBox < 0) {
|
|
66
68
|
throw new Error('Box size is too big ' + JSON.stringify({ boxType }));
|
|
@@ -68,15 +70,15 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
|
|
|
68
70
|
iterator.discard(bytesRemainingInBox);
|
|
69
71
|
return [];
|
|
70
72
|
};
|
|
71
|
-
const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes,
|
|
73
|
+
const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes, state, signal, }) => {
|
|
72
74
|
const box = await (0, mdat_1.parseMdat)({
|
|
73
75
|
data: iterator,
|
|
74
76
|
size: boxSize,
|
|
75
77
|
fileOffset,
|
|
76
78
|
existingBoxes: parsedBoxes,
|
|
77
|
-
|
|
79
|
+
state,
|
|
78
80
|
signal,
|
|
79
|
-
maySkipSampleProcessing:
|
|
81
|
+
maySkipSampleProcessing: state.supportsContentRange,
|
|
80
82
|
});
|
|
81
83
|
if ((box.status === 'samples-processed' || box.status === 'samples-buffered') &&
|
|
82
84
|
box.fileOffset + boxSize === iterator.counter.getOffset()) {
|
|
@@ -94,7 +96,7 @@ const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes,
|
|
|
94
96
|
};
|
|
95
97
|
};
|
|
96
98
|
exports.parseMdatPartially = parseMdatPartially;
|
|
97
|
-
const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes,
|
|
99
|
+
const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, state, signal, logLevel, fields, }) => {
|
|
98
100
|
const fileOffset = iterator.counter.getOffset();
|
|
99
101
|
const bytesRemaining = iterator.bytesRemaining();
|
|
100
102
|
const boxSizeRaw = iterator.getFourByteNumber();
|
|
@@ -125,9 +127,9 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
125
127
|
if (bytesRemaining < boxSize) {
|
|
126
128
|
if (boxType === 'mdat') {
|
|
127
129
|
// Check if the moov atom is at the end
|
|
128
|
-
const shouldSkip =
|
|
129
|
-
(!(0, get_tracks_1.hasTracks)({ type: 'iso-base-media', boxes: parsedBoxes },
|
|
130
|
-
|
|
130
|
+
const shouldSkip = (0, may_skip_video_data_1.maySkipVideoData)({ state }) ||
|
|
131
|
+
(!(0, get_tracks_1.hasTracks)({ type: 'iso-base-media', boxes: parsedBoxes }, state) &&
|
|
132
|
+
state.supportsContentRange);
|
|
131
133
|
if (shouldSkip) {
|
|
132
134
|
const skipTo = fileOffset + boxSize;
|
|
133
135
|
const bytesToSkip = skipTo - iterator.counter.getOffset();
|
|
@@ -152,7 +154,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
152
154
|
boxSize,
|
|
153
155
|
fileOffset,
|
|
154
156
|
parsedBoxes,
|
|
155
|
-
|
|
157
|
+
state,
|
|
156
158
|
signal,
|
|
157
159
|
});
|
|
158
160
|
}
|
|
@@ -227,7 +229,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
227
229
|
iterator,
|
|
228
230
|
offset: fileOffset,
|
|
229
231
|
size: boxSize,
|
|
230
|
-
|
|
232
|
+
state,
|
|
231
233
|
signal,
|
|
232
234
|
fields,
|
|
233
235
|
});
|
|
@@ -322,7 +324,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
322
324
|
iterator,
|
|
323
325
|
offset: fileOffset,
|
|
324
326
|
size: boxSize,
|
|
325
|
-
|
|
327
|
+
state,
|
|
326
328
|
signal,
|
|
327
329
|
fields,
|
|
328
330
|
});
|
|
@@ -369,12 +371,12 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
369
371
|
iterator,
|
|
370
372
|
offset: fileOffset,
|
|
371
373
|
size: boxSize,
|
|
372
|
-
|
|
374
|
+
state,
|
|
373
375
|
signal,
|
|
374
376
|
logLevel,
|
|
375
377
|
fields,
|
|
376
378
|
});
|
|
377
|
-
|
|
379
|
+
state.callbacks.tracks.setIsDone();
|
|
378
380
|
return {
|
|
379
381
|
type: 'complete',
|
|
380
382
|
box,
|
|
@@ -387,7 +389,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
387
389
|
data: iterator,
|
|
388
390
|
size: boxSize,
|
|
389
391
|
offsetAtStart: fileOffset,
|
|
390
|
-
|
|
392
|
+
state,
|
|
391
393
|
signal,
|
|
392
394
|
logLevel,
|
|
393
395
|
fields,
|
|
@@ -395,7 +397,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
395
397
|
const transformedTrack = (0, make_track_1.makeBaseMediaTrack)(box);
|
|
396
398
|
if (transformedTrack) {
|
|
397
399
|
await (0, register_track_1.registerTrack)({
|
|
398
|
-
|
|
400
|
+
state,
|
|
399
401
|
track: transformedTrack,
|
|
400
402
|
container: 'mp4',
|
|
401
403
|
});
|
|
@@ -502,9 +504,9 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
502
504
|
size: boxSize,
|
|
503
505
|
fileOffset,
|
|
504
506
|
existingBoxes: parsedBoxes,
|
|
505
|
-
|
|
507
|
+
state,
|
|
506
508
|
signal,
|
|
507
|
-
maySkipSampleProcessing:
|
|
509
|
+
maySkipSampleProcessing: state.supportsContentRange,
|
|
508
510
|
});
|
|
509
511
|
if (box === null) {
|
|
510
512
|
throw new Error('Unexpected null');
|
|
@@ -521,7 +523,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
521
523
|
boxType,
|
|
522
524
|
iterator,
|
|
523
525
|
bytesRemainingInBox,
|
|
524
|
-
|
|
526
|
+
state,
|
|
525
527
|
signal,
|
|
526
528
|
logLevel,
|
|
527
529
|
fields,
|
|
@@ -540,13 +542,11 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
|
|
|
540
542
|
};
|
|
541
543
|
};
|
|
542
544
|
exports.processBox = processBox;
|
|
543
|
-
const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes,
|
|
544
|
-
|
|
545
|
-
type: 'iso-base-media',
|
|
546
|
-
boxes: initialBoxes,
|
|
547
|
-
};
|
|
545
|
+
const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, state, continueMdat, signal, logLevel, fields, }) => {
|
|
546
|
+
var _a;
|
|
548
547
|
const initialOffset = iterator.counter.getOffset();
|
|
549
|
-
const alreadyHasMdat =
|
|
548
|
+
const alreadyHasMdat = (_a = state.structure
|
|
549
|
+
.getStructureOrNull()) === null || _a === void 0 ? void 0 : _a.boxes.find((b) => b.type === 'mdat-box');
|
|
550
550
|
while (iterator.bytesRemaining() > 0 &&
|
|
551
551
|
iterator.counter.getOffset() - initialOffset < maxBytes) {
|
|
552
552
|
const result = continueMdat
|
|
@@ -555,14 +555,14 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
555
555
|
boxSize: continueMdat.boxSize,
|
|
556
556
|
fileOffset: continueMdat.fileOffset,
|
|
557
557
|
parsedBoxes: initialBoxes,
|
|
558
|
-
|
|
558
|
+
state,
|
|
559
559
|
signal,
|
|
560
560
|
})
|
|
561
561
|
: await (0, exports.processBox)({
|
|
562
562
|
iterator,
|
|
563
563
|
allowIncompleteBoxes,
|
|
564
564
|
parsedBoxes: initialBoxes,
|
|
565
|
-
|
|
565
|
+
state,
|
|
566
566
|
signal,
|
|
567
567
|
logLevel,
|
|
568
568
|
fields,
|
|
@@ -573,14 +573,13 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
573
573
|
}
|
|
574
574
|
return {
|
|
575
575
|
status: 'incomplete',
|
|
576
|
-
segments: structure,
|
|
577
576
|
continueParsing: () => {
|
|
578
577
|
return (0, exports.parseIsoBaseMediaBoxes)({
|
|
579
578
|
iterator,
|
|
580
579
|
maxBytes,
|
|
581
580
|
allowIncompleteBoxes,
|
|
582
|
-
initialBoxes
|
|
583
|
-
|
|
581
|
+
initialBoxes,
|
|
582
|
+
state,
|
|
584
583
|
continueMdat: false,
|
|
585
584
|
signal,
|
|
586
585
|
logLevel,
|
|
@@ -593,14 +592,13 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
593
592
|
if (result.type === 'partial-mdat-box') {
|
|
594
593
|
return {
|
|
595
594
|
status: 'incomplete',
|
|
596
|
-
segments: structure,
|
|
597
595
|
continueParsing: () => {
|
|
598
596
|
return Promise.resolve((0, exports.parseIsoBaseMediaBoxes)({
|
|
599
597
|
iterator,
|
|
600
598
|
maxBytes,
|
|
601
599
|
allowIncompleteBoxes,
|
|
602
|
-
initialBoxes
|
|
603
|
-
|
|
600
|
+
initialBoxes,
|
|
601
|
+
state,
|
|
604
602
|
continueMdat: result,
|
|
605
603
|
signal,
|
|
606
604
|
logLevel,
|
|
@@ -611,8 +609,8 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
611
609
|
};
|
|
612
610
|
}
|
|
613
611
|
if (result.box.type === 'mdat-box' && alreadyHasMdat) {
|
|
614
|
-
|
|
615
|
-
|
|
612
|
+
initialBoxes = initialBoxes.filter((b) => b.type !== 'mdat-box');
|
|
613
|
+
initialBoxes.push(result.box);
|
|
616
614
|
iterator.allowDiscard();
|
|
617
615
|
if (result.box.status !== 'samples-processed') {
|
|
618
616
|
throw new Error('unexpected');
|
|
@@ -620,28 +618,26 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
620
618
|
break;
|
|
621
619
|
}
|
|
622
620
|
else {
|
|
623
|
-
|
|
624
|
-
if ((0, has_all_info_1.hasAllInfo)({ fields, state
|
|
621
|
+
initialBoxes.push(result.box);
|
|
622
|
+
if ((0, has_all_info_1.hasAllInfo)({ fields, state })) {
|
|
625
623
|
return {
|
|
626
624
|
status: 'done',
|
|
627
|
-
segments: structure,
|
|
628
625
|
};
|
|
629
626
|
}
|
|
630
627
|
}
|
|
631
628
|
if (result.skipTo !== null) {
|
|
632
|
-
if (!
|
|
629
|
+
if (!state.supportsContentRange) {
|
|
633
630
|
throw new Error('Content-Range header is not supported by the reader, but was asked to seek');
|
|
634
631
|
}
|
|
635
632
|
return {
|
|
636
633
|
status: 'incomplete',
|
|
637
|
-
segments: structure,
|
|
638
634
|
continueParsing: () => {
|
|
639
635
|
return (0, exports.parseIsoBaseMediaBoxes)({
|
|
640
636
|
iterator,
|
|
641
637
|
maxBytes,
|
|
642
638
|
allowIncompleteBoxes,
|
|
643
|
-
initialBoxes
|
|
644
|
-
|
|
639
|
+
initialBoxes,
|
|
640
|
+
state,
|
|
645
641
|
continueMdat: false,
|
|
646
642
|
signal,
|
|
647
643
|
logLevel,
|
|
@@ -654,14 +650,13 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
654
650
|
if (iterator.bytesRemaining() < 0) {
|
|
655
651
|
return {
|
|
656
652
|
status: 'incomplete',
|
|
657
|
-
segments: structure,
|
|
658
653
|
continueParsing: () => {
|
|
659
654
|
return (0, exports.parseIsoBaseMediaBoxes)({
|
|
660
655
|
iterator,
|
|
661
656
|
maxBytes,
|
|
662
657
|
allowIncompleteBoxes,
|
|
663
|
-
initialBoxes
|
|
664
|
-
|
|
658
|
+
initialBoxes,
|
|
659
|
+
state,
|
|
665
660
|
continueMdat: false,
|
|
666
661
|
signal,
|
|
667
662
|
logLevel,
|
|
@@ -673,16 +668,14 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
673
668
|
}
|
|
674
669
|
iterator.removeBytesRead();
|
|
675
670
|
}
|
|
676
|
-
const mdatState = (0, traversal_1.getMdatBox)(
|
|
671
|
+
const mdatState = (0, traversal_1.getMdatBox)(initialBoxes);
|
|
677
672
|
const skipped = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-skipped' &&
|
|
678
|
-
!
|
|
679
|
-
|
|
680
|
-
const buffered = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-buffered' &&
|
|
681
|
-
!options.parserState.maySkipVideoData();
|
|
673
|
+
!(0, may_skip_video_data_1.maySkipVideoData)({ state }) &&
|
|
674
|
+
state.supportsContentRange;
|
|
675
|
+
const buffered = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-buffered' && !(0, may_skip_video_data_1.maySkipVideoData)({ state });
|
|
682
676
|
if (skipped || buffered) {
|
|
683
677
|
return {
|
|
684
678
|
status: 'incomplete',
|
|
685
|
-
segments: structure,
|
|
686
679
|
continueParsing: () => {
|
|
687
680
|
if (buffered) {
|
|
688
681
|
iterator.skipTo(mdatState.fileOffset, false);
|
|
@@ -691,8 +684,8 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
691
684
|
iterator,
|
|
692
685
|
maxBytes,
|
|
693
686
|
allowIncompleteBoxes: false,
|
|
694
|
-
initialBoxes
|
|
695
|
-
|
|
687
|
+
initialBoxes,
|
|
688
|
+
state,
|
|
696
689
|
continueMdat: false,
|
|
697
690
|
signal,
|
|
698
691
|
logLevel,
|
|
@@ -704,7 +697,6 @@ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes
|
|
|
704
697
|
}
|
|
705
698
|
return {
|
|
706
699
|
status: 'done',
|
|
707
|
-
segments: structure,
|
|
708
700
|
};
|
|
709
701
|
};
|
|
710
702
|
exports.parseIsoBaseMediaBoxes = parseIsoBaseMediaBoxes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
2
|
import type { Options, ParseMediaFields } from '../../../options';
|
|
3
3
|
import type { AnySegment } from '../../../parse-result';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ParserState } from '../../../state/parser-state';
|
|
5
5
|
import type { BaseBox } from '../base-type';
|
|
6
6
|
export interface MebxBox extends BaseBox {
|
|
7
7
|
type: 'mebx-box';
|
|
@@ -9,11 +9,11 @@ export interface MebxBox extends BaseBox {
|
|
|
9
9
|
format: string;
|
|
10
10
|
children: AnySegment[];
|
|
11
11
|
}
|
|
12
|
-
export declare const parseMebx: ({ iterator, offset, size,
|
|
12
|
+
export declare const parseMebx: ({ iterator, offset, size, state, signal, fields, }: {
|
|
13
13
|
iterator: BufferIterator;
|
|
14
14
|
offset: number;
|
|
15
15
|
size: number;
|
|
16
|
-
|
|
16
|
+
state: ParserState;
|
|
17
17
|
signal: AbortSignal | null;
|
|
18
18
|
fields: Options<ParseMediaFields>;
|
|
19
19
|
}) => Promise<MebxBox>;
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMebx = void 0;
|
|
4
4
|
const process_box_1 = require("../process-box");
|
|
5
|
-
const parseMebx = async ({ iterator, offset, size,
|
|
5
|
+
const parseMebx = async ({ iterator, offset, size, state, signal, fields, }) => {
|
|
6
6
|
// reserved, 6 bit
|
|
7
7
|
iterator.discard(6);
|
|
8
8
|
const dataReferenceIndex = iterator.getUint16();
|
|
9
|
+
const boxes = [];
|
|
9
10
|
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
10
11
|
iterator,
|
|
11
12
|
maxBytes: iterator.counter.getOffset() - offset,
|
|
12
13
|
allowIncompleteBoxes: false,
|
|
13
|
-
initialBoxes:
|
|
14
|
-
|
|
14
|
+
initialBoxes: boxes,
|
|
15
|
+
state,
|
|
15
16
|
continueMdat: false,
|
|
16
17
|
signal,
|
|
17
18
|
logLevel: 'info',
|
|
@@ -26,7 +27,7 @@ const parseMebx = async ({ iterator, offset, size, options, signal, fields, }) =
|
|
|
26
27
|
offset,
|
|
27
28
|
dataReferenceIndex,
|
|
28
29
|
format: 'mebx',
|
|
29
|
-
children:
|
|
30
|
+
children: boxes,
|
|
30
31
|
};
|
|
31
32
|
};
|
|
32
33
|
exports.parseMebx = parseMebx;
|