@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
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseEbml = void 0;
|
|
3
|
+
exports.postprocessEbml = exports.parseEbml = void 0;
|
|
4
|
+
const add_new_matroska_tracks_1 = require("../../add-new-matroska-tracks");
|
|
5
|
+
const get_sample_from_block_1 = require("./get-sample-from-block");
|
|
6
|
+
const get_track_1 = require("./get-track");
|
|
4
7
|
const all_segments_1 = require("./segments/all-segments");
|
|
5
|
-
const parseEbml = (iterator) => {
|
|
8
|
+
const parseEbml = async (iterator, parserContext) => {
|
|
6
9
|
const hex = iterator.getMatroskaSegmentId();
|
|
7
10
|
if (hex === null) {
|
|
8
11
|
throw new Error('Not enough bytes left to parse EBML - this should not happen');
|
|
@@ -11,36 +14,58 @@ const parseEbml = (iterator) => {
|
|
|
11
14
|
if (!hasInMap) {
|
|
12
15
|
throw new Error(`Don't know how to parse EBML hex ID ${JSON.stringify(hex)}`);
|
|
13
16
|
}
|
|
17
|
+
const off = iterator.counter.getOffset();
|
|
14
18
|
const size = iterator.getVint();
|
|
19
|
+
const minVintWidth = iterator.counter.getOffset() - off;
|
|
15
20
|
if (size === null) {
|
|
16
21
|
throw new Error('Not enough bytes left to parse EBML - this should not happen');
|
|
17
22
|
}
|
|
18
23
|
if (hasInMap.type === 'uint') {
|
|
24
|
+
const beforeUintOffset = iterator.counter.getOffset();
|
|
19
25
|
const value = iterator.getUint(size);
|
|
20
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
type: hasInMap.name,
|
|
28
|
+
value: {
|
|
29
|
+
value,
|
|
30
|
+
byteLength: iterator.counter.getOffset() - beforeUintOffset,
|
|
31
|
+
},
|
|
32
|
+
minVintWidth,
|
|
33
|
+
};
|
|
21
34
|
}
|
|
22
35
|
if (hasInMap.type === 'string') {
|
|
23
36
|
const value = iterator.getByteString(size);
|
|
24
37
|
return {
|
|
25
38
|
type: hasInMap.name,
|
|
26
39
|
value,
|
|
27
|
-
|
|
40
|
+
minVintWidth,
|
|
28
41
|
};
|
|
29
42
|
}
|
|
30
43
|
if (hasInMap.type === 'float') {
|
|
31
44
|
const value = size === 4 ? iterator.getFloat32() : iterator.getFloat64();
|
|
32
45
|
return {
|
|
33
46
|
type: hasInMap.name,
|
|
34
|
-
value
|
|
35
|
-
|
|
47
|
+
value: {
|
|
48
|
+
value,
|
|
49
|
+
size: size === 4 ? '32' : '64',
|
|
50
|
+
},
|
|
51
|
+
minVintWidth,
|
|
36
52
|
};
|
|
37
53
|
}
|
|
38
|
-
if (hasInMap.type === '
|
|
39
|
-
iterator.discard(size);
|
|
54
|
+
if (hasInMap.type === 'hex-string') {
|
|
40
55
|
return {
|
|
41
56
|
type: hasInMap.name,
|
|
42
|
-
value:
|
|
43
|
-
|
|
57
|
+
value: '0x' +
|
|
58
|
+
[...iterator.getSlice(size)]
|
|
59
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
60
|
+
.join(''),
|
|
61
|
+
minVintWidth,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (hasInMap.type === 'uint8array') {
|
|
65
|
+
return {
|
|
66
|
+
type: hasInMap.name,
|
|
67
|
+
value: iterator.getSlice(size),
|
|
68
|
+
minVintWidth,
|
|
44
69
|
};
|
|
45
70
|
}
|
|
46
71
|
if (hasInMap.type === 'children') {
|
|
@@ -48,8 +73,14 @@ const parseEbml = (iterator) => {
|
|
|
48
73
|
const startOffset = iterator.counter.getOffset();
|
|
49
74
|
// eslint-disable-next-line no-constant-condition
|
|
50
75
|
while (true) {
|
|
51
|
-
const
|
|
52
|
-
|
|
76
|
+
const offset = iterator.counter.getOffset();
|
|
77
|
+
const value = await (0, exports.parseEbml)(iterator, parserContext);
|
|
78
|
+
const remapped = await (0, exports.postprocessEbml)({
|
|
79
|
+
offset,
|
|
80
|
+
ebml: value,
|
|
81
|
+
parserContext,
|
|
82
|
+
});
|
|
83
|
+
children.push(remapped);
|
|
53
84
|
const offsetNow = iterator.counter.getOffset();
|
|
54
85
|
if (offsetNow - startOffset > size) {
|
|
55
86
|
throw new Error(`Offset ${offsetNow - startOffset} is larger than the length of the hex ${size}`);
|
|
@@ -58,9 +89,87 @@ const parseEbml = (iterator) => {
|
|
|
58
89
|
break;
|
|
59
90
|
}
|
|
60
91
|
}
|
|
61
|
-
return { type: hasInMap.name, value: children,
|
|
92
|
+
return { type: hasInMap.name, value: children, minVintWidth };
|
|
62
93
|
}
|
|
63
94
|
// @ts-expect-error
|
|
64
95
|
throw new Error(`Unknown segment type ${hasInMap.type}`);
|
|
65
96
|
};
|
|
66
97
|
exports.parseEbml = parseEbml;
|
|
98
|
+
const postprocessEbml = async ({ offset, ebml, parserContext, }) => {
|
|
99
|
+
if (ebml.type === 'TimestampScale') {
|
|
100
|
+
parserContext.parserState.setTimescale(ebml.value.value);
|
|
101
|
+
}
|
|
102
|
+
if (ebml.type === 'TrackEntry') {
|
|
103
|
+
parserContext.parserState.onTrackEntrySegment(ebml);
|
|
104
|
+
const track = (0, get_track_1.getTrack)({
|
|
105
|
+
track: ebml,
|
|
106
|
+
timescale: parserContext.parserState.getTimescale(),
|
|
107
|
+
});
|
|
108
|
+
if (track) {
|
|
109
|
+
await (0, add_new_matroska_tracks_1.registerTrack)({
|
|
110
|
+
state: parserContext.parserState,
|
|
111
|
+
options: parserContext,
|
|
112
|
+
track,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (ebml.type === 'Timestamp') {
|
|
117
|
+
parserContext.parserState.setTimestampOffset(offset, ebml.value.value);
|
|
118
|
+
}
|
|
119
|
+
if (ebml.type === 'Block' || ebml.type === 'SimpleBlock') {
|
|
120
|
+
const sample = (0, get_sample_from_block_1.getSampleFromBlock)(ebml, parserContext, offset);
|
|
121
|
+
if (sample.type === 'video-sample' && parserContext.nullifySamples) {
|
|
122
|
+
await parserContext.parserState.onVideoSample(sample.videoSample.trackId, sample.videoSample);
|
|
123
|
+
return {
|
|
124
|
+
type: 'Block',
|
|
125
|
+
value: new Uint8Array([]),
|
|
126
|
+
minVintWidth: ebml.minVintWidth,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (sample.type === 'audio-sample' && parserContext.nullifySamples) {
|
|
130
|
+
await parserContext.parserState.onAudioSample(sample.audioSample.trackId, sample.audioSample);
|
|
131
|
+
return {
|
|
132
|
+
type: 'Block',
|
|
133
|
+
value: new Uint8Array([]),
|
|
134
|
+
minVintWidth: ebml.minVintWidth,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (sample.type === 'no-sample' && parserContext.nullifySamples) {
|
|
138
|
+
return {
|
|
139
|
+
type: 'Block',
|
|
140
|
+
value: new Uint8Array([]),
|
|
141
|
+
minVintWidth: ebml.minVintWidth,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (ebml.type === 'BlockGroup') {
|
|
146
|
+
// Blocks don't have information about keyframes.
|
|
147
|
+
// https://ffmpeg.org/pipermail/ffmpeg-devel/2015-June/173825.html
|
|
148
|
+
// "For Blocks, keyframes is
|
|
149
|
+
// inferred by the absence of ReferenceBlock element (as done by matroskadec).""
|
|
150
|
+
const block = ebml.value.find((c) => c.type === 'SimpleBlock' || c.type === 'Block');
|
|
151
|
+
if (!block || (block.type !== 'SimpleBlock' && block.type !== 'Block')) {
|
|
152
|
+
throw new Error('Expected block segment');
|
|
153
|
+
}
|
|
154
|
+
const hasReferenceBlock = ebml.value.find((c) => c.type === 'ReferenceBlock');
|
|
155
|
+
const sample = block.value.length === 0
|
|
156
|
+
? null
|
|
157
|
+
: (0, get_sample_from_block_1.getSampleFromBlock)(block, parserContext, offset);
|
|
158
|
+
if (sample && sample.type === 'partial-video-sample') {
|
|
159
|
+
const completeFrame = {
|
|
160
|
+
...sample.partialVideoSample,
|
|
161
|
+
type: hasReferenceBlock ? 'delta' : 'key',
|
|
162
|
+
};
|
|
163
|
+
await parserContext.parserState.onVideoSample(sample.partialVideoSample.trackId, completeFrame);
|
|
164
|
+
}
|
|
165
|
+
if (parserContext.nullifySamples) {
|
|
166
|
+
return {
|
|
167
|
+
type: 'BlockGroup',
|
|
168
|
+
value: [],
|
|
169
|
+
minVintWidth: ebml.minVintWidth,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return ebml;
|
|
174
|
+
};
|
|
175
|
+
exports.postprocessEbml = postprocessEbml;
|