@remotion/media-parser 4.0.201 → 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/boxes/iso-base-media/mvhd.js +2 -2
- package/dist/boxes/iso-base-media/stsd/keys.js +1 -1
- package/dist/boxes/webm/av1-codec-private.js +1 -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 -8
- package/dist/boxes/webm/make-header.js +43 -20
- package/dist/boxes/webm/parse-ebml.d.ts +9 -4
- package/dist/boxes/webm/parse-ebml.js +122 -13
- package/dist/boxes/webm/segments/all-segments.d.ts +421 -107
- package/dist/boxes/webm/segments/all-segments.js +260 -33
- package/dist/boxes/webm/segments/seek-position.js +1 -1
- package/dist/boxes/webm/segments/seek.d.ts +1 -1
- package/dist/boxes/webm/segments/seek.js +2 -8
- package/dist/boxes/webm/segments/timestamp-scale.js +1 -1
- package/dist/boxes/webm/segments/track-entry.d.ts +3 -191
- package/dist/boxes/webm/segments/track-entry.js +2 -456
- package/dist/boxes/webm/segments.d.ts +3 -16
- package/dist/boxes/webm/segments.js +12 -196
- package/dist/boxes/webm/traversal.d.ts +5 -6
- package/dist/boxes/webm/traversal.js +6 -6
- package/dist/buffer-iterator.d.ts +1 -1
- package/dist/buffer-iterator.js +3 -3
- 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/get-audio-codec.d.ts +1 -1
- package/dist/get-audio-codec.js +13 -13
- package/dist/get-duration.js +12 -14
- package/dist/get-tracks.js +2 -2
- package/dist/get-video-codec.js +13 -13
- package/dist/parse-media.js +4 -1
- package/dist/parser-context.d.ts +1 -0
- package/dist/parser-state.js +3 -2
- 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/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/mvhd.ts +2 -2
- package/src/boxes/iso-base-media/stsd/keys.ts +1 -1
- 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 +58 -51
- package/src/boxes/webm/parse-ebml.ts +170 -16
- package/src/boxes/webm/segments/all-segments.ts +379 -62
- package/src/boxes/webm/segments/track-entry.ts +3 -846
- package/src/boxes/webm/segments.ts +18 -410
- package/src/boxes/webm/traversal.ts +17 -17
- package/src/buffer-iterator.ts +5 -4
- package/src/get-audio-codec.ts +14 -16
- package/src/get-duration.ts +15 -16
- package/src/get-tracks.ts +2 -2
- package/src/get-video-codec.ts +13 -15
- package/src/parse-media.ts +6 -1
- package/src/parser-context.ts +1 -0
- package/src/parser-state.ts +2 -2
- package/src/test/create-matroska.test.ts +237 -23
- package/src/test/matroska.test.ts +283 -348
- package/src/test/mvhd.test.ts +1 -1
- package/src/test/parse-esds.test.ts +2 -2
- package/src/test/parse-stco.test.ts +2 -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/stsd.test.ts +4 -2
- package/src/test/tkhd.test.ts +1 -1
- package/src/traversal.ts +62 -85
- package/tsconfig.tsbuildinfo +1 -1
- 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 -55
- package/src/boxes/webm/segments/timestamp-scale.ts +0 -17
- package/src/boxes/webm/segments/tracks.ts +0 -32
- 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
|
@@ -19,13 +19,13 @@ const parseMvhd = ({ iterator, offset, size, }) => {
|
|
|
19
19
|
const durationInUnits = iterator.getUint32();
|
|
20
20
|
const durationInSeconds = durationInUnits / timeScale;
|
|
21
21
|
const rateArray = iterator.getSlice(4);
|
|
22
|
-
const rateView = (0, buffer_iterator_1.getArrayBufferIterator)(rateArray);
|
|
22
|
+
const rateView = (0, buffer_iterator_1.getArrayBufferIterator)(rateArray, rateArray.length);
|
|
23
23
|
const rate = rateView.getInt8() * 10 +
|
|
24
24
|
rateView.getInt8() +
|
|
25
25
|
rateView.getInt8() * 0.1 +
|
|
26
26
|
rateView.getInt8() * 0.01;
|
|
27
27
|
const volumeArray = iterator.getSlice(2);
|
|
28
|
-
const volumeView = (0, buffer_iterator_1.getArrayBufferIterator)(volumeArray);
|
|
28
|
+
const volumeView = (0, buffer_iterator_1.getArrayBufferIterator)(volumeArray, volumeArray.length);
|
|
29
29
|
const volume = volumeView.getInt8() + volumeView.getInt8() * 0.1;
|
|
30
30
|
// reserved 16bit
|
|
31
31
|
iterator.discard(2);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseKeys = void 0;
|
|
4
4
|
const buffer_iterator_1 = require("../../../buffer-iterator");
|
|
5
5
|
const parseKeys = (data, offset) => {
|
|
6
|
-
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data);
|
|
6
|
+
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data, data.byteLength);
|
|
7
7
|
const size = iterator.getUint32();
|
|
8
8
|
if (size !== data.byteLength) {
|
|
9
9
|
throw new Error(`Expected keys size of ${data.byteLength}, got ${size}`);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseAv1PrivateData = void 0;
|
|
4
4
|
const buffer_iterator_1 = require("../../buffer-iterator");
|
|
5
5
|
const parseAv1PrivateData = (data, colrAtom) => {
|
|
6
|
-
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data);
|
|
6
|
+
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data, data.byteLength);
|
|
7
7
|
iterator.startReadingBits();
|
|
8
8
|
if (iterator.getBits(1) !== 1) {
|
|
9
9
|
iterator.destroy();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const getAudioDescription: (track:
|
|
1
|
+
import type { TrackEntry } from './segments/all-segments';
|
|
2
|
+
export declare const getAudioDescription: (track: TrackEntry) => undefined | Uint8Array;
|
|
@@ -5,7 +5,7 @@ const buffer_iterator_1 = require("../../buffer-iterator");
|
|
|
5
5
|
const traversal_1 = require("../../traversal");
|
|
6
6
|
const getAudioDescription = (track) => {
|
|
7
7
|
const codec = (0, traversal_1.getCodecSegment)(track);
|
|
8
|
-
if (!codec || codec.
|
|
8
|
+
if (!codec || codec.value !== 'A_VORBIS') {
|
|
9
9
|
return undefined;
|
|
10
10
|
}
|
|
11
11
|
// how to parse vorbis private
|
|
@@ -44,7 +44,7 @@ const getAudioDescription = (track) => {
|
|
|
44
44
|
throw new Error('Error parsing vorbis codec private');
|
|
45
45
|
}
|
|
46
46
|
const vorbisBooks = privateData.slice(offset);
|
|
47
|
-
const bufferIterator = (0, buffer_iterator_1.getArrayBufferIterator)(vorbisInfo.slice(0));
|
|
47
|
+
const bufferIterator = (0, buffer_iterator_1.getArrayBufferIterator)(vorbisInfo.slice(0), vorbisInfo.length);
|
|
48
48
|
// type
|
|
49
49
|
bufferIterator.getUint8();
|
|
50
50
|
// vorbis
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const measureEBMLVarInt: (value: number) =>
|
|
2
|
-
export declare const getVariableInt: (value: number,
|
|
1
|
+
export declare const measureEBMLVarInt: (value: number) => 4 | 6 | 1 | 5 | 3 | 2;
|
|
2
|
+
export declare const getVariableInt: (value: number, minWidth: number | null) => Uint8Array;
|
package/dist/boxes/webm/ebml.js
CHANGED
|
@@ -28,7 +28,8 @@ const measureEBMLVarInt = (value) => {
|
|
|
28
28
|
throw new Error('EBML VINT size not supported ' + value);
|
|
29
29
|
};
|
|
30
30
|
exports.measureEBMLVarInt = measureEBMLVarInt;
|
|
31
|
-
const getVariableInt = (value,
|
|
31
|
+
const getVariableInt = (value, minWidth) => {
|
|
32
|
+
const width = Math.max((0, exports.measureEBMLVarInt)(value), minWidth !== null && minWidth !== void 0 ? minWidth : 0);
|
|
32
33
|
switch (width) {
|
|
33
34
|
case 1:
|
|
34
35
|
return new Uint8Array([(1 << 7) | value]);
|
|
@@ -65,6 +66,27 @@ const getVariableInt = (value, width = (0, exports.measureEBMLVarInt)(value)) =>
|
|
|
65
66
|
value >> 8,
|
|
66
67
|
value,
|
|
67
68
|
]);
|
|
69
|
+
case 7:
|
|
70
|
+
return new Uint8Array([
|
|
71
|
+
(1 << 1) | ((value / 2 ** 48) & 0x1),
|
|
72
|
+
(value / 2 ** 40) | 0,
|
|
73
|
+
(value / 2 ** 32) | 0,
|
|
74
|
+
value >> 24,
|
|
75
|
+
value >> 16,
|
|
76
|
+
value >> 8,
|
|
77
|
+
value,
|
|
78
|
+
]);
|
|
79
|
+
case 8:
|
|
80
|
+
return new Uint8Array([
|
|
81
|
+
(1 << 0) | ((value / 2 ** 56) & 0x1),
|
|
82
|
+
(value / 2 ** 48) | 0,
|
|
83
|
+
(value / 2 ** 40) | 0,
|
|
84
|
+
(value / 2 ** 32) | 0,
|
|
85
|
+
value >> 24,
|
|
86
|
+
value >> 16,
|
|
87
|
+
value >> 8,
|
|
88
|
+
value,
|
|
89
|
+
]);
|
|
68
90
|
default:
|
|
69
91
|
throw new Error('Bad EBML VINT size ' + width);
|
|
70
92
|
}
|
|
@@ -9,11 +9,11 @@ const getTracksFromMatroska = (segment, timescale) => {
|
|
|
9
9
|
throw new Error('No tracks segment');
|
|
10
10
|
}
|
|
11
11
|
const tracks = [];
|
|
12
|
-
for (const trackEntrySegment of tracksSegment.
|
|
13
|
-
if (trackEntrySegment.type === '
|
|
12
|
+
for (const trackEntrySegment of tracksSegment.value) {
|
|
13
|
+
if (trackEntrySegment.type === 'Crc32') {
|
|
14
14
|
continue;
|
|
15
15
|
}
|
|
16
|
-
if (trackEntrySegment.type !== '
|
|
16
|
+
if (trackEntrySegment.type !== 'TrackEntry') {
|
|
17
17
|
throw new Error('Expected track entry segment');
|
|
18
18
|
}
|
|
19
19
|
const track = (0, get_track_1.getTrack)({
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ParserContext } from '../../parser-context';
|
|
2
|
+
import type { AudioSample, VideoSample } from '../../webcodec-sample-types';
|
|
3
|
+
import type { BlockSegment, SimpleBlockSegment } from './segments/all-segments';
|
|
4
|
+
type SampleResult = {
|
|
5
|
+
type: 'video-sample';
|
|
6
|
+
videoSample: VideoSample;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'audio-sample';
|
|
9
|
+
audioSample: AudioSample;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'partial-video-sample';
|
|
12
|
+
partialVideoSample: Omit<VideoSample, 'type'>;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'no-sample';
|
|
15
|
+
};
|
|
16
|
+
export declare const getSampleFromBlock: (ebml: BlockSegment | SimpleBlockSegment, parserContext: ParserContext, offset: number) => SampleResult;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSampleFromBlock = void 0;
|
|
4
|
+
const buffer_iterator_1 = require("../../buffer-iterator");
|
|
5
|
+
const all_segments_1 = require("./segments/all-segments");
|
|
6
|
+
const block_simple_block_flags_1 = require("./segments/block-simple-block-flags");
|
|
7
|
+
const getSampleFromBlock = (ebml, parserContext, offset) => {
|
|
8
|
+
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(ebml.value, ebml.value.length);
|
|
9
|
+
const trackNumber = iterator.getVint();
|
|
10
|
+
if (trackNumber === null) {
|
|
11
|
+
throw new Error('Not enough data to get track number, should not happen');
|
|
12
|
+
}
|
|
13
|
+
const timecodeRelativeToCluster = iterator.getUint16();
|
|
14
|
+
const { keyframe } = (0, block_simple_block_flags_1.parseBlockFlags)(iterator, ebml.type === 'SimpleBlock'
|
|
15
|
+
? all_segments_1.matroskaElements.SimpleBlock
|
|
16
|
+
: all_segments_1.matroskaElements.Block);
|
|
17
|
+
const { codec, trackTimescale } = parserContext.parserState.getTrackInfoByNumber(trackNumber);
|
|
18
|
+
const clusterOffset = parserContext.parserState.getTimestampOffsetForByteOffset(offset);
|
|
19
|
+
const timescale = parserContext.parserState.getTimescale();
|
|
20
|
+
if (clusterOffset === undefined) {
|
|
21
|
+
throw new Error('Could not find offset for byte offset ' + offset);
|
|
22
|
+
}
|
|
23
|
+
// https://github.com/hubblec4/Matroska-Chapters-Specs/blob/master/notes.md/#timestampscale
|
|
24
|
+
// The TimestampScale Element is used to calculate the Raw Timestamp of a Block. The timestamp is obtained by adding the Block's timestamp to the Cluster's Timestamp Element, and then multiplying that result by the TimestampScale. The result will be the Block's Raw Timestamp in nanoseconds.
|
|
25
|
+
const timecodeInNanoSeconds = (timecodeRelativeToCluster + clusterOffset) *
|
|
26
|
+
timescale *
|
|
27
|
+
(trackTimescale !== null && trackTimescale !== void 0 ? trackTimescale : 1);
|
|
28
|
+
// Timecode should be in microseconds
|
|
29
|
+
const timecodeInMicroseconds = timecodeInNanoSeconds / 1000;
|
|
30
|
+
if (!codec) {
|
|
31
|
+
throw new Error(`Could not find codec for track ${trackNumber}`);
|
|
32
|
+
}
|
|
33
|
+
const remainingNow = ebml.value.length - (iterator.counter.getOffset() - 0);
|
|
34
|
+
if (codec.startsWith('V_')) {
|
|
35
|
+
const partialVideoSample = {
|
|
36
|
+
data: iterator.getSlice(remainingNow),
|
|
37
|
+
cts: null,
|
|
38
|
+
dts: null,
|
|
39
|
+
duration: undefined,
|
|
40
|
+
trackId: trackNumber,
|
|
41
|
+
timestamp: timecodeInMicroseconds,
|
|
42
|
+
};
|
|
43
|
+
if (keyframe === null) {
|
|
44
|
+
iterator.destroy();
|
|
45
|
+
return {
|
|
46
|
+
type: 'partial-video-sample',
|
|
47
|
+
partialVideoSample,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const sample = {
|
|
51
|
+
...partialVideoSample,
|
|
52
|
+
type: keyframe ? 'key' : 'delta',
|
|
53
|
+
};
|
|
54
|
+
iterator.destroy();
|
|
55
|
+
return {
|
|
56
|
+
type: 'video-sample',
|
|
57
|
+
videoSample: sample,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (codec.startsWith('A_')) {
|
|
61
|
+
const audioSample = {
|
|
62
|
+
data: iterator.getSlice(remainingNow),
|
|
63
|
+
trackId: trackNumber,
|
|
64
|
+
timestamp: timecodeInMicroseconds,
|
|
65
|
+
type: 'key',
|
|
66
|
+
};
|
|
67
|
+
iterator.destroy();
|
|
68
|
+
return {
|
|
69
|
+
type: 'audio-sample',
|
|
70
|
+
audioSample,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
iterator.destroy();
|
|
74
|
+
return {
|
|
75
|
+
type: 'no-sample',
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
exports.getSampleFromBlock = getSampleFromBlock;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AudioTrack, VideoTrack } from '../../get-tracks';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TrackEntry } from './segments/all-segments';
|
|
3
3
|
export declare const getTrack: ({ timescale, track, }: {
|
|
4
4
|
timescale: number;
|
|
5
|
-
track:
|
|
5
|
+
track: TrackEntry;
|
|
6
6
|
}) => VideoTrack | AudioTrack | null;
|
|
@@ -6,12 +6,13 @@ const make_hvc1_codec_strings_1 = require("../../make-hvc1-codec-strings");
|
|
|
6
6
|
const traversal_1 = require("../../traversal");
|
|
7
7
|
const av1_codec_private_1 = require("./av1-codec-private");
|
|
8
8
|
const description_1 = require("./description");
|
|
9
|
+
const track_entry_1 = require("./segments/track-entry");
|
|
9
10
|
const getDescription = (track) => {
|
|
10
11
|
const codec = (0, traversal_1.getCodecSegment)(track);
|
|
11
12
|
if (!codec) {
|
|
12
13
|
return undefined;
|
|
13
14
|
}
|
|
14
|
-
if (codec.
|
|
15
|
+
if (codec.value === 'V_MPEG4/ISO/AVC' || codec.value === 'V_MPEGH/ISO/HEVC') {
|
|
15
16
|
const priv = (0, traversal_1.getPrivateData)(track);
|
|
16
17
|
if (priv) {
|
|
17
18
|
return priv;
|
|
@@ -20,49 +21,49 @@ const getDescription = (track) => {
|
|
|
20
21
|
return undefined;
|
|
21
22
|
};
|
|
22
23
|
const getMatroskaVideoCodecString = ({ track, codecSegment: codec, }) => {
|
|
23
|
-
if (codec.
|
|
24
|
+
if (codec.value === 'V_VP8') {
|
|
24
25
|
return 'vp8';
|
|
25
26
|
}
|
|
26
|
-
if (codec.
|
|
27
|
+
if (codec.value === 'V_VP9') {
|
|
27
28
|
const priv = (0, traversal_1.getPrivateData)(track);
|
|
28
29
|
if (priv) {
|
|
29
30
|
throw new Error('@remotion/media-parser cannot handle the private data for VP9. Do you have an example file you could send so we can implement it?');
|
|
30
31
|
}
|
|
31
32
|
return 'vp09.00.10.08';
|
|
32
33
|
}
|
|
33
|
-
if (codec.
|
|
34
|
+
if (codec.value === 'V_MPEG4/ISO/AVC') {
|
|
34
35
|
const priv = (0, traversal_1.getPrivateData)(track);
|
|
35
36
|
if (priv) {
|
|
36
37
|
return `avc1.${priv[1].toString(16).padStart(2, '0')}${priv[2].toString(16).padStart(2, '0')}${priv[3].toString(16).padStart(2, '0')}`;
|
|
37
38
|
}
|
|
38
39
|
throw new Error('Could not find a CodecPrivate field in TrackEntry');
|
|
39
40
|
}
|
|
40
|
-
if (codec.
|
|
41
|
+
if (codec.value === 'V_AV1') {
|
|
41
42
|
const priv = (0, traversal_1.getPrivateData)(track);
|
|
42
43
|
if (!priv) {
|
|
43
44
|
throw new Error('Expected private data in AV1 track');
|
|
44
45
|
}
|
|
45
46
|
return (0, av1_codec_private_1.parseAv1PrivateData)(priv, null);
|
|
46
47
|
}
|
|
47
|
-
if (codec.
|
|
48
|
+
if (codec.value === 'V_MPEGH/ISO/HEVC') {
|
|
48
49
|
const priv = (0, traversal_1.getPrivateData)(track);
|
|
49
|
-
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(priv);
|
|
50
|
+
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(priv, priv.length);
|
|
50
51
|
return 'hvc1.' + (0, make_hvc1_codec_strings_1.getHvc1CodecString)(iterator);
|
|
51
52
|
}
|
|
52
|
-
throw new Error(`Unknown codec: ${codec.
|
|
53
|
+
throw new Error(`Unknown codec: ${codec.value}`);
|
|
53
54
|
};
|
|
54
55
|
const getMatroskaAudioCodecString = (track) => {
|
|
55
56
|
const codec = (0, traversal_1.getCodecSegment)(track);
|
|
56
57
|
if (!codec) {
|
|
57
58
|
throw new Error('Expected codec segment');
|
|
58
59
|
}
|
|
59
|
-
if (codec.
|
|
60
|
+
if (codec.value === 'A_OPUS') {
|
|
60
61
|
return 'opus';
|
|
61
62
|
}
|
|
62
|
-
if (codec.
|
|
63
|
+
if (codec.value === 'A_VORBIS') {
|
|
63
64
|
return 'vorbis';
|
|
64
65
|
}
|
|
65
|
-
if (codec.
|
|
66
|
+
if (codec.value === 'A_PCM/INT/LIT') {
|
|
66
67
|
// https://github.com/ietf-wg-cellar/matroska-specification/issues/142#issuecomment-330004950
|
|
67
68
|
// Audio samples MUST be considered as signed values, except if the audio bit depth is 8 which MUST be interpreted as unsigned values.
|
|
68
69
|
const bitDepth = (0, traversal_1.getBitDepth)(track);
|
|
@@ -74,9 +75,9 @@ const getMatroskaAudioCodecString = (track) => {
|
|
|
74
75
|
}
|
|
75
76
|
return 'pcm-s' + bitDepth;
|
|
76
77
|
}
|
|
77
|
-
if (codec.
|
|
78
|
+
if (codec.value === 'A_AAC') {
|
|
78
79
|
const priv = (0, traversal_1.getPrivateData)(track);
|
|
79
|
-
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(priv);
|
|
80
|
+
const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(priv, priv.length);
|
|
80
81
|
iterator.startReadingBits();
|
|
81
82
|
/**
|
|
82
83
|
* ChatGPT
|
|
@@ -104,10 +105,10 @@ const getMatroskaAudioCodecString = (track) => {
|
|
|
104
105
|
iterator.destroy();
|
|
105
106
|
return `mp4a.40.${profile.toString().padStart(2, '0')}`;
|
|
106
107
|
}
|
|
107
|
-
if (codec.
|
|
108
|
+
if (codec.value === 'A_MPEG/L3') {
|
|
108
109
|
return 'mp3';
|
|
109
110
|
}
|
|
110
|
-
throw new Error(`Unknown codec: ${codec.
|
|
111
|
+
throw new Error(`Unknown codec: ${codec.value}`);
|
|
111
112
|
};
|
|
112
113
|
const getTrack = ({ timescale, track, }) => {
|
|
113
114
|
const trackType = (0, traversal_1.getTrackTypeSegment)(track);
|
|
@@ -115,7 +116,7 @@ const getTrack = ({ timescale, track, }) => {
|
|
|
115
116
|
throw new Error('Expected track type segment');
|
|
116
117
|
}
|
|
117
118
|
const trackId = (0, traversal_1.getTrackId)(track);
|
|
118
|
-
if (trackType.
|
|
119
|
+
if ((0, track_entry_1.trackTypeToString)(trackType.value.value) === 'video') {
|
|
119
120
|
const width = (0, traversal_1.getWidthSegment)(track);
|
|
120
121
|
if (width === null) {
|
|
121
122
|
throw new Error('Expected width segment');
|
|
@@ -142,26 +143,26 @@ const getTrack = ({ timescale, track, }) => {
|
|
|
142
143
|
trackId,
|
|
143
144
|
codec: codecString,
|
|
144
145
|
description: getDescription(track),
|
|
145
|
-
height: displayHeight ? displayHeight.
|
|
146
|
-
width: displayWidth ? displayWidth.
|
|
146
|
+
height: displayHeight ? displayHeight.value.value : height.value.value,
|
|
147
|
+
width: displayWidth ? displayWidth.value.value : width.value.value,
|
|
147
148
|
sampleAspectRatio: {
|
|
148
149
|
numerator: 1,
|
|
149
150
|
denominator: 1,
|
|
150
151
|
},
|
|
151
152
|
timescale,
|
|
152
153
|
samplePositions: [],
|
|
153
|
-
codedHeight: height.
|
|
154
|
-
codedWidth: width.
|
|
154
|
+
codedHeight: height.value.value,
|
|
155
|
+
codedWidth: width.value.value,
|
|
155
156
|
displayAspectHeight: displayHeight
|
|
156
|
-
? displayHeight.
|
|
157
|
-
: height.
|
|
157
|
+
? displayHeight.value.value
|
|
158
|
+
: height.value.value,
|
|
158
159
|
displayAspectWidth: displayWidth
|
|
159
|
-
? displayWidth.
|
|
160
|
-
: width.
|
|
160
|
+
? displayWidth.value.value
|
|
161
|
+
: width.value.value,
|
|
161
162
|
rotation: 0,
|
|
162
163
|
};
|
|
163
164
|
}
|
|
164
|
-
if (trackType.
|
|
165
|
+
if ((0, track_entry_1.trackTypeToString)(trackType.value.value) === 'audio') {
|
|
165
166
|
const sampleRate = (0, traversal_1.getSampleRate)(track);
|
|
166
167
|
const numberOfChannels = (0, traversal_1.getNumberOfChannels)(track);
|
|
167
168
|
if (sampleRate === null) {
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PossibleEbmlOrUint8Array } from './segments/all-segments';
|
|
2
2
|
export declare const webmPattern: Uint8Array;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[key in keyof Struct & Numbers as Struct[key]['name']]: EmblTypes[Struct[key]['type']];
|
|
6
|
-
};
|
|
7
|
-
type SerializeValue<Struct extends Ebml> = Struct extends EbmlWithChildren ? ChildFields<Struct['children']> : Struct extends EbmlWithString ? string : Struct extends EbmlWithUint8 ? number : Struct extends EbmlWithHexString ? string : undefined;
|
|
8
|
-
export declare const makeMatroskaHeader: <Struct extends Ebml>(struct: Struct, fields: SerializeValue<Struct>) => Uint8Array;
|
|
9
|
-
export {};
|
|
3
|
+
export declare const makeMatroskaBytes: (fields: PossibleEbmlOrUint8Array) => Uint8Array;
|
|
4
|
+
export declare const combineUint8Arrays: (arrays: Uint8Array[]) => Uint8Array;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.combineUint8Arrays = exports.makeMatroskaBytes = exports.webmPattern = void 0;
|
|
4
4
|
const ebml_1 = require("./ebml");
|
|
5
5
|
const all_segments_1 = require("./segments/all-segments");
|
|
6
6
|
exports.webmPattern = new Uint8Array([0x1a, 0x45, 0xdf, 0xa3]);
|
|
@@ -12,12 +12,12 @@ const matroskaToHex = (matrId) => {
|
|
|
12
12
|
}
|
|
13
13
|
return numbers;
|
|
14
14
|
};
|
|
15
|
-
function putUintDynamic(number) {
|
|
15
|
+
function putUintDynamic(number, minimumLength) {
|
|
16
16
|
if (number < 0) {
|
|
17
17
|
throw new Error('This function is designed for non-negative integers only.');
|
|
18
18
|
}
|
|
19
19
|
// Calculate the minimum number of bytes needed to store the integer
|
|
20
|
-
const length = Math.ceil(Math.log2(number + 1) / 8);
|
|
20
|
+
const length = Math.max(minimumLength !== null && minimumLength !== void 0 ? minimumLength : 0, Math.ceil(Math.log2(number + 1) / 8));
|
|
21
21
|
const bytes = new Uint8Array(length);
|
|
22
22
|
for (let i = 0; i < length; i++) {
|
|
23
23
|
// Extract each byte from the number
|
|
@@ -25,24 +25,29 @@ function putUintDynamic(number) {
|
|
|
25
25
|
}
|
|
26
26
|
return bytes;
|
|
27
27
|
}
|
|
28
|
-
const makeFromHeaderStructure = (
|
|
28
|
+
const makeFromHeaderStructure = (fields) => {
|
|
29
|
+
if (fields instanceof Uint8Array) {
|
|
30
|
+
return fields;
|
|
31
|
+
}
|
|
29
32
|
const arrays = [];
|
|
33
|
+
const struct = all_segments_1.ebmlMap[(0, all_segments_1.getIdForName)(fields.type)];
|
|
34
|
+
if (struct.type === 'uint8array') {
|
|
35
|
+
return fields.value;
|
|
36
|
+
}
|
|
30
37
|
if (struct.type === 'children') {
|
|
31
|
-
for (const item of
|
|
32
|
-
arrays.push((0, exports.
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
fields[item.name]));
|
|
38
|
+
for (const item of fields.value) {
|
|
39
|
+
arrays.push((0, exports.makeMatroskaBytes)(item));
|
|
35
40
|
}
|
|
36
|
-
return combineUint8Arrays(arrays);
|
|
41
|
+
return (0, exports.combineUint8Arrays)(arrays);
|
|
37
42
|
}
|
|
38
43
|
if (struct.type === 'string') {
|
|
39
|
-
return new TextEncoder().encode(fields);
|
|
44
|
+
return new TextEncoder().encode(fields.value);
|
|
40
45
|
}
|
|
41
46
|
if (struct.type === 'uint') {
|
|
42
|
-
return putUintDynamic(fields);
|
|
47
|
+
return putUintDynamic(fields.value.value, fields.value.byteLength);
|
|
43
48
|
}
|
|
44
49
|
if (struct.type === 'hex-string') {
|
|
45
|
-
const hex = fields.substring(2);
|
|
50
|
+
const hex = fields.value.substring(2);
|
|
46
51
|
const arr = new Uint8Array(hex.length / 2);
|
|
47
52
|
for (let i = 0; i < hex.length; i += 2) {
|
|
48
53
|
const byte = parseInt(hex.substring(i, i + 2), 16);
|
|
@@ -50,21 +55,38 @@ const makeFromHeaderStructure = (struct, fields) => {
|
|
|
50
55
|
}
|
|
51
56
|
return arr;
|
|
52
57
|
}
|
|
53
|
-
if (struct.type === '
|
|
54
|
-
|
|
58
|
+
if (struct.type === 'float') {
|
|
59
|
+
const value = fields.value;
|
|
60
|
+
if (value.size === '32') {
|
|
61
|
+
const dataView = new DataView(new ArrayBuffer(4));
|
|
62
|
+
dataView.setFloat32(0, value.value);
|
|
63
|
+
return new Uint8Array(dataView.buffer);
|
|
64
|
+
}
|
|
65
|
+
const dataView2 = new DataView(new ArrayBuffer(8));
|
|
66
|
+
dataView2.setFloat64(0, value.value);
|
|
67
|
+
return new Uint8Array(dataView2.buffer);
|
|
55
68
|
}
|
|
56
69
|
throw new Error('Unexpected type');
|
|
57
70
|
};
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
const makeMatroskaBytes = (fields) => {
|
|
72
|
+
if (fields instanceof Uint8Array) {
|
|
73
|
+
return fields;
|
|
74
|
+
}
|
|
75
|
+
const value = makeFromHeaderStructure(fields);
|
|
76
|
+
return (0, exports.combineUint8Arrays)([
|
|
77
|
+
matroskaToHex((0, all_segments_1.getIdForName)(fields.type)),
|
|
78
|
+
(0, ebml_1.getVariableInt)(value.length, fields.minVintWidth),
|
|
63
79
|
value,
|
|
64
80
|
]);
|
|
65
81
|
};
|
|
66
|
-
exports.
|
|
82
|
+
exports.makeMatroskaBytes = makeMatroskaBytes;
|
|
67
83
|
const combineUint8Arrays = (arrays) => {
|
|
84
|
+
if (arrays.length === 0) {
|
|
85
|
+
return new Uint8Array([]);
|
|
86
|
+
}
|
|
87
|
+
if (arrays.length === 1) {
|
|
88
|
+
return arrays[0];
|
|
89
|
+
}
|
|
68
90
|
let totalLength = 0;
|
|
69
91
|
for (const array of arrays) {
|
|
70
92
|
totalLength += array.length;
|
|
@@ -77,3 +99,4 @@ const combineUint8Arrays = (arrays) => {
|
|
|
77
99
|
}
|
|
78
100
|
return result;
|
|
79
101
|
};
|
|
102
|
+
exports.combineUint8Arrays = combineUint8Arrays;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParserContext } from '../../parser-context';
|
|
2
3
|
import type { PossibleEbml } from './segments/all-segments';
|
|
3
|
-
type Prettify<T> = {
|
|
4
|
+
export type Prettify<T> = {
|
|
4
5
|
[K in keyof T]: T[K];
|
|
5
6
|
} & {};
|
|
6
|
-
export declare const parseEbml: (iterator: BufferIterator) => Prettify<PossibleEbml
|
|
7
|
-
export {}
|
|
7
|
+
export declare const parseEbml: (iterator: BufferIterator, parserContext: ParserContext) => Promise<Prettify<PossibleEbml>>;
|
|
8
|
+
export declare const postprocessEbml: ({ offset, ebml, parserContext, }: {
|
|
9
|
+
offset: number;
|
|
10
|
+
ebml: Prettify<PossibleEbml>;
|
|
11
|
+
parserContext: ParserContext;
|
|
12
|
+
}) => Promise<Prettify<PossibleEbml>>;
|