@remotion/media-parser 4.0.248 → 4.0.250
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/avc/key.d.ts +1 -1
- package/dist/boxes/iso-base-media/continue-mdat-routine.d.ts +14 -0
- package/dist/boxes/iso-base-media/continue-mdat-routine.js +74 -0
- package/dist/boxes/iso-base-media/get-children.d.ts +8 -0
- package/dist/boxes/iso-base-media/get-children.js +23 -0
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -22
- package/dist/boxes/iso-base-media/mdat/mdat.js +80 -121
- package/dist/boxes/iso-base-media/moov/moov.d.ts +1 -6
- package/dist/boxes/iso-base-media/moov/moov.js +5 -15
- package/dist/boxes/iso-base-media/parse-all-children.d.ts +8 -0
- package/dist/boxes/iso-base-media/parse-all-children.js +20 -0
- package/dist/boxes/iso-base-media/parse-boxes.d.ts +7 -0
- package/dist/boxes/iso-base-media/parse-boxes.js +46 -0
- package/dist/boxes/iso-base-media/parse-mdat-partially.d.ts +9 -0
- package/dist/boxes/iso-base-media/parse-mdat-partially.js +24 -0
- package/dist/boxes/iso-base-media/process-box.d.ts +2 -29
- package/dist/boxes/iso-base-media/process-box.js +56 -367
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +1 -4
- package/dist/boxes/iso-base-media/stsd/mebx.js +5 -15
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -12
- package/dist/boxes/iso-base-media/stsd/samples.js +24 -70
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +1 -4
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -5
- package/dist/boxes/iso-base-media/trak/trak.d.ts +1 -6
- package/dist/boxes/iso-base-media/trak/trak.js +5 -15
- package/dist/boxes/iso-base-media/traversal.d.ts +0 -2
- package/dist/boxes/iso-base-media/traversal.js +1 -12
- package/dist/boxes/mp3/get-duration.d.ts +2 -0
- package/dist/boxes/mp3/get-duration.js +30 -0
- package/dist/boxes/mp3/get-frame-length.d.ts +13 -0
- package/dist/boxes/mp3/get-frame-length.js +33 -0
- package/dist/boxes/mp3/get-metadata-from-mp3.d.ts +3 -0
- package/dist/boxes/mp3/get-metadata-from-mp3.js +8 -0
- package/dist/boxes/mp3/get-tracks-from-mp3.d.ts +4 -0
- package/dist/boxes/mp3/get-tracks-from-mp3.js +25 -0
- package/dist/boxes/mp3/id3-v1.d.ts +2 -0
- package/dist/boxes/mp3/id3-v1.js +12 -0
- package/dist/boxes/mp3/id3-v2.d.ts +0 -0
- package/dist/boxes/mp3/id3-v2.js +1 -0
- package/dist/boxes/mp3/id3.d.ts +6 -0
- package/dist/boxes/mp3/id3.js +80 -0
- package/dist/boxes/mp3/parse-mp3.d.ts +7 -0
- package/dist/boxes/mp3/parse-mp3.js +41 -0
- package/dist/boxes/mp3/parse-mpeg-header.d.ts +6 -0
- package/dist/boxes/mp3/parse-mpeg-header.js +274 -0
- package/dist/boxes/mp3/samples-per-mpeg-file.d.ts +4 -0
- package/dist/boxes/mp3/samples-per-mpeg-file.js +26 -0
- package/dist/boxes/riff/continue-after-riff-result.d.ts +13 -0
- package/dist/boxes/riff/continue-after-riff-result.js +34 -0
- package/dist/boxes/riff/expect-riff-box.d.ts +1 -7
- package/dist/boxes/riff/expect-riff-box.js +47 -24
- package/dist/boxes/riff/get-tracks-from-avi.d.ts +1 -1
- package/dist/boxes/riff/get-tracks-from-avi.js +6 -10
- package/dist/boxes/riff/parse-box.d.ts +1 -7
- package/dist/boxes/riff/parse-box.js +4 -120
- package/dist/boxes/riff/parse-fmt-box.d.ts +3 -2
- package/dist/boxes/riff/parse-fmt-box.js +7 -5
- package/dist/boxes/riff/parse-list-box.js +15 -14
- package/dist/boxes/riff/parse-movi.d.ts +2 -5
- package/dist/boxes/riff/parse-movi.js +34 -56
- package/dist/boxes/riff/parse-riff-body.d.ts +7 -0
- package/dist/boxes/riff/parse-riff-body.js +25 -0
- package/dist/boxes/riff/parse-riff-box.d.ts +1 -2
- package/dist/boxes/riff/parse-riff-box.js +2 -6
- package/dist/boxes/riff/parse-riff-header.d.ts +7 -0
- package/dist/boxes/riff/parse-riff-header.js +23 -0
- package/dist/boxes/riff/parse-riff.d.ts +7 -0
- package/dist/boxes/riff/parse-riff.js +15 -0
- package/dist/boxes/riff/parse-strf.d.ts +4 -4
- package/dist/boxes/riff/parse-strf.js +4 -8
- package/dist/boxes/riff/parse-strh.js +11 -0
- package/dist/boxes/riff/parse-video-section.d.ts +6 -0
- package/dist/boxes/riff/parse-video-section.js +20 -0
- package/dist/boxes/riff/riff-box.d.ts +4 -5
- package/dist/boxes/riff/traversal.d.ts +1 -2
- package/dist/boxes/riff/traversal.js +1 -6
- package/dist/boxes/transport-stream/get-tracks.d.ts +2 -3
- package/dist/boxes/transport-stream/get-tracks.js +4 -3
- package/dist/boxes/transport-stream/parse-packet.d.ts +1 -7
- package/dist/boxes/transport-stream/parse-packet.js +3 -4
- package/dist/boxes/transport-stream/parse-stream-packet.d.ts +1 -5
- package/dist/boxes/transport-stream/parse-stream-packet.js +10 -12
- package/dist/boxes/transport-stream/parse-transport-stream.d.ts +1 -7
- package/dist/boxes/transport-stream/parse-transport-stream.js +19 -49
- package/dist/boxes/transport-stream/process-stream-buffers.d.ts +1 -2
- package/dist/boxes/transport-stream/process-stream-buffers.js +3 -3
- package/dist/boxes/webm/parse-ebml.js +3 -0
- package/dist/boxes/webm/parse-webm-header.d.ts +2 -4
- package/dist/boxes/webm/parse-webm-header.js +41 -25
- package/dist/boxes/webm/segments/parse-children.d.ts +2 -16
- package/dist/boxes/webm/segments/parse-children.js +7 -130
- package/dist/boxes/webm/segments.d.ts +4 -8
- package/dist/boxes/webm/segments.js +41 -123
- package/dist/buffer-iterator.d.ts +6 -3
- package/dist/buffer-iterator.js +27 -16
- package/dist/bun-reader.d.ts +1 -0
- package/dist/bun-reader.js +17 -0
- package/dist/continue-mdat-routine.d.ts +17 -0
- package/dist/continue-mdat-routine.js +92 -0
- package/dist/emit-available-info.js +42 -28
- package/dist/esm/from-node.mjs +8 -9
- package/dist/esm/index.mjs +5133 -5085
- package/dist/file-types/detect-file-type.js +6 -2
- package/dist/get-audio-codec.d.ts +1 -1
- package/dist/get-audio-codec.js +3 -3
- package/dist/get-container.js +5 -1
- package/dist/get-dimensions.d.ts +1 -1
- package/dist/get-dimensions.js +4 -1
- package/dist/get-duration.js +6 -2
- package/dist/get-fields-from-callbacks.js +1 -0
- package/dist/get-fps.js +3 -0
- package/dist/get-is-hdr.d.ts +1 -1
- package/dist/get-is-hdr.js +3 -3
- package/dist/get-keyframes.js +1 -1
- package/dist/get-tracks.d.ts +2 -2
- package/dist/get-tracks.js +23 -15
- package/dist/get-video-codec.d.ts +1 -1
- package/dist/get-video-codec.js +3 -3
- package/dist/has-all-info.js +4 -3
- package/dist/index.d.ts +65 -21
- package/dist/index.js +1 -1
- package/dist/may-skip-video-data/may-skip-video-data.js +6 -2
- package/dist/may-skip-video-data/need-samples-for-fields.js +1 -0
- package/dist/metadata/get-metadata.d.ts +1 -0
- package/dist/metadata/get-metadata.js +16 -1
- package/dist/options.d.ts +12 -5
- package/dist/parse-media.js +88 -68
- package/dist/parse-result.d.ts +17 -19
- package/dist/parse-video.d.ts +3 -17
- package/dist/parse-video.js +52 -40
- package/dist/readers/from-node.js +7 -8
- package/dist/state/can-skip-tracks.d.ts +8 -1
- package/dist/state/can-skip-tracks.js +38 -26
- package/dist/state/emitted-fields.js +1 -0
- package/dist/state/images.d.ts +9 -0
- package/dist/state/images.js +14 -0
- package/dist/state/iso-base-media/cached-sample-positions.d.ts +15 -0
- package/dist/state/iso-base-media/cached-sample-positions.js +42 -0
- package/dist/state/iso-base-media/iso-state.d.ts +8 -0
- package/dist/state/iso-base-media/iso-state.js +15 -0
- package/dist/state/iso-state.d.ts +4 -0
- package/dist/state/iso-state.js +13 -0
- package/dist/state/mp3.d.ts +11 -0
- package/dist/state/mp3.js +13 -0
- package/dist/state/parser-state.d.ts +57 -11
- package/dist/state/parser-state.js +17 -2
- package/dist/state/sample-callbacks.d.ts +5 -1
- package/dist/state/sample-callbacks.js +8 -2
- package/dist/state/slow-duration-fps.d.ts +2 -1
- package/dist/state/slow-duration-fps.js +52 -18
- package/dist/state/transport-stream.d.ts +8 -0
- package/dist/state/transport-stream.js +11 -0
- package/dist/state/video-section.d.ts +16 -0
- package/dist/state/video-section.js +37 -0
- package/dist/state/webm.d.ts +15 -0
- package/dist/state/webm.js +32 -0
- package/dist/throttled-progress.d.ts +14 -0
- package/dist/throttled-progress.js +44 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/test.json +663 -0
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMebx = void 0;
|
|
4
|
-
const
|
|
5
|
-
const parseMebx = async ({ iterator, offset, size, state,
|
|
4
|
+
const get_children_1 = require("../get-children");
|
|
5
|
+
const parseMebx = async ({ iterator, offset, size, state, }) => {
|
|
6
6
|
// reserved, 6 bit
|
|
7
7
|
iterator.discard(6);
|
|
8
8
|
const dataReferenceIndex = iterator.getUint16();
|
|
9
|
-
const
|
|
10
|
-
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
9
|
+
const children = await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
11
10
|
iterator,
|
|
12
|
-
maxBytes: iterator.counter.getOffset() - offset,
|
|
13
|
-
allowIncompleteBoxes: false,
|
|
14
|
-
initialBoxes: boxes,
|
|
15
11
|
state,
|
|
16
|
-
|
|
17
|
-
signal,
|
|
18
|
-
logLevel: 'info',
|
|
19
|
-
fields,
|
|
12
|
+
size: size - 8,
|
|
20
13
|
});
|
|
21
|
-
if (children.status === 'incomplete') {
|
|
22
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
23
|
-
}
|
|
24
14
|
return {
|
|
25
15
|
type: 'mebx-box',
|
|
26
16
|
boxSize: size,
|
|
27
17
|
offset,
|
|
28
18
|
dataReferenceIndex,
|
|
29
19
|
format: 'mebx',
|
|
30
|
-
children
|
|
20
|
+
children,
|
|
31
21
|
};
|
|
32
22
|
};
|
|
33
23
|
exports.parseMebx = parseMebx;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
|
-
import type { LogLevel } from '../../../log';
|
|
3
|
-
import type { Options, ParseMediaFields } from '../../../options';
|
|
4
2
|
import type { AnySegment, IsoBaseMediaBox } from '../../../parse-result';
|
|
5
3
|
import type { ParserState } from '../../../state/parser-state';
|
|
6
4
|
type SampleBase = {
|
|
@@ -47,22 +45,16 @@ type UnknownSample = SampleBase & {
|
|
|
47
45
|
type: 'unknown';
|
|
48
46
|
};
|
|
49
47
|
export type Sample = AudioSample | VideoSample | UnknownSample;
|
|
50
|
-
type
|
|
48
|
+
type FormatBoxAndNext = {
|
|
51
49
|
sample: Sample | null;
|
|
52
50
|
};
|
|
53
|
-
export declare const
|
|
51
|
+
export declare const processIsoFormatBox: ({ iterator, state, }: {
|
|
54
52
|
iterator: BufferIterator;
|
|
55
53
|
state: ParserState;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
fields: Options<ParseMediaFields>;
|
|
59
|
-
}) => Promise<SampleAndNext>;
|
|
60
|
-
export declare const parseSamples: ({ iterator, maxBytes, state, signal, logLevel, fields, }: {
|
|
54
|
+
}) => Promise<FormatBoxAndNext>;
|
|
55
|
+
export declare const parseIsoFormatBoxes: ({ iterator, maxBytes, state, }: {
|
|
61
56
|
iterator: BufferIterator;
|
|
62
57
|
maxBytes: number;
|
|
63
58
|
state: ParserState;
|
|
64
|
-
signal: AbortSignal | null;
|
|
65
|
-
logLevel: LogLevel;
|
|
66
|
-
fields: Options<ParseMediaFields>;
|
|
67
59
|
}) => Promise<Sample[]>;
|
|
68
60
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.parseIsoFormatBoxes = exports.processIsoFormatBox = void 0;
|
|
4
|
+
const get_children_1 = require("../get-children");
|
|
5
5
|
// https://developer.apple.com/documentation/quicktime-file-format/video_sample_description
|
|
6
6
|
const videoTags = [
|
|
7
7
|
'cvid',
|
|
@@ -62,7 +62,7 @@ const audioTags = [
|
|
|
62
62
|
'mp4a',
|
|
63
63
|
'ac-3',
|
|
64
64
|
];
|
|
65
|
-
const
|
|
65
|
+
const processIsoFormatBox = async ({ iterator, state, }) => {
|
|
66
66
|
const fileOffset = iterator.counter.getOffset();
|
|
67
67
|
const bytesRemaining = iterator.bytesRemaining();
|
|
68
68
|
const boxSize = iterator.getUint32();
|
|
@@ -98,22 +98,11 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
98
98
|
const compressionId = iterator.getUint16();
|
|
99
99
|
const packetSize = iterator.getUint16();
|
|
100
100
|
const sampleRate = iterator.getFixedPointUnsigned1616Number();
|
|
101
|
-
const
|
|
102
|
-
const initialBoxes = [];
|
|
103
|
-
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
101
|
+
const children = await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
104
102
|
iterator,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
initialBoxes,
|
|
108
|
-
state: options,
|
|
109
|
-
continueMdat: false,
|
|
110
|
-
signal,
|
|
111
|
-
logLevel,
|
|
112
|
-
fields,
|
|
103
|
+
state,
|
|
104
|
+
size: boxSize - (iterator.counter.getOffset() - fileOffset),
|
|
113
105
|
});
|
|
114
|
-
if (children.status === 'incomplete') {
|
|
115
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
116
|
-
}
|
|
117
106
|
return {
|
|
118
107
|
sample: {
|
|
119
108
|
format: boxFormat,
|
|
@@ -133,7 +122,7 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
133
122
|
bytesPerPacket: null,
|
|
134
123
|
bytesPerFrame: null,
|
|
135
124
|
bitsPerSample: null,
|
|
136
|
-
children
|
|
125
|
+
children,
|
|
137
126
|
},
|
|
138
127
|
};
|
|
139
128
|
}
|
|
@@ -147,22 +136,11 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
147
136
|
const bytesPerPacket = iterator.getUint32();
|
|
148
137
|
const bytesPerFrame = iterator.getUint32();
|
|
149
138
|
const bytesPerSample = iterator.getUint32();
|
|
150
|
-
const
|
|
151
|
-
const initialBoxes = [];
|
|
152
|
-
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
139
|
+
const children = await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
153
140
|
iterator,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
initialBoxes,
|
|
157
|
-
state: options,
|
|
158
|
-
continueMdat: false,
|
|
159
|
-
signal,
|
|
160
|
-
logLevel,
|
|
161
|
-
fields,
|
|
141
|
+
state,
|
|
142
|
+
size: boxSize - (iterator.counter.getOffset() - fileOffset),
|
|
162
143
|
});
|
|
163
|
-
if (children.status === 'incomplete') {
|
|
164
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
165
|
-
}
|
|
166
144
|
return {
|
|
167
145
|
sample: {
|
|
168
146
|
format: boxFormat,
|
|
@@ -182,7 +160,7 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
182
160
|
bytesPerPacket,
|
|
183
161
|
bytesPerFrame,
|
|
184
162
|
bitsPerSample: bytesPerSample,
|
|
185
|
-
children
|
|
163
|
+
children,
|
|
186
164
|
},
|
|
187
165
|
};
|
|
188
166
|
}
|
|
@@ -200,22 +178,11 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
200
178
|
iterator.getUint32(); // ignore;
|
|
201
179
|
const bytesPerFrame = iterator.getUint32();
|
|
202
180
|
const samplesPerPacket = iterator.getUint32();
|
|
203
|
-
const
|
|
204
|
-
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
181
|
+
const children = await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
205
182
|
iterator,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
initialBoxes: [],
|
|
209
|
-
state: options,
|
|
210
|
-
continueMdat: false,
|
|
211
|
-
signal,
|
|
212
|
-
logLevel,
|
|
213
|
-
fields,
|
|
183
|
+
state,
|
|
184
|
+
size: boxSize - (iterator.counter.getOffset() - fileOffset),
|
|
214
185
|
});
|
|
215
|
-
if (children.status === 'incomplete') {
|
|
216
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
217
|
-
}
|
|
218
|
-
const initialBoxes = [];
|
|
219
186
|
return {
|
|
220
187
|
sample: {
|
|
221
188
|
format: boxFormat,
|
|
@@ -235,7 +202,7 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
235
202
|
bytesPerPacket: null,
|
|
236
203
|
bytesPerFrame,
|
|
237
204
|
bitsPerSample: bitsPerChannel,
|
|
238
|
-
children
|
|
205
|
+
children,
|
|
239
206
|
},
|
|
240
207
|
};
|
|
241
208
|
}
|
|
@@ -257,23 +224,13 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
257
224
|
const depth = iterator.getUint16();
|
|
258
225
|
const colorTableId = iterator.getInt16();
|
|
259
226
|
const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
|
|
260
|
-
const initialBoxes = [];
|
|
261
227
|
const children = bytesRemainingInBox > 8
|
|
262
|
-
? await (0,
|
|
228
|
+
? await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
263
229
|
iterator,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
initialBoxes,
|
|
267
|
-
state: options,
|
|
268
|
-
continueMdat: false,
|
|
269
|
-
signal,
|
|
270
|
-
logLevel,
|
|
271
|
-
fields,
|
|
230
|
+
state,
|
|
231
|
+
size: bytesRemainingInBox,
|
|
272
232
|
})
|
|
273
|
-
: (iterator.discard(bytesRemainingInBox),
|
|
274
|
-
if (children.status === 'incomplete') {
|
|
275
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
276
|
-
}
|
|
233
|
+
: (iterator.discard(bytesRemainingInBox), []);
|
|
277
234
|
return {
|
|
278
235
|
sample: {
|
|
279
236
|
format: boxFormat,
|
|
@@ -295,24 +252,21 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
|
|
|
295
252
|
compressorName,
|
|
296
253
|
depth,
|
|
297
254
|
colorTableId,
|
|
298
|
-
descriptors:
|
|
255
|
+
descriptors: children,
|
|
299
256
|
},
|
|
300
257
|
};
|
|
301
258
|
}
|
|
302
259
|
throw new Error(`Unknown sample format ${boxFormat}`);
|
|
303
260
|
};
|
|
304
|
-
exports.
|
|
305
|
-
const
|
|
261
|
+
exports.processIsoFormatBox = processIsoFormatBox;
|
|
262
|
+
const parseIsoFormatBoxes = async ({ iterator, maxBytes, state, }) => {
|
|
306
263
|
const samples = [];
|
|
307
264
|
const initialOffset = iterator.counter.getOffset();
|
|
308
265
|
while (iterator.bytesRemaining() > 0 &&
|
|
309
266
|
iterator.counter.getOffset() - initialOffset < maxBytes) {
|
|
310
|
-
const { sample } = await (0, exports.
|
|
267
|
+
const { sample } = await (0, exports.processIsoFormatBox)({
|
|
311
268
|
iterator,
|
|
312
269
|
state,
|
|
313
|
-
signal,
|
|
314
|
-
logLevel,
|
|
315
|
-
fields,
|
|
316
270
|
});
|
|
317
271
|
if (sample) {
|
|
318
272
|
samples.push(sample);
|
|
@@ -320,4 +274,4 @@ const parseSamples = async ({ iterator, maxBytes, state, signal, logLevel, field
|
|
|
320
274
|
}
|
|
321
275
|
return samples;
|
|
322
276
|
};
|
|
323
|
-
exports.
|
|
277
|
+
exports.parseIsoFormatBoxes = parseIsoFormatBoxes;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
|
-
import type { Options, ParseMediaFields } from '../../../options';
|
|
3
2
|
import type { ParserState } from '../../../state/parser-state';
|
|
4
3
|
import type { BaseBox } from '../base-type';
|
|
5
4
|
import type { Sample } from './samples';
|
|
@@ -8,11 +7,9 @@ export interface StsdBox extends BaseBox {
|
|
|
8
7
|
numberOfEntries: number;
|
|
9
8
|
samples: Sample[];
|
|
10
9
|
}
|
|
11
|
-
export declare const parseStsd: ({ iterator, offset, size, state,
|
|
10
|
+
export declare const parseStsd: ({ iterator, offset, size, state, }: {
|
|
12
11
|
iterator: BufferIterator;
|
|
13
12
|
offset: number;
|
|
14
13
|
size: number;
|
|
15
14
|
state: ParserState;
|
|
16
|
-
signal: AbortSignal | null;
|
|
17
|
-
fields: Options<ParseMediaFields>;
|
|
18
15
|
}) => Promise<StsdBox>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseStsd = void 0;
|
|
4
4
|
const samples_1 = require("./samples");
|
|
5
|
-
const parseStsd = async ({ iterator, offset, size, state,
|
|
5
|
+
const parseStsd = async ({ iterator, offset, size, state, }) => {
|
|
6
6
|
const version = iterator.getUint8();
|
|
7
7
|
if (version !== 0) {
|
|
8
8
|
throw new Error(`Unsupported STSD version ${version}`);
|
|
@@ -11,13 +11,10 @@ const parseStsd = async ({ iterator, offset, size, state, signal, fields, }) =>
|
|
|
11
11
|
iterator.discard(3);
|
|
12
12
|
const numberOfEntries = iterator.getUint32();
|
|
13
13
|
const bytesRemainingInBox = size - (iterator.counter.getOffset() - offset);
|
|
14
|
-
const boxes = await (0, samples_1.
|
|
14
|
+
const boxes = await (0, samples_1.parseIsoFormatBoxes)({
|
|
15
15
|
iterator,
|
|
16
16
|
maxBytes: bytesRemainingInBox,
|
|
17
17
|
state,
|
|
18
|
-
signal,
|
|
19
|
-
logLevel: 'info',
|
|
20
|
-
fields,
|
|
21
18
|
});
|
|
22
19
|
if (boxes.length !== numberOfEntries) {
|
|
23
20
|
throw new Error(`Expected ${numberOfEntries} sample descriptions, got ${boxes.length}`);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
|
-
import type { LogLevel } from '../../../log';
|
|
3
|
-
import type { Options, ParseMediaFields } from '../../../options';
|
|
4
2
|
import type { AnySegment } from '../../../parse-result';
|
|
5
3
|
import type { ParserState } from '../../../state/parser-state';
|
|
6
4
|
import type { BaseBox } from '../base-type';
|
|
@@ -8,12 +6,9 @@ export interface TrakBox extends BaseBox {
|
|
|
8
6
|
type: 'trak-box';
|
|
9
7
|
children: AnySegment[];
|
|
10
8
|
}
|
|
11
|
-
export declare const parseTrak: ({ data, size, offsetAtStart, state: options,
|
|
9
|
+
export declare const parseTrak: ({ data, size, offsetAtStart, state: options, }: {
|
|
12
10
|
data: BufferIterator;
|
|
13
11
|
size: number;
|
|
14
12
|
offsetAtStart: number;
|
|
15
13
|
state: ParserState;
|
|
16
|
-
signal: AbortSignal | null;
|
|
17
|
-
logLevel: LogLevel;
|
|
18
|
-
fields: Options<ParseMediaFields>;
|
|
19
14
|
}) => Promise<TrakBox>;
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTrak = void 0;
|
|
4
|
-
const
|
|
5
|
-
const parseTrak = async ({ data, size, offsetAtStart, state: options,
|
|
6
|
-
const
|
|
7
|
-
const result = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
4
|
+
const get_children_1 = require("../get-children");
|
|
5
|
+
const parseTrak = async ({ data, size, offsetAtStart, state: options, }) => {
|
|
6
|
+
const children = await (0, get_children_1.getIsoBaseMediaChildren)({
|
|
8
7
|
iterator: data,
|
|
9
|
-
maxBytes: size - (data.counter.getOffset() - offsetAtStart),
|
|
10
|
-
allowIncompleteBoxes: false,
|
|
11
|
-
initialBoxes,
|
|
12
8
|
state: options,
|
|
13
|
-
|
|
14
|
-
signal,
|
|
15
|
-
logLevel,
|
|
16
|
-
fields,
|
|
9
|
+
size: size - 8,
|
|
17
10
|
});
|
|
18
|
-
if (result.status === 'incomplete') {
|
|
19
|
-
throw new Error('Incomplete boxes are not allowed');
|
|
20
|
-
}
|
|
21
11
|
return {
|
|
22
12
|
offset: offsetAtStart,
|
|
23
13
|
boxSize: size,
|
|
24
14
|
type: 'trak-box',
|
|
25
|
-
children
|
|
15
|
+
children,
|
|
26
16
|
};
|
|
27
17
|
};
|
|
28
18
|
exports.parseTrak = parseTrak;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AnySegment, IsoBaseMediaBox, RegularBox } from '../../parse-result';
|
|
2
2
|
import type { FtypBox } from './ftyp';
|
|
3
|
-
import type { MdatBox } from './mdat/mdat';
|
|
4
3
|
import type { MdhdBox } from './mdhd';
|
|
5
4
|
import type { MoovBox } from './moov/moov';
|
|
6
5
|
import type { MvhdBox } from './mvhd';
|
|
@@ -36,4 +35,3 @@ export declare const getStssBox: (trakBox: TrakBox) => StssBox | null;
|
|
|
36
35
|
export declare const getTfdtBox: (segment: IsoBaseMediaBox) => TfdtBox | null;
|
|
37
36
|
export declare const getTfhdBox: (segment: IsoBaseMediaBox) => TfhdBox | null;
|
|
38
37
|
export declare const getTrunBoxes: (segment: IsoBaseMediaBox) => TrunBox[];
|
|
39
|
-
export declare const getMdatBox: (anySegment: AnySegment[]) => MdatBox | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getTrunBoxes = exports.getTfhdBox = exports.getTfdtBox = exports.getStssBox = exports.getStscBox = exports.getStszBox = exports.getCttsBox = exports.getSttsBox = exports.getStcoBox = exports.getVideoDescriptors = exports.getStsdBox = exports.getStblBox = exports.getMdhdBox = exports.getMdiaBox = exports.getTkhdBox = exports.getTraks = exports.getMvhdBox = exports.getMoofBox = exports.getMoovBox = exports.getFtypBox = void 0;
|
|
4
4
|
const getFtypBox = (segments) => {
|
|
5
5
|
const ftypBox = segments.find((s) => s.type === 'ftyp-box');
|
|
6
6
|
if (!ftypBox || ftypBox.type !== 'ftyp-box') {
|
|
@@ -188,14 +188,3 @@ const getTrunBoxes = (segment) => {
|
|
|
188
188
|
return trunBoxes;
|
|
189
189
|
};
|
|
190
190
|
exports.getTrunBoxes = getTrunBoxes;
|
|
191
|
-
const getMdatBox = (anySegment) => {
|
|
192
|
-
const mdat = anySegment.find((b) => b.type === 'mdat-box');
|
|
193
|
-
if (!mdat) {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
if (mdat.type !== 'mdat-box') {
|
|
197
|
-
throw new Error('Expected mdat-box');
|
|
198
|
-
}
|
|
199
|
-
return mdat;
|
|
200
|
-
};
|
|
201
|
-
exports.getMdatBox = getMdatBox;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDurationFromMp3 = void 0;
|
|
4
|
+
const get_frame_length_1 = require("./get-frame-length");
|
|
5
|
+
const samples_per_mpeg_file_1 = require("./samples-per-mpeg-file");
|
|
6
|
+
const getDurationFromMp3 = (state) => {
|
|
7
|
+
if (state.contentLength === null) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const mp3Info = state.mp3Info.getMp3Info();
|
|
11
|
+
if (!mp3Info) {
|
|
12
|
+
throw new Error('No mp3 info');
|
|
13
|
+
}
|
|
14
|
+
const samplesPerFrame = (0, samples_per_mpeg_file_1.getSamplesPerMpegFrame)({
|
|
15
|
+
layer: mp3Info.layer,
|
|
16
|
+
mpegVersion: mp3Info.mpegVersion,
|
|
17
|
+
});
|
|
18
|
+
const frameLengthInBytes = (0, get_frame_length_1.getMpegFrameLength)({
|
|
19
|
+
bitrateKbit: mp3Info.bitrateKbit,
|
|
20
|
+
padding: false,
|
|
21
|
+
samplesPerFrame,
|
|
22
|
+
samplingFrequency: mp3Info.sampleRate,
|
|
23
|
+
layer: mp3Info.layer,
|
|
24
|
+
});
|
|
25
|
+
const frames = Math.floor((state.contentLength - mp3Info.startOfMpegStream) / frameLengthInBytes);
|
|
26
|
+
const samples = frames * samplesPerFrame;
|
|
27
|
+
const durationInSeconds = samples / mp3Info.sampleRate;
|
|
28
|
+
return durationInSeconds;
|
|
29
|
+
};
|
|
30
|
+
exports.getDurationFromMp3 = getDurationFromMp3;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const getAverageMpegFrameLength: ({ samplesPerFrame, bitrateKbit, samplingFrequency, layer, }: {
|
|
2
|
+
samplesPerFrame: number;
|
|
3
|
+
bitrateKbit: number;
|
|
4
|
+
samplingFrequency: number;
|
|
5
|
+
layer: number;
|
|
6
|
+
}) => number;
|
|
7
|
+
export declare const getMpegFrameLength: ({ samplesPerFrame, bitrateKbit, samplingFrequency, padding, layer, }: {
|
|
8
|
+
samplesPerFrame: number;
|
|
9
|
+
bitrateKbit: number;
|
|
10
|
+
samplingFrequency: number;
|
|
11
|
+
padding: boolean;
|
|
12
|
+
layer: number;
|
|
13
|
+
}) => number;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMpegFrameLength = exports.getAverageMpegFrameLength = void 0;
|
|
4
|
+
const getUnroundedMpegFrameLength = ({ samplesPerFrame, bitrateKbit, samplingFrequency, padding, layer, }) => {
|
|
5
|
+
if (layer === 1) {
|
|
6
|
+
throw new Error('MPEG Layer I is not supported');
|
|
7
|
+
}
|
|
8
|
+
return ((((samplesPerFrame / 8) * bitrateKbit) / samplingFrequency) * 1000 +
|
|
9
|
+
(padding ? (layer === 1 ? 4 : 1) : 0));
|
|
10
|
+
};
|
|
11
|
+
const getAverageMpegFrameLength = ({ samplesPerFrame, bitrateKbit, samplingFrequency, layer, }) => {
|
|
12
|
+
const withoutPadding = getUnroundedMpegFrameLength({
|
|
13
|
+
bitrateKbit,
|
|
14
|
+
layer,
|
|
15
|
+
padding: false,
|
|
16
|
+
samplesPerFrame,
|
|
17
|
+
samplingFrequency,
|
|
18
|
+
});
|
|
19
|
+
const rounded = Math.floor(withoutPadding);
|
|
20
|
+
const rest = withoutPadding % 1;
|
|
21
|
+
return rest * (rounded + 1) + (1 - rest) * rounded;
|
|
22
|
+
};
|
|
23
|
+
exports.getAverageMpegFrameLength = getAverageMpegFrameLength;
|
|
24
|
+
const getMpegFrameLength = ({ samplesPerFrame, bitrateKbit, samplingFrequency, padding, layer, }) => {
|
|
25
|
+
return Math.floor(getUnroundedMpegFrameLength({
|
|
26
|
+
bitrateKbit,
|
|
27
|
+
layer,
|
|
28
|
+
padding,
|
|
29
|
+
samplesPerFrame,
|
|
30
|
+
samplingFrequency,
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
exports.getMpegFrameLength = getMpegFrameLength;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetadataFromMp3 = void 0;
|
|
4
|
+
const getMetadataFromMp3 = (mp3Structure) => {
|
|
5
|
+
const findHeader = mp3Structure.boxes.find((b) => b.type === 'id3-header');
|
|
6
|
+
return findHeader ? findHeader.metatags : null;
|
|
7
|
+
};
|
|
8
|
+
exports.getMetadataFromMp3 = getMetadataFromMp3;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ParserState } from '../../state/parser-state';
|
|
2
|
+
import type { AllTracks } from '../riff/get-tracks-from-avi';
|
|
3
|
+
export declare const getTracksFromMp3: (parserState: ParserState) => AllTracks;
|
|
4
|
+
export declare const hasAllTracksFromMp3: (parserState: ParserState) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasAllTracksFromMp3 = exports.getTracksFromMp3 = void 0;
|
|
4
|
+
const getTracksFromMp3 = (parserState) => {
|
|
5
|
+
const tracks = parserState.callbacks.tracks.getTracks();
|
|
6
|
+
if (tracks.length === 0) {
|
|
7
|
+
throw new Error('No tracks found');
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
audioTracks: tracks.filter((t) => t.type === 'audio'),
|
|
11
|
+
otherTracks: [],
|
|
12
|
+
videoTracks: [],
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.getTracksFromMp3 = getTracksFromMp3;
|
|
16
|
+
const hasAllTracksFromMp3 = (parserState) => {
|
|
17
|
+
try {
|
|
18
|
+
(0, exports.getTracksFromMp3)(parserState);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.hasAllTracksFromMp3 = hasAllTracksFromMp3;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseID3V1 = void 0;
|
|
4
|
+
const parseID3V1 = (iterator) => {
|
|
5
|
+
if (iterator.bytesRemaining() < 128) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
// we drop ID3v1 because usually there is also ID3v2 and ID3v3 which are superior.
|
|
9
|
+
// Better than have duplicated data.
|
|
10
|
+
iterator.discard(128);
|
|
11
|
+
};
|
|
12
|
+
exports.parseID3V1 = parseID3V1;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseId3 = void 0;
|
|
4
|
+
function combine28Bits(a, b, c, d) {
|
|
5
|
+
// Mask each number to ignore first bit (& 0x7F)
|
|
6
|
+
const val1 = a & 0x7f; // 7 bits from first byte
|
|
7
|
+
const val2 = b & 0x7f; // 7 bits from second byte
|
|
8
|
+
const val3 = c & 0x7f; // 7 bits from third byte
|
|
9
|
+
const val4 = d & 0x7f; // 7 bits from fourth byte
|
|
10
|
+
// Combine all values using bitwise operations
|
|
11
|
+
return (val1 << 21) | (val2 << 14) | (val3 << 7) | val4;
|
|
12
|
+
}
|
|
13
|
+
const parseId3 = ({ iterator, state, }) => {
|
|
14
|
+
if (iterator.bytesRemaining() < 9) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const { returnToCheckpoint } = iterator.startCheckpoint();
|
|
18
|
+
iterator.discard(3);
|
|
19
|
+
const versionMajor = iterator.getUint8();
|
|
20
|
+
const versionMinor = iterator.getUint8();
|
|
21
|
+
const flags = iterator.getUint8();
|
|
22
|
+
const sizeArr = iterator.getSlice(4);
|
|
23
|
+
const size = combine28Bits(sizeArr[0], sizeArr[1], sizeArr[2], sizeArr[3]);
|
|
24
|
+
if (iterator.bytesRemaining() < size) {
|
|
25
|
+
returnToCheckpoint();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const entries = [];
|
|
29
|
+
const initial = iterator.counter.getOffset();
|
|
30
|
+
while (iterator.counter.getOffset() < size + initial) {
|
|
31
|
+
const name = versionMajor === 3 || versionMajor === 4
|
|
32
|
+
? iterator.getByteString(4, true)
|
|
33
|
+
: iterator.getByteString(3, true);
|
|
34
|
+
if (name === '') {
|
|
35
|
+
iterator.discard(size + initial - iterator.counter.getOffset());
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const s = versionMajor === 3 || versionMajor === 4
|
|
39
|
+
? iterator.getUint32()
|
|
40
|
+
: iterator.getUint24();
|
|
41
|
+
if (versionMajor === 3 || versionMajor === 4) {
|
|
42
|
+
iterator.getUint16(); // flags
|
|
43
|
+
}
|
|
44
|
+
let subtract = 0;
|
|
45
|
+
if (!name.startsWith('W')) {
|
|
46
|
+
iterator.getUint8(); // encoding
|
|
47
|
+
subtract += 1;
|
|
48
|
+
}
|
|
49
|
+
if (name === 'APIC') {
|
|
50
|
+
const { discardRest } = iterator.planBytes(s - subtract);
|
|
51
|
+
const mimeType = iterator.readUntilNullTerminator();
|
|
52
|
+
iterator.getUint16(); // picture type
|
|
53
|
+
const description = iterator.readUntilNullTerminator();
|
|
54
|
+
iterator.discard(1);
|
|
55
|
+
const data = discardRest();
|
|
56
|
+
state.images.addImage({
|
|
57
|
+
data,
|
|
58
|
+
description,
|
|
59
|
+
mimeType,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const information = iterator.getByteString(s - subtract, true);
|
|
64
|
+
entries.push({
|
|
65
|
+
key: name,
|
|
66
|
+
value: information,
|
|
67
|
+
trackId: null,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
state.structure.getStructure().boxes.push({
|
|
72
|
+
type: 'id3-header',
|
|
73
|
+
flags,
|
|
74
|
+
size,
|
|
75
|
+
versionMajor,
|
|
76
|
+
versionMinor,
|
|
77
|
+
metatags: entries,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
exports.parseId3 = parseId3;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
+
import type { ParseResult } from '../../parse-result';
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
|
+
export declare const parseMp3: ({ iterator, state, }: {
|
|
5
|
+
iterator: BufferIterator;
|
|
6
|
+
state: ParserState;
|
|
7
|
+
}) => Promise<ParseResult>;
|