@remotion/media-parser 4.0.249 → 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.
Files changed (121) hide show
  1. package/dist/boxes/iso-base-media/continue-mdat-routine.d.ts +14 -0
  2. package/dist/boxes/iso-base-media/continue-mdat-routine.js +74 -0
  3. package/dist/boxes/iso-base-media/get-children.d.ts +2 -8
  4. package/dist/boxes/iso-base-media/get-children.js +14 -30
  5. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -23
  6. package/dist/boxes/iso-base-media/mdat/mdat.js +80 -130
  7. package/dist/boxes/iso-base-media/moov/moov.d.ts +1 -6
  8. package/dist/boxes/iso-base-media/moov/moov.js +5 -14
  9. package/dist/boxes/iso-base-media/parse-all-children.d.ts +8 -0
  10. package/dist/boxes/iso-base-media/parse-all-children.js +20 -0
  11. package/dist/boxes/iso-base-media/parse-boxes.d.ts +2 -10
  12. package/dist/boxes/iso-base-media/parse-boxes.js +33 -116
  13. package/dist/boxes/iso-base-media/parse-mdat-partially.d.ts +1 -4
  14. package/dist/boxes/iso-base-media/parse-mdat-partially.js +2 -11
  15. package/dist/boxes/iso-base-media/process-box.d.ts +1 -9
  16. package/dist/boxes/iso-base-media/process-box.js +49 -143
  17. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +1 -4
  18. package/dist/boxes/iso-base-media/stsd/mebx.js +5 -14
  19. package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -12
  20. package/dist/boxes/iso-base-media/stsd/samples.js +24 -66
  21. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +1 -4
  22. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -5
  23. package/dist/boxes/iso-base-media/trak/trak.d.ts +1 -6
  24. package/dist/boxes/iso-base-media/trak/trak.js +5 -14
  25. package/dist/boxes/iso-base-media/traversal.d.ts +0 -2
  26. package/dist/boxes/iso-base-media/traversal.js +1 -12
  27. package/dist/boxes/mp3/id3.d.ts +1 -3
  28. package/dist/boxes/mp3/id3.js +7 -5
  29. package/dist/boxes/mp3/parse-mp3.d.ts +2 -3
  30. package/dist/boxes/mp3/parse-mp3.js +3 -19
  31. package/dist/boxes/riff/expect-riff-box.d.ts +1 -9
  32. package/dist/boxes/riff/expect-riff-box.js +47 -25
  33. package/dist/boxes/riff/get-tracks-from-avi.d.ts +1 -1
  34. package/dist/boxes/riff/get-tracks-from-avi.js +6 -10
  35. package/dist/boxes/riff/parse-fmt-box.d.ts +3 -2
  36. package/dist/boxes/riff/parse-fmt-box.js +7 -5
  37. package/dist/boxes/riff/parse-list-box.d.ts +1 -3
  38. package/dist/boxes/riff/parse-list-box.js +16 -16
  39. package/dist/boxes/riff/parse-movi.d.ts +2 -5
  40. package/dist/boxes/riff/parse-movi.js +34 -56
  41. package/dist/boxes/riff/parse-riff-body.d.ts +2 -6
  42. package/dist/boxes/riff/parse-riff-body.js +15 -95
  43. package/dist/boxes/riff/parse-riff-box.d.ts +1 -4
  44. package/dist/boxes/riff/parse-riff-box.js +3 -7
  45. package/dist/boxes/riff/parse-riff-header.d.ts +7 -0
  46. package/dist/boxes/riff/parse-riff-header.js +23 -0
  47. package/dist/boxes/riff/parse-riff.d.ts +7 -0
  48. package/dist/boxes/riff/parse-riff.js +15 -0
  49. package/dist/boxes/riff/parse-strf.d.ts +4 -4
  50. package/dist/boxes/riff/parse-strf.js +4 -8
  51. package/dist/boxes/riff/parse-strh.js +11 -0
  52. package/dist/boxes/riff/parse-video-section.d.ts +6 -0
  53. package/dist/boxes/riff/parse-video-section.js +20 -0
  54. package/dist/boxes/riff/riff-box.d.ts +4 -5
  55. package/dist/boxes/riff/traversal.d.ts +1 -2
  56. package/dist/boxes/riff/traversal.js +1 -6
  57. package/dist/boxes/transport-stream/get-tracks.d.ts +2 -3
  58. package/dist/boxes/transport-stream/get-tracks.js +4 -3
  59. package/dist/boxes/transport-stream/parse-packet.d.ts +1 -7
  60. package/dist/boxes/transport-stream/parse-packet.js +3 -4
  61. package/dist/boxes/transport-stream/parse-stream-packet.d.ts +1 -5
  62. package/dist/boxes/transport-stream/parse-stream-packet.js +10 -12
  63. package/dist/boxes/transport-stream/parse-transport-stream.d.ts +1 -7
  64. package/dist/boxes/transport-stream/parse-transport-stream.js +7 -26
  65. package/dist/boxes/transport-stream/process-stream-buffers.d.ts +1 -2
  66. package/dist/boxes/transport-stream/process-stream-buffers.js +3 -3
  67. package/dist/boxes/webm/parse-ebml.js +3 -0
  68. package/dist/boxes/webm/parse-webm-header.d.ts +2 -4
  69. package/dist/boxes/webm/parse-webm-header.js +41 -25
  70. package/dist/boxes/webm/segments/parse-children.d.ts +2 -16
  71. package/dist/boxes/webm/segments/parse-children.js +7 -130
  72. package/dist/boxes/webm/segments.d.ts +4 -8
  73. package/dist/boxes/webm/segments.js +41 -123
  74. package/dist/buffer-iterator.d.ts +0 -3
  75. package/dist/buffer-iterator.js +6 -16
  76. package/dist/bun-reader.d.ts +1 -0
  77. package/dist/bun-reader.js +17 -0
  78. package/dist/emit-available-info.js +4 -4
  79. package/dist/esm/from-node.mjs +8 -9
  80. package/dist/esm/index.mjs +4224 -4950
  81. package/dist/file-types/detect-file-type.js +4 -2
  82. package/dist/get-audio-codec.d.ts +1 -1
  83. package/dist/get-audio-codec.js +2 -2
  84. package/dist/get-dimensions.js +1 -1
  85. package/dist/get-duration.js +1 -1
  86. package/dist/get-is-hdr.d.ts +1 -1
  87. package/dist/get-is-hdr.js +2 -2
  88. package/dist/get-tracks.d.ts +1 -1
  89. package/dist/get-tracks.js +14 -13
  90. package/dist/get-video-codec.d.ts +1 -1
  91. package/dist/get-video-codec.js +2 -2
  92. package/dist/index.d.ts +50 -24
  93. package/dist/index.js +1 -1
  94. package/dist/may-skip-video-data/may-skip-video-data.js +6 -2
  95. package/dist/parse-media.js +45 -30
  96. package/dist/parse-result.d.ts +1 -18
  97. package/dist/parse-video.d.ts +3 -17
  98. package/dist/parse-video.js +45 -32
  99. package/dist/readers/from-node.js +7 -8
  100. package/dist/state/can-skip-tracks.d.ts +8 -1
  101. package/dist/state/can-skip-tracks.js +38 -27
  102. package/dist/state/iso-base-media/cached-sample-positions.d.ts +15 -0
  103. package/dist/state/iso-base-media/cached-sample-positions.js +42 -0
  104. package/dist/state/iso-base-media/iso-state.d.ts +8 -0
  105. package/dist/state/iso-base-media/iso-state.js +15 -0
  106. package/dist/state/iso-state.d.ts +4 -0
  107. package/dist/state/iso-state.js +13 -0
  108. package/dist/state/parser-state.d.ts +49 -14
  109. package/dist/state/parser-state.js +11 -3
  110. package/dist/state/sample-callbacks.d.ts +5 -1
  111. package/dist/state/sample-callbacks.js +4 -1
  112. package/dist/state/transport-stream.d.ts +8 -0
  113. package/dist/state/transport-stream.js +11 -0
  114. package/dist/state/video-section.d.ts +16 -0
  115. package/dist/state/video-section.js +37 -0
  116. package/dist/state/webm.d.ts +15 -0
  117. package/dist/state/webm.js +32 -0
  118. package/dist/version.d.ts +1 -1
  119. package/dist/version.js +1 -1
  120. package/package.json +3 -3
  121. package/test.json +663 -0
@@ -1,5 +1,4 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
- import type { Options, ParseMediaFields } from '../../../options';
3
2
  import type { AnySegment } from '../../../parse-result';
4
3
  import type { ParserState } from '../../../state/parser-state';
5
4
  import type { BaseBox } from '../base-type';
@@ -9,11 +8,9 @@ export interface MebxBox extends BaseBox {
9
8
  format: string;
10
9
  children: AnySegment[];
11
10
  }
12
- export declare const parseMebx: ({ iterator, offset, size, state, signal, fields, }: {
11
+ export declare const parseMebx: ({ iterator, offset, size, state, }: {
13
12
  iterator: BufferIterator;
14
13
  offset: number;
15
14
  size: number;
16
15
  state: ParserState;
17
- signal: AbortSignal | null;
18
- fields: Options<ParseMediaFields>;
19
16
  }) => Promise<MebxBox>;
@@ -1,32 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMebx = void 0;
4
- const parse_boxes_1 = require("../parse-boxes");
5
- const parseMebx = async ({ iterator, offset, size, state, signal, fields, }) => {
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 boxes = [];
10
- const children = await (0, parse_boxes_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
- signal,
17
- logLevel: 'info',
18
- fields,
12
+ size: size - 8,
19
13
  });
20
- if (children.status === 'incomplete') {
21
- throw new Error('Incomplete boxes are not allowed');
22
- }
23
14
  return {
24
15
  type: 'mebx-box',
25
16
  boxSize: size,
26
17
  offset,
27
18
  dataReferenceIndex,
28
19
  format: 'mebx',
29
- children: boxes,
20
+ children,
30
21
  };
31
22
  };
32
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 SampleAndNext = {
48
+ type FormatBoxAndNext = {
51
49
  sample: Sample | null;
52
50
  };
53
- export declare const processSample: ({ iterator, state: options, signal, logLevel, fields, }: {
51
+ export declare const processIsoFormatBox: ({ iterator, state, }: {
54
52
  iterator: BufferIterator;
55
53
  state: ParserState;
56
- signal: AbortSignal | null;
57
- logLevel: LogLevel;
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.parseSamples = exports.processSample = void 0;
4
- const parse_boxes_1 = require("../parse-boxes");
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 processSample = async ({ iterator, state: options, signal, logLevel, fields, }) => {
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,21 +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 bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
102
- const initialBoxes = [];
103
- const children = await (0, parse_boxes_1.parseIsoBaseMediaBoxes)({
101
+ const children = await (0, get_children_1.getIsoBaseMediaChildren)({
104
102
  iterator,
105
- allowIncompleteBoxes: false,
106
- maxBytes: bytesRemainingInBox,
107
- initialBoxes,
108
- state: options,
109
- signal,
110
- logLevel,
111
- fields,
103
+ state,
104
+ size: boxSize - (iterator.counter.getOffset() - fileOffset),
112
105
  });
113
- if (children.status === 'incomplete') {
114
- throw new Error('Incomplete boxes are not allowed');
115
- }
116
106
  return {
117
107
  sample: {
118
108
  format: boxFormat,
@@ -132,7 +122,7 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
132
122
  bytesPerPacket: null,
133
123
  bytesPerFrame: null,
134
124
  bitsPerSample: null,
135
- children: initialBoxes,
125
+ children,
136
126
  },
137
127
  };
138
128
  }
@@ -146,21 +136,11 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
146
136
  const bytesPerPacket = iterator.getUint32();
147
137
  const bytesPerFrame = iterator.getUint32();
148
138
  const bytesPerSample = iterator.getUint32();
149
- const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
150
- const initialBoxes = [];
151
- const children = await (0, parse_boxes_1.parseIsoBaseMediaBoxes)({
139
+ const children = await (0, get_children_1.getIsoBaseMediaChildren)({
152
140
  iterator,
153
- allowIncompleteBoxes: false,
154
- maxBytes: bytesRemainingInBox,
155
- initialBoxes,
156
- state: options,
157
- signal,
158
- logLevel,
159
- fields,
141
+ state,
142
+ size: boxSize - (iterator.counter.getOffset() - fileOffset),
160
143
  });
161
- if (children.status === 'incomplete') {
162
- throw new Error('Incomplete boxes are not allowed');
163
- }
164
144
  return {
165
145
  sample: {
166
146
  format: boxFormat,
@@ -180,7 +160,7 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
180
160
  bytesPerPacket,
181
161
  bytesPerFrame,
182
162
  bitsPerSample: bytesPerSample,
183
- children: initialBoxes,
163
+ children,
184
164
  },
185
165
  };
186
166
  }
@@ -198,21 +178,11 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
198
178
  iterator.getUint32(); // ignore;
199
179
  const bytesPerFrame = iterator.getUint32();
200
180
  const samplesPerPacket = iterator.getUint32();
201
- const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
202
- const children = await (0, parse_boxes_1.parseIsoBaseMediaBoxes)({
181
+ const children = await (0, get_children_1.getIsoBaseMediaChildren)({
203
182
  iterator,
204
- allowIncompleteBoxes: false,
205
- maxBytes: bytesRemainingInBox,
206
- initialBoxes: [],
207
- state: options,
208
- signal,
209
- logLevel,
210
- fields,
183
+ state,
184
+ size: boxSize - (iterator.counter.getOffset() - fileOffset),
211
185
  });
212
- if (children.status === 'incomplete') {
213
- throw new Error('Incomplete boxes are not allowed');
214
- }
215
- const initialBoxes = [];
216
186
  return {
217
187
  sample: {
218
188
  format: boxFormat,
@@ -232,7 +202,7 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
232
202
  bytesPerPacket: null,
233
203
  bytesPerFrame,
234
204
  bitsPerSample: bitsPerChannel,
235
- children: initialBoxes,
205
+ children,
236
206
  },
237
207
  };
238
208
  }
@@ -254,22 +224,13 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
254
224
  const depth = iterator.getUint16();
255
225
  const colorTableId = iterator.getInt16();
256
226
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
257
- const initialBoxes = [];
258
227
  const children = bytesRemainingInBox > 8
259
- ? await (0, parse_boxes_1.parseIsoBaseMediaBoxes)({
228
+ ? await (0, get_children_1.getIsoBaseMediaChildren)({
260
229
  iterator,
261
- allowIncompleteBoxes: false,
262
- maxBytes: bytesRemainingInBox,
263
- initialBoxes,
264
- state: options,
265
- signal,
266
- logLevel,
267
- fields,
230
+ state,
231
+ size: bytesRemainingInBox,
268
232
  })
269
- : (iterator.discard(bytesRemainingInBox), { status: 'done' });
270
- if (children.status === 'incomplete') {
271
- throw new Error('Incomplete boxes are not allowed');
272
- }
233
+ : (iterator.discard(bytesRemainingInBox), []);
273
234
  return {
274
235
  sample: {
275
236
  format: boxFormat,
@@ -291,24 +252,21 @@ const processSample = async ({ iterator, state: options, signal, logLevel, field
291
252
  compressorName,
292
253
  depth,
293
254
  colorTableId,
294
- descriptors: initialBoxes,
255
+ descriptors: children,
295
256
  },
296
257
  };
297
258
  }
298
259
  throw new Error(`Unknown sample format ${boxFormat}`);
299
260
  };
300
- exports.processSample = processSample;
301
- const parseSamples = async ({ iterator, maxBytes, state, signal, logLevel, fields, }) => {
261
+ exports.processIsoFormatBox = processIsoFormatBox;
262
+ const parseIsoFormatBoxes = async ({ iterator, maxBytes, state, }) => {
302
263
  const samples = [];
303
264
  const initialOffset = iterator.counter.getOffset();
304
265
  while (iterator.bytesRemaining() > 0 &&
305
266
  iterator.counter.getOffset() - initialOffset < maxBytes) {
306
- const { sample } = await (0, exports.processSample)({
267
+ const { sample } = await (0, exports.processIsoFormatBox)({
307
268
  iterator,
308
269
  state,
309
- signal,
310
- logLevel,
311
- fields,
312
270
  });
313
271
  if (sample) {
314
272
  samples.push(sample);
@@ -316,4 +274,4 @@ const parseSamples = async ({ iterator, maxBytes, state, signal, logLevel, field
316
274
  }
317
275
  return samples;
318
276
  };
319
- exports.parseSamples = parseSamples;
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, signal, fields, }: {
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, signal, fields, }) => {
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.parseSamples)({
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, signal, logLevel, fields, }: {
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,27 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTrak = void 0;
4
- const parse_boxes_1 = require("../parse-boxes");
5
- const parseTrak = async ({ data, size, offsetAtStart, state: options, signal, logLevel, fields, }) => {
6
- const initialBoxes = [];
7
- const result = await (0, parse_boxes_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
- signal,
14
- logLevel,
15
- fields,
9
+ size: size - 8,
16
10
  });
17
- if (result.status === 'incomplete') {
18
- throw new Error('Incomplete boxes are not allowed');
19
- }
20
11
  return {
21
12
  offset: offsetAtStart,
22
13
  boxSize: size,
23
14
  type: 'trak-box',
24
- children: initialBoxes,
15
+ children,
25
16
  };
26
17
  };
27
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.getMdatBox = 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;
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;
@@ -1,8 +1,6 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { Mp3Structure } from '../../parse-result';
3
2
  import type { ParserState } from '../../state/parser-state';
4
- export declare const parseId3: ({ iterator, structure, state, }: {
3
+ export declare const parseId3: ({ iterator, state, }: {
5
4
  iterator: BufferIterator;
6
- structure: Mp3Structure;
7
5
  state: ParserState;
8
6
  }) => void;
@@ -10,7 +10,7 @@ function combine28Bits(a, b, c, d) {
10
10
  // Combine all values using bitwise operations
11
11
  return (val1 << 21) | (val2 << 14) | (val3 << 7) | val4;
12
12
  }
13
- const parseId3 = ({ iterator, structure, state, }) => {
13
+ const parseId3 = ({ iterator, state, }) => {
14
14
  if (iterator.bytesRemaining() < 9) {
15
15
  return;
16
16
  }
@@ -28,15 +28,17 @@ const parseId3 = ({ iterator, structure, state, }) => {
28
28
  const entries = [];
29
29
  const initial = iterator.counter.getOffset();
30
30
  while (iterator.counter.getOffset() < size + initial) {
31
- const name = versionMajor === 3
31
+ const name = versionMajor === 3 || versionMajor === 4
32
32
  ? iterator.getByteString(4, true)
33
33
  : iterator.getByteString(3, true);
34
34
  if (name === '') {
35
35
  iterator.discard(size + initial - iterator.counter.getOffset());
36
36
  break;
37
37
  }
38
- const s = versionMajor === 3 ? iterator.getUint32() : iterator.getUint24();
39
- if (versionMajor === 3) {
38
+ const s = versionMajor === 3 || versionMajor === 4
39
+ ? iterator.getUint32()
40
+ : iterator.getUint24();
41
+ if (versionMajor === 3 || versionMajor === 4) {
40
42
  iterator.getUint16(); // flags
41
43
  }
42
44
  let subtract = 0;
@@ -66,7 +68,7 @@ const parseId3 = ({ iterator, structure, state, }) => {
66
68
  });
67
69
  }
68
70
  }
69
- structure.boxes.push({
71
+ state.structure.getStructure().boxes.push({
70
72
  type: 'id3-header',
71
73
  flags,
72
74
  size,
@@ -1,8 +1,7 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { Mp3Structure, ParseResult } from '../../parse-result';
2
+ import type { ParseResult } from '../../parse-result';
3
3
  import type { ParserState } from '../../state/parser-state';
4
- export declare const parseMp3: ({ iterator, structure, state, }: {
4
+ export declare const parseMp3: ({ iterator, state, }: {
5
5
  iterator: BufferIterator;
6
- structure: Mp3Structure;
7
6
  state: ParserState;
8
7
  }) => Promise<ParseResult>;
@@ -4,20 +4,10 @@ exports.parseMp3 = void 0;
4
4
  const id3_1 = require("./id3");
5
5
  const id3_v1_1 = require("./id3-v1");
6
6
  const parse_mpeg_header_1 = require("./parse-mpeg-header");
7
- const parseMp3 = async ({ iterator, structure, state, }) => {
8
- const continueParsing = () => {
9
- return (0, exports.parseMp3)({ iterator, structure, state });
10
- };
11
- if (iterator.bytesRemaining() === 0) {
12
- return Promise.resolve({
13
- status: 'done',
14
- });
15
- }
7
+ const parseMp3 = async ({ iterator, state, }) => {
16
8
  if (iterator.bytesRemaining() < 3) {
17
9
  return {
18
- status: 'incomplete',
19
10
  skipTo: null,
20
- continueParsing,
21
11
  };
22
12
  }
23
13
  const { returnToCheckpoint } = iterator.startCheckpoint();
@@ -27,17 +17,13 @@ const parseMp3 = async ({ iterator, structure, state, }) => {
27
17
  if (bytes[0] === 0x54 && bytes[1] === 0x41 && bytes[2] === 0x47) {
28
18
  (0, id3_v1_1.parseID3V1)(iterator);
29
19
  return {
30
- status: 'incomplete',
31
- continueParsing,
32
20
  skipTo: null,
33
21
  };
34
22
  }
35
23
  // ID3 v2 or v3
36
24
  if (bytes[0] === 0x49 && bytes[1] === 0x44 && bytes[2] === 0x33) {
37
- (0, id3_1.parseId3)({ iterator, structure, state });
25
+ (0, id3_1.parseId3)({ iterator, state });
38
26
  return {
39
- status: 'incomplete',
40
- continueParsing,
41
27
  skipTo: null,
42
28
  };
43
29
  }
@@ -47,11 +33,9 @@ const parseMp3 = async ({ iterator, structure, state, }) => {
47
33
  state,
48
34
  });
49
35
  return {
50
- status: 'incomplete',
51
- continueParsing,
52
36
  skipTo: null,
53
37
  };
54
38
  }
55
- throw new Error('Unknown MP3 header ');
39
+ throw new Error('Unknown MP3 header ' + JSON.stringify(bytes));
56
40
  };
57
41
  exports.parseMp3 = parseMp3;
@@ -1,19 +1,11 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { Options, ParseMediaFields } from '../../options';
3
- import type { RiffStructure } from '../../parse-result';
4
2
  import type { ParserState } from '../../state/parser-state';
5
3
  import type { RiffBox } from './riff-box';
6
4
  export type RiffResult = {
7
- type: 'incomplete';
8
- continueParsing: () => Promise<RiffResult>;
9
- } | {
10
- type: 'complete';
11
5
  box: RiffBox | null;
12
6
  skipTo: number | null;
13
7
  };
14
- export declare const expectRiffBox: ({ iterator, state, structure, fields, }: {
8
+ export declare const expectRiffBox: ({ iterator, state, }: {
15
9
  iterator: BufferIterator;
16
10
  state: ParserState;
17
- structure: RiffStructure;
18
- fields: Options<ParseMediaFields>;
19
11
  }) => Promise<RiffResult>;
@@ -1,49 +1,71 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expectRiffBox = void 0;
4
+ const register_track_1 = require("../../register-track");
5
+ const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
4
6
  const is_movi_1 = require("./is-movi");
5
- const parse_movi_1 = require("./parse-movi");
6
7
  const parse_riff_box_1 = require("./parse-riff-box");
7
- const expectRiffBox = async ({ iterator, state, structure, fields, }) => {
8
+ const parse_video_section_1 = require("./parse-video-section");
9
+ const expectRiffBox = async ({ iterator, state, }) => {
8
10
  // Need at least 16 bytes to read LIST,size,movi,size
9
11
  if (iterator.bytesRemaining() < 16) {
10
12
  return {
11
- type: 'incomplete',
12
- continueParsing() {
13
- return (0, exports.expectRiffBox)({ structure, iterator, state, fields });
14
- },
13
+ box: null,
14
+ skipTo: null,
15
15
  };
16
16
  }
17
+ const checkpoint = iterator.startCheckpoint();
17
18
  const ckId = iterator.getByteString(4, false);
18
19
  const ckSize = iterator.getUint32Le();
19
20
  if ((0, is_movi_1.isMoviAtom)(iterator, ckId)) {
20
21
  iterator.discard(4);
21
- return (0, parse_movi_1.parseMovi)({
22
- iterator,
23
- maxOffset: ckSize + iterator.counter.getOffset() - 4,
24
- state,
25
- structure,
22
+ state.videoSection.setVideoSection({
23
+ start: iterator.counter.getOffset(),
24
+ size: ckSize - 4,
26
25
  });
26
+ return (0, parse_video_section_1.parseVideoSection)({ state, iterator });
27
27
  }
28
28
  if (iterator.bytesRemaining() < ckSize) {
29
- iterator.counter.decrement(8);
29
+ checkpoint.returnToCheckpoint();
30
30
  return {
31
- type: 'incomplete',
32
- continueParsing: () => {
33
- return (0, exports.expectRiffBox)({ structure, iterator, state, fields });
34
- },
31
+ box: null,
32
+ skipTo: null,
35
33
  };
36
34
  }
35
+ const box = await (0, parse_riff_box_1.parseRiffBox)({
36
+ id: ckId,
37
+ iterator,
38
+ size: ckSize,
39
+ state,
40
+ });
41
+ if (box.type === 'strh-box') {
42
+ if (box.strf.type === 'strf-box-audio' && state.onAudioTrack) {
43
+ const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
44
+ index: state.riff.getNextTrackIndex(),
45
+ strf: box.strf,
46
+ });
47
+ await (0, register_track_1.registerTrack)({
48
+ state,
49
+ track: audioTrack,
50
+ container: 'avi',
51
+ });
52
+ }
53
+ if (state.onVideoTrack && box.strf.type === 'strf-box-video') {
54
+ const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
55
+ strh: box,
56
+ index: state.riff.getNextTrackIndex(),
57
+ strf: box.strf,
58
+ });
59
+ (0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
60
+ state,
61
+ track: videoTrack,
62
+ container: 'avi',
63
+ });
64
+ }
65
+ state.riff.incrementNextTrackIndex();
66
+ }
37
67
  return {
38
- type: 'complete',
39
- box: await (0, parse_riff_box_1.parseRiffBox)({
40
- id: ckId,
41
- iterator,
42
- size: ckSize,
43
- boxes: structure.boxes,
44
- state,
45
- fields,
46
- }),
68
+ box,
47
69
  skipTo: null,
48
70
  };
49
71
  };
@@ -19,4 +19,4 @@ export declare const makeAviVideoTrack: ({ strh, strf, index, }: {
19
19
  index: number;
20
20
  }) => VideoTrack;
21
21
  export declare const getTracksFromAvi: (structure: RiffStructure, state: ParserState) => AllTracks;
22
- export declare const hasAllTracksFromAvi: (structure: RiffStructure, state: ParserState) => boolean;
22
+ export declare const hasAllTracksFromAvi: (state: ParserState) => boolean;