@remotion/media-parser 4.0.194 → 4.0.196
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-new-matroska-tracks.d.ts +8 -0
- package/dist/add-new-matroska-tracks.js +14 -0
- package/dist/av1-codec-string.d.ts +3 -0
- package/dist/av1-codec-string.js +91 -0
- package/dist/boxes/iso-base-media/esds/decoder-specific-config.d.ts +14 -0
- package/dist/boxes/iso-base-media/esds/decoder-specific-config.js +38 -0
- package/dist/boxes/iso-base-media/esds/esds-descriptors.d.ts +8 -0
- package/dist/boxes/iso-base-media/esds/esds-descriptors.js +22 -2
- package/dist/boxes/iso-base-media/ftype.d.ts +9 -0
- package/dist/boxes/iso-base-media/ftype.js +31 -0
- package/dist/boxes/iso-base-media/make-track.d.ts +3 -0
- package/dist/boxes/iso-base-media/make-track.js +112 -0
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +6 -2
- package/dist/boxes/iso-base-media/mdat/mdat.js +90 -6
- package/dist/boxes/iso-base-media/moov/moov.d.ts +4 -2
- package/dist/boxes/iso-base-media/moov/moov.js +4 -2
- package/dist/boxes/iso-base-media/mvhd.js +7 -1
- package/dist/boxes/iso-base-media/process-box.d.ts +20 -3
- package/dist/boxes/iso-base-media/process-box.js +322 -34
- package/dist/boxes/iso-base-media/stsd/av1c.d.ts +9 -0
- package/dist/boxes/iso-base-media/stsd/av1c.js +10 -0
- package/dist/boxes/iso-base-media/stsd/avcc-hvcc.d.ts +20 -0
- package/dist/boxes/iso-base-media/stsd/avcc-hvcc.js +73 -0
- package/dist/boxes/iso-base-media/stsd/avcc.d.ts +10 -0
- package/dist/boxes/iso-base-media/stsd/avcc.js +21 -0
- package/dist/boxes/iso-base-media/stsd/colr.d.ts +11 -0
- package/dist/boxes/iso-base-media/stsd/colr.js +35 -0
- package/dist/boxes/iso-base-media/stsd/ctts.d.ts +19 -0
- package/dist/boxes/iso-base-media/stsd/ctts.js +30 -0
- package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +11 -0
- package/dist/boxes/iso-base-media/stsd/hvcc.js +17 -0
- package/dist/boxes/iso-base-media/stsd/keys.js +1 -0
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +4 -2
- package/dist/boxes/iso-base-media/stsd/mebx.js +4 -2
- package/dist/boxes/iso-base-media/stsd/pasp.d.ts +12 -0
- package/dist/boxes/iso-base-media/stsd/pasp.js +17 -0
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +12 -5
- package/dist/boxes/iso-base-media/stsd/samples.js +27 -10
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +4 -2
- package/dist/boxes/iso-base-media/stsd/stsd.js +6 -2
- package/dist/boxes/iso-base-media/stsd/stss.d.ts +13 -0
- package/dist/boxes/iso-base-media/stsd/stss.js +28 -0
- package/dist/boxes/iso-base-media/stsd/stsz.d.ts +9 -3
- package/dist/boxes/iso-base-media/stsd/stsz.js +14 -2
- package/dist/boxes/iso-base-media/stsd/stts.d.ts +15 -0
- package/dist/boxes/iso-base-media/stsd/stts.js +35 -0
- package/dist/boxes/iso-base-media/tkhd.d.ts +3 -0
- package/dist/boxes/iso-base-media/tkhd.js +41 -14
- package/dist/boxes/iso-base-media/trak/trak.d.ts +4 -2
- package/dist/boxes/iso-base-media/trak/trak.js +4 -2
- package/dist/boxes/iso-base-media/void-box.d.ts +4 -0
- package/dist/boxes/iso-base-media/void-box.js +2 -0
- package/dist/boxes/webm/allowed-partial-segments.d.ts +1 -0
- package/dist/boxes/webm/allowed-partial-segments.js +4 -0
- package/dist/boxes/webm/av1-codec-private.d.ts +2 -0
- package/dist/boxes/webm/av1-codec-private.js +95 -0
- package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.d.ts +14 -0
- package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.js +67 -0
- package/dist/boxes/webm/bitstream/av1/bitstream-frame.d.ts +11 -0
- package/dist/boxes/webm/bitstream/av1/bitstream-frame.js +14 -0
- package/dist/boxes/webm/bitstream/av1/chroma-sample-position.d.ts +6 -0
- package/dist/boxes/webm/bitstream/av1/chroma-sample-position.js +9 -0
- package/dist/boxes/webm/bitstream/av1/color-config.d.ts +16 -0
- package/dist/boxes/webm/bitstream/av1/color-config.js +103 -0
- package/dist/boxes/webm/bitstream/av1/color-primaries.d.ts +14 -0
- package/dist/boxes/webm/bitstream/av1/color-primaries.js +17 -0
- package/dist/boxes/webm/bitstream/av1/decoder-model-info.d.ts +9 -0
- package/dist/boxes/webm/bitstream/av1/decoder-model-info.js +17 -0
- package/dist/boxes/webm/bitstream/av1/header-segment.d.ts +51 -0
- package/dist/boxes/webm/bitstream/av1/header-segment.js +183 -0
- package/dist/boxes/webm/bitstream/av1/matrix-coefficients.d.ts +17 -0
- package/dist/boxes/webm/bitstream/av1/matrix-coefficients.js +20 -0
- package/dist/boxes/webm/bitstream/av1/operating-parameters-info.d.ts +10 -0
- package/dist/boxes/webm/bitstream/av1/operating-parameters-info.js +15 -0
- package/dist/boxes/webm/bitstream/av1/temporal-point-info.d.ts +5 -0
- package/dist/boxes/webm/bitstream/av1/temporal-point-info.js +8 -0
- package/dist/boxes/webm/bitstream/av1/timing-info.d.ts +8 -0
- package/dist/boxes/webm/bitstream/av1/timing-info.js +20 -0
- package/dist/boxes/webm/bitstream/av1/transfer-characteristics.d.ts +21 -0
- package/dist/boxes/webm/bitstream/av1/transfer-characteristics.js +24 -0
- package/dist/boxes/webm/bitstream/av1/uvlc.d.ts +2 -0
- package/dist/boxes/webm/bitstream/av1/uvlc.js +20 -0
- package/dist/boxes/webm/bitstream/av1.d.ts +20 -0
- package/dist/boxes/webm/bitstream/av1.js +118 -0
- package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.d.ts +0 -0
- package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.js +1 -0
- package/dist/boxes/webm/description.d.ts +2 -0
- package/dist/boxes/webm/description.js +83 -0
- package/dist/boxes/webm/get-ready-tracks.d.ts +3 -0
- package/dist/boxes/webm/get-ready-tracks.js +29 -0
- package/dist/boxes/webm/get-track.d.ts +6 -0
- package/dist/boxes/webm/get-track.js +183 -0
- package/dist/boxes/webm/parse-webm-header.d.ts +2 -1
- package/dist/boxes/webm/parse-webm-header.js +2 -2
- package/dist/boxes/webm/segments/all-segments.d.ts +269 -0
- package/dist/boxes/webm/segments/all-segments.js +277 -0
- package/dist/boxes/webm/segments/duration.d.ts +1 -1
- package/dist/boxes/webm/segments/duration.js +13 -9
- package/dist/boxes/webm/segments/info.d.ts +2 -1
- package/dist/boxes/webm/segments/info.js +12 -4
- package/dist/boxes/webm/segments/main.d.ts +0 -2
- package/dist/boxes/webm/segments/main.js +0 -11
- package/dist/boxes/webm/segments/muxing.d.ts +1 -1
- package/dist/boxes/webm/segments/muxing.js +1 -2
- package/dist/boxes/webm/segments/parse-children.d.ts +11 -1
- package/dist/boxes/webm/segments/parse-children.js +82 -6
- package/dist/boxes/webm/segments/seek-head.d.ts +2 -1
- package/dist/boxes/webm/segments/seek-head.js +12 -3
- package/dist/boxes/webm/segments/seek-position.d.ts +1 -1
- package/dist/boxes/webm/segments/seek-position.js +1 -2
- package/dist/boxes/webm/segments/seek.d.ts +7 -2
- package/dist/boxes/webm/segments/seek.js +22 -9
- package/dist/boxes/webm/segments/track-entry.d.ts +102 -22
- package/dist/boxes/webm/segments/track-entry.js +269 -57
- package/dist/boxes/webm/segments/tracks.d.ts +2 -1
- package/dist/boxes/webm/segments/tracks.js +12 -4
- package/dist/boxes/webm/segments/void.d.ts +1 -1
- package/dist/boxes/webm/segments/void.js +1 -2
- package/dist/boxes/webm/segments/writing.d.ts +1 -1
- package/dist/boxes/webm/segments/writing.js +1 -2
- package/dist/boxes/webm/segments.d.ts +8 -4
- package/dist/boxes/webm/segments.js +176 -40
- package/dist/boxes/webm/traversal.d.ts +7 -0
- package/dist/boxes/webm/traversal.js +25 -0
- package/dist/buffer-iterator.d.ts +15 -1
- package/dist/buffer-iterator.js +115 -46
- package/dist/combine-uint8array.d.ts +1 -0
- package/dist/combine-uint8array.js +13 -0
- package/dist/from-fetch.d.ts +2 -0
- package/dist/from-fetch.js +54 -0
- package/dist/from-node.js +6 -0
- package/dist/from-web-file.d.ts +2 -0
- package/dist/from-web-file.js +34 -0
- package/dist/from-web.js +6 -9
- package/dist/get-audio-codec.d.ts +19 -0
- package/dist/get-audio-codec.js +153 -60
- package/dist/get-dimensions.d.ts +8 -2
- package/dist/get-dimensions.js +13 -91
- package/dist/get-duration.js +4 -7
- package/dist/get-fps.d.ts +4 -3
- package/dist/get-fps.js +17 -116
- package/dist/get-sample-aspect-ratio.d.ts +37 -0
- package/dist/get-sample-aspect-ratio.js +137 -0
- package/dist/get-sample-positions.d.ts +11 -1
- package/dist/get-sample-positions.js +31 -2
- package/dist/get-tracks.d.ts +44 -5
- package/dist/get-tracks.js +66 -48
- package/dist/get-video-codec.d.ts +2 -0
- package/dist/get-video-codec.js +47 -31
- package/dist/get-video-metadata.d.ts +2 -0
- package/dist/get-video-metadata.js +44 -0
- package/dist/has-all-info.d.ts +2 -1
- package/dist/has-all-info.js +14 -5
- package/dist/index.d.ts +1 -0
- package/dist/make-hvc1-codec-strings.d.ts +2 -0
- package/dist/make-hvc1-codec-strings.js +47 -0
- package/dist/options.d.ts +26 -4
- package/dist/parse-media.js +62 -17
- package/dist/parse-result.d.ts +16 -5
- package/dist/parse-video.d.ts +11 -2
- package/dist/parse-video.js +14 -6
- package/dist/parser-context.d.ts +8 -0
- package/dist/parser-context.js +2 -0
- package/dist/parser-state.d.ts +23 -0
- package/dist/parser-state.js +112 -0
- package/dist/read-and-increment-offset.d.ts +28 -0
- package/dist/read-and-increment-offset.js +177 -0
- package/dist/reader.d.ts +2 -2
- package/dist/traversal.d.ts +37 -0
- package/dist/traversal.js +244 -1
- package/dist/understand-vorbis.d.ts +1 -0
- package/dist/understand-vorbis.js +12 -0
- package/dist/webcodec-sample-types.d.ts +21 -0
- package/dist/webcodec-sample-types.js +2 -0
- package/package.json +10 -2
- package/src/add-new-matroska-tracks.ts +23 -0
- package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +61 -0
- package/src/boxes/iso-base-media/esds/esds-descriptors.ts +33 -2
- package/src/boxes/iso-base-media/make-track.ts +157 -0
- package/src/boxes/iso-base-media/mdat/mdat.ts +131 -0
- package/src/boxes/iso-base-media/moov/moov.ts +8 -3
- package/src/boxes/iso-base-media/mvhd.ts +7 -1
- package/src/boxes/iso-base-media/process-box.ts +388 -38
- package/src/boxes/iso-base-media/stsd/av1c.ts +19 -0
- package/src/boxes/iso-base-media/stsd/avcc.ts +36 -0
- package/src/boxes/iso-base-media/stsd/colr.ts +49 -0
- package/src/boxes/iso-base-media/stsd/ctts.ts +55 -0
- package/src/boxes/iso-base-media/stsd/hvcc.ts +32 -0
- package/src/boxes/iso-base-media/stsd/keys.ts +2 -0
- package/src/boxes/iso-base-media/stsd/mebx.ts +8 -3
- package/src/boxes/iso-base-media/stsd/pasp.ts +32 -0
- package/src/boxes/iso-base-media/stsd/samples.ts +43 -16
- package/src/boxes/iso-base-media/stsd/stco.ts +50 -0
- package/src/boxes/iso-base-media/stsd/stsc.ts +61 -0
- package/src/boxes/iso-base-media/stsd/stsd.ts +10 -3
- package/src/boxes/iso-base-media/stsd/stss.ts +47 -0
- package/src/boxes/iso-base-media/stsd/stsz.ts +75 -0
- package/src/boxes/iso-base-media/tkhd.ts +63 -16
- package/src/boxes/iso-base-media/trak/trak.ts +8 -3
- package/src/boxes/iso-base-media/void-box.ts +4 -0
- package/src/boxes/webm/allowed-partial-segments.ts +1 -0
- package/src/boxes/webm/av1-codec-private.ts +113 -0
- package/src/boxes/webm/description.ts +101 -0
- package/src/boxes/webm/get-ready-tracks.ts +36 -0
- package/src/boxes/webm/get-track.ts +250 -0
- package/src/boxes/webm/parse-webm-header.ts +6 -2
- package/src/boxes/webm/segments/all-segments.ts +285 -0
- package/src/boxes/webm/segments/duration.ts +15 -8
- package/src/boxes/webm/segments/info.ts +18 -4
- package/src/boxes/webm/segments/main.ts +0 -13
- package/src/boxes/webm/segments/muxing.ts +1 -1
- package/src/boxes/webm/segments/parse-children.ts +132 -9
- package/src/boxes/webm/segments/seek-head.ts +17 -4
- package/src/boxes/webm/segments/seek-position.ts +1 -2
- package/src/boxes/webm/segments/seek.ts +31 -9
- package/src/boxes/webm/segments/track-entry.ts +475 -65
- package/src/boxes/webm/segments/tracks.ts +17 -7
- package/src/boxes/webm/segments/void.ts +4 -2
- package/src/boxes/webm/segments/writing.ts +1 -1
- package/src/boxes/webm/segments.ts +266 -42
- package/src/boxes/webm/traversal.ts +32 -0
- package/src/buffer-iterator.ts +140 -45
- package/src/combine-uint8array.ts +13 -0
- package/src/{from-web.ts → from-fetch.ts} +9 -1
- package/src/from-node.ts +8 -0
- package/src/from-web-file.ts +39 -0
- package/src/get-audio-codec.ts +213 -84
- package/src/get-dimensions.ts +25 -132
- package/src/get-duration.ts +4 -8
- package/src/get-fps.ts +27 -172
- package/src/get-sample-aspect-ratio.ts +204 -0
- package/src/get-sample-positions.ts +93 -0
- package/src/get-tracks.ts +147 -0
- package/src/get-video-codec.ts +62 -47
- package/src/has-all-info.ts +35 -5
- package/src/index.ts +8 -0
- package/src/make-hvc1-codec-strings.ts +55 -0
- package/src/options.ts +48 -9
- package/src/parse-media.ts +90 -21
- package/src/parse-result.ts +28 -4
- package/src/parse-video.ts +30 -7
- package/src/parser-context.ts +9 -0
- package/src/parser-state.ts +151 -0
- package/src/reader.ts +2 -2
- package/src/test/aspect-ratio.test.ts +42 -0
- package/src/test/av1.test.ts +108 -0
- package/src/test/duration.test.ts +5 -21
- package/src/test/matroska.test.ts +350 -31
- package/src/test/mvhd.test.ts +6 -1
- package/src/test/parse-esds.test.ts +29 -6
- package/src/test/parse-stco.test.ts +59 -0
- package/src/test/parse-stsc.test.ts +104 -0
- package/src/test/parse-stsz.test.ts +57 -0
- package/src/test/parse-stts.test.ts +1 -1
- package/src/test/parse-video.test.ts +23 -35
- package/src/test/parse-webm.test.ts +5 -5
- package/src/test/stream-local.test.ts +542 -46
- package/src/test/stream-remote.test.ts +15 -13
- package/src/test/stream-samples.test.ts +259 -0
- package/src/test/stsd.test.ts +60 -8
- package/src/test/tkhd.test.ts +4 -1
- package/src/traversal.ts +496 -0
- package/src/webcodec-sample-types.ts +30 -0
- package/tsconfig.json +5 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/boxes.json +0 -1
- package/dist/boxes/iso-base-media/esds-descriptors.d.ts +0 -21
- package/dist/boxes/iso-base-media/esds-descriptors.js +0 -62
- package/dist/boxes/iso-base-media/esds.d.ts +0 -15
- package/dist/boxes/iso-base-media/esds.js +0 -27
- package/dist/get-codec.d.ts +0 -4
- package/dist/get-codec.js +0 -22
- /package/dist/{get-samples.d.ts → boxes/webm/bitstream/av1/frame.d.ts} +0 -0
- /package/dist/{get-samples.js → boxes/webm/bitstream/av1/frame.js} +0 -0
- /package/src/boxes/iso-base-media/{stts → stsd}/stts.ts +0 -0
package/dist/get-video-codec.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVideoCodec = exports.hasVideoCodec = void 0;
|
|
4
|
-
|
|
3
|
+
exports.getVideoCodec = exports.getVideoCodecString = exports.hasVideoCodec = void 0;
|
|
4
|
+
const av1_codec_private_1 = require("./boxes/webm/av1-codec-private");
|
|
5
5
|
const get_fps_1 = require("./get-fps");
|
|
6
|
+
const get_sample_aspect_ratio_1 = require("./get-sample-aspect-ratio");
|
|
7
|
+
const traversal_1 = require("./traversal");
|
|
6
8
|
const hasVideoCodec = (boxes) => {
|
|
7
9
|
try {
|
|
8
10
|
return (0, exports.getVideoCodec)(boxes) !== null;
|
|
@@ -12,36 +14,47 @@ const hasVideoCodec = (boxes) => {
|
|
|
12
14
|
}
|
|
13
15
|
};
|
|
14
16
|
exports.hasVideoCodec = hasVideoCodec;
|
|
17
|
+
const getVideoCodecString = (trakBox) => {
|
|
18
|
+
const videoSample = (0, get_sample_aspect_ratio_1.getVideoSample)(trakBox);
|
|
19
|
+
const avccBox = (0, get_sample_aspect_ratio_1.getAvccBox)(trakBox);
|
|
20
|
+
const hvccBox = (0, get_sample_aspect_ratio_1.getHvccBox)(trakBox);
|
|
21
|
+
const av1cBox = (0, get_sample_aspect_ratio_1.getAv1CBox)(trakBox);
|
|
22
|
+
if (!videoSample) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (avccBox) {
|
|
26
|
+
return `${videoSample.format}.${avccBox.configurationString}`;
|
|
27
|
+
}
|
|
28
|
+
if (hvccBox) {
|
|
29
|
+
return `${videoSample.format}.${hvccBox.configurationString}`;
|
|
30
|
+
}
|
|
31
|
+
if (av1cBox) {
|
|
32
|
+
const colrAtom = (0, get_sample_aspect_ratio_1.getColrBox)(videoSample);
|
|
33
|
+
return (0, av1_codec_private_1.parseAv1PrivateData)(av1cBox.privateData, colrAtom);
|
|
34
|
+
}
|
|
35
|
+
return videoSample.format;
|
|
36
|
+
};
|
|
37
|
+
exports.getVideoCodecString = getVideoCodecString;
|
|
15
38
|
const getVideoCodec = (boxes) => {
|
|
16
|
-
const moovBox =
|
|
17
|
-
if (moovBox
|
|
18
|
-
const trakBox = moovBox.
|
|
19
|
-
if (trakBox
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return 'h265';
|
|
36
|
-
}
|
|
37
|
-
if (videoSample.format === 'avc1') {
|
|
38
|
-
return 'h264';
|
|
39
|
-
}
|
|
40
|
-
if (videoSample.format === 'ap4h') {
|
|
41
|
-
return 'prores';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
39
|
+
const moovBox = (0, traversal_1.getMoovBox)(boxes);
|
|
40
|
+
if (moovBox) {
|
|
41
|
+
const trakBox = (0, traversal_1.getTraks)(moovBox).filter((t) => (0, get_fps_1.trakBoxContainsVideo)(t))[0];
|
|
42
|
+
if (trakBox) {
|
|
43
|
+
const stsdBox = (0, traversal_1.getStsdBox)(trakBox);
|
|
44
|
+
if (stsdBox && stsdBox.type === 'stsd-box') {
|
|
45
|
+
const videoSample = stsdBox.samples.find((s) => s.type === 'video');
|
|
46
|
+
if (videoSample && videoSample.type === 'video') {
|
|
47
|
+
if (videoSample.format === 'hvc1') {
|
|
48
|
+
return 'h265';
|
|
49
|
+
}
|
|
50
|
+
if (videoSample.format === 'avc1') {
|
|
51
|
+
return 'h264';
|
|
52
|
+
}
|
|
53
|
+
if (videoSample.format === 'av01') {
|
|
54
|
+
return 'av1';
|
|
55
|
+
}
|
|
56
|
+
if (videoSample.format === 'ap4h') {
|
|
57
|
+
return 'prores';
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
}
|
|
@@ -71,6 +84,9 @@ const getVideoCodec = (boxes) => {
|
|
|
71
84
|
if (trackType.codec === 'V_MPEG4/ISO/AVC') {
|
|
72
85
|
return 'h264';
|
|
73
86
|
}
|
|
87
|
+
if (trackType.codec === 'V_MPEGH/ISO/HEVC') {
|
|
88
|
+
return 'h265';
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
}
|
|
76
92
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMedia = void 0;
|
|
4
|
+
const buffer_iterator_1 = require("./buffer-iterator");
|
|
5
|
+
const from_web_1 = require("./from-web");
|
|
6
|
+
const get_dimensions_1 = require("./get-dimensions");
|
|
7
|
+
const get_duration_1 = require("./get-duration");
|
|
8
|
+
const get_fps_1 = require("./get-fps");
|
|
9
|
+
const has_all_info_1 = require("./has-all-info");
|
|
10
|
+
const parse_video_1 = require("./parse-video");
|
|
11
|
+
const parseMedia = async (src, options, readerInterface = from_web_1.webReader) => {
|
|
12
|
+
const reader = await readerInterface.read(src, null);
|
|
13
|
+
const returnValue = {};
|
|
14
|
+
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(new Uint8Array([]));
|
|
15
|
+
let parseResult = (0, parse_video_1.parseVideo)(iterator);
|
|
16
|
+
while (parseResult.status === 'incomplete') {
|
|
17
|
+
const result = await reader.read();
|
|
18
|
+
if (result.done) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
iterator.addData(result.value);
|
|
22
|
+
parseResult = parseResult.continueParsing();
|
|
23
|
+
if ((0, has_all_info_1.hasAllInfo)(options, parseResult)) {
|
|
24
|
+
if (!reader.closed) {
|
|
25
|
+
reader.cancel(new Error('has all information'));
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (options.dimensions) {
|
|
31
|
+
returnValue.dimensions = (0, get_dimensions_1.getDimensions)(parseResult.segments);
|
|
32
|
+
}
|
|
33
|
+
if (options.durationInSeconds) {
|
|
34
|
+
returnValue.durationInSeconds = (0, get_duration_1.getDuration)(parseResult.segments);
|
|
35
|
+
}
|
|
36
|
+
if (options.fps) {
|
|
37
|
+
returnValue.fps = (0, get_fps_1.getFps)(parseResult.segments);
|
|
38
|
+
}
|
|
39
|
+
if (options.boxes) {
|
|
40
|
+
returnValue.boxes = parseResult.segments;
|
|
41
|
+
}
|
|
42
|
+
return returnValue;
|
|
43
|
+
};
|
|
44
|
+
exports.parseMedia = parseMedia;
|
package/dist/has-all-info.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Options } from './options';
|
|
2
2
|
import type { ParseResult } from './parse-result';
|
|
3
|
-
|
|
3
|
+
import type { ParserState } from './parser-state';
|
|
4
|
+
export declare const hasAllInfo: (options: Options<boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean>, parseResult: ParseResult, state: ParserState) => boolean;
|
package/dist/has-all-info.js
CHANGED
|
@@ -5,8 +5,9 @@ const get_audio_codec_1 = require("./get-audio-codec");
|
|
|
5
5
|
const get_dimensions_1 = require("./get-dimensions");
|
|
6
6
|
const get_duration_1 = require("./get-duration");
|
|
7
7
|
const get_fps_1 = require("./get-fps");
|
|
8
|
+
const get_tracks_1 = require("./get-tracks");
|
|
8
9
|
const get_video_codec_1 = require("./get-video-codec");
|
|
9
|
-
const hasAllInfo = (options, parseResult) => {
|
|
10
|
+
const hasAllInfo = (options, parseResult, state) => {
|
|
10
11
|
const keys = Object.entries(options)
|
|
11
12
|
.filter(([, value]) => value)
|
|
12
13
|
.map(([key]) => key);
|
|
@@ -17,17 +18,25 @@ const hasAllInfo = (options, parseResult) => {
|
|
|
17
18
|
if (key === 'durationInSeconds') {
|
|
18
19
|
return (0, get_duration_1.hasDuration)(parseResult.segments);
|
|
19
20
|
}
|
|
20
|
-
if (key === 'dimensions'
|
|
21
|
-
|
|
21
|
+
if (key === 'dimensions' ||
|
|
22
|
+
key === 'rotation' ||
|
|
23
|
+
key === 'unrotatedDimension') {
|
|
24
|
+
return (0, get_dimensions_1.hasDimensions)(parseResult.segments, state);
|
|
22
25
|
}
|
|
23
26
|
if (key === 'fps') {
|
|
24
27
|
return (0, get_fps_1.hasFps)(parseResult.segments) !== null;
|
|
25
28
|
}
|
|
26
29
|
if (key === 'videoCodec') {
|
|
27
|
-
return (0, get_video_codec_1.hasVideoCodec)(parseResult.segments)
|
|
30
|
+
return (0, get_video_codec_1.hasVideoCodec)(parseResult.segments);
|
|
28
31
|
}
|
|
29
32
|
if (key === 'audioCodec') {
|
|
30
|
-
return (0, get_audio_codec_1.hasAudioCodec)(parseResult.segments)
|
|
33
|
+
return (0, get_audio_codec_1.hasAudioCodec)(parseResult.segments);
|
|
34
|
+
}
|
|
35
|
+
if (key === 'tracks') {
|
|
36
|
+
return (0, get_tracks_1.hasTracks)(parseResult.segments);
|
|
37
|
+
}
|
|
38
|
+
if (key === 'internalStats') {
|
|
39
|
+
return false;
|
|
31
40
|
}
|
|
32
41
|
throw new Error(`Unknown key: ${key}`);
|
|
33
42
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHvc1CodecString = void 0;
|
|
4
|
+
const getHvc1CodecString = (data) => {
|
|
5
|
+
const configurationVersion = data.getUint8();
|
|
6
|
+
if (configurationVersion !== 1) {
|
|
7
|
+
throw new Error(`Unsupported HVCC version ${configurationVersion}`);
|
|
8
|
+
}
|
|
9
|
+
const generalProfileSpaceTierFlagAndIdc = data.getUint8();
|
|
10
|
+
let generalProfileCompatibility = data.getUint32();
|
|
11
|
+
// unsigned int(2) general_profile_space;
|
|
12
|
+
// unsigned int(1) general_tier_flag;
|
|
13
|
+
// unsigned int(5) general_profile_idc;
|
|
14
|
+
const generalProfileSpace = generalProfileSpaceTierFlagAndIdc >> 6;
|
|
15
|
+
const generalTierFlag = generalProfileSpaceTierFlagAndIdc >> 5;
|
|
16
|
+
const generalProfileIdc = generalProfileSpaceTierFlagAndIdc >> 0;
|
|
17
|
+
// general_constraint_indicator_flags(48)
|
|
18
|
+
const generalConstraintIndicator = data.getSlice(6);
|
|
19
|
+
const generalLevelIdc = data.getUint8();
|
|
20
|
+
let reversedGeneralProfileSpace = 0;
|
|
21
|
+
for (let i = 0; i < 32; i++) {
|
|
22
|
+
reversedGeneralProfileSpace |= generalProfileCompatibility & 1;
|
|
23
|
+
if (i === 31)
|
|
24
|
+
break;
|
|
25
|
+
reversedGeneralProfileSpace <<= 1;
|
|
26
|
+
generalProfileCompatibility >>= 1;
|
|
27
|
+
}
|
|
28
|
+
const profileSpaceChar = generalProfileSpace === 0
|
|
29
|
+
? ''
|
|
30
|
+
: generalProfileSpace === 1
|
|
31
|
+
? 'A'
|
|
32
|
+
: generalProfileSpace === 2
|
|
33
|
+
? 'B'
|
|
34
|
+
: 'C';
|
|
35
|
+
const generalTierChar = generalTierFlag === 0 ? 'L' : 'H';
|
|
36
|
+
let hasByte = false;
|
|
37
|
+
let generalConstraintString = '';
|
|
38
|
+
for (let i = 5; i >= 0; i--) {
|
|
39
|
+
if (generalConstraintIndicator[i] || hasByte) {
|
|
40
|
+
generalConstraintString =
|
|
41
|
+
generalConstraintIndicator[i].toString(16) + generalConstraintString;
|
|
42
|
+
hasByte = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return `${profileSpaceChar}${generalProfileIdc.toString(16)}.${reversedGeneralProfileSpace.toString(16)}.${generalTierChar}${generalLevelIdc}.${generalConstraintString}`;
|
|
46
|
+
};
|
|
47
|
+
exports.getHvc1CodecString = getHvc1CodecString;
|
package/dist/options.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import type { Dimensions } from './get-dimensions';
|
|
2
|
+
import type { AudioTrack, VideoTrack } from './get-tracks';
|
|
2
3
|
import type { AnySegment } from './parse-result';
|
|
4
|
+
import type { InternalStats } from './parser-state';
|
|
3
5
|
import type { ReaderInterface } from './reader';
|
|
6
|
+
import type { OnAudioTrack, OnVideoTrack } from './webcodec-sample-types';
|
|
4
7
|
export type KnownVideoCodecs = 'h264' | 'h265' | 'vp8' | 'vp9' | 'av1' | 'prores';
|
|
5
|
-
export type KnownAudioCodecs = 'aac' | 'mp3' | 'aiff' | 'opus' | 'pcm' | 'unknown';
|
|
6
|
-
export type Options<EnableDimensions extends boolean, EnableDuration extends boolean, EnableBoxes extends boolean, EnableFps extends boolean, EnableVideoCodec extends boolean, EnableAudioCodec extends boolean> = {
|
|
8
|
+
export type KnownAudioCodecs = 'aac' | 'mp3' | 'aiff' | 'opus' | 'pcm' | 'vorbis' | 'unknown';
|
|
9
|
+
export type Options<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> = {
|
|
7
10
|
dimensions?: EnableDimensions;
|
|
8
11
|
durationInSeconds?: EnableDuration;
|
|
9
12
|
boxes?: EnableBoxes;
|
|
10
13
|
fps?: EnableFps;
|
|
11
14
|
videoCodec?: EnableVideoCodec;
|
|
12
15
|
audioCodec?: EnableAudioCodec;
|
|
16
|
+
tracks?: EnableTracks;
|
|
17
|
+
rotation?: EnableRotation;
|
|
18
|
+
unrotatedDimension?: EnableUnrotatedDimensions;
|
|
19
|
+
internalStats?: EnableInternalStats;
|
|
13
20
|
};
|
|
14
|
-
export type Metadata<EnableDimensions extends boolean, EnableDuration extends boolean, EnableBoxes extends boolean, EnableFps extends boolean, EnableVideoCodec extends boolean, EnableAudioCodec extends boolean> = (EnableDimensions extends true ? {
|
|
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 ? {
|
|
15
22
|
dimensions: Dimensions;
|
|
16
23
|
} : {}) & (EnableDuration extends true ? {
|
|
17
24
|
durationInSeconds: number | null;
|
|
@@ -23,5 +30,20 @@ export type Metadata<EnableDimensions extends boolean, EnableDuration extends bo
|
|
|
23
30
|
videoCodec: KnownVideoCodecs | null;
|
|
24
31
|
} : {}) & (EnableAudioCodec extends true ? {
|
|
25
32
|
audioCodec: KnownAudioCodecs | null;
|
|
33
|
+
} : {}) & (EnableTracks extends true ? {
|
|
34
|
+
videoTracks: VideoTrack[];
|
|
35
|
+
audioTracks: AudioTrack[];
|
|
36
|
+
} : {}) & (EnableRotation extends true ? {
|
|
37
|
+
rotation: number | null;
|
|
38
|
+
} : {}) & (EnableUnrotatedDimensions extends true ? {
|
|
39
|
+
unrotatedDimension: Dimensions;
|
|
40
|
+
} : {}) & (EnableInternalStats extends true ? {
|
|
41
|
+
internalStats: InternalStats;
|
|
26
42
|
} : {});
|
|
27
|
-
export type ParseMedia = <EnableDimensions extends boolean, EnableDuration extends boolean, EnableBoxes extends boolean, EnableFps extends boolean, EnableVideoCodec extends boolean, EnableAudioCodec extends boolean
|
|
43
|
+
export type ParseMedia = <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>(options: {
|
|
44
|
+
src: string | File;
|
|
45
|
+
fields?: Options<EnableDimensions, EnableDuration, EnableBoxes, EnableFps, EnableVideoCodec, EnableAudioCodec, EnableTracks, EnableRotation, EnableUnrotatedDimensions, EnableInternalStats>;
|
|
46
|
+
reader?: ReaderInterface;
|
|
47
|
+
onAudioTrack?: OnAudioTrack;
|
|
48
|
+
onVideoTrack?: OnVideoTrack;
|
|
49
|
+
}) => Promise<Metadata<EnableDimensions, EnableDuration, EnableBoxes, EnableFps, EnableVideoCodec, EnableAudioCodec, EnableTracks, EnableRotation, EnableUnrotatedDimensions, EnableInternalStats>>;
|
package/dist/parse-media.js
CHANGED
|
@@ -2,38 +2,59 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMedia = void 0;
|
|
4
4
|
const buffer_iterator_1 = require("./buffer-iterator");
|
|
5
|
-
const
|
|
5
|
+
const from_fetch_1 = require("./from-fetch");
|
|
6
6
|
const get_audio_codec_1 = require("./get-audio-codec");
|
|
7
7
|
const get_dimensions_1 = require("./get-dimensions");
|
|
8
8
|
const get_duration_1 = require("./get-duration");
|
|
9
9
|
const get_fps_1 = require("./get-fps");
|
|
10
|
+
const get_tracks_1 = require("./get-tracks");
|
|
10
11
|
const get_video_codec_1 = require("./get-video-codec");
|
|
11
12
|
const has_all_info_1 = require("./has-all-info");
|
|
12
13
|
const parse_video_1 = require("./parse-video");
|
|
13
|
-
const
|
|
14
|
+
const parser_state_1 = require("./parser-state");
|
|
15
|
+
const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.fetchReader, onAudioTrack, onVideoTrack, }) => {
|
|
14
16
|
const { reader, contentLength } = await readerInterface.read(src, null);
|
|
15
17
|
let currentReader = reader;
|
|
16
18
|
const returnValue = {};
|
|
17
19
|
let iterator = null;
|
|
18
20
|
let parseResult = null;
|
|
21
|
+
const state = (0, parser_state_1.makeParserState)({
|
|
22
|
+
hasAudioCallbacks: onAudioTrack !== null,
|
|
23
|
+
hasVideoCallbacks: onVideoTrack !== null,
|
|
24
|
+
});
|
|
25
|
+
const options = {
|
|
26
|
+
canSkipVideoData: !(onAudioTrack || onVideoTrack),
|
|
27
|
+
onAudioTrack: onAudioTrack !== null && onAudioTrack !== void 0 ? onAudioTrack : null,
|
|
28
|
+
onVideoTrack: onVideoTrack !== null && onVideoTrack !== void 0 ? onVideoTrack : null,
|
|
29
|
+
parserState: state,
|
|
30
|
+
};
|
|
19
31
|
while (parseResult === null || parseResult.status === 'incomplete') {
|
|
20
32
|
const result = await currentReader.read();
|
|
21
|
-
if (result.done) {
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
33
|
if (iterator) {
|
|
25
|
-
|
|
34
|
+
if (!result.done) {
|
|
35
|
+
iterator.addData(result.value);
|
|
36
|
+
}
|
|
26
37
|
}
|
|
27
38
|
else {
|
|
39
|
+
if (result.done) {
|
|
40
|
+
throw new Error('Unexpectedly reached EOF');
|
|
41
|
+
}
|
|
28
42
|
iterator = (0, buffer_iterator_1.getArrayBufferIterator)(result.value, contentLength !== null && contentLength !== void 0 ? contentLength : undefined);
|
|
29
43
|
}
|
|
30
|
-
if (parseResult) {
|
|
31
|
-
parseResult = parseResult.continueParsing();
|
|
44
|
+
if (parseResult && parseResult.status === 'incomplete') {
|
|
45
|
+
parseResult = await parseResult.continueParsing();
|
|
32
46
|
}
|
|
33
47
|
else {
|
|
34
|
-
parseResult = (0, parse_video_1.parseVideo)(
|
|
48
|
+
parseResult = await (0, parse_video_1.parseVideo)({
|
|
49
|
+
iterator,
|
|
50
|
+
options,
|
|
51
|
+
});
|
|
35
52
|
}
|
|
36
|
-
if
|
|
53
|
+
// TODO Better: Check if no active listeners are registered
|
|
54
|
+
// Also maybe check for canSkipVideoData
|
|
55
|
+
if ((0, has_all_info_1.hasAllInfo)(fields !== null && fields !== void 0 ? fields : {}, parseResult, state) &&
|
|
56
|
+
!onVideoTrack &&
|
|
57
|
+
!onAudioTrack) {
|
|
37
58
|
if (!currentReader.closed) {
|
|
38
59
|
currentReader.cancel(new Error('has all information'));
|
|
39
60
|
}
|
|
@@ -53,24 +74,48 @@ const parseMedia = async (src, options, readerInterface = from_web_1.webReader)
|
|
|
53
74
|
if (!parseResult) {
|
|
54
75
|
throw new Error('Could not parse video');
|
|
55
76
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
77
|
+
if (fields === null || fields === void 0 ? void 0 : fields.dimensions) {
|
|
78
|
+
const dimensions = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
79
|
+
returnValue.dimensions = {
|
|
80
|
+
width: dimensions.width,
|
|
81
|
+
height: dimensions.height,
|
|
82
|
+
};
|
|
58
83
|
}
|
|
59
|
-
if (
|
|
84
|
+
if (fields === null || fields === void 0 ? void 0 : fields.unrotatedDimension) {
|
|
85
|
+
const dimensions = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
86
|
+
returnValue.unrotatedDimension = {
|
|
87
|
+
width: dimensions.unrotatedWidth,
|
|
88
|
+
height: dimensions.unrotatedHeight,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (fields === null || fields === void 0 ? void 0 : fields.rotation) {
|
|
92
|
+
const dimensions = (0, get_dimensions_1.getDimensions)(parseResult.segments, state);
|
|
93
|
+
returnValue.rotation = dimensions.rotation;
|
|
94
|
+
}
|
|
95
|
+
if (fields === null || fields === void 0 ? void 0 : fields.durationInSeconds) {
|
|
60
96
|
returnValue.durationInSeconds = (0, get_duration_1.getDuration)(parseResult.segments);
|
|
61
97
|
}
|
|
62
|
-
if (
|
|
98
|
+
if (fields === null || fields === void 0 ? void 0 : fields.fps) {
|
|
63
99
|
returnValue.fps = (0, get_fps_1.getFps)(parseResult.segments);
|
|
64
100
|
}
|
|
65
|
-
if (
|
|
101
|
+
if (fields === null || fields === void 0 ? void 0 : fields.videoCodec) {
|
|
66
102
|
returnValue.videoCodec = (0, get_video_codec_1.getVideoCodec)(parseResult.segments);
|
|
67
103
|
}
|
|
68
|
-
if (
|
|
104
|
+
if (fields === null || fields === void 0 ? void 0 : fields.audioCodec) {
|
|
69
105
|
returnValue.audioCodec = (0, get_audio_codec_1.getAudioCodec)(parseResult.segments);
|
|
70
106
|
}
|
|
71
|
-
if (
|
|
107
|
+
if (fields === null || fields === void 0 ? void 0 : fields.tracks) {
|
|
108
|
+
const { audioTracks, videoTracks } = (0, get_tracks_1.getTracks)(parseResult.segments, state);
|
|
109
|
+
returnValue.audioTracks = audioTracks;
|
|
110
|
+
returnValue.videoTracks = videoTracks;
|
|
111
|
+
}
|
|
112
|
+
if (fields === null || fields === void 0 ? void 0 : fields.boxes) {
|
|
72
113
|
returnValue.boxes = parseResult.segments;
|
|
73
114
|
}
|
|
115
|
+
if (fields === null || fields === void 0 ? void 0 : fields.internalStats) {
|
|
116
|
+
returnValue.internalStats = state.getInternalStats();
|
|
117
|
+
}
|
|
118
|
+
iterator === null || iterator === void 0 ? void 0 : iterator.destroy();
|
|
74
119
|
return returnValue;
|
|
75
120
|
};
|
|
76
121
|
exports.parseMedia = parseMedia;
|
package/dist/parse-result.d.ts
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
import type { BaseBox } from './boxes/iso-base-media/base-type';
|
|
2
2
|
import type { EsdsBox } from './boxes/iso-base-media/esds/esds';
|
|
3
3
|
import type { FtypBox } from './boxes/iso-base-media/ftyp';
|
|
4
|
+
import type { MdatBox } from './boxes/iso-base-media/mdat/mdat';
|
|
4
5
|
import type { MdhdBox } from './boxes/iso-base-media/mdhd';
|
|
5
6
|
import type { MoovBox } from './boxes/iso-base-media/moov/moov';
|
|
6
7
|
import type { MvhdBox } from './boxes/iso-base-media/mvhd';
|
|
8
|
+
import type { Av1CBox } from './boxes/iso-base-media/stsd/av1c';
|
|
9
|
+
import type { AvccBox } from './boxes/iso-base-media/stsd/avcc';
|
|
10
|
+
import type { ColorParameterBox } from './boxes/iso-base-media/stsd/colr';
|
|
11
|
+
import type { CttsBox } from './boxes/iso-base-media/stsd/ctts';
|
|
12
|
+
import type { HvccBox } from './boxes/iso-base-media/stsd/hvcc';
|
|
7
13
|
import type { KeysBox } from './boxes/iso-base-media/stsd/keys';
|
|
8
14
|
import type { MebxBox } from './boxes/iso-base-media/stsd/mebx';
|
|
15
|
+
import type { PaspBox } from './boxes/iso-base-media/stsd/pasp';
|
|
16
|
+
import type { StcoBox } from './boxes/iso-base-media/stsd/stco';
|
|
17
|
+
import type { StscBox } from './boxes/iso-base-media/stsd/stsc';
|
|
9
18
|
import type { StsdBox } from './boxes/iso-base-media/stsd/stsd';
|
|
10
|
-
import type {
|
|
19
|
+
import type { StssBox } from './boxes/iso-base-media/stsd/stss';
|
|
20
|
+
import type { StszBox } from './boxes/iso-base-media/stsd/stsz';
|
|
21
|
+
import type { SttsBox } from './boxes/iso-base-media/stsd/stts';
|
|
11
22
|
import type { TkhdBox } from './boxes/iso-base-media/tkhd';
|
|
12
23
|
import type { TrakBox } from './boxes/iso-base-media/trak/trak';
|
|
24
|
+
import type { VoidBox } from './boxes/iso-base-media/void-box';
|
|
13
25
|
import type { MatroskaSegment } from './boxes/webm/segments';
|
|
14
|
-
interface RegularBox extends BaseBox {
|
|
26
|
+
export interface RegularBox extends BaseBox {
|
|
15
27
|
boxType: string;
|
|
16
28
|
boxSize: number;
|
|
17
29
|
children: AnySegment[];
|
|
18
30
|
offset: number;
|
|
19
31
|
type: 'regular-box';
|
|
20
32
|
}
|
|
21
|
-
export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | EsdsBox;
|
|
33
|
+
export type IsoBaseMediaBox = RegularBox | FtypBox | MvhdBox | TkhdBox | StsdBox | MebxBox | KeysBox | MoovBox | TrakBox | SttsBox | MdhdBox | EsdsBox | MdatBox | StszBox | StcoBox | StscBox | AvccBox | HvccBox | VoidBox | StssBox | PaspBox | CttsBox | Av1CBox | ColorParameterBox;
|
|
22
34
|
export type AnySegment = MatroskaSegment | IsoBaseMediaBox;
|
|
23
35
|
export type ParseResult = {
|
|
24
36
|
status: 'done';
|
|
@@ -27,6 +39,5 @@ export type ParseResult = {
|
|
|
27
39
|
status: 'incomplete';
|
|
28
40
|
segments: AnySegment[];
|
|
29
41
|
skipTo: number | null;
|
|
30
|
-
continueParsing: () => ParseResult
|
|
42
|
+
continueParsing: () => Promise<ParseResult>;
|
|
31
43
|
};
|
|
32
|
-
export {};
|
package/dist/parse-video.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { BufferIterator } from './buffer-iterator';
|
|
2
2
|
import type { IsoBaseMediaBox, ParseResult } from './parse-result';
|
|
3
|
+
import type { ParserContext } from './parser-context';
|
|
4
|
+
export type PartialMdatBox = {
|
|
5
|
+
type: 'partial-mdat-box';
|
|
6
|
+
boxSize: number;
|
|
7
|
+
fileOffset: number;
|
|
8
|
+
};
|
|
3
9
|
export type BoxAndNext = {
|
|
4
10
|
type: 'complete';
|
|
5
11
|
box: IsoBaseMediaBox;
|
|
@@ -7,5 +13,8 @@ export type BoxAndNext = {
|
|
|
7
13
|
skipTo: number | null;
|
|
8
14
|
} | {
|
|
9
15
|
type: 'incomplete';
|
|
10
|
-
};
|
|
11
|
-
export declare const parseVideo: (iterator
|
|
16
|
+
} | PartialMdatBox;
|
|
17
|
+
export declare const parseVideo: ({ iterator, options, }: {
|
|
18
|
+
iterator: BufferIterator;
|
|
19
|
+
options: ParserContext;
|
|
20
|
+
}) => Promise<ParseResult>;
|
package/dist/parse-video.js
CHANGED
|
@@ -3,16 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseVideo = void 0;
|
|
4
4
|
const process_box_1 = require("./boxes/iso-base-media/process-box");
|
|
5
5
|
const parse_webm_header_1 = require("./boxes/webm/parse-webm-header");
|
|
6
|
-
const parseVideo = (iterator) => {
|
|
6
|
+
const parseVideo = ({ iterator, options, }) => {
|
|
7
7
|
if (iterator.bytesRemaining() === 0) {
|
|
8
|
-
return {
|
|
8
|
+
return Promise.resolve({
|
|
9
9
|
status: 'incomplete',
|
|
10
10
|
segments: [],
|
|
11
11
|
continueParsing: () => {
|
|
12
|
-
return (0, exports.parseVideo)(
|
|
12
|
+
return (0, exports.parseVideo)({
|
|
13
|
+
iterator,
|
|
14
|
+
options,
|
|
15
|
+
});
|
|
13
16
|
},
|
|
14
17
|
skipTo: null,
|
|
15
|
-
};
|
|
18
|
+
});
|
|
16
19
|
}
|
|
17
20
|
if (iterator.isIsoBaseMedia()) {
|
|
18
21
|
return (0, process_box_1.parseBoxes)({
|
|
@@ -20,11 +23,16 @@ const parseVideo = (iterator) => {
|
|
|
20
23
|
maxBytes: Infinity,
|
|
21
24
|
allowIncompleteBoxes: true,
|
|
22
25
|
initialBoxes: [],
|
|
26
|
+
options,
|
|
27
|
+
continueMdat: false,
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
30
|
if (iterator.isWebm()) {
|
|
26
|
-
return (0, parse_webm_header_1.parseWebm)(iterator);
|
|
31
|
+
return Promise.resolve((0, parse_webm_header_1.parseWebm)(iterator, options));
|
|
32
|
+
}
|
|
33
|
+
if (iterator.isMp3()) {
|
|
34
|
+
return Promise.reject(new Error('MP3 files are not yet supported'));
|
|
27
35
|
}
|
|
28
|
-
|
|
36
|
+
return Promise.reject(new Error('Unknown video format'));
|
|
29
37
|
};
|
|
30
38
|
exports.parseVideo = parseVideo;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ParserState } from './parser-state';
|
|
2
|
+
import type { OnAudioTrack, OnVideoTrack } from './webcodec-sample-types';
|
|
3
|
+
export type ParserContext = {
|
|
4
|
+
onAudioTrack: OnAudioTrack | null;
|
|
5
|
+
onVideoTrack: OnVideoTrack | null;
|
|
6
|
+
canSkipVideoData: boolean;
|
|
7
|
+
parserState: ParserState;
|
|
8
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OnTrackEntrySegment } from './boxes/webm/segments';
|
|
2
|
+
import type { CodecSegment } from './boxes/webm/segments/track-entry';
|
|
3
|
+
import type { AudioSample, OnAudioSample, OnVideoSample, VideoSample } from './webcodec-sample-types';
|
|
4
|
+
export type InternalStats = {
|
|
5
|
+
samplesThatHadToBeQueued: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const makeParserState: ({ hasAudioCallbacks, hasVideoCallbacks, }: {
|
|
8
|
+
hasAudioCallbacks: boolean;
|
|
9
|
+
hasVideoCallbacks: boolean;
|
|
10
|
+
}) => {
|
|
11
|
+
onTrackEntrySegment: OnTrackEntrySegment;
|
|
12
|
+
getTrackInfoByNumber: (id: number) => CodecSegment;
|
|
13
|
+
registerVideoSampleCallback: (id: number, callback: OnVideoSample | null) => Promise<void>;
|
|
14
|
+
registerAudioSampleCallback: (id: number, callback: OnAudioSample | null) => Promise<void>;
|
|
15
|
+
onAudioSample: (trackId: number, audioSample: AudioSample) => Promise<void>;
|
|
16
|
+
onVideoSample: (trackId: number, videoSample: VideoSample) => Promise<void>;
|
|
17
|
+
getInternalStats: () => {
|
|
18
|
+
samplesThatHadToBeQueued: number;
|
|
19
|
+
};
|
|
20
|
+
getTimescale: () => number;
|
|
21
|
+
setTimescale: (newTimescale: number) => void;
|
|
22
|
+
};
|
|
23
|
+
export type ParserState = ReturnType<typeof makeParserState>;
|