@remotion/media-parser 4.0.251 → 4.0.252

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 (126) hide show
  1. package/dist/aac-codecprivate.d.ts +2 -1
  2. package/dist/aac-codecprivate.js +28 -7
  3. package/dist/buffer-iterator.d.ts +5 -1
  4. package/dist/buffer-iterator.js +5 -5
  5. package/dist/containers/aac/parse-aac.js +3 -2
  6. package/dist/containers/flac/get-channel-count.d.ts +1 -1
  7. package/dist/containers/flac/get-duration-from-flac.js +1 -4
  8. package/dist/containers/flac/get-sample-rate.js +1 -1
  9. package/dist/containers/flac/parse-flac-frame.js +3 -9
  10. package/dist/containers/flac/parse-flac.js +2 -7
  11. package/dist/containers/flac/parse-header.js +2 -2
  12. package/dist/containers/flac/parse-metadata.js +2 -2
  13. package/dist/containers/flac/parse-streaminfo.js +3 -3
  14. package/dist/containers/flac/parse-unknown-block.js +2 -2
  15. package/dist/containers/iso-base-media/base-media-box.d.ts +1 -4
  16. package/dist/containers/iso-base-media/get-actual-number-of-channels.js +1 -1
  17. package/dist/containers/iso-base-media/get-children.js +2 -2
  18. package/dist/containers/iso-base-media/get-keyframes.d.ts +2 -2
  19. package/dist/containers/iso-base-media/get-keyframes.js +3 -2
  20. package/dist/containers/iso-base-media/get-moov-atom.d.ts +6 -0
  21. package/dist/containers/iso-base-media/get-moov-atom.js +73 -0
  22. package/dist/containers/iso-base-media/get-video-codec-from-iso-track.js +1 -1
  23. package/dist/containers/iso-base-media/mdat/mdat.d.ts +2 -1
  24. package/dist/containers/iso-base-media/mdat/mdat.js +13 -8
  25. package/dist/containers/iso-base-media/parse-boxes.js +4 -26
  26. package/dist/containers/iso-base-media/process-box.js +50 -163
  27. package/dist/containers/iso-base-media/stsd/samples.js +1 -0
  28. package/dist/containers/iso-base-media/traversal.d.ts +2 -1
  29. package/dist/containers/iso-base-media/traversal.js +6 -2
  30. package/dist/containers/mp3/get-duration.js +0 -3
  31. package/dist/containers/mp3/id3.js +1 -1
  32. package/dist/containers/mp3/parse-mp3.js +4 -12
  33. package/dist/containers/mp3/parse-mpeg-header.js +1 -1
  34. package/dist/containers/riff/expect-riff-box.d.ts +1 -2
  35. package/dist/containers/riff/expect-riff-box.js +4 -14
  36. package/dist/containers/riff/get-tracks-from-avi.js +1 -1
  37. package/dist/containers/riff/parse-list-box.js +3 -5
  38. package/dist/containers/riff/parse-movi.d.ts +2 -4
  39. package/dist/containers/riff/parse-movi.js +9 -27
  40. package/dist/containers/riff/parse-riff-body.js +17 -11
  41. package/dist/containers/riff/parse-riff-header.js +2 -7
  42. package/dist/containers/riff/parse-video-section.d.ts +1 -1
  43. package/dist/containers/riff/parse-video-section.js +5 -7
  44. package/dist/containers/transport-stream/adts-header.js +1 -0
  45. package/dist/containers/transport-stream/get-tracks.js +1 -1
  46. package/dist/containers/transport-stream/parse-packet.js +1 -1
  47. package/dist/containers/transport-stream/parse-transport-stream.js +3 -10
  48. package/dist/containers/transport-stream/process-stream-buffers.js +1 -1
  49. package/dist/containers/wav/get-duration-from-wav.js +1 -4
  50. package/dist/containers/wav/parse-data.js +6 -6
  51. package/dist/containers/wav/parse-fmt.js +2 -2
  52. package/dist/containers/wav/parse-header.js +2 -2
  53. package/dist/containers/wav/parse-id3.js +2 -4
  54. package/dist/containers/wav/parse-list.js +2 -2
  55. package/dist/containers/wav/parse-video-section.js +2 -5
  56. package/dist/containers/webm/parse-ebml.js +1 -1
  57. package/dist/containers/webm/parse-webm-header.js +3 -10
  58. package/dist/download-and-parse-media.d.ts +2 -0
  59. package/dist/download-and-parse-media.js +70 -0
  60. package/dist/emit-available-info.d.ts +2 -3
  61. package/dist/emit-available-info.js +36 -36
  62. package/dist/esm/from-fetch.mjs +1 -1
  63. package/dist/esm/from-node.mjs +1 -1
  64. package/dist/esm/from-web-file.mjs +7 -7
  65. package/dist/esm/index.mjs +702 -637
  66. package/dist/esm/node.mjs +113 -0
  67. package/dist/get-audio-codec.js +3 -0
  68. package/dist/get-dimensions.js +2 -2
  69. package/dist/get-duration.js +3 -6
  70. package/dist/get-fps.d.ts +4 -4
  71. package/dist/get-fps.js +13 -11
  72. package/dist/get-keyframes.d.ts +1 -2
  73. package/dist/get-keyframes.js +4 -3
  74. package/dist/get-location.d.ts +2 -2
  75. package/dist/get-location.js +2 -2
  76. package/dist/get-tracks.d.ts +3 -5
  77. package/dist/get-tracks.js +8 -14
  78. package/dist/has-all-info.js +3 -3
  79. package/dist/index.d.ts +127 -101
  80. package/dist/index.js +3 -1
  81. package/dist/init-video.d.ts +1 -1
  82. package/dist/init-video.js +8 -8
  83. package/dist/internal-parse-media.d.ts +2 -0
  84. package/dist/internal-parse-media.js +221 -0
  85. package/dist/make-hvc1-codec-strings.js +4 -4
  86. package/dist/metadata/get-metadata.d.ts +2 -1
  87. package/dist/metadata/get-metadata.js +3 -2
  88. package/dist/metadata/metadata-from-iso.d.ts +2 -2
  89. package/dist/metadata/metadata-from-iso.js +2 -2
  90. package/dist/options.d.ts +56 -33
  91. package/dist/parse-and-download-media.d.ts +2 -0
  92. package/dist/parse-and-download-media.js +57 -0
  93. package/dist/parse-media.js +5 -201
  94. package/dist/parse-result.d.ts +2 -6
  95. package/dist/perform-seek.d.ts +5 -8
  96. package/dist/perform-seek.js +16 -9
  97. package/dist/readers/from-fetch.js +1 -1
  98. package/dist/readers/from-node.js +1 -1
  99. package/dist/readers/from-web-file.js +9 -9
  100. package/dist/readers/reader.d.ts +7 -2
  101. package/dist/register-track.js +5 -0
  102. package/dist/run-parse-iteration.d.ts +1 -1
  103. package/dist/run-parse-iteration.js +2 -2
  104. package/dist/skip.d.ts +5 -0
  105. package/dist/skip.js +8 -0
  106. package/dist/state/has-tracks-section.d.ts +3 -1
  107. package/dist/state/has-tracks-section.js +7 -1
  108. package/dist/state/iso-base-media/cached-sample-positions.js +1 -1
  109. package/dist/state/iso-base-media/iso-state.d.ts +4 -2
  110. package/dist/state/iso-base-media/iso-state.js +2 -5
  111. package/dist/state/iso-base-media/moov-box.d.ts +5 -0
  112. package/dist/state/iso-base-media/moov-box.js +13 -0
  113. package/dist/state/last-eventloop-break.d.ts +4 -0
  114. package/dist/state/last-eventloop-break.js +18 -0
  115. package/dist/state/parser-state.d.ts +122 -101
  116. package/dist/state/parser-state.js +21 -3
  117. package/dist/state/sample-callbacks.d.ts +2 -1
  118. package/dist/state/structure.d.ts +7 -0
  119. package/dist/state/structure.js +56 -6
  120. package/dist/version.d.ts +1 -1
  121. package/dist/version.js +1 -1
  122. package/dist/writers/node.d.ts +4 -0
  123. package/dist/writers/node.js +81 -0
  124. package/dist/writers/writer.d.ts +17 -0
  125. package/dist/writers/writer.js +2 -0
  126. package/package.json +12 -9
@@ -36,14 +36,12 @@ const processBox = async (state) => {
36
36
  const fileOffset = iterator.counter.getOffset();
37
37
  const { returnToCheckpoint } = iterator.startCheckpoint();
38
38
  const bytesRemaining = iterator.bytesRemaining();
39
+ const startOff = iterator.counter.getOffset();
39
40
  const boxSizeRaw = iterator.getFourByteNumber();
40
41
  if (boxSizeRaw === 0) {
41
42
  return {
42
- box: {
43
- type: 'void-box',
44
- boxSize: 0,
45
- },
46
- skipTo: null,
43
+ type: 'void-box',
44
+ boxSize: 0,
47
45
  };
48
46
  }
49
47
  // If `boxSize === 1`, the 8 bytes after the box type are the size of the box.
@@ -55,200 +53,126 @@ const processBox = async (state) => {
55
53
  const boxType = iterator.getByteString(4, false);
56
54
  const boxSize = boxSizeRaw === 1 ? iterator.getEightByteNumber() : boxSizeRaw;
57
55
  log_1.Log.trace(state.logLevel, 'Found box', boxType, boxSize);
56
+ const headerLength = iterator.counter.getOffset() - startOff;
58
57
  if (boxType === 'mdat') {
59
58
  state.videoSection.setVideoSection({
60
- size: boxSize - 8,
59
+ size: boxSize - headerLength,
61
60
  start: iterator.counter.getOffset(),
62
61
  });
63
- return {
64
- box: null,
65
- skipTo: null,
66
- };
62
+ return null;
67
63
  }
68
64
  if (bytesRemaining < boxSize) {
69
65
  returnToCheckpoint();
70
- return {
71
- box: null,
72
- skipTo: null,
73
- };
66
+ return null;
74
67
  }
75
68
  if (boxType === 'ftyp') {
76
- const box = (0, ftyp_1.parseFtyp)({ iterator, size: boxSize, offset: fileOffset });
77
- return {
78
- box,
79
- skipTo: null,
80
- };
69
+ return (0, ftyp_1.parseFtyp)({ iterator, size: boxSize, offset: fileOffset });
81
70
  }
82
71
  if (boxType === 'colr') {
83
- const box = (0, colr_1.parseColorParameterBox)({
72
+ return (0, colr_1.parseColorParameterBox)({
84
73
  iterator,
85
74
  size: boxSize,
86
75
  });
87
- return {
88
- box,
89
- skipTo: null,
90
- };
91
76
  }
92
77
  if (boxType === 'mvhd') {
93
- const box = (0, mvhd_1.parseMvhd)({ iterator, offset: fileOffset, size: boxSize });
94
- return {
95
- box,
96
- skipTo: null,
97
- };
78
+ return (0, mvhd_1.parseMvhd)({ iterator, offset: fileOffset, size: boxSize });
98
79
  }
99
80
  if (boxType === 'tkhd') {
100
- const box = (0, tkhd_1.parseTkhd)({ iterator, offset: fileOffset, size: boxSize });
101
- return {
102
- box,
103
- skipTo: null,
104
- };
81
+ return (0, tkhd_1.parseTkhd)({ iterator, offset: fileOffset, size: boxSize });
105
82
  }
106
83
  if (boxType === 'trun') {
107
- const box = (0, trun_1.parseTrun)({ iterator, offset: fileOffset, size: boxSize });
108
- return {
109
- box,
110
- skipTo: null,
111
- };
84
+ return (0, trun_1.parseTrun)({ iterator, offset: fileOffset, size: boxSize });
112
85
  }
113
86
  if (boxType === 'tfdt') {
114
- const box = (0, tfdt_1.parseTfdt)({ iterator, size: boxSize, offset: fileOffset });
115
- return {
116
- box,
117
- skipTo: null,
118
- };
87
+ return (0, tfdt_1.parseTfdt)({ iterator, size: boxSize, offset: fileOffset });
119
88
  }
120
89
  if (boxType === 'stsd') {
121
- const box = await (0, stsd_1.parseStsd)({
90
+ return (0, stsd_1.parseStsd)({
122
91
  offset: fileOffset,
123
92
  size: boxSize,
124
93
  state,
125
94
  });
126
- return {
127
- box,
128
- skipTo: null,
129
- };
130
95
  }
131
96
  if (boxType === 'stsz') {
132
- const box = (0, stsz_1.parseStsz)({
97
+ return (0, stsz_1.parseStsz)({
133
98
  iterator,
134
99
  offset: fileOffset,
135
100
  size: boxSize,
136
101
  });
137
- return {
138
- box,
139
- skipTo: null,
140
- };
141
102
  }
142
103
  if (boxType === 'stco' || boxType === 'co64') {
143
- const box = (0, stco_1.parseStco)({
104
+ return (0, stco_1.parseStco)({
144
105
  iterator,
145
106
  offset: fileOffset,
146
107
  size: boxSize,
147
108
  mode64Bit: boxType === 'co64',
148
109
  });
149
- return {
150
- box,
151
- skipTo: null,
152
- };
153
110
  }
154
111
  if (boxType === 'pasp') {
155
- const box = (0, pasp_1.parsePasp)({
112
+ return (0, pasp_1.parsePasp)({
156
113
  iterator,
157
114
  offset: fileOffset,
158
115
  size: boxSize,
159
116
  });
160
- return {
161
- box,
162
- skipTo: null,
163
- };
164
117
  }
165
118
  if (boxType === 'stss') {
166
- const box = (0, stss_1.parseStss)({
119
+ return (0, stss_1.parseStss)({
167
120
  iterator,
168
121
  offset: fileOffset,
169
122
  boxSize,
170
123
  });
171
- return {
172
- box,
173
- skipTo: null,
174
- };
175
124
  }
176
125
  if (boxType === 'ctts') {
177
- const box = (0, ctts_1.parseCtts)({
126
+ return (0, ctts_1.parseCtts)({
178
127
  iterator,
179
128
  offset: fileOffset,
180
129
  size: boxSize,
181
130
  });
182
- return {
183
- box,
184
- skipTo: null,
185
- };
186
131
  }
187
132
  if (boxType === 'stsc') {
188
- const box = (0, stsc_1.parseStsc)({
133
+ return (0, stsc_1.parseStsc)({
189
134
  iterator,
190
135
  offset: fileOffset,
191
136
  size: boxSize,
192
137
  });
193
- return {
194
- box,
195
- skipTo: null,
196
- };
197
138
  }
198
139
  if (boxType === 'mebx') {
199
- const box = await (0, mebx_1.parseMebx)({
140
+ return (0, mebx_1.parseMebx)({
200
141
  offset: fileOffset,
201
142
  size: boxSize,
202
143
  state,
203
144
  });
204
- return {
205
- box,
206
- skipTo: null,
207
- };
208
145
  }
209
146
  if (boxType === 'hdlr') {
210
- const box = await (0, hdlr_1.parseHdlr)({ iterator, size: boxSize, offset: fileOffset });
211
- return {
212
- box,
213
- skipTo: null,
214
- };
147
+ return (0, hdlr_1.parseHdlr)({ iterator, size: boxSize, offset: fileOffset });
215
148
  }
216
149
  if (boxType === 'keys') {
217
- const box = (0, keys_1.parseKeys)({ iterator, size: boxSize, offset: fileOffset });
218
- return {
219
- box,
220
- skipTo: null,
221
- };
150
+ return (0, keys_1.parseKeys)({ iterator, size: boxSize, offset: fileOffset });
222
151
  }
223
152
  if (boxType === 'ilst') {
224
- const box = (0, ilst_1.parseIlstBox)({
153
+ return (0, ilst_1.parseIlstBox)({
225
154
  iterator,
226
155
  offset: fileOffset,
227
156
  size: boxSize,
228
157
  });
229
- return {
230
- box,
231
- skipTo: null,
232
- };
233
158
  }
234
159
  if (boxType === 'moov') {
235
160
  if (state.callbacks.tracks.hasAllTracks()) {
236
161
  iterator.discard(boxSize - 8);
237
- return {
238
- box: null,
239
- skipTo: null,
240
- };
162
+ return null;
163
+ }
164
+ if (state.iso.moov.getMoovBox()) {
165
+ log_1.Log.verbose(state.logLevel, 'Moov box already parsed, skipping');
166
+ iterator.discard(boxSize - 8);
167
+ return null;
241
168
  }
242
169
  const box = await (0, moov_1.parseMoov)({
243
170
  offset: fileOffset,
244
171
  size: boxSize,
245
172
  state,
246
173
  });
247
- state.callbacks.tracks.setIsDone();
248
- return {
249
- box,
250
- skipTo: null,
251
- };
174
+ state.callbacks.tracks.setIsDone(state.logLevel);
175
+ return box;
252
176
  }
253
177
  if (boxType === 'trak') {
254
178
  const box = await (0, trak_1.parseTrak)({
@@ -264,85 +188,54 @@ const processBox = async (state) => {
264
188
  container: 'mp4',
265
189
  });
266
190
  }
267
- return {
268
- box,
269
- skipTo: null,
270
- };
191
+ return box;
271
192
  }
272
193
  if (boxType === 'stts') {
273
- const box = (0, stts_1.parseStts)({
194
+ return (0, stts_1.parseStts)({
274
195
  data: iterator,
275
196
  size: boxSize,
276
197
  fileOffset,
277
198
  });
278
- return {
279
- box,
280
- skipTo: null,
281
- };
282
199
  }
283
200
  if (boxType === 'avcC') {
284
- const box = (0, avcc_1.parseAvcc)({
201
+ return (0, avcc_1.parseAvcc)({
285
202
  data: iterator,
286
203
  size: boxSize,
287
204
  });
288
- return {
289
- box,
290
- skipTo: null,
291
- };
292
205
  }
293
206
  if (boxType === 'av1C') {
294
- const box = (0, av1c_1.parseAv1C)({
207
+ return (0, av1c_1.parseAv1C)({
295
208
  data: iterator,
296
209
  size: boxSize,
297
210
  });
298
- return {
299
- box,
300
- skipTo: null,
301
- };
302
211
  }
303
212
  if (boxType === 'hvcC') {
304
- const box = (0, hvcc_1.parseHvcc)({
213
+ return (0, hvcc_1.parseHvcc)({
305
214
  data: iterator,
306
215
  size: boxSize,
307
216
  offset: fileOffset,
308
217
  });
309
- return {
310
- box,
311
- skipTo: null,
312
- };
313
218
  }
314
219
  if (boxType === 'tfhd') {
315
- const box = (0, tfhd_1.getTfhd)({
220
+ return (0, tfhd_1.getTfhd)({
316
221
  iterator,
317
222
  offset: fileOffset,
318
223
  size: boxSize,
319
224
  });
320
- return {
321
- box,
322
- skipTo: null,
323
- };
324
225
  }
325
226
  if (boxType === 'mdhd') {
326
- const box = (0, mdhd_1.parseMdhd)({
227
+ return (0, mdhd_1.parseMdhd)({
327
228
  data: iterator,
328
229
  size: boxSize,
329
230
  fileOffset,
330
231
  });
331
- return {
332
- box,
333
- skipTo: null,
334
- };
335
232
  }
336
233
  if (boxType === 'esds') {
337
- const box = (0, esds_1.parseEsds)({
234
+ return (0, esds_1.parseEsds)({
338
235
  data: iterator,
339
236
  size: boxSize,
340
237
  fileOffset,
341
238
  });
342
- return {
343
- box,
344
- skipTo: null,
345
- };
346
239
  }
347
240
  if (boxType === 'mdia' ||
348
241
  boxType === 'minf' ||
@@ -359,26 +252,20 @@ const processBox = async (state) => {
359
252
  size: boxSize - 8,
360
253
  });
361
254
  return {
362
- box: {
363
- type: 'regular-box',
364
- boxType,
365
- boxSize,
366
- children,
367
- offset: fileOffset,
368
- },
369
- skipTo: null,
370
- };
371
- }
372
- iterator.discard(boxSize - 8);
373
- return {
374
- box: {
375
255
  type: 'regular-box',
376
256
  boxType,
377
257
  boxSize,
378
- children: [],
258
+ children,
379
259
  offset: fileOffset,
380
- },
381
- skipTo: null,
260
+ };
261
+ }
262
+ iterator.discard(boxSize - 8);
263
+ return {
264
+ type: 'regular-box',
265
+ boxType,
266
+ boxSize,
267
+ children: [],
268
+ offset: fileOffset,
382
269
  };
383
270
  };
384
271
  exports.processBox = processBox;
@@ -31,6 +31,7 @@ const videoTags = [
31
31
  'v410',
32
32
  'v210',
33
33
  'hvc1',
34
+ 'hev1',
34
35
  'ap4h',
35
36
  'av01',
36
37
  ];
@@ -1,4 +1,5 @@
1
1
  import type { AnySegment } from '../../parse-result';
2
+ import type { ParserState } from '../../state/parser-state';
2
3
  import type { IsoBaseMediaBox, RegularBox } from './base-media-box';
3
4
  import type { FtypBox } from './ftyp';
4
5
  import type { MdhdBox } from './mdhd';
@@ -17,7 +18,7 @@ import type { TkhdBox } from './tkhd';
17
18
  import type { TrakBox } from './trak/trak';
18
19
  import type { TrunBox } from './trun';
19
20
  export declare const getFtypBox: (segments: AnySegment[]) => FtypBox | null;
20
- export declare const getMoovBox: (segments: IsoBaseMediaBox[]) => MoovBox | null;
21
+ export declare const getMoovBox: (state: ParserState) => MoovBox | null;
21
22
  export declare const getMoofBox: (main: AnySegment[]) => IsoBaseMediaBox | null;
22
23
  export declare const getMvhdBox: (moovBox: MoovBox) => MvhdBox | null;
23
24
  export declare const getTraks: (moovBox: MoovBox) => TrakBox[];
@@ -9,8 +9,12 @@ const getFtypBox = (segments) => {
9
9
  return ftypBox;
10
10
  };
11
11
  exports.getFtypBox = getFtypBox;
12
- const getMoovBox = (segments) => {
13
- const moovBox = segments.find((s) => s.type === 'moov-box');
12
+ const getMoovBox = (state) => {
13
+ if (state.iso.moov.getMoovBox()) {
14
+ return state.iso.moov.getMoovBox();
15
+ }
16
+ const structure = state.getIsoStructure();
17
+ const moovBox = structure.boxes.find((s) => s.type === 'moov-box');
14
18
  if (!moovBox || moovBox.type !== 'moov-box') {
15
19
  return null;
16
20
  }
@@ -4,9 +4,6 @@ exports.getDurationFromMp3 = void 0;
4
4
  const get_frame_length_1 = require("./get-frame-length");
5
5
  const samples_per_mpeg_file_1 = require("./samples-per-mpeg-file");
6
6
  const getDurationFromMp3 = (state) => {
7
- if (state.contentLength === null) {
8
- return null;
9
- }
10
7
  const mp3Info = state.mp3Info.getMp3Info();
11
8
  if (!mp3Info) {
12
9
  throw new Error('No mp3 info');
@@ -69,7 +69,7 @@ const parseId3 = ({ state }) => {
69
69
  });
70
70
  }
71
71
  }
72
- state.structure.getStructure().boxes.push({
72
+ state.getMp3Structure().boxes.push({
73
73
  type: 'id3-header',
74
74
  flags,
75
75
  size,
@@ -7,9 +7,7 @@ const parse_mpeg_header_1 = require("./parse-mpeg-header");
7
7
  const parseMp3 = async (state) => {
8
8
  const { iterator } = state;
9
9
  if (iterator.bytesRemaining() < 3) {
10
- return {
11
- skipTo: null,
12
- };
10
+ return null;
13
11
  }
14
12
  const { returnToCheckpoint } = iterator.startCheckpoint();
15
13
  const bytes = iterator.getSlice(3);
@@ -17,24 +15,18 @@ const parseMp3 = async (state) => {
17
15
  // ID3 v1
18
16
  if (bytes[0] === 0x54 && bytes[1] === 0x41 && bytes[2] === 0x47) {
19
17
  (0, id3_v1_1.parseID3V1)(iterator);
20
- return {
21
- skipTo: null,
22
- };
18
+ return null;
23
19
  }
24
20
  // ID3 v2 or v3
25
21
  if (bytes[0] === 0x49 && bytes[1] === 0x44 && bytes[2] === 0x33) {
26
22
  (0, id3_1.parseId3)({ state });
27
- return {
28
- skipTo: null,
29
- };
23
+ return null;
30
24
  }
31
25
  if (bytes[0] === 0xff) {
32
26
  await (0, parse_mpeg_header_1.parseMpegHeader)({
33
27
  state,
34
28
  });
35
- return {
36
- skipTo: null,
37
- };
29
+ return null;
38
30
  }
39
31
  throw new Error('Unknown MP3 header ' + JSON.stringify(bytes));
40
32
  };
@@ -243,7 +243,7 @@ const parseMpegHeader = async ({ state, }) => {
243
243
  trakBox: null,
244
244
  },
245
245
  });
246
- state.callbacks.tracks.setIsDone();
246
+ state.callbacks.tracks.setIsDone(state.logLevel);
247
247
  }
248
248
  const mp3Info = state.mp3Info.getMp3Info();
249
249
  if (!mp3Info) {
@@ -2,6 +2,5 @@ import type { ParserState } from '../../state/parser-state';
2
2
  import type { RiffBox } from './riff-box';
3
3
  export type RiffResult = {
4
4
  box: RiffBox | null;
5
- skipTo: number | null;
6
5
  };
7
- export declare const expectRiffBox: (state: ParserState) => Promise<RiffResult>;
6
+ export declare const expectRiffBox: (state: ParserState) => Promise<RiffBox | null>;
@@ -5,15 +5,11 @@ const register_track_1 = require("../../register-track");
5
5
  const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
6
6
  const is_movi_1 = require("./is-movi");
7
7
  const parse_riff_box_1 = require("./parse-riff-box");
8
- const parse_video_section_1 = require("./parse-video-section");
9
8
  const expectRiffBox = async (state) => {
10
9
  const { iterator } = state;
11
10
  // Need at least 16 bytes to read LIST,size,movi,size
12
11
  if (state.iterator.bytesRemaining() < 16) {
13
- return {
14
- box: null,
15
- skipTo: null,
16
- };
12
+ return null;
17
13
  }
18
14
  const checkpoint = iterator.startCheckpoint();
19
15
  const ckId = iterator.getByteString(4, false);
@@ -24,14 +20,11 @@ const expectRiffBox = async (state) => {
24
20
  start: iterator.counter.getOffset(),
25
21
  size: ckSize - 4,
26
22
  });
27
- return (0, parse_video_section_1.parseVideoSection)(state);
23
+ return null;
28
24
  }
29
25
  if (iterator.bytesRemaining() < ckSize) {
30
26
  checkpoint.returnToCheckpoint();
31
- return {
32
- box: null,
33
- skipTo: null,
34
- };
27
+ return null;
35
28
  }
36
29
  const box = await (0, parse_riff_box_1.parseRiffBox)({
37
30
  id: ckId,
@@ -64,9 +57,6 @@ const expectRiffBox = async (state) => {
64
57
  }
65
58
  state.riff.incrementNextTrackIndex();
66
59
  }
67
- return {
68
- box,
69
- skipTo: null,
70
- };
60
+ return box;
71
61
  };
72
62
  exports.expectRiffBox = expectRiffBox;
@@ -94,7 +94,7 @@ const getTracksFromAvi = (structure, state) => {
94
94
  exports.getTracksFromAvi = getTracksFromAvi;
95
95
  const hasAllTracksFromAvi = (state) => {
96
96
  try {
97
- const structure = state.structure.getStructure();
97
+ const structure = state.getRiffStructure();
98
98
  const numberOfTracks = (0, exports.getNumberOfTracks)(structure);
99
99
  const tracks = (0, exports.getTracksFromAvi)(structure, state);
100
100
  return (tracks.videoTracks.length +
@@ -12,13 +12,11 @@ const parseListBox = async ({ size, state, }) => {
12
12
  const boxes = [];
13
13
  const maxOffset = counter + size;
14
14
  while (iterator.counter.getOffset() < maxOffset) {
15
- const result = await (0, expect_riff_box_1.expectRiffBox)(state);
16
- if (result.box !== null) {
17
- boxes.push(result.box);
18
- }
19
- else {
15
+ const box = await (0, expect_riff_box_1.expectRiffBox)(state);
16
+ if (box === null) {
20
17
  throw new Error('Unexpected result');
21
18
  }
19
+ boxes.push(box);
22
20
  }
23
21
  return {
24
22
  type: 'list-box',
@@ -1,11 +1,9 @@
1
1
  import type { ParserState } from '../../state/parser-state';
2
- import type { RiffResult } from './expect-riff-box';
3
2
  export declare const handleChunk: ({ state, ckId, ckSize, }: {
4
3
  state: ParserState;
5
4
  ckId: string;
6
5
  ckSize: number;
7
6
  }) => Promise<void>;
8
- export declare const parseMovi: ({ maxOffset, state, }: {
9
- maxOffset: number;
7
+ export declare const parseMovi: ({ state, }: {
10
8
  state: ParserState;
11
- }) => Promise<RiffResult>;
9
+ }) => Promise<void>;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMovi = exports.handleChunk = void 0;
4
4
  const convert_audio_or_video_sample_1 = require("../../convert-audio-or-video-sample");
5
- const may_skip_video_data_1 = require("../../state/may-skip-video-data");
6
5
  const key_1 = require("../avc/key");
7
6
  const parse_avc_1 = require("../avc/parse-avc");
8
7
  const traversal_1 = require("./traversal");
@@ -24,7 +23,7 @@ const handleChunk = async ({ state, ckId, ckSize, }) => {
24
23
  const videoChunk = ckId.match(/^([0-9]{2})dc$/);
25
24
  if (videoChunk) {
26
25
  const trackId = parseInt(videoChunk[1], 10);
27
- const strh = getStrhForIndex(state.structure.getStructure(), trackId);
26
+ const strh = getStrhForIndex(state.getRiffStructure(), trackId);
28
27
  const samplesPerSecond = strh.rate / strh.scale;
29
28
  const nthSample = state.callbacks.getSamplesForTrack(trackId);
30
29
  const timeInSec = nthSample / samplesPerSecond;
@@ -34,9 +33,9 @@ const handleChunk = async ({ state, ckId, ckSize, }) => {
34
33
  const keyOrDelta = (0, key_1.getKeyFrameOrDeltaFromAvcInfo)(infos);
35
34
  const avcProfile = infos.find((i) => i.type === 'avc-profile');
36
35
  const ppsProfile = infos.find((i) => i.type === 'avc-pps');
37
- if (avcProfile && ppsProfile) {
36
+ if (avcProfile && ppsProfile && !state.riff.getAvcProfile()) {
38
37
  await state.riff.onProfile({ pps: ppsProfile, sps: avcProfile });
39
- state.callbacks.tracks.setIsDone();
38
+ state.callbacks.tracks.setIsDone(state.logLevel);
40
39
  }
41
40
  // We must also NOT pass a duration because if the the next sample is 0,
42
41
  // this sample would be longer. Chrome will pad it with silence.
@@ -57,7 +56,7 @@ const handleChunk = async ({ state, ckId, ckSize, }) => {
57
56
  const audioChunk = ckId.match(/^([0-9]{2})wb$/);
58
57
  if (audioChunk) {
59
58
  const trackId = parseInt(audioChunk[1], 10);
60
- const strh = getStrhForIndex(state.structure.getStructure(), trackId);
59
+ const strh = getStrhForIndex(state.getRiffStructure(), trackId);
61
60
  const samplesPerSecond = strh.rate / strh.scale;
62
61
  const nthSample = state.callbacks.getSamplesForTrack(trackId);
63
62
  const timeInSec = nthSample / samplesPerSecond;
@@ -82,34 +81,21 @@ const handleChunk = async ({ state, ckId, ckSize, }) => {
82
81
  }
83
82
  };
84
83
  exports.handleChunk = handleChunk;
85
- const parseMovi = async ({ maxOffset, state, }) => {
86
- if ((0, may_skip_video_data_1.maySkipVideoData)({
87
- state,
88
- }) &&
89
- state.riff.getAvcProfile()) {
90
- return {
91
- box: null,
92
- skipTo: maxOffset,
93
- };
94
- }
84
+ const parseMovi = async ({ state, }) => {
95
85
  const { iterator } = state;
96
86
  if (iterator.bytesRemaining() < 8) {
97
- return {
98
- box: null,
99
- skipTo: null,
100
- };
87
+ return Promise.resolve();
101
88
  }
102
89
  const checkpoint = iterator.startCheckpoint();
103
90
  const ckId = iterator.getByteString(4, false);
104
91
  const ckSize = iterator.getUint32Le();
105
92
  if (iterator.bytesRemaining() < ckSize) {
106
93
  checkpoint.returnToCheckpoint();
107
- return {
108
- box: null,
109
- skipTo: null,
110
- };
94
+ return Promise.resolve();
111
95
  }
112
96
  await (0, exports.handleChunk)({ state, ckId, ckSize });
97
+ const videoSection = state.videoSection.getVideoSection();
98
+ const maxOffset = videoSection.start + videoSection.size;
113
99
  // Discard added zeroes
114
100
  while (iterator.counter.getOffset() < maxOffset &&
115
101
  iterator.bytesRemaining() > 0) {
@@ -118,9 +104,5 @@ const parseMovi = async ({ maxOffset, state, }) => {
118
104
  break;
119
105
  }
120
106
  }
121
- return {
122
- box: null,
123
- skipTo: null,
124
- };
125
107
  };
126
108
  exports.parseMovi = parseMovi;