@remotion/media-parser 4.0.200 → 4.0.202
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/av1-codec-string.d.ts +5 -0
- package/dist/av1-codec-string.js +18 -1
- package/dist/bitstream/av1.d.ts +2 -0
- package/dist/bitstream/av1.js +12 -0
- package/dist/boxes/iso-base-media/avcc-hvcc.d.ts +20 -0
- package/dist/boxes/iso-base-media/avcc-hvcc.js +73 -0
- package/dist/boxes/iso-base-media/avcc.d.ts +18 -0
- package/dist/boxes/iso-base-media/avcc.js +27 -0
- package/dist/boxes/iso-base-media/esds-descriptors.d.ts +21 -0
- package/dist/boxes/iso-base-media/esds-descriptors.js +62 -0
- package/dist/boxes/iso-base-media/esds.d.ts +15 -0
- package/dist/boxes/iso-base-media/esds.js +27 -0
- package/dist/boxes/iso-base-media/mdat/mdat.js +2 -1
- package/dist/boxes/iso-base-media/moov/moov.js +1 -0
- package/dist/boxes/iso-base-media/mvhd.js +2 -2
- package/dist/boxes/iso-base-media/process-box.d.ts +4 -2
- package/dist/boxes/iso-base-media/process-box.js +56 -40
- package/dist/boxes/iso-base-media/stsd/keys.js +1 -1
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +2 -1
- package/dist/boxes/iso-base-media/stsd/mebx.js +2 -1
- package/dist/boxes/iso-base-media/stsd/samples.js +3 -0
- package/dist/boxes/iso-base-media/stsd/stco.d.ts +3 -2
- package/dist/boxes/iso-base-media/stsd/stco.js +2 -2
- package/dist/boxes/iso-base-media/trak/trak.js +1 -0
- package/dist/boxes/webm/av1-codec-private.js +1 -1
- package/dist/boxes/webm/bitstream/av1.js +10 -1
- package/dist/boxes/webm/description.d.ts +2 -2
- package/dist/boxes/webm/description.js +2 -2
- package/dist/boxes/webm/ebml.d.ts +2 -2
- package/dist/boxes/webm/ebml.js +23 -1
- package/dist/boxes/webm/get-ready-tracks.d.ts +1 -1
- package/dist/boxes/webm/get-ready-tracks.js +3 -3
- package/dist/boxes/webm/get-sample-from-block.d.ts +17 -0
- package/dist/boxes/webm/get-sample-from-block.js +78 -0
- package/dist/boxes/webm/get-track.d.ts +2 -2
- package/dist/boxes/webm/get-track.js +26 -25
- package/dist/boxes/webm/make-header.d.ts +3 -1
- package/dist/boxes/webm/make-header.js +90 -32
- package/dist/boxes/webm/parse-ebml.d.ts +12 -0
- package/dist/boxes/webm/parse-ebml.js +175 -0
- package/dist/boxes/webm/parse-webm-header.js +8 -9
- package/dist/boxes/webm/segments/all-segments.d.ts +572 -1
- package/dist/boxes/webm/segments/all-segments.js +353 -2
- package/dist/boxes/webm/segments/track-entry.d.ts +5 -189
- package/dist/boxes/webm/segments/track-entry.js +2 -457
- package/dist/boxes/webm/segments.d.ts +3 -16
- package/dist/boxes/webm/segments.js +40 -219
- package/dist/boxes/webm/traversal.d.ts +5 -5
- package/dist/boxes/webm/traversal.js +17 -6
- package/dist/buffer-iterator.d.ts +10 -7
- package/dist/buffer-iterator.js +83 -7
- package/dist/create/create-media.d.ts +2 -0
- package/dist/create/create-media.js +36 -0
- package/dist/create/matroska-header.d.ts +1 -0
- package/dist/create/matroska-header.js +66 -0
- package/dist/create/matroska-info.d.ts +4 -0
- package/dist/create/matroska-info.js +39 -0
- package/dist/create/matroska-segment.d.ts +1 -0
- package/dist/create/matroska-segment.js +12 -0
- package/dist/create/matroska-trackentry.d.ts +21 -0
- package/dist/create/matroska-trackentry.js +191 -0
- package/dist/create-media.d.ts +1 -0
- package/dist/create-media.js +78 -0
- package/dist/from-fetch.js +13 -3
- package/dist/from-input-type-file.d.ts +2 -0
- package/dist/from-input-type-file.js +37 -0
- package/dist/from-node.js +9 -2
- package/dist/from-web-file.js +6 -1
- package/dist/from-web.js +15 -6
- package/dist/get-audio-codec.d.ts +2 -2
- package/dist/get-audio-codec.js +13 -13
- package/dist/get-codec.d.ts +4 -0
- package/dist/get-codec.js +22 -0
- package/dist/get-duration.js +12 -14
- package/dist/get-sample-positions.js +1 -1
- package/dist/get-tracks.js +2 -2
- package/dist/get-video-codec.js +13 -13
- package/dist/has-all-info.js +1 -1
- package/dist/options.d.ts +3 -2
- package/dist/parse-media.js +17 -10
- package/dist/parse-video.js +16 -0
- package/dist/parser-context.d.ts +1 -0
- package/dist/parser-state.d.ts +4 -3
- package/dist/parser-state.js +16 -3
- package/dist/reader.d.ts +1 -1
- package/dist/readers/from-fetch.d.ts +2 -0
- package/dist/readers/from-fetch.js +64 -0
- package/dist/readers/from-node.d.ts +2 -0
- package/dist/readers/from-node.js +40 -0
- package/dist/readers/from-web-file.d.ts +2 -0
- package/dist/readers/from-web-file.js +39 -0
- package/dist/readers/reader.d.ts +11 -0
- package/dist/readers/reader.js +2 -0
- package/dist/traversal.d.ts +19 -17
- package/dist/traversal.js +38 -39
- package/dist/web-file.d.ts +2 -0
- package/dist/web-file.js +37 -0
- package/dist/writers/web-fs.d.ts +2 -0
- package/dist/writers/web-fs.js +28 -0
- package/dist/writers/writer.d.ts +9 -0
- package/dist/writers/writer.js +2 -0
- package/input.webm +0 -0
- package/package.json +2 -2
- package/src/boxes/iso-base-media/mdat/mdat.ts +2 -1
- package/src/boxes/iso-base-media/moov/moov.ts +1 -0
- package/src/boxes/iso-base-media/mvhd.ts +2 -2
- package/src/boxes/iso-base-media/process-box.ts +70 -40
- package/src/boxes/iso-base-media/stsd/keys.ts +1 -1
- package/src/boxes/iso-base-media/stsd/mebx.ts +3 -0
- package/src/boxes/iso-base-media/stsd/samples.ts +3 -0
- package/src/boxes/iso-base-media/stsd/stco.ts +5 -3
- package/src/boxes/iso-base-media/trak/trak.ts +1 -0
- package/src/boxes/webm/av1-codec-private.ts +1 -1
- package/src/boxes/webm/description.ts +7 -4
- package/src/boxes/webm/ebml.ts +24 -4
- package/src/boxes/webm/get-ready-tracks.ts +4 -4
- package/src/boxes/webm/get-sample-from-block.ts +125 -0
- package/src/boxes/webm/get-track.ts +38 -31
- package/src/boxes/webm/make-header.ts +129 -32
- package/src/boxes/webm/parse-ebml.ts +247 -0
- package/src/boxes/webm/parse-webm-header.ts +8 -12
- package/src/boxes/webm/segments/all-segments.ts +539 -1
- package/src/boxes/webm/segments/track-entry.ts +5 -843
- package/src/boxes/webm/segments.ts +48 -435
- package/src/boxes/webm/traversal.ts +28 -15
- package/src/buffer-iterator.ts +104 -10
- package/src/from-fetch.ts +22 -3
- package/src/from-node.ts +18 -4
- package/src/from-web-file.ts +11 -1
- package/src/get-audio-codec.ts +14 -16
- package/src/get-duration.ts +15 -16
- package/src/get-sample-positions.ts +1 -1
- package/src/get-tracks.ts +2 -2
- package/src/get-video-codec.ts +13 -15
- package/src/has-all-info.ts +1 -1
- package/src/options.ts +3 -2
- package/src/parse-media.ts +20 -9
- package/src/parse-video.ts +17 -0
- package/src/parser-context.ts +1 -0
- package/src/parser-state.ts +22 -5
- package/src/reader.ts +1 -0
- package/src/test/create-matroska.test.ts +255 -7
- package/src/test/matroska.test.ts +311 -334
- package/src/test/mvhd.test.ts +1 -1
- package/src/test/parse-esds.test.ts +2 -2
- package/src/test/parse-stco.test.ts +4 -2
- package/src/test/parse-stsc.test.ts +2 -2
- package/src/test/parse-stsz.test.ts +2 -2
- package/src/test/parse-stts.test.ts +1 -1
- package/src/test/stream-local.test.ts +23 -9
- package/src/test/stream-remote.test.ts +23 -19
- package/src/test/stsd.test.ts +6 -2
- package/src/test/tkhd.test.ts +1 -1
- package/src/traversal.ts +62 -85
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/boxes/iso-base-media/ftype.d.ts +0 -9
- package/dist/boxes/iso-base-media/ftype.js +0 -31
- package/dist/get-video-metadata.d.ts +0 -2
- package/dist/get-video-metadata.js +0 -44
- package/dist/read-and-increment-offset.d.ts +0 -28
- package/dist/read-and-increment-offset.js +0 -177
- package/dist/understand-vorbis.d.ts +0 -1
- package/dist/understand-vorbis.js +0 -12
- package/src/boxes/webm/segments/duration.ts +0 -29
- package/src/boxes/webm/segments/info.ts +0 -34
- package/src/boxes/webm/segments/main.ts +0 -6
- package/src/boxes/webm/segments/muxing.ts +0 -18
- package/src/boxes/webm/segments/seek-head.ts +0 -34
- package/src/boxes/webm/segments/seek-position.ts +0 -18
- package/src/boxes/webm/segments/seek.ts +0 -45
- package/src/boxes/webm/segments/timestamp-scale.ts +0 -17
- package/src/boxes/webm/segments/tracks.ts +0 -32
- package/src/boxes/webm/segments/unknown.ts +0 -19
- package/src/boxes/webm/segments/void.ts +0 -18
- package/src/boxes/webm/segments/writing.ts +0 -18
- package/src/combine-uint8array.ts +0 -13
- /package/dist/{boxes/webm/bitstream/av1/frame.d.ts → get-samples.d.ts} +0 -0
- /package/dist/{boxes/webm/bitstream/av1/frame.js → get-samples.js} +0 -0
- /package/dist/{boxes/webm/bitstream/h264/get-h264-descriptor.d.ts → sample-aspect-ratio.d.ts} +0 -0
- /package/dist/{boxes/webm/bitstream/h264/get-h264-descriptor.js → sample-aspect-ratio.js} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVideoCodec = exports.hasVideoCodec = void 0;
|
|
4
|
+
const hasVideoCodec = (boxes) => {
|
|
5
|
+
try {
|
|
6
|
+
return boxes.some((b) => b.type === 'ftyp-box');
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.hasVideoCodec = hasVideoCodec;
|
|
13
|
+
const getVideoCodec = (boxes) => {
|
|
14
|
+
const ftypBox = boxes.find((b) => b.type === 'ftyp-box');
|
|
15
|
+
if (ftypBox && ftypBox.type === 'ftyp-box') {
|
|
16
|
+
if (ftypBox.compatibleBrands.find((b) => b === 'avc1')) {
|
|
17
|
+
return 'h264';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
exports.getVideoCodec = getVideoCodec;
|
package/dist/get-duration.js
CHANGED
|
@@ -3,33 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.hasDuration = exports.getDuration = void 0;
|
|
4
4
|
const traversal_1 = require("./traversal");
|
|
5
5
|
const getDurationFromMatroska = (segments) => {
|
|
6
|
-
const mainSegment = segments.find((s) => s.type === '
|
|
7
|
-
if (!mainSegment || mainSegment.type !== '
|
|
6
|
+
const mainSegment = segments.find((s) => s.type === 'Segment');
|
|
7
|
+
if (!mainSegment || mainSegment.type !== 'Segment') {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
|
-
const { children } = mainSegment;
|
|
10
|
+
const { value: children } = mainSegment;
|
|
11
11
|
if (!children) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
|
-
const infoSegment = children.find((s) => s.type === '
|
|
14
|
+
const infoSegment = children.find((s) => s.type === 'Info');
|
|
15
15
|
const relevantBoxes = [
|
|
16
|
-
...mainSegment.
|
|
17
|
-
...(infoSegment && infoSegment.type === '
|
|
18
|
-
? infoSegment.children
|
|
19
|
-
: []),
|
|
16
|
+
...mainSegment.value,
|
|
17
|
+
...(infoSegment && infoSegment.type === 'Info' ? infoSegment.value : []),
|
|
20
18
|
];
|
|
21
|
-
const timestampScale = relevantBoxes.find((s) => s.type === '
|
|
22
|
-
if (!timestampScale || timestampScale.type !== '
|
|
19
|
+
const timestampScale = relevantBoxes.find((s) => s.type === 'TimestampScale');
|
|
20
|
+
if (!timestampScale || timestampScale.type !== 'TimestampScale') {
|
|
23
21
|
return null;
|
|
24
22
|
}
|
|
25
|
-
const duration = relevantBoxes.find((s) => s.type === '
|
|
26
|
-
if (!duration || duration.type !== '
|
|
23
|
+
const duration = relevantBoxes.find((s) => s.type === 'Duration');
|
|
24
|
+
if (!duration || duration.type !== 'Duration') {
|
|
27
25
|
return null;
|
|
28
26
|
}
|
|
29
|
-
return (duration.
|
|
27
|
+
return (duration.value.value / timestampScale.value.value) * 1000;
|
|
30
28
|
};
|
|
31
29
|
const getDuration = (boxes) => {
|
|
32
|
-
const matroskaBox = boxes.find((b) => b.type === '
|
|
30
|
+
const matroskaBox = boxes.find((b) => b.type === 'Segment');
|
|
33
31
|
if (matroskaBox) {
|
|
34
32
|
return getDurationFromMatroska(boxes);
|
|
35
33
|
}
|
|
@@ -38,7 +38,7 @@ const getSamplePositions = ({ stcoBox, stszBox, stscBox, stssBox, sttsBox, cttsB
|
|
|
38
38
|
const ctsOffset = cttsEntries[samples.length];
|
|
39
39
|
const cts = dts + ctsOffset;
|
|
40
40
|
samples.push({
|
|
41
|
-
offset: chunks[i] + offsetInThisChunk,
|
|
41
|
+
offset: Number(chunks[i]) + offsetInThisChunk,
|
|
42
42
|
size,
|
|
43
43
|
isKeyframe,
|
|
44
44
|
dts,
|
package/dist/get-tracks.js
CHANGED
|
@@ -31,8 +31,8 @@ const getTracks = (segments, state) => {
|
|
|
31
31
|
const videoTracks = [];
|
|
32
32
|
const audioTracks = [];
|
|
33
33
|
const otherTracks = [];
|
|
34
|
-
const mainSegment = segments.find((s) => s.type === '
|
|
35
|
-
if (mainSegment && mainSegment.type === '
|
|
34
|
+
const mainSegment = segments.find((s) => s.type === 'Segment');
|
|
35
|
+
if (mainSegment && mainSegment.type === 'Segment') {
|
|
36
36
|
const matroskaTracks = (0, get_ready_tracks_1.getTracksFromMatroska)(mainSegment, state.getTimescale());
|
|
37
37
|
for (const track of matroskaTracks) {
|
|
38
38
|
if (track.type === 'video') {
|
package/dist/get-video-codec.js
CHANGED
|
@@ -60,31 +60,31 @@ const getVideoCodec = (boxes) => {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
const mainSegment = boxes.find((b) => b.type === '
|
|
64
|
-
if (!mainSegment || mainSegment.type !== '
|
|
63
|
+
const mainSegment = boxes.find((b) => b.type === 'Segment');
|
|
64
|
+
if (!mainSegment || mainSegment.type !== 'Segment') {
|
|
65
65
|
return null;
|
|
66
66
|
}
|
|
67
|
-
const tracksSegment = mainSegment.
|
|
68
|
-
if (!tracksSegment || tracksSegment.type !== '
|
|
67
|
+
const tracksSegment = mainSegment.value.find((b) => b.type === 'Tracks');
|
|
68
|
+
if (!tracksSegment || tracksSegment.type !== 'Tracks') {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
|
-
for (const track of tracksSegment.
|
|
72
|
-
if (track.type === '
|
|
73
|
-
const trackType = track.
|
|
74
|
-
if (trackType && trackType.type === '
|
|
75
|
-
if (trackType.
|
|
71
|
+
for (const track of tracksSegment.value) {
|
|
72
|
+
if (track.type === 'TrackEntry') {
|
|
73
|
+
const trackType = track.value.find((b) => b.type === 'CodecID');
|
|
74
|
+
if (trackType && trackType.type === 'CodecID') {
|
|
75
|
+
if (trackType.value === 'V_VP8') {
|
|
76
76
|
return 'vp8';
|
|
77
77
|
}
|
|
78
|
-
if (trackType.
|
|
78
|
+
if (trackType.value === 'V_VP9') {
|
|
79
79
|
return 'vp9';
|
|
80
80
|
}
|
|
81
|
-
if (trackType.
|
|
81
|
+
if (trackType.value === 'V_AV1') {
|
|
82
82
|
return 'av1';
|
|
83
83
|
}
|
|
84
|
-
if (trackType.
|
|
84
|
+
if (trackType.value === 'V_MPEG4/ISO/AVC') {
|
|
85
85
|
return 'h264';
|
|
86
86
|
}
|
|
87
|
-
if (trackType.
|
|
87
|
+
if (trackType.value === 'V_MPEGH/ISO/HEVC') {
|
|
88
88
|
return 'h265';
|
|
89
89
|
}
|
|
90
90
|
}
|
package/dist/has-all-info.js
CHANGED
|
@@ -20,7 +20,7 @@ const hasAllInfo = (options, parseResult, state) => {
|
|
|
20
20
|
}
|
|
21
21
|
if (key === 'dimensions' ||
|
|
22
22
|
key === 'rotation' ||
|
|
23
|
-
key === '
|
|
23
|
+
key === 'unrotatedDimensions') {
|
|
24
24
|
return (0, get_dimensions_1.hasDimensions)(parseResult.segments, state);
|
|
25
25
|
}
|
|
26
26
|
if (key === 'fps') {
|
package/dist/options.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type Options<EnableDimensions extends boolean, EnableDuration extends boo
|
|
|
15
15
|
audioCodec?: EnableAudioCodec;
|
|
16
16
|
tracks?: EnableTracks;
|
|
17
17
|
rotation?: EnableRotation;
|
|
18
|
-
|
|
18
|
+
unrotatedDimensions?: EnableUnrotatedDimensions;
|
|
19
19
|
internalStats?: EnableInternalStats;
|
|
20
20
|
};
|
|
21
21
|
export type Metadata<EnableDimensions extends boolean, EnableDuration extends boolean, EnableBoxes extends boolean, EnableFps extends boolean, EnableVideoCodec extends boolean, EnableAudioCodec extends boolean, EnableTracks extends boolean, EnableRotation extends boolean, EnableUnrotatedDimensions extends boolean, EnableInternalStats extends boolean> = (EnableDimensions extends true ? {
|
|
@@ -36,7 +36,7 @@ export type Metadata<EnableDimensions extends boolean, EnableDuration extends bo
|
|
|
36
36
|
} : {}) & (EnableRotation extends true ? {
|
|
37
37
|
rotation: number | null;
|
|
38
38
|
} : {}) & (EnableUnrotatedDimensions extends true ? {
|
|
39
|
-
|
|
39
|
+
unrotatedDimensions: Dimensions;
|
|
40
40
|
} : {}) & (EnableInternalStats extends true ? {
|
|
41
41
|
internalStats: InternalStats;
|
|
42
42
|
} : {});
|
|
@@ -46,4 +46,5 @@ export type ParseMedia = <EnableDimensions extends boolean, EnableDuration exten
|
|
|
46
46
|
reader?: ReaderInterface;
|
|
47
47
|
onAudioTrack?: OnAudioTrack;
|
|
48
48
|
onVideoTrack?: OnVideoTrack;
|
|
49
|
+
signal?: AbortSignal;
|
|
49
50
|
}) => Promise<Metadata<EnableDimensions, EnableDuration, EnableBoxes, EnableFps, EnableVideoCodec, EnableAudioCodec, EnableTracks, EnableRotation, EnableUnrotatedDimensions, EnableInternalStats>>;
|
package/dist/parse-media.js
CHANGED
|
@@ -12,23 +12,30 @@ const get_video_codec_1 = require("./get-video-codec");
|
|
|
12
12
|
const has_all_info_1 = require("./has-all-info");
|
|
13
13
|
const parse_video_1 = require("./parse-video");
|
|
14
14
|
const parser_state_1 = require("./parser-state");
|
|
15
|
-
const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.fetchReader, onAudioTrack, onVideoTrack, }) => {
|
|
16
|
-
const { reader, contentLength } = await readerInterface.read(src, null);
|
|
17
|
-
let currentReader = reader;
|
|
18
|
-
const returnValue = {};
|
|
19
|
-
let iterator = null;
|
|
20
|
-
let parseResult = null;
|
|
15
|
+
const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.fetchReader, onAudioTrack, onVideoTrack, signal, }) => {
|
|
21
16
|
const state = (0, parser_state_1.makeParserState)({
|
|
22
17
|
hasAudioCallbacks: onAudioTrack !== null,
|
|
23
18
|
hasVideoCallbacks: onVideoTrack !== null,
|
|
19
|
+
signal,
|
|
24
20
|
});
|
|
21
|
+
const { reader, contentLength } = await readerInterface.read(src, null, signal);
|
|
22
|
+
let currentReader = reader;
|
|
23
|
+
const returnValue = {};
|
|
24
|
+
let iterator = null;
|
|
25
|
+
let parseResult = null;
|
|
25
26
|
const options = {
|
|
26
27
|
canSkipVideoData: !(onAudioTrack || onVideoTrack),
|
|
27
28
|
onAudioTrack: onAudioTrack !== null && onAudioTrack !== void 0 ? onAudioTrack : null,
|
|
28
29
|
onVideoTrack: onVideoTrack !== null && onVideoTrack !== void 0 ? onVideoTrack : null,
|
|
29
30
|
parserState: state,
|
|
31
|
+
nullifySamples: !(typeof process !== 'undefined' &&
|
|
32
|
+
typeof process.env !== 'undefined' &&
|
|
33
|
+
process.env.KEEP_SAMPLES === 'true'),
|
|
30
34
|
};
|
|
31
35
|
while (parseResult === null || parseResult.status === 'incomplete') {
|
|
36
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
37
|
+
throw new Error('Aborted');
|
|
38
|
+
}
|
|
32
39
|
const result = await currentReader.read();
|
|
33
40
|
if (iterator) {
|
|
34
41
|
if (!result.done) {
|
|
@@ -39,7 +46,7 @@ const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.
|
|
|
39
46
|
if (result.done) {
|
|
40
47
|
throw new Error('Unexpectedly reached EOF');
|
|
41
48
|
}
|
|
42
|
-
iterator = (0, buffer_iterator_1.getArrayBufferIterator)(result.value, contentLength !== null && contentLength !== void 0 ? contentLength :
|
|
49
|
+
iterator = (0, buffer_iterator_1.getArrayBufferIterator)(result.value, contentLength !== null && contentLength !== void 0 ? contentLength : 1000000000);
|
|
43
50
|
}
|
|
44
51
|
if (parseResult && parseResult.status === 'incomplete') {
|
|
45
52
|
parseResult = await parseResult.continueParsing();
|
|
@@ -66,7 +73,7 @@ const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.
|
|
|
66
73
|
if (!currentReader.closed) {
|
|
67
74
|
currentReader.cancel(new Error('skipped ahead'));
|
|
68
75
|
}
|
|
69
|
-
const { reader: newReader } = await readerInterface.read(src, parseResult.skipTo);
|
|
76
|
+
const { reader: newReader } = await readerInterface.read(src, parseResult.skipTo, signal);
|
|
70
77
|
currentReader = newReader;
|
|
71
78
|
iterator.skipTo(parseResult.skipTo);
|
|
72
79
|
}
|
|
@@ -81,9 +88,9 @@ const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.
|
|
|
81
88
|
height: dimensions.height,
|
|
82
89
|
};
|
|
83
90
|
}
|
|
84
|
-
if (fields === null || fields === void 0 ? void 0 : fields.
|
|
91
|
+
if (fields === null || fields === void 0 ? void 0 : fields.unrotatedDimensions) {
|
|
85
92
|
const dimensions = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
86
|
-
returnValue.
|
|
93
|
+
returnValue.unrotatedDimensions = {
|
|
87
94
|
width: dimensions.unrotatedWidth,
|
|
88
95
|
height: dimensions.unrotatedHeight,
|
|
89
96
|
};
|
package/dist/parse-video.js
CHANGED
|
@@ -17,6 +17,21 @@ const parseVideo = ({ iterator, options, }) => {
|
|
|
17
17
|
skipTo: null,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
if (iterator.isRiff()) {
|
|
21
|
+
throw new Error('AVI files are not yet supported');
|
|
22
|
+
/*
|
|
23
|
+
iterator.discard(4);
|
|
24
|
+
return parseBoxes({
|
|
25
|
+
iterator,
|
|
26
|
+
maxBytes: Infinity,
|
|
27
|
+
allowIncompleteBoxes: true,
|
|
28
|
+
initialBoxes: [],
|
|
29
|
+
options,
|
|
30
|
+
continueMdat: false,
|
|
31
|
+
littleEndian: true,
|
|
32
|
+
});
|
|
33
|
+
*/
|
|
34
|
+
}
|
|
20
35
|
if (iterator.isIsoBaseMedia()) {
|
|
21
36
|
return (0, process_box_1.parseBoxes)({
|
|
22
37
|
iterator,
|
|
@@ -25,6 +40,7 @@ const parseVideo = ({ iterator, options, }) => {
|
|
|
25
40
|
initialBoxes: [],
|
|
26
41
|
options,
|
|
27
42
|
continueMdat: false,
|
|
43
|
+
littleEndian: false,
|
|
28
44
|
});
|
|
29
45
|
}
|
|
30
46
|
if (iterator.isWebm()) {
|
package/dist/parser-context.d.ts
CHANGED
package/dist/parser-state.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { OnTrackEntrySegment } from './boxes/webm/segments';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TrackInfo } from './boxes/webm/segments/track-entry';
|
|
3
3
|
import type { AudioSample, OnAudioSample, OnVideoSample, VideoSample } from './webcodec-sample-types';
|
|
4
4
|
export type InternalStats = {};
|
|
5
|
-
export declare const makeParserState: ({ hasAudioCallbacks, hasVideoCallbacks, }: {
|
|
5
|
+
export declare const makeParserState: ({ hasAudioCallbacks, hasVideoCallbacks, signal, }: {
|
|
6
6
|
hasAudioCallbacks: boolean;
|
|
7
7
|
hasVideoCallbacks: boolean;
|
|
8
|
+
signal: AbortSignal | undefined;
|
|
8
9
|
}) => {
|
|
9
10
|
onTrackEntrySegment: OnTrackEntrySegment;
|
|
10
|
-
getTrackInfoByNumber: (id: number) =>
|
|
11
|
+
getTrackInfoByNumber: (id: number) => TrackInfo;
|
|
11
12
|
registerVideoSampleCallback: (id: number, callback: OnVideoSample | null) => Promise<void>;
|
|
12
13
|
setTimestampOffset: (byteOffset: number, timestamp: number) => void;
|
|
13
14
|
getTimestampOffsetForByteOffset: (byteOffset: number) => number | undefined;
|
package/dist/parser-state.js
CHANGED
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makeParserState = void 0;
|
|
4
4
|
const traversal_1 = require("./boxes/webm/traversal");
|
|
5
5
|
const traversal_2 = require("./traversal");
|
|
6
|
-
const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, }) => {
|
|
6
|
+
const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, signal, }) => {
|
|
7
7
|
const trackEntries = {};
|
|
8
8
|
const onTrackEntrySegment = (trackEntry) => {
|
|
9
|
+
var _a;
|
|
9
10
|
const trackId = (0, traversal_2.getTrackId)(trackEntry);
|
|
10
11
|
if (!trackId) {
|
|
11
12
|
throw new Error('Expected track id');
|
|
@@ -17,7 +18,11 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, }) => {
|
|
|
17
18
|
if (!codec) {
|
|
18
19
|
throw new Error('Expected codec');
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
const trackTimescale = (0, traversal_1.getTrackTimestampScale)(trackEntry);
|
|
22
|
+
trackEntries[trackId] = {
|
|
23
|
+
codec: codec.value,
|
|
24
|
+
trackTimescale: (_a = trackTimescale === null || trackTimescale === void 0 ? void 0 : trackTimescale.value) !== null && _a !== void 0 ? _a : null,
|
|
25
|
+
};
|
|
21
26
|
};
|
|
22
27
|
const videoSampleCallbacks = {};
|
|
23
28
|
const audioSampleCallbacks = {};
|
|
@@ -26,8 +31,10 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, }) => {
|
|
|
26
31
|
const declinedTrackNumbers = [];
|
|
27
32
|
let timescale = null;
|
|
28
33
|
const getTimescale = () => {
|
|
34
|
+
// https://www.matroska.org/technical/notes.html
|
|
35
|
+
// When using the default value of TimestampScale of “1,000,000”, one Segment Tick represents one millisecond.
|
|
29
36
|
if (timescale === null) {
|
|
30
|
-
|
|
37
|
+
return 1000000;
|
|
31
38
|
}
|
|
32
39
|
return timescale;
|
|
33
40
|
};
|
|
@@ -85,6 +92,9 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, }) => {
|
|
|
85
92
|
queuedAudioSamples[id] = [];
|
|
86
93
|
},
|
|
87
94
|
onAudioSample: async (trackId, audioSample) => {
|
|
95
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
96
|
+
throw new Error('Aborted');
|
|
97
|
+
}
|
|
88
98
|
const callback = audioSampleCallbacks[trackId];
|
|
89
99
|
if (callback) {
|
|
90
100
|
await callback(audioSample);
|
|
@@ -99,6 +109,9 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, }) => {
|
|
|
99
109
|
}
|
|
100
110
|
},
|
|
101
111
|
onVideoSample: async (trackId, videoSample) => {
|
|
112
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
113
|
+
throw new Error('Aborted');
|
|
114
|
+
}
|
|
102
115
|
const callback = videoSampleCallbacks[trackId];
|
|
103
116
|
if (callback) {
|
|
104
117
|
await callback(videoSample);
|
package/dist/reader.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ type ReadResult = {
|
|
|
2
2
|
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
3
3
|
contentLength: number | null;
|
|
4
4
|
};
|
|
5
|
-
type ReadContent = (src: string | File, range: [number, number] | number | null) => Promise<ReadResult>;
|
|
5
|
+
type ReadContent = (src: string | File, range: [number, number] | number | null, signal: AbortSignal | undefined) => Promise<ReadResult>;
|
|
6
6
|
type GetLength = (src: string | File) => Promise<number>;
|
|
7
7
|
export type ReaderInterface = {
|
|
8
8
|
read: ReadContent;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchReader = void 0;
|
|
4
|
+
exports.fetchReader = {
|
|
5
|
+
read: async (src, range, signal) => {
|
|
6
|
+
if (typeof src !== 'string') {
|
|
7
|
+
throw new Error('src must be a string when using `fetchReader`');
|
|
8
|
+
}
|
|
9
|
+
const resolvedUrl = typeof window !== 'undefined' && typeof window.location !== 'undefined'
|
|
10
|
+
? new URL(src, window.location.origin).toString()
|
|
11
|
+
: src;
|
|
12
|
+
if (!resolvedUrl.startsWith('https://') &&
|
|
13
|
+
!resolvedUrl.startsWith('http://')) {
|
|
14
|
+
return Promise.reject(new Error(resolvedUrl +
|
|
15
|
+
' is not a URL - needs to start with http:// or https://. If you want to read a local file, pass `nodeReader` to parseMedia().'));
|
|
16
|
+
}
|
|
17
|
+
const res = await fetch(resolvedUrl, {
|
|
18
|
+
headers: range === null
|
|
19
|
+
? {}
|
|
20
|
+
: typeof range === 'number'
|
|
21
|
+
? {
|
|
22
|
+
Range: `bytes=${range}`,
|
|
23
|
+
}
|
|
24
|
+
: {
|
|
25
|
+
Range: `bytes=${`${range[0]}-${range[1]}`}`,
|
|
26
|
+
},
|
|
27
|
+
signal,
|
|
28
|
+
// Disable Next.js caching
|
|
29
|
+
cache: 'no-store',
|
|
30
|
+
});
|
|
31
|
+
if (res.status.toString().startsWith('4') ||
|
|
32
|
+
res.status.toString().startsWith('5')) {
|
|
33
|
+
throw new Error(`Server returned status code ${res.status} for ${src}`);
|
|
34
|
+
}
|
|
35
|
+
if (!res.body) {
|
|
36
|
+
throw new Error('No body');
|
|
37
|
+
}
|
|
38
|
+
const length = res.headers.get('content-length');
|
|
39
|
+
const contentLength = length === null ? null : parseInt(length, 10);
|
|
40
|
+
const reader = res.body.getReader();
|
|
41
|
+
if (signal) {
|
|
42
|
+
signal.addEventListener('abort', () => {
|
|
43
|
+
reader.cancel();
|
|
44
|
+
}, { once: true });
|
|
45
|
+
}
|
|
46
|
+
return { reader, contentLength };
|
|
47
|
+
},
|
|
48
|
+
getLength: async (src) => {
|
|
49
|
+
if (typeof src !== 'string') {
|
|
50
|
+
throw new Error('src must be a string when using `fetchReader`');
|
|
51
|
+
}
|
|
52
|
+
const res = await fetch(src, {
|
|
53
|
+
method: 'HEAD',
|
|
54
|
+
});
|
|
55
|
+
if (!res.body) {
|
|
56
|
+
throw new Error('No body');
|
|
57
|
+
}
|
|
58
|
+
const length = res.headers.get('content-length');
|
|
59
|
+
if (!length) {
|
|
60
|
+
throw new Error('No content-length');
|
|
61
|
+
}
|
|
62
|
+
return parseInt(length, 10);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nodeReader = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
exports.nodeReader = {
|
|
8
|
+
read: async (src, range, signal) => {
|
|
9
|
+
if (typeof src !== 'string') {
|
|
10
|
+
throw new Error('src must be a string when using `nodeReader`');
|
|
11
|
+
}
|
|
12
|
+
const stream = (0, fs_1.createReadStream)(src, {
|
|
13
|
+
start: range === null ? 0 : typeof range === 'number' ? range : range[0],
|
|
14
|
+
end: range === null
|
|
15
|
+
? Infinity
|
|
16
|
+
: typeof range === 'number'
|
|
17
|
+
? Infinity
|
|
18
|
+
: range[1],
|
|
19
|
+
signal,
|
|
20
|
+
});
|
|
21
|
+
const stats = await (0, promises_1.stat)(src);
|
|
22
|
+
const reader = stream_1.Readable.toWeb(stream).getReader();
|
|
23
|
+
if (signal) {
|
|
24
|
+
signal.addEventListener('abort', () => {
|
|
25
|
+
reader.cancel();
|
|
26
|
+
}, { once: true });
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
reader,
|
|
30
|
+
contentLength: stats.size,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
getLength: async (src) => {
|
|
34
|
+
if (typeof src !== 'string') {
|
|
35
|
+
throw new Error('src must be a string when using `nodeReader`');
|
|
36
|
+
}
|
|
37
|
+
const stats = await (0, promises_1.stat)(src);
|
|
38
|
+
return stats.size;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webFileReader = void 0;
|
|
4
|
+
exports.webFileReader = {
|
|
5
|
+
read: (file, range, signal) => {
|
|
6
|
+
if (typeof file === 'string') {
|
|
7
|
+
throw new Error('`inputTypeFileReader` only supports `File` objects');
|
|
8
|
+
}
|
|
9
|
+
const part = range === null
|
|
10
|
+
? file
|
|
11
|
+
: typeof range === 'number'
|
|
12
|
+
? file.slice(range)
|
|
13
|
+
: file.slice(range[0], range[1]);
|
|
14
|
+
const reader = new FileReader();
|
|
15
|
+
reader.readAsArrayBuffer(file);
|
|
16
|
+
if (signal) {
|
|
17
|
+
signal.addEventListener('abort', () => {
|
|
18
|
+
reader.abort();
|
|
19
|
+
}, { once: true });
|
|
20
|
+
}
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
reader.onload = () => {
|
|
23
|
+
resolve({
|
|
24
|
+
reader: part.stream().getReader(),
|
|
25
|
+
contentLength: file.size,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
reader.onerror = (error) => {
|
|
29
|
+
reject(error);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
getLength: (src) => {
|
|
34
|
+
if (typeof src === 'string') {
|
|
35
|
+
throw new Error('`inputTypeFileReader` only supports `File` objects');
|
|
36
|
+
}
|
|
37
|
+
return Promise.resolve(src.size);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type ReadResult = {
|
|
2
|
+
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
3
|
+
contentLength: number | null;
|
|
4
|
+
};
|
|
5
|
+
type ReadContent = (src: string | File, range: [number, number] | number | null, signal: AbortSignal | undefined) => Promise<ReadResult>;
|
|
6
|
+
type GetLength = (src: string | File) => Promise<number>;
|
|
7
|
+
export type ReaderInterface = {
|
|
8
|
+
read: ReadContent;
|
|
9
|
+
getLength: GetLength;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
package/dist/traversal.d.ts
CHANGED
|
@@ -11,9 +11,7 @@ import type { StszBox } from './boxes/iso-base-media/stsd/stsz';
|
|
|
11
11
|
import type { SttsBox } from './boxes/iso-base-media/stsd/stts';
|
|
12
12
|
import type { TkhdBox } from './boxes/iso-base-media/tkhd';
|
|
13
13
|
import type { TrakBox } from './boxes/iso-base-media/trak/trak';
|
|
14
|
-
import type { MainSegment } from './boxes/webm/segments/
|
|
15
|
-
import type { TimestampScaleSegment } from './boxes/webm/segments/timestamp-scale';
|
|
16
|
-
import type { AudioSegment, ClusterSegment, CodecSegment, DisplayHeightSegment, DisplayWidthSegment, HeightSegment, TrackEntrySegment, TrackTypeSegment, VideoSegment, WidthSegment } from './boxes/webm/segments/track-entry';
|
|
14
|
+
import type { AudioSegment, ClusterSegment, CodecIdSegment, DisplayHeightSegment, DisplayWidthSegment, HeightSegment, MainSegment, TimestampScaleSegment, TrackEntry, TrackTypeSegment, VideoSegment, WidthSegment } from './boxes/webm/segments/all-segments';
|
|
17
15
|
import type { AnySegment, RegularBox } from './parse-result';
|
|
18
16
|
export declare const getFtypBox: (segments: AnySegment[]) => FtypBox | null;
|
|
19
17
|
export declare const getMoovBox: (segments: AnySegment[]) => MoovBox | null;
|
|
@@ -32,21 +30,25 @@ export declare const getStszBox: (trakBox: TrakBox) => StszBox | null;
|
|
|
32
30
|
export declare const getStscBox: (trakBox: TrakBox) => StscBox | null;
|
|
33
31
|
export declare const getStssBox: (trakBox: TrakBox) => StssBox | null;
|
|
34
32
|
export declare const getClusterSegment: (segment: MainSegment) => ClusterSegment | null;
|
|
35
|
-
export declare const getTracksSegment: (segment: MainSegment) =>
|
|
33
|
+
export declare const getTracksSegment: (segment: MainSegment) => {
|
|
34
|
+
type: "Tracks";
|
|
35
|
+
value: import("./boxes/webm/segments/all-segments").PossibleEbml[];
|
|
36
|
+
minVintWidth: number;
|
|
37
|
+
} | null;
|
|
36
38
|
export declare const getTimescaleSegment: (segment: MainSegment) => TimestampScaleSegment | null;
|
|
37
|
-
export declare const getVideoSegment: (track:
|
|
38
|
-
export declare const getAudioSegment: (track:
|
|
39
|
-
export declare const getSampleRate: (track:
|
|
40
|
-
export declare const getNumberOfChannels: (track:
|
|
41
|
-
export declare const getBitDepth: (track:
|
|
42
|
-
export declare const getPrivateData: (track:
|
|
43
|
-
export declare const getWidthSegment: (track:
|
|
44
|
-
export declare const getHeightSegment: (track:
|
|
45
|
-
export declare const getDisplayWidthSegment: (track:
|
|
46
|
-
export declare const getDisplayHeightSegment: (track:
|
|
47
|
-
export declare const getTrackTypeSegment: (track:
|
|
48
|
-
export declare const getTrackId: (track:
|
|
49
|
-
export declare const getCodecSegment: (track:
|
|
39
|
+
export declare const getVideoSegment: (track: TrackEntry) => VideoSegment | null;
|
|
40
|
+
export declare const getAudioSegment: (track: TrackEntry) => AudioSegment | null;
|
|
41
|
+
export declare const getSampleRate: (track: TrackEntry) => number | null;
|
|
42
|
+
export declare const getNumberOfChannels: (track: TrackEntry) => number;
|
|
43
|
+
export declare const getBitDepth: (track: TrackEntry) => number | null;
|
|
44
|
+
export declare const getPrivateData: (track: TrackEntry) => Uint8Array | null;
|
|
45
|
+
export declare const getWidthSegment: (track: TrackEntry) => WidthSegment | null;
|
|
46
|
+
export declare const getHeightSegment: (track: TrackEntry) => HeightSegment | null;
|
|
47
|
+
export declare const getDisplayWidthSegment: (track: TrackEntry) => DisplayWidthSegment | null;
|
|
48
|
+
export declare const getDisplayHeightSegment: (track: TrackEntry) => DisplayHeightSegment | null;
|
|
49
|
+
export declare const getTrackTypeSegment: (track: TrackEntry) => TrackTypeSegment | null;
|
|
50
|
+
export declare const getTrackId: (track: TrackEntry) => number;
|
|
51
|
+
export declare const getCodecSegment: (track: TrackEntry) => CodecIdSegment | null;
|
|
50
52
|
export declare const hasSkippedMdatProcessing: (anySegment: AnySegment[]) => {
|
|
51
53
|
skipped: false;
|
|
52
54
|
fileOffset?: undefined;
|