@remotion/media-parser 4.0.201 → 4.0.204
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 +0 -5
- package/dist/av1-codec-string.js +1 -18
- 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/get-sample-positions-from-track.d.ts +4 -0
- package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +48 -0
- package/dist/boxes/iso-base-media/mvhd.js +2 -2
- package/dist/boxes/iso-base-media/stsd/keys.js +1 -1
- package/dist/boxes/iso-base-media/tfdt.d.ts +12 -0
- package/dist/boxes/iso-base-media/tfdt.js +20 -0
- package/dist/boxes/iso-base-media/tfhd.d.ts +16 -0
- package/dist/boxes/iso-base-media/tfhd.js +41 -0
- package/dist/boxes/iso-base-media/trun.d.ts +21 -0
- package/dist/boxes/iso-base-media/trun.js +44 -0
- package/dist/boxes/webm/av1-codec-private.js +1 -1
- package/dist/boxes/webm/bitstream/av1.js +1 -10
- 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/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/tracks.d.ts +8 -0
- package/dist/boxes/webm/tracks.js +21 -0
- 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/from-web.js +6 -15
- 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/get-video-metadata.d.ts +2 -0
- package/dist/get-video-metadata.js +44 -0
- package/dist/parse-media.js +4 -1
- package/dist/parser-context.d.ts +1 -0
- package/dist/parser-state.js +3 -2
- package/dist/read-and-increment-offset.d.ts +28 -0
- package/dist/read-and-increment-offset.js +177 -0
- package/dist/samples-from-moof.d.ts +6 -0
- package/dist/samples-from-moof.js +74 -0
- package/dist/traversal.d.ts +19 -17
- package/dist/traversal.js +38 -39
- package/dist/understand-vorbis.d.ts +1 -0
- package/dist/understand-vorbis.js +12 -0
- package/input.webm +0 -0
- package/package.json +2 -2
- package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +69 -0
- package/src/boxes/iso-base-media/make-track.ts +4 -45
- package/src/boxes/iso-base-media/mdat/mdat.ts +33 -24
- package/src/boxes/iso-base-media/mdhd.ts +10 -7
- package/src/boxes/iso-base-media/mvhd.ts +17 -16
- package/src/boxes/iso-base-media/process-box.ts +42 -0
- package/src/boxes/iso-base-media/stsd/keys.ts +1 -1
- package/src/boxes/iso-base-media/tfdt.ts +37 -0
- package/src/boxes/iso-base-media/tfhd.ts +66 -0
- package/src/boxes/iso-base-media/tkhd.ts +11 -13
- package/src/boxes/iso-base-media/trun.ts +74 -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 +40 -33
- 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 +8 -6
- package/src/get-audio-codec.ts +14 -16
- package/src/get-duration.ts +55 -21
- package/src/get-tracks.ts +6 -6
- package/src/get-video-codec.ts +13 -15
- package/src/has-all-info.ts +1 -1
- package/src/parse-media.ts +7 -2
- package/src/parse-result.ts +7 -1
- package/src/parser-context.ts +1 -0
- package/src/parser-state.ts +2 -2
- package/src/samples-from-moof.ts +101 -0
- 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/samples-from-moof.test.ts +2496 -0
- package/src/test/stream-local.test.ts +28 -30
- package/src/test/stream-samples.test.ts +153 -231
- package/src/test/stsd.test.ts +4 -2
- package/src/test/tkhd.test.ts +1 -1
- package/src/traversal.ts +118 -86
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/bitstream/av1.d.ts +0 -2
- package/dist/bitstream/av1.js +0 -12
- package/dist/boxes/iso-base-media/avcc-hvcc.d.ts +0 -20
- package/dist/boxes/iso-base-media/avcc-hvcc.js +0 -73
- package/dist/boxes/iso-base-media/avcc.d.ts +0 -18
- package/dist/boxes/iso-base-media/avcc.js +0 -27
- 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/from-input-type-file.d.ts +0 -2
- package/dist/from-input-type-file.js +0 -37
- package/dist/get-codec.d.ts +0 -4
- package/dist/get-codec.js +0 -22
- package/dist/web-file.d.ts +0 -2
- package/dist/web-file.js +0 -37
- 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
- /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/dist/{sample-aspect-ratio.d.ts → boxes/webm/bitstream/h264/get-h264-descriptor.d.ts} +0 -0
- /package/dist/{sample-aspect-ratio.js → boxes/webm/bitstream/h264/get-h264-descriptor.js} +0 -0
|
@@ -1,205 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.expectSegment = void 0;
|
|
4
|
-
const add_new_matroska_tracks_1 = require("../../add-new-matroska-tracks");
|
|
5
|
-
const get_track_1 = require("./get-track");
|
|
6
4
|
const parse_ebml_1 = require("./parse-ebml");
|
|
7
|
-
const all_segments_1 = require("./segments/all-segments");
|
|
8
|
-
const duration_1 = require("./segments/duration");
|
|
9
|
-
const info_1 = require("./segments/info");
|
|
10
|
-
const muxing_1 = require("./segments/muxing");
|
|
11
5
|
const parse_children_1 = require("./segments/parse-children");
|
|
12
|
-
const seek_1 = require("./segments/seek");
|
|
13
|
-
const seek_head_1 = require("./segments/seek-head");
|
|
14
|
-
const seek_position_1 = require("./segments/seek-position");
|
|
15
|
-
const timestamp_scale_1 = require("./segments/timestamp-scale");
|
|
16
|
-
const track_entry_1 = require("./segments/track-entry");
|
|
17
|
-
const tracks_1 = require("./segments/tracks");
|
|
18
|
-
const void_1 = require("./segments/void");
|
|
19
|
-
const writing_1 = require("./segments/writing");
|
|
20
6
|
const parseSegment = async ({ segmentId, iterator, length, parserContext, headerReadSoFar, }) => {
|
|
21
7
|
if (length === 0) {
|
|
22
8
|
throw new Error(`Expected length of ${segmentId} to be greater than 0`);
|
|
23
9
|
}
|
|
24
|
-
if (segmentId === '0x114d9b74') {
|
|
25
|
-
return (0, seek_head_1.parseSeekHeadSegment)(iterator, length, parserContext);
|
|
26
|
-
}
|
|
27
|
-
if (segmentId === '0x53ab') {
|
|
28
|
-
return (0, seek_1.parseSeekIdSegment)(iterator, length);
|
|
29
|
-
}
|
|
30
|
-
if (segmentId === '0x4dbb') {
|
|
31
|
-
return (0, seek_1.parseSeekSegment)(iterator, length, parserContext);
|
|
32
|
-
}
|
|
33
|
-
if (segmentId === '0x53ac') {
|
|
34
|
-
return (0, seek_position_1.parseSeekPositionSegment)(iterator, length);
|
|
35
|
-
}
|
|
36
|
-
if (segmentId === '0xec') {
|
|
37
|
-
return (0, void_1.parseVoidSegment)(iterator, length);
|
|
38
|
-
}
|
|
39
|
-
if (segmentId === '0x1549a966') {
|
|
40
|
-
return (0, info_1.parseInfoSegment)(iterator, length, parserContext);
|
|
41
|
-
}
|
|
42
|
-
if (segmentId === all_segments_1.matroskaElements.TimestampScale) {
|
|
43
|
-
const timestampScale = (0, timestamp_scale_1.parseTimestampScaleSegment)(iterator);
|
|
44
|
-
parserContext.parserState.setTimescale(timestampScale.timestampScale);
|
|
45
|
-
return timestampScale;
|
|
46
|
-
}
|
|
47
|
-
if (segmentId === '0x4d80') {
|
|
48
|
-
return (0, muxing_1.parseMuxingSegment)(iterator, length);
|
|
49
|
-
}
|
|
50
|
-
if (segmentId === '0x5741') {
|
|
51
|
-
return (0, writing_1.parseWritingSegment)(iterator, length);
|
|
52
|
-
}
|
|
53
|
-
if (segmentId === '0x4489') {
|
|
54
|
-
return (0, duration_1.parseDurationSegment)(iterator, length);
|
|
55
|
-
}
|
|
56
|
-
if (segmentId === '0x1654ae6b') {
|
|
57
|
-
return (0, tracks_1.parseTracksSegment)(iterator, length, parserContext);
|
|
58
|
-
}
|
|
59
|
-
if (segmentId === all_segments_1.matroskaElements.TrackEntry) {
|
|
60
|
-
const trackEntry = await (0, track_entry_1.parseTrackEntry)(iterator, length, parserContext);
|
|
61
|
-
parserContext.parserState.onTrackEntrySegment(trackEntry);
|
|
62
|
-
const track = (0, get_track_1.getTrack)({
|
|
63
|
-
track: trackEntry,
|
|
64
|
-
timescale: parserContext.parserState.getTimescale(),
|
|
65
|
-
});
|
|
66
|
-
if (track) {
|
|
67
|
-
await (0, add_new_matroska_tracks_1.registerTrack)({
|
|
68
|
-
state: parserContext.parserState,
|
|
69
|
-
options: parserContext,
|
|
70
|
-
track,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return trackEntry;
|
|
74
|
-
}
|
|
75
|
-
if (segmentId === '0xd7') {
|
|
76
|
-
return (0, track_entry_1.parseTrackNumber)(iterator, length);
|
|
77
|
-
}
|
|
78
|
-
if (segmentId === '0x73c5') {
|
|
79
|
-
return (0, track_entry_1.parseTrackUID)(iterator, length);
|
|
80
|
-
}
|
|
81
|
-
if (segmentId === '0x9c') {
|
|
82
|
-
return (0, track_entry_1.parseFlagLacing)(iterator, length);
|
|
83
|
-
}
|
|
84
|
-
if (segmentId === '0x22b59c') {
|
|
85
|
-
return (0, track_entry_1.parseLanguageSegment)(iterator, length);
|
|
86
|
-
}
|
|
87
|
-
if (segmentId === '0x86') {
|
|
88
|
-
return (0, track_entry_1.parseCodecSegment)(iterator, length);
|
|
89
|
-
}
|
|
90
|
-
if (segmentId === '0x83') {
|
|
91
|
-
return (0, track_entry_1.parseTrackTypeSegment)(iterator, length);
|
|
92
|
-
}
|
|
93
|
-
if (segmentId === '0x55ee') {
|
|
94
|
-
return (0, track_entry_1.parseMaxBlockAdditionId)(iterator, length);
|
|
95
|
-
}
|
|
96
|
-
if (segmentId === '0x55b0') {
|
|
97
|
-
return (0, track_entry_1.parseColorSegment)(iterator, length);
|
|
98
|
-
}
|
|
99
|
-
if (segmentId === '0x23e383') {
|
|
100
|
-
return (0, track_entry_1.parseDefaultDurationSegment)(iterator, length);
|
|
101
|
-
}
|
|
102
|
-
if (segmentId === '0xe0') {
|
|
103
|
-
return (0, track_entry_1.parseVideoSegment)(iterator, length, parserContext);
|
|
104
|
-
}
|
|
105
|
-
if (segmentId === '0xe1') {
|
|
106
|
-
return (0, track_entry_1.parseAudioSegment)(iterator, length, parserContext);
|
|
107
|
-
}
|
|
108
|
-
if (segmentId === '0xb0') {
|
|
109
|
-
return (0, track_entry_1.parseWidthSegment)(iterator, length);
|
|
110
|
-
}
|
|
111
|
-
if (segmentId === '0xba') {
|
|
112
|
-
return (0, track_entry_1.parseHeightSegment)(iterator, length);
|
|
113
|
-
}
|
|
114
|
-
if (segmentId === all_segments_1.matroskaElements.DisplayWidth) {
|
|
115
|
-
return (0, track_entry_1.parseDisplayWidthSegment)(iterator, length);
|
|
116
|
-
}
|
|
117
|
-
if (segmentId === all_segments_1.matroskaElements.DisplayHeight) {
|
|
118
|
-
return (0, track_entry_1.parseDisplayHeightSegment)(iterator, length);
|
|
119
|
-
}
|
|
120
|
-
if (segmentId === '0x9a') {
|
|
121
|
-
return (0, track_entry_1.parseInterlacedSegment)(iterator, length);
|
|
122
|
-
}
|
|
123
|
-
if (segmentId === '0x53c0') {
|
|
124
|
-
return (0, track_entry_1.parseAlphaModeSegment)(iterator, length);
|
|
125
|
-
}
|
|
126
|
-
if (segmentId === '0x63a2') {
|
|
127
|
-
return (0, track_entry_1.parseCodecPrivateSegment)(iterator, length);
|
|
128
|
-
}
|
|
129
|
-
if (segmentId === '0x7ba9') {
|
|
130
|
-
return (0, track_entry_1.parseTitleSegment)(iterator, length);
|
|
131
|
-
}
|
|
132
|
-
if (segmentId === '0xbf') {
|
|
133
|
-
return (0, track_entry_1.parseCrc32Segment)(iterator, length);
|
|
134
|
-
}
|
|
135
|
-
if (segmentId === '0x73a4') {
|
|
136
|
-
return (0, track_entry_1.parseSegmentUUIDSegment)(iterator, length);
|
|
137
|
-
}
|
|
138
|
-
if (segmentId === '0x88') {
|
|
139
|
-
return (0, track_entry_1.parseDefaultFlagSegment)(iterator, length);
|
|
140
|
-
}
|
|
141
|
-
if (segmentId === '0x1254c367') {
|
|
142
|
-
return (0, track_entry_1.parseTagsSegment)(iterator, length, parserContext);
|
|
143
|
-
}
|
|
144
|
-
if (segmentId === '0x7373') {
|
|
145
|
-
return (0, track_entry_1.parseTagSegment)(iterator, length);
|
|
146
|
-
}
|
|
147
|
-
if (segmentId === all_segments_1.matroskaElements.SamplingFrequency) {
|
|
148
|
-
return (0, track_entry_1.parseSamplingFrequencySegment)(iterator, length);
|
|
149
|
-
}
|
|
150
|
-
if (segmentId === all_segments_1.matroskaElements.Channels) {
|
|
151
|
-
return (0, track_entry_1.parseChannelsSegment)(iterator, length);
|
|
152
|
-
}
|
|
153
|
-
if (segmentId === all_segments_1.matroskaElements.BitDepth) {
|
|
154
|
-
return (0, track_entry_1.parseBitDepthSegment)(iterator, length);
|
|
155
|
-
}
|
|
156
|
-
if (segmentId === all_segments_1.matroskaElements.Timestamp) {
|
|
157
|
-
const offset = iterator.counter.getOffset();
|
|
158
|
-
const timestampSegment = (0, track_entry_1.parseTimestampSegment)(iterator, length);
|
|
159
|
-
parserContext.parserState.setTimestampOffset(offset, timestampSegment.timestamp);
|
|
160
|
-
return timestampSegment;
|
|
161
|
-
}
|
|
162
|
-
if (segmentId === all_segments_1.matroskaElements.SimpleBlock ||
|
|
163
|
-
segmentId === all_segments_1.matroskaElements.Block) {
|
|
164
|
-
return (0, track_entry_1.parseSimpleBlockOrBlockSegment)({
|
|
165
|
-
iterator,
|
|
166
|
-
length,
|
|
167
|
-
parserContext,
|
|
168
|
-
type: segmentId,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
if (segmentId === all_segments_1.matroskaElements.ReferenceBlock) {
|
|
172
|
-
return (0, track_entry_1.parseReferenceBlockSegment)(iterator, length);
|
|
173
|
-
}
|
|
174
|
-
if (segmentId === all_segments_1.matroskaElements.BlockAdditions) {
|
|
175
|
-
return (0, track_entry_1.parseBlockAdditionsSegment)(iterator, length);
|
|
176
|
-
}
|
|
177
|
-
if (segmentId === '0xa0') {
|
|
178
|
-
const blockGroup = await (0, track_entry_1.parseBlockGroupSegment)(iterator, length, parserContext);
|
|
179
|
-
// Blocks don't have information about keyframes.
|
|
180
|
-
// https://ffmpeg.org/pipermail/ffmpeg-devel/2015-June/173825.html
|
|
181
|
-
// "For Blocks, keyframes is
|
|
182
|
-
// inferred by the absence of ReferenceBlock element (as done by matroskadec).""
|
|
183
|
-
const block = blockGroup.children.find((c) => c.type === 'simple-block-or-block-segment');
|
|
184
|
-
if (!block || block.type !== 'simple-block-or-block-segment') {
|
|
185
|
-
throw new Error('Expected block segment');
|
|
186
|
-
}
|
|
187
|
-
const hasReferenceBlock = blockGroup.children.find((c) => c.type === 'reference-block-segment');
|
|
188
|
-
const partialVideoSample = block.videoSample;
|
|
189
|
-
if (partialVideoSample) {
|
|
190
|
-
const completeFrame = {
|
|
191
|
-
...partialVideoSample,
|
|
192
|
-
type: hasReferenceBlock ? 'delta' : 'key',
|
|
193
|
-
};
|
|
194
|
-
await parserContext.parserState.onVideoSample(partialVideoSample.trackId, completeFrame);
|
|
195
|
-
}
|
|
196
|
-
return blockGroup;
|
|
197
|
-
}
|
|
198
|
-
if (segmentId === '0xa1') {
|
|
199
|
-
return (0, track_entry_1.parseBlockElementSegment)(iterator, length);
|
|
200
|
-
}
|
|
201
10
|
iterator.counter.decrement(headerReadSoFar);
|
|
202
|
-
|
|
11
|
+
const offset = iterator.counter.getOffset();
|
|
12
|
+
const ebml = await (0, parse_ebml_1.parseEbml)(iterator, parserContext);
|
|
13
|
+
const remapped = await (0, parse_ebml_1.postprocessEbml)({ offset, ebml, parserContext });
|
|
14
|
+
return remapped;
|
|
203
15
|
};
|
|
204
16
|
const expectSegment = async (iterator, parserContext) => {
|
|
205
17
|
const offset = iterator.counter.getOffset();
|
|
@@ -225,7 +37,9 @@ const expectSegment = async (iterator, parserContext) => {
|
|
|
225
37
|
skipTo: null,
|
|
226
38
|
};
|
|
227
39
|
}
|
|
40
|
+
const offsetBeforeVInt = iterator.counter.getOffset();
|
|
228
41
|
const length = iterator.getVint();
|
|
42
|
+
const offsetAfterVInt = iterator.counter.getOffset();
|
|
229
43
|
if (length === null) {
|
|
230
44
|
iterator.counter.decrement(iterator.counter.getOffset() - offset);
|
|
231
45
|
return {
|
|
@@ -245,12 +59,14 @@ const expectSegment = async (iterator, parserContext) => {
|
|
|
245
59
|
initialChildren: [],
|
|
246
60
|
wrap: segmentId === '0x18538067'
|
|
247
61
|
? (s) => ({
|
|
248
|
-
type: '
|
|
249
|
-
|
|
62
|
+
type: 'Segment',
|
|
63
|
+
value: s,
|
|
64
|
+
minVintWidth: offsetAfterVInt - offsetBeforeVInt,
|
|
250
65
|
})
|
|
251
66
|
: (s) => ({
|
|
252
|
-
type: '
|
|
253
|
-
|
|
67
|
+
type: 'Cluster',
|
|
68
|
+
value: s,
|
|
69
|
+
minVintWidth: offsetAfterVInt - offsetBeforeVInt,
|
|
254
70
|
}),
|
|
255
71
|
parserContext,
|
|
256
72
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParserContext } from '../../parser-context';
|
|
3
|
+
import type { MatroskaSegment } from './segments';
|
|
4
|
+
export type TracksSegment = {
|
|
5
|
+
type: 'tracks-segment';
|
|
6
|
+
children: MatroskaSegment[];
|
|
7
|
+
};
|
|
8
|
+
export declare const parseTracksSegment: (iterator: BufferIterator, length: number, parserContext: ParserContext) => Promise<TracksSegment>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTracksSegment = void 0;
|
|
4
|
+
const parse_children_1 = require("./segments/parse-children");
|
|
5
|
+
const parseTracksSegment = async (iterator, length, parserContext) => {
|
|
6
|
+
const children = await (0, parse_children_1.expectChildren)({
|
|
7
|
+
iterator,
|
|
8
|
+
length,
|
|
9
|
+
initialChildren: [],
|
|
10
|
+
wrap: null,
|
|
11
|
+
parserContext,
|
|
12
|
+
});
|
|
13
|
+
if (children.status === 'incomplete') {
|
|
14
|
+
throw new Error('Incomplete children');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
type: 'tracks-segment',
|
|
18
|
+
children: children.segments,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.parseTracksSegment = parseTracksSegment;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { AnySegment } from '../../parse-result';
|
|
2
|
-
import type { MainSegment } from './segments/
|
|
3
|
-
import type { CodecSegment, TrackEntrySegment } from './segments/track-entry';
|
|
2
|
+
import type { CodecIdSegment, MainSegment, TrackEntry } from './segments/all-segments';
|
|
4
3
|
export declare const getMainSegment: (segments: AnySegment[]) => MainSegment | null;
|
|
5
|
-
export declare const getTrackNumber: (track:
|
|
6
|
-
export declare const getTrackCodec: (track:
|
|
7
|
-
export declare const getTrackTimestampScale: (track:
|
|
8
|
-
export declare const getTrackByNumber: (tracks:
|
|
4
|
+
export declare const getTrackNumber: (track: TrackEntry) => import("./segments/all-segments").UintWithSize | null;
|
|
5
|
+
export declare const getTrackCodec: (track: TrackEntry) => CodecIdSegment | null;
|
|
6
|
+
export declare const getTrackTimestampScale: (track: TrackEntry) => import("./segments/all-segments").FloatWithSize | null;
|
|
7
|
+
export declare const getTrackByNumber: (tracks: TrackEntry[], id: number) => TrackEntry | undefined;
|
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTrackByNumber = exports.getTrackTimestampScale = exports.getTrackCodec = exports.getTrackNumber = exports.getMainSegment = void 0;
|
|
4
4
|
const getMainSegment = (segments) => {
|
|
5
|
-
return segments.find((s) => s.type === '
|
|
5
|
+
return segments.find((s) => s.type === 'Segment');
|
|
6
6
|
};
|
|
7
7
|
exports.getMainSegment = getMainSegment;
|
|
8
8
|
const getTrackNumber = (track) => {
|
|
9
9
|
var _a;
|
|
10
|
-
const child = track.
|
|
11
|
-
return (_a = child === null || child === void 0 ? void 0 : child.
|
|
10
|
+
const child = track.value.find((b) => b.type === 'TrackNumber');
|
|
11
|
+
return (_a = child === null || child === void 0 ? void 0 : child.value) !== null && _a !== void 0 ? _a : null;
|
|
12
12
|
};
|
|
13
13
|
exports.getTrackNumber = getTrackNumber;
|
|
14
14
|
const getTrackCodec = (track) => {
|
|
15
|
-
const child = track.
|
|
15
|
+
const child = track.value.find((b) => b.type === 'CodecID');
|
|
16
16
|
return child !== null && child !== void 0 ? child : null;
|
|
17
17
|
};
|
|
18
18
|
exports.getTrackCodec = getTrackCodec;
|
|
19
19
|
const getTrackTimestampScale = (track) => {
|
|
20
|
-
const child = track.
|
|
20
|
+
const child = track.value.find((b) => b.type === 'TrackTimestampScale');
|
|
21
21
|
if (!child) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
@@ -30,7 +30,7 @@ exports.getTrackTimestampScale = getTrackTimestampScale;
|
|
|
30
30
|
const getTrackByNumber = (tracks, id) => {
|
|
31
31
|
return tracks.find((track) => {
|
|
32
32
|
const trackNumber = (0, exports.getTrackNumber)(track);
|
|
33
|
-
return trackNumber === id;
|
|
33
|
+
return (trackNumber === null || trackNumber === void 0 ? void 0 : trackNumber.value) === id;
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
exports.getTrackByNumber = getTrackByNumber;
|
|
@@ -8,7 +8,7 @@ export declare class OffsetCounter {
|
|
|
8
8
|
discardBytes(amount: number): void;
|
|
9
9
|
decrement(amount: number): void;
|
|
10
10
|
}
|
|
11
|
-
export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes
|
|
11
|
+
export declare const getArrayBufferIterator: (initialData: Uint8Array, maxBytes: number | null) => {
|
|
12
12
|
startReadingBits: () => void;
|
|
13
13
|
stopReadingBits: () => void;
|
|
14
14
|
skipTo: (offset: number) => void;
|
package/dist/buffer-iterator.js
CHANGED
|
@@ -62,9 +62,9 @@ const makeOffsetCounter = () => {
|
|
|
62
62
|
};
|
|
63
63
|
const getArrayBufferIterator = (initialData, maxBytes) => {
|
|
64
64
|
const buf = new ArrayBuffer(initialData.byteLength, {
|
|
65
|
-
maxByteLength: maxBytes
|
|
66
|
-
?
|
|
67
|
-
:
|
|
65
|
+
maxByteLength: maxBytes === null
|
|
66
|
+
? initialData.byteLength
|
|
67
|
+
: Math.min(maxBytes, 2 ** 32),
|
|
68
68
|
});
|
|
69
69
|
if (!buf.resize) {
|
|
70
70
|
throw new Error('`ArrayBuffer.resize` is not supported in this Runtime. On the server: Use at least Node.js 20 or Bun. In the browser: Chrome 111, Edge 111, Safari 16.4, Firefox 128, Opera 111');
|
package/dist/from-web.js
CHANGED
|
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.webReader = void 0;
|
|
4
4
|
exports.webReader = {
|
|
5
5
|
read: async (src, range) => {
|
|
6
|
-
if (typeof src !== 'string') {
|
|
7
|
-
throw new Error('src must be a string when using `webReader`');
|
|
8
|
-
}
|
|
9
6
|
const resolvedUrl = typeof window !== 'undefined' && typeof window.location !== 'undefined'
|
|
10
7
|
? new URL(src, window.location.origin).toString()
|
|
11
8
|
: src;
|
|
@@ -17,28 +14,22 @@ exports.webReader = {
|
|
|
17
14
|
const res = await fetch(resolvedUrl, {
|
|
18
15
|
headers: range === null
|
|
19
16
|
? {}
|
|
20
|
-
:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
: {
|
|
25
|
-
Range: `bytes=${`${range[0]}-${range[1]}`}`,
|
|
26
|
-
},
|
|
27
|
-
// Disable Next.js caching
|
|
28
|
-
cache: 'no-store',
|
|
17
|
+
: {
|
|
18
|
+
Range: `bytes=${`${range[0]}-${range[1]}`}`,
|
|
19
|
+
},
|
|
29
20
|
});
|
|
30
21
|
if (!res.body) {
|
|
31
22
|
throw new Error('No body');
|
|
32
23
|
}
|
|
33
24
|
const length = res.headers.get('content-length');
|
|
25
|
+
if (!length) {
|
|
26
|
+
throw new Error('No content-length');
|
|
27
|
+
}
|
|
34
28
|
const contentLength = length === null ? null : parseInt(length, 10);
|
|
35
29
|
const reader = res.body.getReader();
|
|
36
30
|
return { reader, contentLength };
|
|
37
31
|
},
|
|
38
32
|
getLength: async (src) => {
|
|
39
|
-
if (typeof src !== 'string') {
|
|
40
|
-
throw new Error('src must be a string when using `webReader`');
|
|
41
|
-
}
|
|
42
33
|
const res = await fetch(src, {
|
|
43
34
|
method: 'HEAD',
|
|
44
35
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MoovBox } from './boxes/iso-base-media/moov/moov';
|
|
2
2
|
import type { TrakBox } from './boxes/iso-base-media/trak/trak';
|
|
3
|
-
import type { MainSegment } from './boxes/webm/segments/
|
|
3
|
+
import type { MainSegment } from './boxes/webm/segments/all-segments';
|
|
4
4
|
import type { KnownAudioCodecs } from './options';
|
|
5
5
|
import type { AnySegment } from './parse-result';
|
|
6
6
|
export declare const hasAudioCodec: (boxes: AnySegment[]) => boolean;
|
package/dist/get-audio-codec.js
CHANGED
|
@@ -115,27 +115,27 @@ const getAudioCodecFromIso = (moov) => {
|
|
|
115
115
|
};
|
|
116
116
|
exports.getAudioCodecFromIso = getAudioCodecFromIso;
|
|
117
117
|
const getAudioCodecFromMatroska = (mainSegment) => {
|
|
118
|
-
const tracksSegment = mainSegment.
|
|
119
|
-
if (!tracksSegment || tracksSegment.type !== '
|
|
118
|
+
const tracksSegment = mainSegment.value.find((b) => b.type === 'Tracks');
|
|
119
|
+
if (!tracksSegment || tracksSegment.type !== 'Tracks') {
|
|
120
120
|
return null;
|
|
121
121
|
}
|
|
122
|
-
for (const track of tracksSegment.
|
|
123
|
-
if (track.type === '
|
|
124
|
-
const trackType = track.
|
|
125
|
-
if (trackType && trackType.type === '
|
|
126
|
-
if (trackType.
|
|
122
|
+
for (const track of tracksSegment.value) {
|
|
123
|
+
if (track.type === 'TrackEntry') {
|
|
124
|
+
const trackType = track.value.find((b) => b.type === 'CodecID');
|
|
125
|
+
if (trackType && trackType.type === 'CodecID') {
|
|
126
|
+
if (trackType.value === 'A_OPUS') {
|
|
127
127
|
return 'opus';
|
|
128
128
|
}
|
|
129
|
-
if (trackType.
|
|
129
|
+
if (trackType.value === 'A_VORBIS') {
|
|
130
130
|
return 'vorbis';
|
|
131
131
|
}
|
|
132
|
-
if (trackType.
|
|
132
|
+
if (trackType.value === 'A_PCM/INT/LIT') {
|
|
133
133
|
return 'pcm';
|
|
134
134
|
}
|
|
135
|
-
if (trackType.
|
|
135
|
+
if (trackType.value === 'A_AAC') {
|
|
136
136
|
return 'aac';
|
|
137
137
|
}
|
|
138
|
-
if (trackType.
|
|
138
|
+
if (trackType.value === 'A_MPEG/L3') {
|
|
139
139
|
return 'mp3';
|
|
140
140
|
}
|
|
141
141
|
}
|
|
@@ -190,8 +190,8 @@ const getAudioCodec = (boxes) => {
|
|
|
190
190
|
}
|
|
191
191
|
throw new Error('Unknown audio format: ' + codec.format);
|
|
192
192
|
}
|
|
193
|
-
const mainSegment = boxes.find((b) => b.type === '
|
|
194
|
-
if (!mainSegment || mainSegment.type !== '
|
|
193
|
+
const mainSegment = boxes.find((b) => b.type === 'Segment');
|
|
194
|
+
if (!mainSegment || mainSegment.type !== 'Segment') {
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
197
|
return (0, exports.getAudioCodecFromMatroska)(mainSegment);
|
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
|
}
|
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
|
}
|
|
@@ -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/parse-media.js
CHANGED
|
@@ -28,6 +28,9 @@ const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.
|
|
|
28
28
|
onAudioTrack: onAudioTrack !== null && onAudioTrack !== void 0 ? onAudioTrack : null,
|
|
29
29
|
onVideoTrack: onVideoTrack !== null && onVideoTrack !== void 0 ? onVideoTrack : null,
|
|
30
30
|
parserState: state,
|
|
31
|
+
nullifySamples: !(typeof process !== 'undefined' &&
|
|
32
|
+
typeof process.env !== 'undefined' &&
|
|
33
|
+
process.env.KEEP_SAMPLES === 'true'),
|
|
31
34
|
};
|
|
32
35
|
while (parseResult === null || parseResult.status === 'incomplete') {
|
|
33
36
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
@@ -43,7 +46,7 @@ const parseMedia = async ({ src, fields, reader: readerInterface = from_fetch_1.
|
|
|
43
46
|
if (result.done) {
|
|
44
47
|
throw new Error('Unexpectedly reached EOF');
|
|
45
48
|
}
|
|
46
|
-
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);
|
|
47
50
|
}
|
|
48
51
|
if (parseResult && parseResult.status === 'incomplete') {
|
|
49
52
|
parseResult = await parseResult.continueParsing();
|
package/dist/parser-context.d.ts
CHANGED
package/dist/parser-state.js
CHANGED
|
@@ -6,6 +6,7 @@ const traversal_2 = require("./traversal");
|
|
|
6
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');
|
|
@@ -19,8 +20,8 @@ const makeParserState = ({ hasAudioCallbacks, hasVideoCallbacks, signal, }) => {
|
|
|
19
20
|
}
|
|
20
21
|
const trackTimescale = (0, traversal_1.getTrackTimestampScale)(trackEntry);
|
|
21
22
|
trackEntries[trackId] = {
|
|
22
|
-
codec: codec.
|
|
23
|
-
trackTimescale,
|
|
23
|
+
codec: codec.value,
|
|
24
|
+
trackTimescale: (_a = trackTimescale === null || trackTimescale === void 0 ? void 0 : trackTimescale.value) !== null && _a !== void 0 ? _a : null,
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
const videoSampleCallbacks = {};
|