@remotion/media-parser 4.0.241 → 4.0.243
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add-avc-profile-to-track.js +2 -2
- package/dist/boxes/avc/codec-private.js +2 -2
- package/dist/boxes/avc/create-sps-pps-data.d.ts +2 -0
- package/dist/boxes/avc/create-sps-pps-data.js +28 -0
- package/dist/boxes/iso-base-media/get-keyframes.d.ts +3 -0
- package/dist/boxes/iso-base-media/get-keyframes.js +30 -0
- package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -3
- package/dist/boxes/iso-base-media/mdat/mdat.js +9 -5
- package/dist/boxes/iso-base-media/moov/moov.d.ts +3 -3
- package/dist/boxes/iso-base-media/moov/moov.js +5 -4
- package/dist/boxes/iso-base-media/process-box.d.ts +9 -9
- package/dist/boxes/iso-base-media/process-box.js +48 -56
- package/dist/boxes/iso-base-media/stsd/mebx.d.ts +3 -3
- package/dist/boxes/iso-base-media/stsd/mebx.js +5 -4
- package/dist/boxes/iso-base-media/stsd/samples.d.ts +5 -5
- package/dist/boxes/iso-base-media/stsd/samples.js +19 -16
- package/dist/boxes/iso-base-media/stsd/stsd.d.ts +3 -3
- package/dist/boxes/iso-base-media/stsd/stsd.js +2 -2
- package/dist/boxes/iso-base-media/trak/trak.d.ts +3 -3
- package/dist/boxes/iso-base-media/trak/trak.js +7 -6
- package/dist/boxes/riff/expect-riff-box.d.ts +3 -3
- package/dist/boxes/riff/expect-riff-box.js +5 -5
- package/dist/boxes/riff/get-tracks-from-avi.js +1 -1
- package/dist/boxes/riff/parse-box.d.ts +7 -7
- package/dist/boxes/riff/parse-box.js +29 -24
- package/dist/boxes/riff/parse-list-box.d.ts +3 -3
- package/dist/boxes/riff/parse-list-box.js +2 -2
- package/dist/boxes/riff/parse-movi.d.ts +5 -5
- package/dist/boxes/riff/parse-movi.js +35 -20
- package/dist/boxes/riff/parse-riff-box.d.ts +3 -3
- package/dist/boxes/riff/parse-riff-box.js +2 -2
- package/dist/boxes/transport-stream/get-tracks.js +1 -1
- package/dist/boxes/transport-stream/handle-aac-packet.d.ts +4 -3
- package/dist/boxes/transport-stream/handle-aac-packet.js +6 -4
- package/dist/boxes/transport-stream/handle-avc-packet.d.ts +4 -3
- package/dist/boxes/transport-stream/handle-avc-packet.js +8 -6
- package/dist/boxes/transport-stream/parse-packet.d.ts +3 -3
- package/dist/boxes/transport-stream/parse-packet.js +2 -2
- package/dist/boxes/transport-stream/parse-stream-packet.d.ts +3 -3
- package/dist/boxes/transport-stream/parse-stream-packet.js +14 -7
- package/dist/boxes/transport-stream/parse-transport-stream.d.ts +5 -6
- package/dist/boxes/transport-stream/parse-transport-stream.js +10 -9
- package/dist/boxes/transport-stream/process-stream-buffers.d.ts +6 -5
- package/dist/boxes/transport-stream/process-stream-buffers.js +18 -8
- package/dist/boxes/webm/ebml.d.ts +1 -1
- package/dist/boxes/webm/get-sample-from-block.d.ts +2 -2
- package/dist/boxes/webm/get-sample-from-block.js +8 -4
- package/dist/boxes/webm/parse-ebml.d.ts +4 -4
- package/dist/boxes/webm/parse-ebml.js +18 -18
- package/dist/boxes/webm/parse-webm-header.d.ts +5 -5
- package/dist/boxes/webm/parse-webm-header.js +6 -5
- package/dist/boxes/webm/segments/parse-children.d.ts +5 -5
- package/dist/boxes/webm/segments/parse-children.js +12 -13
- package/dist/boxes/webm/segments.d.ts +3 -3
- package/dist/boxes/webm/segments.js +13 -13
- package/dist/convert-audio-or-video-sample.js +5 -2
- package/dist/create/matroska/create-matroska-media.js +2 -0
- package/dist/create/progress-tracker.js +2 -2
- package/dist/emit-available-info.d.ts +4 -5
- package/dist/emit-available-info.js +171 -57
- package/dist/esm/index.mjs +899 -501
- package/dist/file-types/detect-file-type.js +4 -2
- package/dist/get-duration.d.ts +1 -0
- package/dist/get-duration.js +14 -1
- package/dist/get-fields-from-callbacks.js +5 -0
- package/dist/get-fps.d.ts +1 -0
- package/dist/get-fps.js +17 -12
- package/dist/get-keyframes.d.ts +5 -0
- package/dist/get-keyframes.js +20 -0
- package/dist/get-tracks.d.ts +7 -1
- package/dist/get-tracks.js +15 -10
- package/dist/has-all-info.d.ts +2 -5
- package/dist/has-all-info.js +23 -4
- package/dist/index.d.ts +2 -1
- package/dist/may-skip-video-data/may-skip-video-data.d.ts +4 -0
- package/dist/may-skip-video-data/may-skip-video-data.js +14 -0
- package/dist/may-skip-video-data/need-samples-for-fields.d.ts +5 -0
- package/dist/may-skip-video-data/need-samples-for-fields.js +33 -0
- package/dist/options.d.ts +32 -0
- package/dist/parse-media.js +12 -40
- package/dist/parse-result.d.ts +2 -4
- package/dist/parse-video.d.ts +5 -5
- package/dist/parse-video.js +24 -10
- package/dist/register-track.d.ts +5 -5
- package/dist/register-track.js +12 -12
- package/dist/state/can-skip-tracks.js +5 -0
- package/dist/state/emitted-fields.d.ts +2 -0
- package/dist/state/emitted-fields.js +31 -0
- package/dist/state/has-tracks-section.d.ts +1 -0
- package/dist/state/keyframes.d.ts +6 -0
- package/dist/state/keyframes.js +15 -0
- package/dist/state/parser-state.d.ts +60 -29
- package/dist/state/parser-state.js +32 -150
- package/dist/state/riff.d.ts +10 -0
- package/dist/state/riff.js +32 -0
- package/dist/state/sample-callbacks.d.ts +31 -0
- package/dist/state/sample-callbacks.js +101 -0
- package/dist/state/slow-duration-fps.d.ts +8 -0
- package/dist/state/slow-duration-fps.js +36 -0
- package/dist/state/structure.d.ts +7 -0
- package/dist/state/structure.js +21 -0
- package/dist/state/tracks-and-samples.d.ts +0 -0
- package/dist/state/tracks-and-samples.js +1 -0
- package/dist/state/webm.d.ts +11 -0
- package/dist/state/webm.js +67 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webcodec-sample-types.d.ts +2 -0
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import type { BufferIterator } from '../../../buffer-iterator';
|
|
|
2
2
|
import type { LogLevel } from '../../../log';
|
|
3
3
|
import type { Options, ParseMediaFields } from '../../../options';
|
|
4
4
|
import type { AnySegment, IsoBaseMediaBox } from '../../../parse-result';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ParserState } from '../../../state/parser-state';
|
|
6
6
|
type SampleBase = {
|
|
7
7
|
format: string;
|
|
8
8
|
offset: number;
|
|
@@ -50,17 +50,17 @@ export type Sample = AudioSample | VideoSample | UnknownSample;
|
|
|
50
50
|
type SampleAndNext = {
|
|
51
51
|
sample: Sample | null;
|
|
52
52
|
};
|
|
53
|
-
export declare const processSample: ({ iterator, options, signal, logLevel, fields, }: {
|
|
53
|
+
export declare const processSample: ({ iterator, state: options, signal, logLevel, fields, }: {
|
|
54
54
|
iterator: BufferIterator;
|
|
55
|
-
|
|
55
|
+
state: ParserState;
|
|
56
56
|
signal: AbortSignal | null;
|
|
57
57
|
logLevel: LogLevel;
|
|
58
58
|
fields: Options<ParseMediaFields>;
|
|
59
59
|
}) => Promise<SampleAndNext>;
|
|
60
|
-
export declare const parseSamples: ({ iterator, maxBytes,
|
|
60
|
+
export declare const parseSamples: ({ iterator, maxBytes, state, signal, logLevel, fields, }: {
|
|
61
61
|
iterator: BufferIterator;
|
|
62
62
|
maxBytes: number;
|
|
63
|
-
|
|
63
|
+
state: ParserState;
|
|
64
64
|
signal: AbortSignal | null;
|
|
65
65
|
logLevel: LogLevel;
|
|
66
66
|
fields: Options<ParseMediaFields>;
|
|
@@ -62,7 +62,7 @@ const audioTags = [
|
|
|
62
62
|
'mp4a',
|
|
63
63
|
'ac-3',
|
|
64
64
|
];
|
|
65
|
-
const processSample = async ({ iterator, options, signal, logLevel, fields, }) => {
|
|
65
|
+
const processSample = async ({ iterator, state: options, signal, logLevel, fields, }) => {
|
|
66
66
|
const fileOffset = iterator.counter.getOffset();
|
|
67
67
|
const bytesRemaining = iterator.bytesRemaining();
|
|
68
68
|
const boxSize = iterator.getUint32();
|
|
@@ -99,12 +99,13 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
99
99
|
const packetSize = iterator.getUint16();
|
|
100
100
|
const sampleRate = iterator.getFixedPointUnsigned1616Number();
|
|
101
101
|
const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
|
|
102
|
+
const initialBoxes = [];
|
|
102
103
|
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
103
104
|
iterator,
|
|
104
105
|
allowIncompleteBoxes: false,
|
|
105
106
|
maxBytes: bytesRemainingInBox,
|
|
106
|
-
initialBoxes
|
|
107
|
-
options,
|
|
107
|
+
initialBoxes,
|
|
108
|
+
state: options,
|
|
108
109
|
continueMdat: false,
|
|
109
110
|
signal,
|
|
110
111
|
logLevel,
|
|
@@ -132,7 +133,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
132
133
|
bytesPerPacket: null,
|
|
133
134
|
bytesPerFrame: null,
|
|
134
135
|
bitsPerSample: null,
|
|
135
|
-
children:
|
|
136
|
+
children: initialBoxes,
|
|
136
137
|
},
|
|
137
138
|
};
|
|
138
139
|
}
|
|
@@ -147,12 +148,13 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
147
148
|
const bytesPerFrame = iterator.getUint32();
|
|
148
149
|
const bytesPerSample = iterator.getUint32();
|
|
149
150
|
const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
|
|
151
|
+
const initialBoxes = [];
|
|
150
152
|
const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
151
153
|
iterator,
|
|
152
154
|
allowIncompleteBoxes: false,
|
|
153
155
|
maxBytes: bytesRemainingInBox,
|
|
154
|
-
initialBoxes
|
|
155
|
-
options,
|
|
156
|
+
initialBoxes,
|
|
157
|
+
state: options,
|
|
156
158
|
continueMdat: false,
|
|
157
159
|
signal,
|
|
158
160
|
logLevel,
|
|
@@ -180,7 +182,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
180
182
|
bytesPerPacket,
|
|
181
183
|
bytesPerFrame,
|
|
182
184
|
bitsPerSample: bytesPerSample,
|
|
183
|
-
children:
|
|
185
|
+
children: initialBoxes,
|
|
184
186
|
},
|
|
185
187
|
};
|
|
186
188
|
}
|
|
@@ -204,7 +206,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
204
206
|
allowIncompleteBoxes: false,
|
|
205
207
|
maxBytes: bytesRemainingInBox,
|
|
206
208
|
initialBoxes: [],
|
|
207
|
-
options,
|
|
209
|
+
state: options,
|
|
208
210
|
continueMdat: false,
|
|
209
211
|
signal,
|
|
210
212
|
logLevel,
|
|
@@ -213,6 +215,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
213
215
|
if (children.status === 'incomplete') {
|
|
214
216
|
throw new Error('Incomplete boxes are not allowed');
|
|
215
217
|
}
|
|
218
|
+
const initialBoxes = [];
|
|
216
219
|
return {
|
|
217
220
|
sample: {
|
|
218
221
|
format: boxFormat,
|
|
@@ -232,7 +235,7 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
232
235
|
bytesPerPacket: null,
|
|
233
236
|
bytesPerFrame,
|
|
234
237
|
bitsPerSample: bitsPerChannel,
|
|
235
|
-
children:
|
|
238
|
+
children: initialBoxes,
|
|
236
239
|
},
|
|
237
240
|
};
|
|
238
241
|
}
|
|
@@ -254,20 +257,20 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
254
257
|
const depth = iterator.getUint16();
|
|
255
258
|
const colorTableId = iterator.getInt16();
|
|
256
259
|
const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
|
|
260
|
+
const initialBoxes = [];
|
|
257
261
|
const children = bytesRemainingInBox > 8
|
|
258
262
|
? await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
259
263
|
iterator,
|
|
260
264
|
allowIncompleteBoxes: false,
|
|
261
265
|
maxBytes: bytesRemainingInBox,
|
|
262
|
-
initialBoxes
|
|
263
|
-
options,
|
|
266
|
+
initialBoxes,
|
|
267
|
+
state: options,
|
|
264
268
|
continueMdat: false,
|
|
265
269
|
signal,
|
|
266
270
|
logLevel,
|
|
267
271
|
fields,
|
|
268
272
|
})
|
|
269
|
-
: (iterator.discard(bytesRemainingInBox),
|
|
270
|
-
{ status: 'done', segments: { boxes: [], type: 'iso-base-media' } });
|
|
273
|
+
: (iterator.discard(bytesRemainingInBox), { status: 'done' });
|
|
271
274
|
if (children.status === 'incomplete') {
|
|
272
275
|
throw new Error('Incomplete boxes are not allowed');
|
|
273
276
|
}
|
|
@@ -292,21 +295,21 @@ const processSample = async ({ iterator, options, signal, logLevel, fields, }) =
|
|
|
292
295
|
compressorName,
|
|
293
296
|
depth,
|
|
294
297
|
colorTableId,
|
|
295
|
-
descriptors:
|
|
298
|
+
descriptors: initialBoxes,
|
|
296
299
|
},
|
|
297
300
|
};
|
|
298
301
|
}
|
|
299
302
|
throw new Error(`Unknown sample format ${boxFormat}`);
|
|
300
303
|
};
|
|
301
304
|
exports.processSample = processSample;
|
|
302
|
-
const parseSamples = async ({ iterator, maxBytes,
|
|
305
|
+
const parseSamples = async ({ iterator, maxBytes, state, signal, logLevel, fields, }) => {
|
|
303
306
|
const samples = [];
|
|
304
307
|
const initialOffset = iterator.counter.getOffset();
|
|
305
308
|
while (iterator.bytesRemaining() > 0 &&
|
|
306
309
|
iterator.counter.getOffset() - initialOffset < maxBytes) {
|
|
307
310
|
const { sample } = await (0, exports.processSample)({
|
|
308
311
|
iterator,
|
|
309
|
-
|
|
312
|
+
state,
|
|
310
313
|
signal,
|
|
311
314
|
logLevel,
|
|
312
315
|
fields,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../../buffer-iterator';
|
|
2
2
|
import type { Options, ParseMediaFields } from '../../../options';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserState } from '../../../state/parser-state';
|
|
4
4
|
import type { BaseBox } from '../base-type';
|
|
5
5
|
import type { Sample } from './samples';
|
|
6
6
|
export interface StsdBox extends BaseBox {
|
|
@@ -8,11 +8,11 @@ export interface StsdBox extends BaseBox {
|
|
|
8
8
|
numberOfEntries: number;
|
|
9
9
|
samples: Sample[];
|
|
10
10
|
}
|
|
11
|
-
export declare const parseStsd: ({ iterator, offset, size,
|
|
11
|
+
export declare const parseStsd: ({ iterator, offset, size, state, signal, fields, }: {
|
|
12
12
|
iterator: BufferIterator;
|
|
13
13
|
offset: number;
|
|
14
14
|
size: number;
|
|
15
|
-
|
|
15
|
+
state: ParserState;
|
|
16
16
|
signal: AbortSignal | null;
|
|
17
17
|
fields: Options<ParseMediaFields>;
|
|
18
18
|
}) => 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,
|
|
5
|
+
const parseStsd = async ({ iterator, offset, size, state, signal, fields, }) => {
|
|
6
6
|
const version = iterator.getUint8();
|
|
7
7
|
if (version !== 0) {
|
|
8
8
|
throw new Error(`Unsupported STSD version ${version}`);
|
|
@@ -14,7 +14,7 @@ const parseStsd = async ({ iterator, offset, size, options, signal, fields, }) =
|
|
|
14
14
|
const boxes = await (0, samples_1.parseSamples)({
|
|
15
15
|
iterator,
|
|
16
16
|
maxBytes: bytesRemainingInBox,
|
|
17
|
-
|
|
17
|
+
state,
|
|
18
18
|
signal,
|
|
19
19
|
logLevel: 'info',
|
|
20
20
|
fields,
|
|
@@ -2,17 +2,17 @@ import type { BufferIterator } from '../../../buffer-iterator';
|
|
|
2
2
|
import type { LogLevel } from '../../../log';
|
|
3
3
|
import type { Options, ParseMediaFields } from '../../../options';
|
|
4
4
|
import type { AnySegment } from '../../../parse-result';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ParserState } from '../../../state/parser-state';
|
|
6
6
|
import type { BaseBox } from '../base-type';
|
|
7
7
|
export interface TrakBox extends BaseBox {
|
|
8
8
|
type: 'trak-box';
|
|
9
9
|
children: AnySegment[];
|
|
10
10
|
}
|
|
11
|
-
export declare const parseTrak: ({ data, size, offsetAtStart, options, signal, logLevel, fields, }: {
|
|
11
|
+
export declare const parseTrak: ({ data, size, offsetAtStart, state: options, signal, logLevel, fields, }: {
|
|
12
12
|
data: BufferIterator;
|
|
13
13
|
size: number;
|
|
14
14
|
offsetAtStart: number;
|
|
15
|
-
|
|
15
|
+
state: ParserState;
|
|
16
16
|
signal: AbortSignal | null;
|
|
17
17
|
logLevel: LogLevel;
|
|
18
18
|
fields: Options<ParseMediaFields>;
|
|
@@ -2,26 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseTrak = void 0;
|
|
4
4
|
const process_box_1 = require("../process-box");
|
|
5
|
-
const parseTrak = async ({ data, size, offsetAtStart, options, signal, logLevel, fields, }) => {
|
|
6
|
-
const
|
|
5
|
+
const parseTrak = async ({ data, size, offsetAtStart, state: options, signal, logLevel, fields, }) => {
|
|
6
|
+
const initialBoxes = [];
|
|
7
|
+
const result = await (0, process_box_1.parseIsoBaseMediaBoxes)({
|
|
7
8
|
iterator: data,
|
|
8
9
|
maxBytes: size - (data.counter.getOffset() - offsetAtStart),
|
|
9
10
|
allowIncompleteBoxes: false,
|
|
10
|
-
initialBoxes
|
|
11
|
-
options,
|
|
11
|
+
initialBoxes,
|
|
12
|
+
state: options,
|
|
12
13
|
continueMdat: false,
|
|
13
14
|
signal,
|
|
14
15
|
logLevel,
|
|
15
16
|
fields,
|
|
16
17
|
});
|
|
17
|
-
if (
|
|
18
|
+
if (result.status === 'incomplete') {
|
|
18
19
|
throw new Error('Incomplete boxes are not allowed');
|
|
19
20
|
}
|
|
20
21
|
return {
|
|
21
22
|
offset: offsetAtStart,
|
|
22
23
|
boxSize: size,
|
|
23
24
|
type: 'trak-box',
|
|
24
|
-
children:
|
|
25
|
+
children: initialBoxes,
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
exports.parseTrak = parseTrak;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { RiffStructure } from '../../parse-result';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
4
|
import type { RiffBox } from './riff-box';
|
|
5
5
|
export type RiffResult = {
|
|
6
6
|
type: 'incomplete';
|
|
@@ -10,8 +10,8 @@ export type RiffResult = {
|
|
|
10
10
|
box: RiffBox | null;
|
|
11
11
|
skipTo: number | null;
|
|
12
12
|
};
|
|
13
|
-
export declare const expectRiffBox: ({ iterator,
|
|
13
|
+
export declare const expectRiffBox: ({ iterator, state, structure, }: {
|
|
14
14
|
iterator: BufferIterator;
|
|
15
|
-
|
|
15
|
+
state: ParserState;
|
|
16
16
|
structure: RiffStructure;
|
|
17
17
|
}) => Promise<RiffResult>;
|
|
@@ -4,13 +4,13 @@ exports.expectRiffBox = void 0;
|
|
|
4
4
|
const is_movi_1 = require("./is-movi");
|
|
5
5
|
const parse_movi_1 = require("./parse-movi");
|
|
6
6
|
const parse_riff_box_1 = require("./parse-riff-box");
|
|
7
|
-
const expectRiffBox = async ({ iterator,
|
|
7
|
+
const expectRiffBox = async ({ iterator, state, structure, }) => {
|
|
8
8
|
// Need at least 16 bytes to read LIST,size,movi,size
|
|
9
9
|
if (iterator.bytesRemaining() < 16) {
|
|
10
10
|
return {
|
|
11
11
|
type: 'incomplete',
|
|
12
12
|
continueParsing() {
|
|
13
|
-
return (0, exports.expectRiffBox)({ structure, iterator,
|
|
13
|
+
return (0, exports.expectRiffBox)({ structure, iterator, state });
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -21,7 +21,7 @@ const expectRiffBox = async ({ iterator, options, structure, }) => {
|
|
|
21
21
|
return (0, parse_movi_1.parseMovi)({
|
|
22
22
|
iterator,
|
|
23
23
|
maxOffset: ckSize + iterator.counter.getOffset() - 4,
|
|
24
|
-
|
|
24
|
+
state,
|
|
25
25
|
structure,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
@@ -30,7 +30,7 @@ const expectRiffBox = async ({ iterator, options, structure, }) => {
|
|
|
30
30
|
return {
|
|
31
31
|
type: 'incomplete',
|
|
32
32
|
continueParsing: () => {
|
|
33
|
-
return (0, exports.expectRiffBox)({ structure, iterator,
|
|
33
|
+
return (0, exports.expectRiffBox)({ structure, iterator, state });
|
|
34
34
|
},
|
|
35
35
|
};
|
|
36
36
|
}
|
|
@@ -41,7 +41,7 @@ const expectRiffBox = async ({ iterator, options, structure, }) => {
|
|
|
41
41
|
iterator,
|
|
42
42
|
size: ckSize,
|
|
43
43
|
boxes: structure.boxes,
|
|
44
|
-
|
|
44
|
+
state,
|
|
45
45
|
}),
|
|
46
46
|
skipTo: null,
|
|
47
47
|
};
|
|
@@ -82,7 +82,7 @@ const getTracksFromAvi = (structure, state) => {
|
|
|
82
82
|
continue;
|
|
83
83
|
}
|
|
84
84
|
if (strf.type === 'strf-box-video') {
|
|
85
|
-
videoTracks.push((0, add_avc_profile_to_track_1.addAvcProfileToTrack)((0, exports.makeAviVideoTrack)({ strh, strf, index: i }), state.getAvcProfile()));
|
|
85
|
+
videoTracks.push((0, add_avc_profile_to_track_1.addAvcProfileToTrack)((0, exports.makeAviVideoTrack)({ strh, strf, index: i }), state.riff.getAvcProfile()));
|
|
86
86
|
}
|
|
87
87
|
else if (strh.fccType === 'auds') {
|
|
88
88
|
audioTracks.push((0, exports.makeAviAudioTrack)({ strf, index: i }));
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { Options, ParseMediaFields } from '../../options';
|
|
3
3
|
import type { ParseResult, RiffStructure } from '../../parse-result';
|
|
4
|
-
import type {
|
|
5
|
-
export declare const parseRiffBody: ({ iterator, structure, maxOffset,
|
|
4
|
+
import type { ParserState } from '../../state/parser-state';
|
|
5
|
+
export declare const parseRiffBody: ({ iterator, structure, maxOffset, state, }: {
|
|
6
6
|
iterator: BufferIterator;
|
|
7
7
|
structure: RiffStructure;
|
|
8
8
|
maxOffset: number;
|
|
9
|
-
|
|
10
|
-
}) => Promise<ParseResult
|
|
11
|
-
export declare const parseRiff: ({ iterator,
|
|
9
|
+
state: ParserState;
|
|
10
|
+
}) => Promise<ParseResult>;
|
|
11
|
+
export declare const parseRiff: ({ iterator, state, fields, }: {
|
|
12
12
|
iterator: BufferIterator;
|
|
13
|
-
|
|
13
|
+
state: ParserState;
|
|
14
14
|
fields: Options<ParseMediaFields>;
|
|
15
|
-
}) => Promise<ParseResult
|
|
15
|
+
}) => Promise<ParseResult>;
|
|
@@ -7,7 +7,7 @@ const register_track_1 = require("../../register-track");
|
|
|
7
7
|
const expect_riff_box_1 = require("./expect-riff-box");
|
|
8
8
|
const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
|
|
9
9
|
const traversal_1 = require("./traversal");
|
|
10
|
-
const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, options, }) => {
|
|
10
|
+
const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, state: options, }) => {
|
|
11
11
|
if (result.type === 'incomplete') {
|
|
12
12
|
return Promise.resolve({
|
|
13
13
|
status: 'incomplete',
|
|
@@ -17,7 +17,7 @@ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, op
|
|
|
17
17
|
structure,
|
|
18
18
|
iterator,
|
|
19
19
|
maxOffset,
|
|
20
|
-
options,
|
|
20
|
+
state: options,
|
|
21
21
|
}));
|
|
22
22
|
},
|
|
23
23
|
segments: structure,
|
|
@@ -27,26 +27,25 @@ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, op
|
|
|
27
27
|
if (result.type === 'complete' && result.box) {
|
|
28
28
|
structure.boxes.push(result.box);
|
|
29
29
|
}
|
|
30
|
-
return (0, exports.parseRiffBody)({ iterator, maxOffset, options, structure });
|
|
30
|
+
return (0, exports.parseRiffBody)({ iterator, maxOffset, state: options, structure });
|
|
31
31
|
};
|
|
32
|
-
const parseRiffBody = async ({ iterator, structure, maxOffset,
|
|
32
|
+
const parseRiffBody = async ({ iterator, structure, maxOffset, state, }) => {
|
|
33
33
|
while (iterator.bytesRemaining() > 0 &&
|
|
34
34
|
iterator.counter.getOffset() < maxOffset) {
|
|
35
35
|
const result = await (0, expect_riff_box_1.expectRiffBox)({
|
|
36
36
|
iterator,
|
|
37
|
-
|
|
37
|
+
state,
|
|
38
38
|
structure,
|
|
39
39
|
});
|
|
40
40
|
if (result.type === 'complete' && result.skipTo !== null) {
|
|
41
41
|
return {
|
|
42
42
|
status: 'incomplete',
|
|
43
43
|
skipTo: result.skipTo,
|
|
44
|
-
segments: structure,
|
|
45
44
|
continueParsing() {
|
|
46
45
|
return Promise.resolve(continueAfterRiffBoxResult({
|
|
47
46
|
iterator,
|
|
48
47
|
maxOffset,
|
|
49
|
-
|
|
48
|
+
state,
|
|
50
49
|
result,
|
|
51
50
|
structure,
|
|
52
51
|
}));
|
|
@@ -60,12 +59,11 @@ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
|
|
|
60
59
|
return Promise.resolve(continueAfterRiffBoxResult({
|
|
61
60
|
iterator,
|
|
62
61
|
maxOffset,
|
|
63
|
-
|
|
62
|
+
state,
|
|
64
63
|
result: await result.continueParsing(),
|
|
65
64
|
structure,
|
|
66
65
|
}));
|
|
67
66
|
},
|
|
68
|
-
segments: structure,
|
|
69
67
|
skipTo: null,
|
|
70
68
|
};
|
|
71
69
|
}
|
|
@@ -75,14 +73,14 @@ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
|
|
|
75
73
|
structure.boxes.push(result.box);
|
|
76
74
|
// When parsing an AVI
|
|
77
75
|
if (result.box.type === 'list-box' && result.box.listType === 'hdrl') {
|
|
78
|
-
const tracks = (0, get_tracks_1.getTracks)(structure,
|
|
76
|
+
const tracks = (0, get_tracks_1.getTracks)(structure, state);
|
|
79
77
|
if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
|
|
80
|
-
|
|
78
|
+
state.callbacks.tracks.setIsDone();
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
// When parsing a WAV
|
|
84
82
|
if (result.box.type === 'wave-format-box') {
|
|
85
|
-
|
|
83
|
+
state.callbacks.tracks.setIsDone();
|
|
86
84
|
}
|
|
87
85
|
if (result.box.type === 'strf-box-video' ||
|
|
88
86
|
result.box.type === 'strf-box-audio') {
|
|
@@ -91,56 +89,63 @@ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
|
|
|
91
89
|
if (!strh || !strf) {
|
|
92
90
|
throw new Error('strh or strf box missing');
|
|
93
91
|
}
|
|
94
|
-
if (strf.type === 'strf-box-audio' &&
|
|
92
|
+
if (strf.type === 'strf-box-audio' && state.onAudioTrack) {
|
|
95
93
|
const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
|
|
96
|
-
index:
|
|
94
|
+
index: state.riff.getNextTrackIndex(),
|
|
97
95
|
strf,
|
|
98
96
|
});
|
|
99
97
|
await (0, register_track_1.registerTrack)({
|
|
100
|
-
|
|
98
|
+
state,
|
|
101
99
|
track: audioTrack,
|
|
102
100
|
container: 'avi',
|
|
103
101
|
});
|
|
104
102
|
}
|
|
105
|
-
if (
|
|
103
|
+
if (state.onVideoTrack && strf.type === 'strf-box-video') {
|
|
106
104
|
const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
|
|
107
105
|
strh,
|
|
108
|
-
index:
|
|
106
|
+
index: state.riff.getNextTrackIndex(),
|
|
109
107
|
strf,
|
|
110
108
|
});
|
|
111
109
|
(0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
|
|
112
|
-
|
|
110
|
+
state,
|
|
113
111
|
track: videoTrack,
|
|
114
112
|
container: 'avi',
|
|
115
113
|
});
|
|
116
114
|
}
|
|
117
|
-
|
|
115
|
+
state.riff.incrementNextTrackIndex();
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
return {
|
|
121
119
|
status: 'done',
|
|
122
|
-
segments: structure,
|
|
123
120
|
};
|
|
124
121
|
};
|
|
125
122
|
exports.parseRiffBody = parseRiffBody;
|
|
126
|
-
const parseRiff = ({ iterator,
|
|
127
|
-
const structure = { type: 'riff', boxes: [] };
|
|
123
|
+
const parseRiff = ({ iterator, state, fields, }) => {
|
|
128
124
|
const riff = iterator.getByteString(4);
|
|
129
125
|
if (riff !== 'RIFF') {
|
|
130
126
|
throw new Error('Not a RIFF file');
|
|
131
127
|
}
|
|
128
|
+
const structure = state.structure.getStructure();
|
|
129
|
+
if (structure.type !== 'riff') {
|
|
130
|
+
throw new Error('Structure is not a RIFF structure');
|
|
131
|
+
}
|
|
132
132
|
const size = iterator.getUint32Le();
|
|
133
133
|
const fileType = iterator.getByteString(4);
|
|
134
134
|
if (fileType !== 'WAVE' && fileType !== 'AVI') {
|
|
135
135
|
throw new Error(`File type ${fileType} not supported`);
|
|
136
136
|
}
|
|
137
137
|
structure.boxes.push({ type: 'riff-header', fileSize: size, fileType });
|
|
138
|
-
if ((0, has_all_info_1.hasAllInfo)({ fields,
|
|
138
|
+
if ((0, has_all_info_1.hasAllInfo)({ fields, state })) {
|
|
139
139
|
return Promise.resolve({
|
|
140
140
|
status: 'done',
|
|
141
141
|
segments: structure,
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
return (0, exports.parseRiffBody)({
|
|
144
|
+
return (0, exports.parseRiffBody)({
|
|
145
|
+
iterator,
|
|
146
|
+
maxOffset: Infinity,
|
|
147
|
+
state,
|
|
148
|
+
structure,
|
|
149
|
+
});
|
|
145
150
|
};
|
|
146
151
|
exports.parseRiff = parseRiff;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParserState } from '../../state/parser-state';
|
|
3
3
|
import type { RiffBox } from './riff-box';
|
|
4
|
-
export declare const parseListBox: ({ iterator, size,
|
|
4
|
+
export declare const parseListBox: ({ iterator, size, state, }: {
|
|
5
5
|
iterator: BufferIterator;
|
|
6
6
|
size: number;
|
|
7
|
-
|
|
7
|
+
state: ParserState;
|
|
8
8
|
}) => Promise<RiffBox>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseListBox = void 0;
|
|
4
4
|
const parse_box_1 = require("./parse-box");
|
|
5
|
-
const parseListBox = async ({ iterator, size,
|
|
5
|
+
const parseListBox = async ({ iterator, size, state, }) => {
|
|
6
6
|
const counter = iterator.counter.getOffset();
|
|
7
7
|
const listType = iterator.getByteString(4);
|
|
8
8
|
if (listType === 'movi') {
|
|
@@ -16,7 +16,7 @@ const parseListBox = async ({ iterator, size, options, }) => {
|
|
|
16
16
|
structure,
|
|
17
17
|
iterator,
|
|
18
18
|
maxOffset: counter + size,
|
|
19
|
-
|
|
19
|
+
state,
|
|
20
20
|
});
|
|
21
21
|
if (result.status === 'incomplete') {
|
|
22
22
|
throw new Error(`Should only parse complete boxes (${listType})`);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { BufferIterator } from '../../buffer-iterator';
|
|
2
2
|
import type { RiffStructure } from '../../parse-result';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ParserState } from '../../state/parser-state';
|
|
4
4
|
import type { RiffResult } from './expect-riff-box';
|
|
5
|
-
export declare const handleChunk: ({ iterator,
|
|
5
|
+
export declare const handleChunk: ({ iterator, state, structure, ckId, ckSize, }: {
|
|
6
6
|
iterator: BufferIterator;
|
|
7
|
-
|
|
7
|
+
state: ParserState;
|
|
8
8
|
structure: RiffStructure;
|
|
9
9
|
ckId: string;
|
|
10
10
|
ckSize: number;
|
|
11
11
|
}) => Promise<void>;
|
|
12
|
-
export declare const parseMovi: ({ iterator, maxOffset,
|
|
12
|
+
export declare const parseMovi: ({ iterator, maxOffset, state, structure, }: {
|
|
13
13
|
iterator: BufferIterator;
|
|
14
14
|
maxOffset: number;
|
|
15
|
-
|
|
15
|
+
state: ParserState;
|
|
16
16
|
structure: RiffStructure;
|
|
17
17
|
}) => Promise<RiffResult>;
|