@remotion/media-parser 4.0.289 → 4.0.291

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 (167) hide show
  1. package/dist/containers/flac/get-channel-count.d.ts +1 -1
  2. package/dist/containers/iso-base-media/base-media-box.d.ts +0 -1
  3. package/dist/containers/iso-base-media/collect-sample-positions-from-moof-boxes.d.ts +4 -1
  4. package/dist/containers/iso-base-media/collect-sample-positions-from-moof-boxes.js +9 -5
  5. package/dist/containers/iso-base-media/find-keyframe-before-time.js +16 -11
  6. package/dist/containers/iso-base-media/find-track-to-seek.d.ts +14 -0
  7. package/dist/containers/iso-base-media/find-track-to-seek.js +39 -0
  8. package/dist/containers/iso-base-media/get-children.js +2 -2
  9. package/dist/containers/iso-base-media/get-keyframes.js +6 -1
  10. package/dist/containers/iso-base-media/get-mfra-seeking-box.d.ts +3 -1
  11. package/dist/containers/iso-base-media/get-mfra-seeking-box.js +5 -1
  12. package/dist/containers/iso-base-media/get-moov-atom.js +6 -3
  13. package/dist/containers/iso-base-media/get-sample-position-bounds.js +3 -1
  14. package/dist/containers/iso-base-media/get-sample-positions-from-track.js +1 -1
  15. package/dist/containers/iso-base-media/get-seeking-byte-from-fragmented-mp4.d.ts +14 -0
  16. package/dist/containers/iso-base-media/get-seeking-byte-from-fragmented-mp4.js +89 -0
  17. package/dist/containers/iso-base-media/get-seeking-byte.d.ts +3 -3
  18. package/dist/containers/iso-base-media/get-seeking-byte.js +32 -96
  19. package/dist/containers/iso-base-media/get-video-codec-from-iso-track.d.ts +1 -1
  20. package/dist/containers/iso-base-media/mdat/calculate-jump-marks.d.ts +6 -0
  21. package/dist/containers/iso-base-media/mdat/calculate-jump-marks.js +131 -0
  22. package/dist/containers/iso-base-media/mdat/mdat.d.ts +2 -2
  23. package/dist/containers/iso-base-media/mdat/mdat.js +18 -2
  24. package/dist/containers/iso-base-media/mfra/find-best-segment-from-tfra.d.ts +3 -3
  25. package/dist/containers/iso-base-media/mfra/find-best-segment-from-tfra.js +2 -2
  26. package/dist/containers/iso-base-media/mfra/get-mfra-atom.d.ts +5 -1
  27. package/dist/containers/iso-base-media/mfra/get-mfra-atom.js +3 -1
  28. package/dist/containers/iso-base-media/mfra/get-mfro-atom.d.ts +5 -1
  29. package/dist/containers/iso-base-media/mfra/get-mfro-atom.js +3 -1
  30. package/dist/containers/iso-base-media/parse-boxes.js +5 -2
  31. package/dist/containers/iso-base-media/process-box.d.ts +16 -5
  32. package/dist/containers/iso-base-media/process-box.js +206 -118
  33. package/dist/containers/iso-base-media/sample-positions.d.ts +25 -0
  34. package/dist/containers/iso-base-media/sample-positions.js +37 -0
  35. package/dist/containers/iso-base-media/seeking-hints.d.ts +1 -1
  36. package/dist/containers/iso-base-media/stsd/samples.js +1 -0
  37. package/dist/containers/iso-base-media/stsd/stsc.d.ts +1 -6
  38. package/dist/containers/iso-base-media/stsd/stsc.js +2 -5
  39. package/dist/containers/iso-base-media/stsd/stss.d.ts +1 -1
  40. package/dist/containers/iso-base-media/stsd/stss.js +2 -2
  41. package/dist/containers/iso-base-media/turn-sample-positions-into-array.d.ts +19 -0
  42. package/dist/containers/iso-base-media/turn-sample-positions-into-array.js +73 -0
  43. package/dist/containers/m3u/after-manifest-fetch.d.ts +5 -1
  44. package/dist/containers/m3u/after-manifest-fetch.js +3 -1
  45. package/dist/containers/m3u/first-sample-in-m3u-chunk.d.ts +13 -0
  46. package/dist/containers/m3u/first-sample-in-m3u-chunk.js +31 -0
  47. package/dist/containers/m3u/get-seeking-byte.d.ts +13 -0
  48. package/dist/containers/m3u/get-seeking-byte.js +32 -0
  49. package/dist/containers/m3u/get-streams.d.ts +1 -0
  50. package/dist/containers/m3u/get-streams.js +1 -0
  51. package/dist/containers/m3u/iterate-over-segment-files.d.ts +5 -3
  52. package/dist/containers/m3u/iterate-over-segment-files.js +11 -1
  53. package/dist/containers/m3u/parse-m3u-media-directive.js +1 -0
  54. package/dist/containers/m3u/parse-m3u.js +8 -0
  55. package/dist/containers/m3u/process-m3u-chunk.d.ts +12 -0
  56. package/dist/containers/m3u/process-m3u-chunk.js +274 -0
  57. package/dist/containers/m3u/run-over-m3u.js +7 -80
  58. package/dist/containers/m3u/sample-sorter.d.ts +1 -0
  59. package/dist/containers/m3u/sample-sorter.js +4 -1
  60. package/dist/containers/m3u/seek/get-chunk-to-seek-to.d.ts +5 -0
  61. package/dist/containers/m3u/seek/get-chunk-to-seek-to.js +14 -0
  62. package/dist/containers/m3u/seeking-hints.d.ts +2 -0
  63. package/dist/containers/m3u/seeking-hints.js +9 -0
  64. package/dist/containers/m3u/select-stream.d.ts +2 -1
  65. package/dist/containers/m3u/select-stream.js +7 -2
  66. package/dist/containers/m3u/types.d.ts +1 -0
  67. package/dist/containers/mp3/get-duration.d.ts +5 -0
  68. package/dist/containers/riff/seek/fetch-idx1.d.ts +3 -1
  69. package/dist/containers/riff/seek/fetch-idx1.js +3 -1
  70. package/dist/containers/transport-stream/handle-aac-packet.d.ts +2 -2
  71. package/dist/containers/transport-stream/handle-avc-packet.d.ts +2 -2
  72. package/dist/containers/transport-stream/process-audio.d.ts +2 -2
  73. package/dist/containers/transport-stream/process-stream-buffers.d.ts +3 -3
  74. package/dist/containers/transport-stream/process-video.d.ts +2 -2
  75. package/dist/containers/wav/get-duration-from-wav.d.ts +0 -1
  76. package/dist/containers/webm/get-sample-from-block.d.ts +12 -2
  77. package/dist/containers/webm/get-sample-from-block.js +40 -9
  78. package/dist/containers/webm/parse-ebml.js +28 -10
  79. package/dist/containers/webm/seek/fetch-web-cues.d.ts +3 -1
  80. package/dist/containers/webm/seek/fetch-web-cues.js +3 -1
  81. package/dist/containers/webm/state-for-processing.d.ts +2 -2
  82. package/dist/controller/media-parser-controller.d.ts +1 -1
  83. package/dist/controller/media-parser-controller.js +6 -2
  84. package/dist/controller/seek-signal.d.ts +1 -5
  85. package/dist/download-and-parse-media.js +1 -1
  86. package/dist/esm/index.mjs +1400 -611
  87. package/dist/esm/node.mjs +23 -3
  88. package/dist/esm/server-worker.mjs +8 -1
  89. package/dist/esm/universal.mjs +168 -15
  90. package/dist/esm/web.mjs +145 -13
  91. package/dist/esm/worker-server-entry.mjs +1467 -635
  92. package/dist/esm/worker-web-entry.mjs +1439 -634
  93. package/dist/esm/worker.mjs +8 -1
  94. package/dist/get-audio-codec.js +3 -0
  95. package/dist/get-duration.js +2 -1
  96. package/dist/get-fps.js +2 -1
  97. package/dist/get-sample-positions-from-mp4.js +10 -5
  98. package/dist/get-sample-positions.js +4 -4
  99. package/dist/get-seeking-byte.d.ts +5 -3
  100. package/dist/get-seeking-byte.js +19 -10
  101. package/dist/get-seeking-hints.d.ts +3 -3
  102. package/dist/get-seeking-hints.js +18 -13
  103. package/dist/get-tracks.d.ts +9 -1
  104. package/dist/get-tracks.js +13 -6
  105. package/dist/index.d.ts +21 -5
  106. package/dist/init-video.js +3 -2
  107. package/dist/internal-parse-media.js +13 -4
  108. package/dist/iterator/buffer-iterator.js +5 -3
  109. package/dist/metadata/metadata-from-iso.js +2 -1
  110. package/dist/options.d.ts +6 -1
  111. package/dist/parse-loop.js +22 -6
  112. package/dist/parse-media-on-worker-entry.js +1 -0
  113. package/dist/parse-media.js +1 -1
  114. package/dist/parse-result.d.ts +2 -2
  115. package/dist/perform-seek.d.ts +3 -1
  116. package/dist/perform-seek.js +3 -1
  117. package/dist/readers/fetch/get-body-and-reader.js +17 -2
  118. package/dist/readers/from-fetch.d.ts +17 -1
  119. package/dist/readers/from-fetch.js +68 -13
  120. package/dist/readers/from-node.js +24 -2
  121. package/dist/readers/from-web-file.js +3 -0
  122. package/dist/readers/reader.d.ts +19 -2
  123. package/dist/readers/universal.js +9 -0
  124. package/dist/readers/web.js +6 -0
  125. package/dist/register-track.d.ts +3 -3
  126. package/dist/seek-backwards.d.ts +3 -1
  127. package/dist/seek-backwards.js +4 -1
  128. package/dist/seek-forwards.d.ts +3 -1
  129. package/dist/seek-forwards.js +3 -1
  130. package/dist/seeking-hints.d.ts +4 -1
  131. package/dist/set-seeking-hints.js +4 -0
  132. package/dist/skip.d.ts +5 -0
  133. package/dist/skip.js +6 -1
  134. package/dist/state/can-skip-tracks.d.ts +1 -0
  135. package/dist/state/can-skip-tracks.js +10 -6
  136. package/dist/state/iso-base-media/cached-sample-positions.d.ts +15 -1
  137. package/dist/state/iso-base-media/cached-sample-positions.js +9 -4
  138. package/dist/state/iso-base-media/iso-state.d.ts +5 -1
  139. package/dist/state/iso-base-media/iso-state.js +2 -1
  140. package/dist/state/iso-base-media/lazy-mfra-load.d.ts +3 -1
  141. package/dist/state/iso-base-media/lazy-mfra-load.js +2 -1
  142. package/dist/state/keyframes.js +1 -0
  143. package/dist/state/m3u-state.d.ts +15 -4
  144. package/dist/state/m3u-state.js +20 -0
  145. package/dist/state/matroska/lazy-cues-fetch.d.ts +3 -1
  146. package/dist/state/matroska/lazy-cues-fetch.js +2 -1
  147. package/dist/state/matroska/webm.d.ts +3 -1
  148. package/dist/state/matroska/webm.js +2 -1
  149. package/dist/state/mp3.d.ts +16 -5
  150. package/dist/state/mp3.js +7 -5
  151. package/dist/state/parser-state.d.ts +31 -15
  152. package/dist/state/parser-state.js +19 -5
  153. package/dist/state/riff/lazy-idx1-fetch.d.ts +5 -3
  154. package/dist/state/riff/lazy-idx1-fetch.js +2 -1
  155. package/dist/state/riff.d.ts +5 -3
  156. package/dist/state/riff.js +2 -1
  157. package/dist/state/sample-callbacks.d.ts +3 -2
  158. package/dist/state/sample-callbacks.js +3 -3
  159. package/dist/version.d.ts +1 -1
  160. package/dist/version.js +1 -1
  161. package/dist/work-on-seek-request.d.ts +6 -3
  162. package/dist/work-on-seek-request.js +13 -13
  163. package/dist/worker/forward-controller-to-worker.js +1 -1
  164. package/dist/worker/serialize-error.js +26 -3
  165. package/dist/worker/worker-types.d.ts +7 -1
  166. package/dist/worker-server.js +2 -2
  167. package/package.json +3 -3
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processBox = void 0;
4
4
  const log_1 = require("../../log");
5
5
  const register_track_1 = require("../../register-track");
6
+ const skip_1 = require("../../skip");
6
7
  const esds_1 = require("./esds/esds");
7
8
  const ftyp_1 = require("./ftyp");
8
9
  const get_children_1 = require("./get-children");
@@ -41,8 +42,11 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
41
42
  const boxSizeRaw = iterator.getFourByteNumber();
42
43
  if (boxSizeRaw === 0) {
43
44
  return {
44
- type: 'void-box',
45
- boxSize: 0,
45
+ type: 'box',
46
+ box: {
47
+ type: 'void-box',
48
+ boxSize: 0,
49
+ },
46
50
  };
47
51
  }
48
52
  // If `boxSize === 1`, the 8 bytes after the box type are the size of the box.
@@ -58,120 +62,177 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
58
62
  const headerLength = iterator.counter.getOffset() - startOff;
59
63
  if (boxType === 'mdat') {
60
64
  if (!onlyIfMdatAtomExpected) {
61
- return null;
65
+ return { type: 'nothing' };
62
66
  }
63
67
  const { mediaSectionState } = onlyIfMdatAtomExpected;
64
68
  mediaSectionState.addMediaSection({
65
69
  size: boxSize - headerLength,
66
70
  start: iterator.counter.getOffset(),
67
71
  });
68
- return null;
72
+ return { type: 'nothing' };
69
73
  }
70
74
  if (bytesRemaining < boxSize) {
71
75
  returnToCheckpoint();
72
- return null;
76
+ return {
77
+ type: 'fetch-more-data',
78
+ bytesNeeded: (0, skip_1.makeFetchMoreData)(boxSize - bytesRemaining),
79
+ };
73
80
  }
74
81
  if (boxType === 'ftyp') {
75
- return (0, ftyp_1.parseFtyp)({ iterator, size: boxSize, offset: fileOffset });
82
+ return {
83
+ type: 'box',
84
+ box: await (0, ftyp_1.parseFtyp)({ iterator, size: boxSize, offset: fileOffset }),
85
+ };
76
86
  }
77
87
  if (boxType === 'colr') {
78
- return (0, colr_1.parseColorParameterBox)({
79
- iterator,
80
- size: boxSize,
81
- });
88
+ return {
89
+ type: 'box',
90
+ box: await (0, colr_1.parseColorParameterBox)({
91
+ iterator,
92
+ size: boxSize,
93
+ }),
94
+ };
82
95
  }
83
96
  if (boxType === 'mvhd') {
84
- return (0, mvhd_1.parseMvhd)({ iterator, offset: fileOffset, size: boxSize });
97
+ return {
98
+ type: 'box',
99
+ box: await (0, mvhd_1.parseMvhd)({ iterator, offset: fileOffset, size: boxSize }),
100
+ };
85
101
  }
86
102
  if (boxType === 'tkhd') {
87
- return (0, tkhd_1.parseTkhd)({ iterator, offset: fileOffset, size: boxSize });
103
+ return {
104
+ type: 'box',
105
+ box: await (0, tkhd_1.parseTkhd)({ iterator, offset: fileOffset, size: boxSize }),
106
+ };
88
107
  }
89
108
  if (boxType === 'trun') {
90
- return (0, trun_1.parseTrun)({ iterator, offset: fileOffset, size: boxSize });
109
+ return {
110
+ type: 'box',
111
+ box: await (0, trun_1.parseTrun)({ iterator, offset: fileOffset, size: boxSize }),
112
+ };
91
113
  }
92
114
  if (boxType === 'tfdt') {
93
- return (0, tfdt_1.parseTfdt)({ iterator, size: boxSize, offset: fileOffset });
115
+ return {
116
+ type: 'box',
117
+ box: await (0, tfdt_1.parseTfdt)({ iterator, size: boxSize, offset: fileOffset }),
118
+ };
94
119
  }
95
120
  if (boxType === 'stsd') {
96
- return (0, stsd_1.parseStsd)({
97
- offset: fileOffset,
98
- size: boxSize,
99
- iterator,
100
- logLevel,
101
- contentLength,
102
- });
121
+ return {
122
+ type: 'box',
123
+ box: await (0, stsd_1.parseStsd)({
124
+ offset: fileOffset,
125
+ size: boxSize,
126
+ iterator,
127
+ logLevel,
128
+ contentLength,
129
+ }),
130
+ };
103
131
  }
104
132
  if (boxType === 'stsz') {
105
- return (0, stsz_1.parseStsz)({
106
- iterator,
107
- offset: fileOffset,
108
- size: boxSize,
109
- });
133
+ return {
134
+ type: 'box',
135
+ box: await (0, stsz_1.parseStsz)({
136
+ iterator,
137
+ offset: fileOffset,
138
+ size: boxSize,
139
+ }),
140
+ };
110
141
  }
111
142
  if (boxType === 'stco' || boxType === 'co64') {
112
- return (0, stco_1.parseStco)({
113
- iterator,
114
- offset: fileOffset,
115
- size: boxSize,
116
- mode64Bit: boxType === 'co64',
117
- });
143
+ return {
144
+ type: 'box',
145
+ box: await (0, stco_1.parseStco)({
146
+ iterator,
147
+ offset: fileOffset,
148
+ size: boxSize,
149
+ mode64Bit: boxType === 'co64',
150
+ }),
151
+ };
118
152
  }
119
153
  if (boxType === 'pasp') {
120
- return (0, pasp_1.parsePasp)({
121
- iterator,
122
- offset: fileOffset,
123
- size: boxSize,
124
- });
154
+ return {
155
+ type: 'box',
156
+ box: await (0, pasp_1.parsePasp)({
157
+ iterator,
158
+ offset: fileOffset,
159
+ size: boxSize,
160
+ }),
161
+ };
125
162
  }
126
163
  if (boxType === 'stss') {
127
- return (0, stss_1.parseStss)({
128
- iterator,
129
- offset: fileOffset,
130
- boxSize,
131
- });
164
+ return {
165
+ type: 'box',
166
+ box: await (0, stss_1.parseStss)({
167
+ iterator,
168
+ offset: fileOffset,
169
+ boxSize,
170
+ }),
171
+ };
132
172
  }
133
173
  if (boxType === 'ctts') {
134
- return (0, ctts_1.parseCtts)({
135
- iterator,
136
- offset: fileOffset,
137
- size: boxSize,
138
- });
174
+ return {
175
+ type: 'box',
176
+ box: await (0, ctts_1.parseCtts)({
177
+ iterator,
178
+ offset: fileOffset,
179
+ size: boxSize,
180
+ }),
181
+ };
139
182
  }
140
183
  if (boxType === 'stsc') {
141
- return (0, stsc_1.parseStsc)({
142
- iterator,
143
- offset: fileOffset,
144
- size: boxSize,
145
- });
184
+ return {
185
+ type: 'box',
186
+ box: await (0, stsc_1.parseStsc)({
187
+ iterator,
188
+ offset: fileOffset,
189
+ size: boxSize,
190
+ }),
191
+ };
146
192
  }
147
193
  if (boxType === 'mebx') {
148
- return (0, mebx_1.parseMebx)({
149
- offset: fileOffset,
150
- size: boxSize,
151
- iterator,
152
- logLevel,
153
- contentLength,
154
- });
194
+ return {
195
+ type: 'box',
196
+ box: await (0, mebx_1.parseMebx)({
197
+ offset: fileOffset,
198
+ size: boxSize,
199
+ iterator,
200
+ logLevel,
201
+ contentLength,
202
+ }),
203
+ };
155
204
  }
156
205
  if (boxType === 'hdlr') {
157
- return (0, hdlr_1.parseHdlr)({ iterator, size: boxSize, offset: fileOffset });
206
+ return {
207
+ type: 'box',
208
+ box: await (0, hdlr_1.parseHdlr)({ iterator, size: boxSize, offset: fileOffset }),
209
+ };
158
210
  }
159
211
  if (boxType === 'keys') {
160
- return (0, keys_1.parseKeys)({ iterator, size: boxSize, offset: fileOffset });
212
+ return {
213
+ type: 'box',
214
+ box: await (0, keys_1.parseKeys)({ iterator, size: boxSize, offset: fileOffset }),
215
+ };
161
216
  }
162
217
  if (boxType === 'ilst') {
163
- return (0, ilst_1.parseIlstBox)({
164
- iterator,
165
- offset: fileOffset,
166
- size: boxSize,
167
- });
218
+ return {
219
+ type: 'box',
220
+ box: await (0, ilst_1.parseIlstBox)({
221
+ iterator,
222
+ offset: fileOffset,
223
+ size: boxSize,
224
+ }),
225
+ };
168
226
  }
169
227
  if (boxType === 'tfra') {
170
- return (0, tfra_1.parseTfraBox)({
171
- iterator,
172
- offset: fileOffset,
173
- size: boxSize,
174
- });
228
+ return {
229
+ type: 'box',
230
+ box: await (0, tfra_1.parseTfraBox)({
231
+ iterator,
232
+ offset: fileOffset,
233
+ size: boxSize,
234
+ }),
235
+ };
175
236
  }
176
237
  if (boxType === 'moov') {
177
238
  if (!onlyIfMoovAtomExpected) {
@@ -180,14 +241,14 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
180
241
  const { tracks, isoState } = onlyIfMoovAtomExpected;
181
242
  if (tracks.hasAllTracks()) {
182
243
  iterator.discard(boxSize - 8);
183
- return null;
244
+ return { type: 'nothing' };
184
245
  }
185
246
  if (isoState &&
186
247
  isoState.moov.getMoovBoxAndPrecomputed() &&
187
248
  !((_a = isoState.moov.getMoovBoxAndPrecomputed()) === null || _a === void 0 ? void 0 : _a.precomputed)) {
188
249
  log_1.Log.verbose(logLevel, 'Moov box already parsed, skipping');
189
250
  iterator.discard(boxSize - 8);
190
- return null;
251
+ return { type: 'nothing' };
191
252
  }
192
253
  const box = await (0, moov_1.parseMoov)({
193
254
  offset: fileOffset,
@@ -198,7 +259,7 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
198
259
  contentLength,
199
260
  });
200
261
  tracks.setIsDone(logLevel);
201
- return box;
262
+ return { type: 'box', box };
202
263
  }
203
264
  if (boxType === 'trak') {
204
265
  if (!onlyIfMoovAtomExpected) {
@@ -233,54 +294,75 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
233
294
  onAudioTrack,
234
295
  });
235
296
  }
236
- return box;
297
+ return { type: 'box', box };
237
298
  }
238
299
  if (boxType === 'stts') {
239
- return (0, stts_1.parseStts)({
240
- data: iterator,
241
- size: boxSize,
242
- fileOffset,
243
- });
300
+ return {
301
+ type: 'box',
302
+ box: await (0, stts_1.parseStts)({
303
+ data: iterator,
304
+ size: boxSize,
305
+ fileOffset,
306
+ }),
307
+ };
244
308
  }
245
309
  if (boxType === 'avcC') {
246
- return (0, avcc_1.parseAvcc)({
247
- data: iterator,
248
- size: boxSize,
249
- });
310
+ return {
311
+ type: 'box',
312
+ box: await (0, avcc_1.parseAvcc)({
313
+ data: iterator,
314
+ size: boxSize,
315
+ }),
316
+ };
250
317
  }
251
318
  if (boxType === 'av1C') {
252
- return (0, av1c_1.parseAv1C)({
253
- data: iterator,
254
- size: boxSize,
255
- });
319
+ return {
320
+ type: 'box',
321
+ box: await (0, av1c_1.parseAv1C)({
322
+ data: iterator,
323
+ size: boxSize,
324
+ }),
325
+ };
256
326
  }
257
327
  if (boxType === 'hvcC') {
258
- return (0, hvcc_1.parseHvcc)({
259
- data: iterator,
260
- size: boxSize,
261
- offset: fileOffset,
262
- });
328
+ return {
329
+ type: 'box',
330
+ box: await (0, hvcc_1.parseHvcc)({
331
+ data: iterator,
332
+ size: boxSize,
333
+ offset: fileOffset,
334
+ }),
335
+ };
263
336
  }
264
337
  if (boxType === 'tfhd') {
265
- return (0, tfhd_1.getTfhd)({
266
- iterator,
267
- offset: fileOffset,
268
- size: boxSize,
269
- });
338
+ return {
339
+ type: 'box',
340
+ box: await (0, tfhd_1.getTfhd)({
341
+ iterator,
342
+ offset: fileOffset,
343
+ size: boxSize,
344
+ }),
345
+ };
270
346
  }
271
347
  if (boxType === 'mdhd') {
272
- return (0, mdhd_1.parseMdhd)({
273
- data: iterator,
274
- size: boxSize,
275
- fileOffset,
276
- });
348
+ return {
349
+ type: 'box',
350
+ box: await (0, mdhd_1.parseMdhd)({
351
+ data: iterator,
352
+ size: boxSize,
353
+ fileOffset,
354
+ }),
355
+ };
277
356
  }
278
357
  if (boxType === 'esds') {
279
- return (0, esds_1.parseEsds)({
280
- data: iterator,
281
- size: boxSize,
282
- fileOffset,
283
- });
358
+ return {
359
+ type: 'box',
360
+ box: await (0, esds_1.parseEsds)({
361
+ data: iterator,
362
+ size: boxSize,
363
+ fileOffset,
364
+ }),
365
+ };
284
366
  }
285
367
  if (boxType === 'moof') {
286
368
  (_b = onlyIfMoovAtomExpected === null || onlyIfMoovAtomExpected === void 0 ? void 0 : onlyIfMoovAtomExpected.isoState) === null || _b === void 0 ? void 0 : _b.mfra.triggerLoad();
@@ -304,20 +386,26 @@ const processBox = async ({ iterator, logLevel, onlyIfMoovAtomExpected, onlyIfMd
304
386
  contentLength,
305
387
  });
306
388
  return {
307
- type: 'regular-box',
308
- boxType,
309
- boxSize,
310
- children,
311
- offset: fileOffset,
389
+ type: 'box',
390
+ box: {
391
+ type: 'regular-box',
392
+ boxType,
393
+ boxSize,
394
+ children,
395
+ offset: fileOffset,
396
+ },
312
397
  };
313
398
  }
314
399
  iterator.discard(boxSize - 8);
315
400
  return {
316
- type: 'regular-box',
317
- boxType,
318
- boxSize,
319
- children: [],
320
- offset: fileOffset,
401
+ type: 'box',
402
+ box: {
403
+ type: 'regular-box',
404
+ boxType,
405
+ boxSize,
406
+ children: [],
407
+ offset: fileOffset,
408
+ },
321
409
  };
322
410
  };
323
411
  exports.processBox = processBox;
@@ -0,0 +1,25 @@
1
+ import type { SamplePosition } from '../../get-sample-positions';
2
+ import type { CttsBox } from './stsd/ctts';
3
+ import type { StcoBox } from './stsd/stco';
4
+ import type { StscBox } from './stsd/stsc';
5
+ import type { StssBox } from './stsd/stss';
6
+ import type { StszBox } from './stsd/stsz';
7
+ import type { SttsBox } from './stsd/stts';
8
+ export type GroupOfSamplePositions = {
9
+ type: 'array';
10
+ boxes: SamplePosition[];
11
+ } | {
12
+ type: 'map';
13
+ boxes: {
14
+ stszBox: StszBox;
15
+ stcoBox: StcoBox;
16
+ stscBox: StscBox;
17
+ sttsBox: SttsBox;
18
+ stssBox: StssBox | null;
19
+ cttsBox: CttsBox | null;
20
+ };
21
+ };
22
+ export declare const hasNoSamplePositions: (samplePositions: GroupOfSamplePositions) => boolean;
23
+ export declare const hasNoSamplePositionsGroup: (samplePositions: GroupOfSamplePositions[]) => boolean;
24
+ export declare const getKeyframesFromGroupOfSamplePositions: (samplePositions: GroupOfSamplePositions) => SamplePosition[];
25
+ export declare const groupGetKeyframesFromGroupOfSamplePositions: (samplePositions: GroupOfSamplePositions[]) => SamplePosition[];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupGetKeyframesFromGroupOfSamplePositions = exports.getKeyframesFromGroupOfSamplePositions = exports.hasNoSamplePositionsGroup = exports.hasNoSamplePositions = void 0;
4
+ const turn_sample_positions_into_array_1 = require("./turn-sample-positions-into-array");
5
+ const hasNoSamplePositions = (samplePositions) => {
6
+ if (samplePositions.type === 'array') {
7
+ return samplePositions.boxes.length === 0;
8
+ }
9
+ return samplePositions.boxes.stcoBox.entryCount === 0;
10
+ };
11
+ exports.hasNoSamplePositions = hasNoSamplePositions;
12
+ const hasNoSamplePositionsGroup = (samplePositions) => {
13
+ return samplePositions.every((s) => (0, exports.hasNoSamplePositions)(s));
14
+ };
15
+ exports.hasNoSamplePositionsGroup = hasNoSamplePositionsGroup;
16
+ const getKeyframesFromGroupOfSamplePositions = (samplePositions) => {
17
+ if (samplePositions.type === 'array') {
18
+ return samplePositions.boxes.filter((s) => s.isKeyframe);
19
+ }
20
+ if (!samplePositions.boxes.stssBox) {
21
+ return (0, turn_sample_positions_into_array_1.turnSamplePositionsIntoArraySlow)({
22
+ ...samplePositions.boxes,
23
+ onlyKeyframes: true,
24
+ });
25
+ }
26
+ return (0, turn_sample_positions_into_array_1.turnSamplePositionsIntoArraySlow)({
27
+ ...samplePositions.boxes,
28
+ onlyKeyframes: false,
29
+ });
30
+ };
31
+ exports.getKeyframesFromGroupOfSamplePositions = getKeyframesFromGroupOfSamplePositions;
32
+ const groupGetKeyframesFromGroupOfSamplePositions = (samplePositions) => {
33
+ return samplePositions
34
+ .map((s) => (0, exports.getKeyframesFromGroupOfSamplePositions)(s))
35
+ .flat();
36
+ };
37
+ exports.groupGetKeyframesFromGroupOfSamplePositions = groupGetKeyframesFromGroupOfSamplePositions;
@@ -10,7 +10,7 @@ export declare const getSeekingHintsFromMp4: ({ structureState, isoState, mp4Hea
10
10
  mp4HeaderSegment: IsoBaseMediaStructure | null;
11
11
  mediaSectionState: MediaSectionState;
12
12
  }) => IsoBaseMediaSeekingHints | null;
13
- export declare const setSeekingHintsForMp4: ({ hints, state, }: {
13
+ export declare const setSeekingHintsForMp4: ({}: {
14
14
  hints: IsoBaseMediaSeekingHints;
15
15
  state: ParserState;
16
16
  }) => void;
@@ -62,6 +62,7 @@ const audioTags = [
62
62
  '.mp3',
63
63
  'mp4a',
64
64
  'ac-3',
65
+ 'Opus',
65
66
  ];
66
67
  const processIsoFormatBox = async ({ iterator, logLevel, contentLength, }) => {
67
68
  const fileOffset = iterator.counter.getOffset();
@@ -1,19 +1,14 @@
1
1
  import type { BufferIterator } from '../../../iterator/buffer-iterator';
2
2
  import type { BaseBox } from '../base-type';
3
- type StscEntry = {
4
- firstChunk: number;
5
- samplesPerChunk: number;
6
- };
7
3
  export interface StscBox extends BaseBox {
8
4
  type: 'stsc-box';
9
5
  version: number;
10
6
  flags: number[];
11
7
  entryCount: number;
12
- entries: StscEntry[];
8
+ entries: Map<number, number>;
13
9
  }
14
10
  export declare const parseStsc: ({ iterator, offset, size, }: {
15
11
  iterator: BufferIterator;
16
12
  offset: number;
17
13
  size: number;
18
14
  }) => StscBox;
19
- export {};
@@ -8,7 +8,7 @@ const parseStsc = ({ iterator, offset, size, }) => {
8
8
  }
9
9
  const flags = iterator.getSlice(3);
10
10
  const entryCount = iterator.getUint32();
11
- const entries = [];
11
+ const entries = new Map();
12
12
  for (let i = 0; i < entryCount; i++) {
13
13
  const firstChunk = iterator.getUint32();
14
14
  const samplesPerChunk = iterator.getUint32();
@@ -16,10 +16,7 @@ const parseStsc = ({ iterator, offset, size, }) => {
16
16
  if (sampleDescriptionIndex !== 1) {
17
17
  throw new Error(`Expected sampleDescriptionIndex to be 1, but got ${sampleDescriptionIndex}`);
18
18
  }
19
- entries.push({
20
- firstChunk,
21
- samplesPerChunk,
22
- });
19
+ entries.set(firstChunk, samplesPerChunk);
23
20
  }
24
21
  return {
25
22
  type: 'stsc-box',
@@ -4,7 +4,7 @@ export interface StssBox extends BaseBox {
4
4
  type: 'stss-box';
5
5
  version: number;
6
6
  flags: number[];
7
- sampleNumber: number[];
7
+ sampleNumber: Set<number>;
8
8
  }
9
9
  export declare const parseStss: ({ iterator, offset, boxSize, }: {
10
10
  iterator: BufferIterator;
@@ -8,9 +8,9 @@ const parseStss = ({ iterator, offset, boxSize, }) => {
8
8
  }
9
9
  const flags = iterator.getSlice(3);
10
10
  const sampleCount = iterator.getUint32();
11
- const sampleNumber = [];
11
+ const sampleNumber = new Set();
12
12
  for (let i = 0; i < sampleCount; i++) {
13
- sampleNumber.push(iterator.getUint32());
13
+ sampleNumber.add(iterator.getUint32());
14
14
  }
15
15
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - offset);
16
16
  if (bytesRemainingInBox > 0) {
@@ -0,0 +1,19 @@
1
+ import type { SamplePosition } from '../../get-sample-positions';
2
+ import type { GroupOfSamplePositions } from './sample-positions';
3
+ import type { CttsBox } from './stsd/ctts';
4
+ import type { StcoBox } from './stsd/stco';
5
+ import type { StscBox } from './stsd/stsc';
6
+ import type { StssBox } from './stsd/stss';
7
+ import type { StszBox } from './stsd/stsz';
8
+ import type { SttsBox } from './stsd/stts';
9
+ export declare const turnSamplePositionsIntoArraySlow: ({ stcoBox, stszBox, stscBox, stssBox, sttsBox, cttsBox, onlyKeyframes, }: {
10
+ stcoBox: StcoBox;
11
+ stszBox: StszBox;
12
+ stscBox: StscBox;
13
+ stssBox: StssBox | null;
14
+ sttsBox: SttsBox;
15
+ cttsBox: CttsBox | null;
16
+ onlyKeyframes: boolean;
17
+ }) => SamplePosition[];
18
+ export declare const turnIntoOld: (samplePositions: GroupOfSamplePositions) => SamplePosition[];
19
+ export declare const turnGroupIntoOld: (samplePositions: GroupOfSamplePositions[]) => SamplePosition[];