@remotion/media-parser 4.0.209 → 4.0.211

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 (290) hide show
  1. package/buffer.js +2 -0
  2. package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +1 -1
  3. package/dist/boxes/iso-base-media/make-track.js +14 -2
  4. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +13 -4
  5. package/dist/boxes/iso-base-media/mdat/mdat.js +20 -5
  6. package/dist/boxes/iso-base-media/moov/moov.d.ts +2 -1
  7. package/dist/boxes/iso-base-media/moov/moov.js +2 -1
  8. package/dist/boxes/iso-base-media/process-box.d.ts +6 -3
  9. package/dist/boxes/iso-base-media/process-box.js +66 -12
  10. package/dist/boxes/iso-base-media/stsd/avcc.d.ts +1 -1
  11. package/dist/boxes/iso-base-media/stsd/avcc.js +2 -2
  12. package/dist/boxes/iso-base-media/stsd/ctts.js +2 -5
  13. package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +1 -1
  14. package/dist/boxes/iso-base-media/stsd/hvcc.js +2 -2
  15. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +2 -1
  16. package/dist/boxes/iso-base-media/stsd/mebx.js +2 -1
  17. package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -2
  18. package/dist/boxes/iso-base-media/stsd/samples.js +69 -11
  19. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +2 -1
  20. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -1
  21. package/dist/boxes/iso-base-media/trak/trak.d.ts +2 -1
  22. package/dist/boxes/iso-base-media/trak/trak.js +2 -1
  23. package/dist/boxes/iso-base-media/traversal.d.ts +39 -0
  24. package/dist/boxes/iso-base-media/traversal.js +201 -0
  25. package/dist/boxes/webm/color.d.ts +4 -0
  26. package/dist/boxes/webm/color.js +127 -0
  27. package/dist/boxes/webm/description.js +1 -1
  28. package/dist/boxes/webm/ebml.d.ts +1 -1
  29. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  30. package/dist/boxes/webm/get-sample-from-block.js +1 -1
  31. package/dist/boxes/webm/make-track.d.ts +9 -0
  32. package/dist/boxes/webm/make-track.js +260 -0
  33. package/dist/boxes/webm/parse-ebml.js +2 -2
  34. package/dist/boxes/webm/segments/all-segments.d.ts +36 -3
  35. package/dist/boxes/webm/segments/all-segments.js +34 -6
  36. package/dist/boxes/webm/segments/parse-children.js +6 -0
  37. package/dist/boxes/webm/traversal.d.ts +26 -1
  38. package/dist/boxes/webm/traversal.js +214 -1
  39. package/dist/buffer-iterator.d.ts +4 -1
  40. package/dist/buffer-iterator.js +31 -5
  41. package/dist/create/cluster-segment.js +0 -2
  42. package/dist/create/cluster.d.ts +16 -2
  43. package/dist/create/cluster.js +17 -10
  44. package/dist/create/create-media.d.ts +4 -2
  45. package/dist/create/create-media.js +101 -22
  46. package/dist/create/make-duration-with-padding.d.ts +1 -1
  47. package/dist/create/make-duration-with-padding.js +3 -3
  48. package/dist/create/matroska-cues.d.ts +6 -0
  49. package/dist/create/matroska-cues.js +49 -0
  50. package/dist/create/matroska-info.js +1 -1
  51. package/dist/create/matroska-seek.d.ts +6 -0
  52. package/dist/create/matroska-seek.js +32 -0
  53. package/dist/create/matroska-segment.d.ts +1 -0
  54. package/dist/create/matroska-segment.js +3 -2
  55. package/dist/create/matroska-trackentry.d.ts +9 -14
  56. package/dist/create/matroska-trackentry.js +79 -102
  57. package/dist/emit-available-info.d.ts +12 -0
  58. package/dist/emit-available-info.js +133 -0
  59. package/dist/esm/buffer.mjs +57 -0
  60. package/dist/esm/from-fetch.mjs +107 -0
  61. package/dist/esm/from-node.mjs +49 -0
  62. package/dist/esm/from-web-file.mjs +49 -0
  63. package/dist/esm/index.mjs +6822 -0
  64. package/dist/esm/web-fs.mjs +67 -0
  65. package/dist/get-audio-codec.d.ts +5 -5
  66. package/dist/get-audio-codec.js +44 -57
  67. package/dist/get-container.d.ts +4 -0
  68. package/dist/get-container.js +26 -0
  69. package/dist/get-duration.js +1 -1
  70. package/dist/get-fps.js +1 -1
  71. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  72. package/dist/get-sample-aspect-ratio.js +19 -19
  73. package/dist/get-tracks.d.ts +13 -0
  74. package/dist/get-tracks.js +8 -8
  75. package/dist/get-video-codec.d.ts +5 -2
  76. package/dist/get-video-codec.js +111 -21
  77. package/dist/has-all-info.d.ts +2 -2
  78. package/dist/has-all-info.js +23 -9
  79. package/dist/index.d.ts +4 -1
  80. package/dist/options.d.ts +97 -30
  81. package/dist/parse-media.js +59 -69
  82. package/dist/parse-video.d.ts +2 -1
  83. package/dist/parse-video.js +3 -1
  84. package/dist/parser-context.d.ts +1 -0
  85. package/dist/parser-state.js +1 -2
  86. package/dist/readers/from-fetch.d.ts +12 -0
  87. package/dist/readers/from-fetch.js +83 -17
  88. package/dist/readers/from-node.js +14 -3
  89. package/dist/readers/from-web-file.js +15 -2
  90. package/dist/readers/reader.d.ts +7 -1
  91. package/dist/samples-from-moof.js +1 -1
  92. package/dist/truthy.d.ts +3 -0
  93. package/dist/truthy.js +7 -0
  94. package/dist/writers/buffer.d.ts +2 -0
  95. package/dist/writers/buffer.js +58 -0
  96. package/dist/writers/web-fs.d.ts +1 -0
  97. package/dist/writers/web-fs.js +42 -18
  98. package/dist/writers/writer.d.ts +4 -2
  99. package/fetch.js +2 -0
  100. package/node.js +2 -0
  101. package/package.json +43 -8
  102. package/web-file.js +2 -0
  103. package/web-fs.js +2 -0
  104. package/.eslintrc +0 -8
  105. package/dist/av1-codec-string.d.ts +0 -3
  106. package/dist/av1-codec-string.js +0 -91
  107. package/dist/boxes/iso-base-media/ftype.d.ts +0 -9
  108. package/dist/boxes/iso-base-media/ftype.js +0 -31
  109. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.d.ts +0 -20
  110. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.js +0 -73
  111. package/dist/boxes/iso-base-media/stts/stts.d.ts +0 -15
  112. package/dist/boxes/iso-base-media/stts/stts.js +0 -35
  113. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.d.ts +0 -14
  114. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.js +0 -67
  115. package/dist/boxes/webm/bitstream/av1/bitstream-frame.d.ts +0 -11
  116. package/dist/boxes/webm/bitstream/av1/bitstream-frame.js +0 -14
  117. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.d.ts +0 -6
  118. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.js +0 -9
  119. package/dist/boxes/webm/bitstream/av1/color-config.d.ts +0 -16
  120. package/dist/boxes/webm/bitstream/av1/color-config.js +0 -103
  121. package/dist/boxes/webm/bitstream/av1/color-primaries.d.ts +0 -14
  122. package/dist/boxes/webm/bitstream/av1/color-primaries.js +0 -17
  123. package/dist/boxes/webm/bitstream/av1/decoder-model-info.d.ts +0 -9
  124. package/dist/boxes/webm/bitstream/av1/decoder-model-info.js +0 -17
  125. package/dist/boxes/webm/bitstream/av1/frame.d.ts +0 -0
  126. package/dist/boxes/webm/bitstream/av1/frame.js +0 -1
  127. package/dist/boxes/webm/bitstream/av1/header-segment.d.ts +0 -51
  128. package/dist/boxes/webm/bitstream/av1/header-segment.js +0 -183
  129. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.d.ts +0 -17
  130. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.js +0 -20
  131. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.d.ts +0 -10
  132. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.js +0 -15
  133. package/dist/boxes/webm/bitstream/av1/temporal-point-info.d.ts +0 -5
  134. package/dist/boxes/webm/bitstream/av1/temporal-point-info.js +0 -8
  135. package/dist/boxes/webm/bitstream/av1/timing-info.d.ts +0 -8
  136. package/dist/boxes/webm/bitstream/av1/timing-info.js +0 -20
  137. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.d.ts +0 -21
  138. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.js +0 -24
  139. package/dist/boxes/webm/bitstream/av1/uvlc.d.ts +0 -2
  140. package/dist/boxes/webm/bitstream/av1/uvlc.js +0 -20
  141. package/dist/boxes/webm/bitstream/av1.d.ts +0 -20
  142. package/dist/boxes/webm/bitstream/av1.js +0 -118
  143. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.d.ts +0 -0
  144. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.js +0 -1
  145. package/dist/boxes/webm/segments/duration.d.ts +0 -6
  146. package/dist/boxes/webm/segments/duration.js +0 -19
  147. package/dist/boxes/webm/segments/info.d.ts +0 -9
  148. package/dist/boxes/webm/segments/info.js +0 -22
  149. package/dist/boxes/webm/segments/main.d.ts +0 -5
  150. package/dist/boxes/webm/segments/main.js +0 -2
  151. package/dist/boxes/webm/segments/muxing.d.ts +0 -6
  152. package/dist/boxes/webm/segments/muxing.js +0 -11
  153. package/dist/boxes/webm/segments/seek-head.d.ts +0 -9
  154. package/dist/boxes/webm/segments/seek-head.js +0 -22
  155. package/dist/boxes/webm/segments/seek-position.d.ts +0 -6
  156. package/dist/boxes/webm/segments/seek-position.js +0 -11
  157. package/dist/boxes/webm/segments/seek.d.ts +0 -13
  158. package/dist/boxes/webm/segments/seek.js +0 -35
  159. package/dist/boxes/webm/segments/timestamp-scale.d.ts +0 -6
  160. package/dist/boxes/webm/segments/timestamp-scale.js +0 -11
  161. package/dist/boxes/webm/segments/tracks.d.ts +0 -8
  162. package/dist/boxes/webm/segments/tracks.js +0 -21
  163. package/dist/boxes/webm/segments/unknown.d.ts +0 -6
  164. package/dist/boxes/webm/segments/unknown.js +0 -11
  165. package/dist/boxes/webm/segments/void.d.ts +0 -6
  166. package/dist/boxes/webm/segments/void.js +0 -11
  167. package/dist/boxes/webm/segments/writing.d.ts +0 -6
  168. package/dist/boxes/webm/segments/writing.js +0 -11
  169. package/dist/boxes/webm/tracks.d.ts +0 -8
  170. package/dist/boxes/webm/tracks.js +0 -21
  171. package/dist/combine-uint8array.d.ts +0 -1
  172. package/dist/combine-uint8array.js +0 -13
  173. package/dist/from-web.d.ts +0 -2
  174. package/dist/from-web.js +0 -45
  175. package/dist/get-video-metadata.d.ts +0 -2
  176. package/dist/get-video-metadata.js +0 -44
  177. package/dist/read-and-increment-offset.d.ts +0 -28
  178. package/dist/read-and-increment-offset.js +0 -177
  179. package/dist/understand-vorbis.d.ts +0 -1
  180. package/dist/understand-vorbis.js +0 -12
  181. package/input.webm +0 -0
  182. package/src/add-new-matroska-tracks.ts +0 -23
  183. package/src/boxes/iso-base-media/base-type.ts +0 -4
  184. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  185. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  186. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  187. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  188. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  189. package/src/boxes/iso-base-media/make-track.ts +0 -116
  190. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  191. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  192. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  193. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  194. package/src/boxes/iso-base-media/process-box.ts +0 -748
  195. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  196. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  197. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  198. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  199. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  200. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  201. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  202. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  203. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  204. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  205. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  206. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  207. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  208. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  209. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  210. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  211. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  212. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  213. package/src/boxes/iso-base-media/to-date.ts +0 -9
  214. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  215. package/src/boxes/iso-base-media/trun.ts +0 -74
  216. package/src/boxes/iso-base-media/void-box.ts +0 -4
  217. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  218. package/src/boxes/webm/av1-codec-private.ts +0 -113
  219. package/src/boxes/webm/description.ts +0 -104
  220. package/src/boxes/webm/ebml.ts +0 -98
  221. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  222. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  223. package/src/boxes/webm/get-track.ts +0 -257
  224. package/src/boxes/webm/make-header.ts +0 -253
  225. package/src/boxes/webm/parse-ebml.ts +0 -259
  226. package/src/boxes/webm/parse-webm-header.ts +0 -18
  227. package/src/boxes/webm/segments/all-segments.ts +0 -888
  228. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  229. package/src/boxes/webm/segments/parse-children.ts +0 -144
  230. package/src/boxes/webm/segments/track-entry.ts +0 -38
  231. package/src/boxes/webm/segments.ts +0 -147
  232. package/src/boxes/webm/traversal.ts +0 -45
  233. package/src/buffer-iterator.ts +0 -555
  234. package/src/create/cluster-segment.ts +0 -62
  235. package/src/create/cluster.ts +0 -64
  236. package/src/create/create-media.ts +0 -136
  237. package/src/create/make-duration-with-padding.ts +0 -15
  238. package/src/create/matroska-header.ts +0 -63
  239. package/src/create/matroska-info.ts +0 -30
  240. package/src/create/matroska-segment.ts +0 -10
  241. package/src/create/matroska-trackentry.ts +0 -325
  242. package/src/create/timescale.ts +0 -1
  243. package/src/get-audio-codec.ts +0 -270
  244. package/src/get-dimensions.ts +0 -47
  245. package/src/get-duration.ts +0 -103
  246. package/src/get-fps.ts +0 -113
  247. package/src/get-sample-aspect-ratio.ts +0 -204
  248. package/src/get-sample-positions.ts +0 -93
  249. package/src/get-tracks.ts +0 -147
  250. package/src/get-video-codec.ts +0 -117
  251. package/src/has-all-info.ts +0 -81
  252. package/src/index.ts +0 -18
  253. package/src/make-hvc1-codec-strings.ts +0 -55
  254. package/src/options.ts +0 -118
  255. package/src/parse-media.ts +0 -183
  256. package/src/parse-result.ts +0 -79
  257. package/src/parse-video.ts +0 -83
  258. package/src/parser-context.ts +0 -10
  259. package/src/parser-state.ts +0 -178
  260. package/src/readers/from-fetch.ts +0 -90
  261. package/src/readers/from-node.ts +0 -51
  262. package/src/readers/from-web-file.ts +0 -49
  263. package/src/readers/reader.ts +0 -15
  264. package/src/samples-from-moof.ts +0 -102
  265. package/src/test/aspect-ratio.test.ts +0 -42
  266. package/src/test/av1.test.ts +0 -108
  267. package/src/test/create-matroska.test.ts +0 -287
  268. package/src/test/duration.test.ts +0 -18
  269. package/src/test/keys.test.ts +0 -47
  270. package/src/test/matroska.test.ts +0 -463
  271. package/src/test/mvhd.test.ts +0 -94
  272. package/src/test/parse-esds.test.ts +0 -98
  273. package/src/test/parse-stco.test.ts +0 -61
  274. package/src/test/parse-stsc.test.ts +0 -104
  275. package/src/test/parse-stsz.test.ts +0 -57
  276. package/src/test/parse-stts.test.ts +0 -38
  277. package/src/test/parse-video.test.ts +0 -101
  278. package/src/test/parse-webm.test.ts +0 -17
  279. package/src/test/samples-from-moof.test.ts +0 -2496
  280. package/src/test/stream-local.test.ts +0 -743
  281. package/src/test/stream-remote.test.ts +0 -59
  282. package/src/test/stream-samples.test.ts +0 -181
  283. package/src/test/stsd.test.ts +0 -265
  284. package/src/test/tkhd.test.ts +0 -87
  285. package/src/traversal.ts +0 -528
  286. package/src/webcodec-sample-types.ts +0 -29
  287. package/src/writers/web-fs.ts +0 -50
  288. package/src/writers/writer.ts +0 -12
  289. package/tsconfig.json +0 -14
  290. package/tsconfig.tsbuildinfo +0 -1
@@ -61,7 +61,7 @@ const audioTags = [
61
61
  'mp4a',
62
62
  'ac-3',
63
63
  ];
64
- const processSample = async ({ iterator, options, }) => {
64
+ const processSample = async ({ iterator, options, signal, }) => {
65
65
  const fileOffset = iterator.counter.getOffset();
66
66
  const bytesRemaining = iterator.bytesRemaining();
67
67
  const boxSize = iterator.getUint32();
@@ -106,6 +106,7 @@ const processSample = async ({ iterator, options, }) => {
106
106
  options,
107
107
  continueMdat: false,
108
108
  littleEndian: false,
109
+ signal,
109
110
  });
110
111
  if (children.status === 'incomplete') {
111
112
  throw new Error('Incomplete boxes are not allowed');
@@ -152,6 +153,7 @@ const processSample = async ({ iterator, options, }) => {
152
153
  options,
153
154
  continueMdat: false,
154
155
  littleEndian: false,
156
+ signal,
155
157
  });
156
158
  if (children.status === 'incomplete') {
157
159
  throw new Error('Incomplete boxes are not allowed');
@@ -179,6 +181,57 @@ const processSample = async ({ iterator, options, }) => {
179
181
  },
180
182
  };
181
183
  }
184
+ if (version === 2) {
185
+ const numberOfChannels = iterator.getUint16();
186
+ const sampleSize = iterator.getUint16();
187
+ const compressionId = iterator.getUint16();
188
+ const packetSize = iterator.getUint16();
189
+ iterator.getFixedPointUnsigned1616Number(); // LQ sample rate;
190
+ iterator.getUint32(); // ignore
191
+ const higherSampleRate = iterator.getFloat64();
192
+ iterator.getUint32(); // ignore;
193
+ iterator.getUint32(); // ignore, always 0x7F000000?
194
+ const bitsPerCodedSample = iterator.getUint32();
195
+ iterator.getUint32(); // ignore;
196
+ const bytesPerFrame = iterator.getUint32();
197
+ const samplesPerPacket = iterator.getUint32();
198
+ const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
199
+ const children = await (0, process_box_1.parseBoxes)({
200
+ iterator,
201
+ allowIncompleteBoxes: false,
202
+ maxBytes: bytesRemainingInBox,
203
+ initialBoxes: [],
204
+ options,
205
+ continueMdat: false,
206
+ littleEndian: false,
207
+ signal,
208
+ });
209
+ if (children.status === 'incomplete') {
210
+ throw new Error('Incomplete boxes are not allowed');
211
+ }
212
+ return {
213
+ sample: {
214
+ format: boxFormat,
215
+ offset: fileOffset,
216
+ dataReferenceIndex,
217
+ version,
218
+ revisionLevel,
219
+ vendor: [...Array.from(new Uint8Array(vendor))],
220
+ size: boxSize,
221
+ type: 'audio',
222
+ numberOfChannels,
223
+ sampleSize,
224
+ compressionId,
225
+ packetSize,
226
+ sampleRate: higherSampleRate,
227
+ samplesPerPacket,
228
+ bytesPerPacket: null,
229
+ bytesPerFrame,
230
+ bitsPerSample: bitsPerCodedSample,
231
+ children: children.segments,
232
+ },
233
+ };
234
+ }
182
235
  throw new Error(`Unsupported version ${version}`);
183
236
  }
184
237
  if (isVideo) {
@@ -197,15 +250,19 @@ const processSample = async ({ iterator, options, }) => {
197
250
  const depth = iterator.getUint16();
198
251
  const colorTableId = iterator.getInt16();
199
252
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
200
- const children = await (0, process_box_1.parseBoxes)({
201
- iterator,
202
- allowIncompleteBoxes: false,
203
- maxBytes: bytesRemainingInBox,
204
- initialBoxes: [],
205
- options,
206
- continueMdat: false,
207
- littleEndian: false,
208
- });
253
+ const children = bytesRemainingInBox > 8
254
+ ? await (0, process_box_1.parseBoxes)({
255
+ iterator,
256
+ allowIncompleteBoxes: false,
257
+ maxBytes: bytesRemainingInBox,
258
+ initialBoxes: [],
259
+ options,
260
+ continueMdat: false,
261
+ littleEndian: false,
262
+ signal,
263
+ })
264
+ : (iterator.discard(bytesRemainingInBox),
265
+ { status: 'done', segments: [] });
209
266
  if (children.status === 'incomplete') {
210
267
  throw new Error('Incomplete boxes are not allowed');
211
268
  }
@@ -237,7 +294,7 @@ const processSample = async ({ iterator, options, }) => {
237
294
  throw new Error(`Unknown sample format ${boxFormat}`);
238
295
  };
239
296
  exports.processSample = processSample;
240
- const parseSamples = async ({ iterator, maxBytes, options, }) => {
297
+ const parseSamples = async ({ iterator, maxBytes, options, signal, }) => {
241
298
  const samples = [];
242
299
  const initialOffset = iterator.counter.getOffset();
243
300
  while (iterator.bytesRemaining() > 0 &&
@@ -245,6 +302,7 @@ const parseSamples = async ({ iterator, maxBytes, options, }) => {
245
302
  const { sample } = await (0, exports.processSample)({
246
303
  iterator,
247
304
  options,
305
+ signal,
248
306
  });
249
307
  if (sample) {
250
308
  samples.push(sample);
@@ -7,9 +7,10 @@ export interface StsdBox extends BaseBox {
7
7
  numberOfEntries: number;
8
8
  samples: Sample[];
9
9
  }
10
- export declare const parseStsd: ({ iterator, offset, size, options, }: {
10
+ export declare const parseStsd: ({ iterator, offset, size, options, signal, }: {
11
11
  iterator: BufferIterator;
12
12
  offset: number;
13
13
  size: number;
14
14
  options: ParserContext;
15
+ signal: AbortSignal | null;
15
16
  }) => 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, options, }) => {
5
+ const parseStsd = async ({ iterator, offset, size, options, signal, }) => {
6
6
  const version = iterator.getUint8();
7
7
  if (version !== 0) {
8
8
  throw new Error(`Unsupported STSD version ${version}`);
@@ -15,6 +15,7 @@ const parseStsd = async ({ iterator, offset, size, options, }) => {
15
15
  iterator,
16
16
  maxBytes: bytesRemainingInBox,
17
17
  options,
18
+ signal,
18
19
  });
19
20
  if (boxes.length !== numberOfEntries) {
20
21
  throw new Error(`Expected ${numberOfEntries} sample descriptions, got ${boxes.length}`);
@@ -6,9 +6,10 @@ export interface TrakBox extends BaseBox {
6
6
  type: 'trak-box';
7
7
  children: AnySegment[];
8
8
  }
9
- export declare const parseTrak: ({ data, size, offsetAtStart, options, }: {
9
+ export declare const parseTrak: ({ data, size, offsetAtStart, options, signal, }: {
10
10
  data: BufferIterator;
11
11
  size: number;
12
12
  offsetAtStart: number;
13
13
  options: ParserContext;
14
+ signal: AbortSignal | null;
14
15
  }) => Promise<TrakBox>;
@@ -2,7 +2,7 @@
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, }) => {
5
+ const parseTrak = async ({ data, size, offsetAtStart, options, signal, }) => {
6
6
  const children = await (0, process_box_1.parseBoxes)({
7
7
  iterator: data,
8
8
  maxBytes: size - (data.counter.getOffset() - offsetAtStart),
@@ -11,6 +11,7 @@ const parseTrak = async ({ data, size, offsetAtStart, options, }) => {
11
11
  options,
12
12
  continueMdat: false,
13
13
  littleEndian: false,
14
+ signal,
14
15
  });
15
16
  if (children.status === 'incomplete') {
16
17
  throw new Error('Incomplete boxes are not allowed');
@@ -0,0 +1,39 @@
1
+ import type { AnySegment, IsoBaseMediaBox, RegularBox } from '../../parse-result';
2
+ import type { FtypBox } from './ftyp';
3
+ import type { MdatBox } from './mdat/mdat';
4
+ import type { MdhdBox } from './mdhd';
5
+ import type { MoovBox } from './moov/moov';
6
+ import type { MvhdBox } from './mvhd';
7
+ import type { CttsBox } from './stsd/ctts';
8
+ import type { StcoBox } from './stsd/stco';
9
+ import type { StscBox } from './stsd/stsc';
10
+ import type { StsdBox } from './stsd/stsd';
11
+ import type { StssBox } from './stsd/stss';
12
+ import type { StszBox } from './stsd/stsz';
13
+ import type { SttsBox } from './stsd/stts';
14
+ import type { TfdtBox } from './tfdt';
15
+ import type { TfhdBox } from './tfhd';
16
+ import type { TkhdBox } from './tkhd';
17
+ import type { TrakBox } from './trak/trak';
18
+ import type { TrunBox } from './trun';
19
+ export declare const getFtypBox: (segments: AnySegment[]) => FtypBox | null;
20
+ export declare const getMoovBox: (segments: AnySegment[]) => MoovBox | null;
21
+ export declare const getMoofBox: (main: AnySegment[]) => IsoBaseMediaBox | null;
22
+ export declare const getMvhdBox: (moovBox: MoovBox) => MvhdBox | null;
23
+ export declare const getTraks: (moovBox: MoovBox) => TrakBox[];
24
+ export declare const getTkhdBox: (trakBox: TrakBox) => TkhdBox | null;
25
+ export declare const getMdiaBox: (trakBox: TrakBox) => RegularBox | null;
26
+ export declare const getMdhdBox: (trakBox: TrakBox) => MdhdBox | null;
27
+ export declare const getStblBox: (trakBox: TrakBox) => RegularBox | null;
28
+ export declare const getStsdBox: (trakBox: TrakBox) => StsdBox | null;
29
+ export declare const getVideoDescriptors: (trakBox: TrakBox) => Uint8Array | null;
30
+ export declare const getStcoBox: (trakBox: TrakBox) => StcoBox | null;
31
+ export declare const getSttsBox: (trakBox: TrakBox) => SttsBox | null;
32
+ export declare const getCttsBox: (trakBox: TrakBox) => CttsBox | null;
33
+ export declare const getStszBox: (trakBox: TrakBox) => StszBox | null;
34
+ export declare const getStscBox: (trakBox: TrakBox) => StscBox | null;
35
+ export declare const getStssBox: (trakBox: TrakBox) => StssBox | null;
36
+ export declare const getTfdtBox: (segment: IsoBaseMediaBox) => TfdtBox | null;
37
+ export declare const getTfhdBox: (segment: IsoBaseMediaBox) => TfhdBox | null;
38
+ export declare const getTrunBoxes: (segment: IsoBaseMediaBox) => TrunBox[];
39
+ export declare const getMdatBox: (anySegment: AnySegment[]) => MdatBox | null;
@@ -0,0 +1,201 @@
1
+ "use strict";
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;
4
+ const getFtypBox = (segments) => {
5
+ const ftypBox = segments.find((s) => s.type === 'ftyp-box');
6
+ if (!ftypBox || ftypBox.type !== 'ftyp-box') {
7
+ return null;
8
+ }
9
+ return ftypBox;
10
+ };
11
+ exports.getFtypBox = getFtypBox;
12
+ const getMoovBox = (segments) => {
13
+ const moovBox = segments.find((s) => s.type === 'moov-box');
14
+ if (!moovBox || moovBox.type !== 'moov-box') {
15
+ return null;
16
+ }
17
+ return moovBox;
18
+ };
19
+ exports.getMoovBox = getMoovBox;
20
+ const getMoofBox = (main) => {
21
+ const moofBox = main.find((s) => s.type === 'regular-box' && s.boxType === 'moof');
22
+ if (!moofBox || moofBox.type !== 'regular-box') {
23
+ return null;
24
+ }
25
+ return moofBox;
26
+ };
27
+ exports.getMoofBox = getMoofBox;
28
+ const getMvhdBox = (moovBox) => {
29
+ const mvHdBox = moovBox.children.find((s) => s.type === 'mvhd-box');
30
+ if (!mvHdBox || mvHdBox.type !== 'mvhd-box') {
31
+ return null;
32
+ }
33
+ return mvHdBox;
34
+ };
35
+ exports.getMvhdBox = getMvhdBox;
36
+ const getTraks = (moovBox) => {
37
+ return moovBox.children.filter((s) => s.type === 'trak-box');
38
+ };
39
+ exports.getTraks = getTraks;
40
+ const getTkhdBox = (trakBox) => {
41
+ const tkhdBox = trakBox.children.find((s) => s.type === 'tkhd-box');
42
+ return tkhdBox;
43
+ };
44
+ exports.getTkhdBox = getTkhdBox;
45
+ const getMdiaBox = (trakBox) => {
46
+ const mdiaBox = trakBox.children.find((s) => s.type === 'regular-box' && s.boxType === 'mdia');
47
+ if (!mdiaBox || mdiaBox.type !== 'regular-box') {
48
+ return null;
49
+ }
50
+ return mdiaBox;
51
+ };
52
+ exports.getMdiaBox = getMdiaBox;
53
+ const getMdhdBox = (trakBox) => {
54
+ const mdiaBox = (0, exports.getMdiaBox)(trakBox);
55
+ if (!mdiaBox) {
56
+ return null;
57
+ }
58
+ const mdhdBox = mdiaBox.children.find((c) => c.type === 'mdhd-box');
59
+ return mdhdBox;
60
+ };
61
+ exports.getMdhdBox = getMdhdBox;
62
+ const getStblBox = (trakBox) => {
63
+ const mdiaBox = (0, exports.getMdiaBox)(trakBox);
64
+ if (!mdiaBox) {
65
+ return null;
66
+ }
67
+ const minfBox = mdiaBox.children.find((s) => s.type === 'regular-box' && s.boxType === 'minf');
68
+ if (!minfBox || minfBox.type !== 'regular-box') {
69
+ return null;
70
+ }
71
+ const stblBox = minfBox.children.find((s) => s.type === 'regular-box' && s.boxType === 'stbl');
72
+ if (!stblBox || stblBox.type !== 'regular-box') {
73
+ return null;
74
+ }
75
+ return stblBox;
76
+ };
77
+ exports.getStblBox = getStblBox;
78
+ const getStsdBox = (trakBox) => {
79
+ const stblBox = (0, exports.getStblBox)(trakBox);
80
+ if (!stblBox || stblBox.type !== 'regular-box') {
81
+ return null;
82
+ }
83
+ const stsdBox = stblBox.children.find((s) => s.type === 'stsd-box');
84
+ return stsdBox;
85
+ };
86
+ exports.getStsdBox = getStsdBox;
87
+ const getVideoDescriptors = (trakBox) => {
88
+ var _a;
89
+ const stsdBox = (0, exports.getStsdBox)(trakBox);
90
+ if (!stsdBox) {
91
+ return null;
92
+ }
93
+ const descriptors = stsdBox.samples.map((s) => {
94
+ return s.type === 'video'
95
+ ? s.descriptors.map((d) => {
96
+ return d.type === 'avcc-box'
97
+ ? d.privateData
98
+ : d.type === 'hvcc-box'
99
+ ? d.privateData
100
+ : null;
101
+ })
102
+ : [];
103
+ });
104
+ return (_a = descriptors.flat(1).filter(Boolean)[0]) !== null && _a !== void 0 ? _a : null;
105
+ };
106
+ exports.getVideoDescriptors = getVideoDescriptors;
107
+ const getStcoBox = (trakBox) => {
108
+ const stblBox = (0, exports.getStblBox)(trakBox);
109
+ if (!stblBox || stblBox.type !== 'regular-box') {
110
+ return null;
111
+ }
112
+ const stcoBox = stblBox.children.find((s) => s.type === 'stco-box');
113
+ return stcoBox;
114
+ };
115
+ exports.getStcoBox = getStcoBox;
116
+ const getSttsBox = (trakBox) => {
117
+ const stblBox = (0, exports.getStblBox)(trakBox);
118
+ if (!stblBox || stblBox.type !== 'regular-box') {
119
+ return null;
120
+ }
121
+ const sttsBox = stblBox.children.find((s) => s.type === 'stts-box');
122
+ return sttsBox;
123
+ };
124
+ exports.getSttsBox = getSttsBox;
125
+ const getCttsBox = (trakBox) => {
126
+ const stblBox = (0, exports.getStblBox)(trakBox);
127
+ if (!stblBox || stblBox.type !== 'regular-box') {
128
+ return null;
129
+ }
130
+ const cttsBox = stblBox.children.find((s) => s.type === 'ctts-box');
131
+ return cttsBox;
132
+ };
133
+ exports.getCttsBox = getCttsBox;
134
+ const getStszBox = (trakBox) => {
135
+ const stblBox = (0, exports.getStblBox)(trakBox);
136
+ if (!stblBox || stblBox.type !== 'regular-box') {
137
+ return null;
138
+ }
139
+ const stszBox = stblBox.children.find((s) => s.type === 'stsz-box');
140
+ return stszBox;
141
+ };
142
+ exports.getStszBox = getStszBox;
143
+ const getStscBox = (trakBox) => {
144
+ const stblBox = (0, exports.getStblBox)(trakBox);
145
+ if (!stblBox || stblBox.type !== 'regular-box') {
146
+ return null;
147
+ }
148
+ const stcoBox = stblBox.children.find((b) => b.type === 'stsc-box');
149
+ return stcoBox;
150
+ };
151
+ exports.getStscBox = getStscBox;
152
+ const getStssBox = (trakBox) => {
153
+ const stblBox = (0, exports.getStblBox)(trakBox);
154
+ if (!stblBox || stblBox.type !== 'regular-box') {
155
+ return null;
156
+ }
157
+ const stssBox = stblBox.children.find((b) => b.type === 'stss-box');
158
+ return stssBox;
159
+ };
160
+ exports.getStssBox = getStssBox;
161
+ const getTfdtBox = (segment) => {
162
+ if (segment.type !== 'regular-box' || segment.boxType !== 'traf') {
163
+ throw new Error('Expected traf-box');
164
+ }
165
+ const tfhdBox = segment.children.find((c) => c.type === 'tfdt-box');
166
+ if (!tfhdBox || tfhdBox.type !== 'tfdt-box') {
167
+ throw new Error('Expected tfhd-box');
168
+ }
169
+ return tfhdBox;
170
+ };
171
+ exports.getTfdtBox = getTfdtBox;
172
+ const getTfhdBox = (segment) => {
173
+ if (segment.type !== 'regular-box' || segment.boxType !== 'traf') {
174
+ throw new Error('Expected traf-box');
175
+ }
176
+ const tfhdBox = segment.children.find((c) => c.type === 'tfhd-box');
177
+ if (!tfhdBox || tfhdBox.type !== 'tfhd-box') {
178
+ throw new Error('Expected tfhd-box');
179
+ }
180
+ return tfhdBox;
181
+ };
182
+ exports.getTfhdBox = getTfhdBox;
183
+ const getTrunBoxes = (segment) => {
184
+ if (segment.type !== 'regular-box' || segment.boxType !== 'traf') {
185
+ throw new Error('Expected traf-box');
186
+ }
187
+ const trunBoxes = segment.children.filter((c) => c.type === 'trun-box');
188
+ return trunBoxes;
189
+ };
190
+ exports.getTrunBoxes = getTrunBoxes;
191
+ const getMdatBox = (anySegment) => {
192
+ const mdat = anySegment.find((b) => b.type === 'mdat-box');
193
+ if (!mdat) {
194
+ return null;
195
+ }
196
+ if (mdat.type !== 'mdat-box') {
197
+ throw new Error('Expected mdat-box');
198
+ }
199
+ return mdat;
200
+ };
201
+ exports.getMdatBox = getMdatBox;
@@ -0,0 +1,4 @@
1
+ import type { VideoTrackColorParams } from '../../get-tracks';
2
+ import type { ColourSegment } from './segments/all-segments';
3
+ export declare const parseColorSegment: (colourSegment: ColourSegment) => VideoTrackColorParams;
4
+ export declare const makeMatroskaColorBytes: ({ transferCharacteristics, matrixCoefficients, primaries, fullRange, }: VideoTrackColorParams) => import("./segments/all-segments").BytesAndOffset;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeMatroskaColorBytes = exports.parseColorSegment = void 0;
4
+ const truthy_1 = require("../../truthy");
5
+ const make_header_1 = require("./make-header");
6
+ const traversal_1 = require("./traversal");
7
+ const parseColorSegment = (colourSegment) => {
8
+ const transferCharacteristics = (0, traversal_1.getTransferCharacteristicsSegment)(colourSegment);
9
+ const matrixCoefficients = (0, traversal_1.getMatrixCoefficientsSegment)(colourSegment);
10
+ const primaries = (0, traversal_1.getPrimariesSegment)(colourSegment);
11
+ const range = (0, traversal_1.getRangeSegment)(colourSegment);
12
+ return {
13
+ transferCharacteristics: transferCharacteristics
14
+ ? transferCharacteristics.value.value === 1
15
+ ? 'bt709'
16
+ : transferCharacteristics.value.value === 6
17
+ ? 'smpte170m'
18
+ : transferCharacteristics.value.value === 13
19
+ ? 'iec61966-2-1'
20
+ : null
21
+ : null,
22
+ matrixCoefficients: matrixCoefficients
23
+ ? matrixCoefficients.value.value === 1
24
+ ? 'bt709'
25
+ : matrixCoefficients.value.value === 6
26
+ ? 'smpte170m'
27
+ : matrixCoefficients.value.value === 5
28
+ ? 'bt470bg'
29
+ : null
30
+ : null,
31
+ primaries: primaries
32
+ ? primaries.value.value === 1
33
+ ? 'bt709'
34
+ : primaries.value.value === 6
35
+ ? 'smpte170m'
36
+ : primaries.value.value === 5
37
+ ? 'bt470bg'
38
+ : null
39
+ : null,
40
+ fullRange: (transferCharacteristics === null || transferCharacteristics === void 0 ? void 0 : transferCharacteristics.value.value) && (matrixCoefficients === null || matrixCoefficients === void 0 ? void 0 : matrixCoefficients.value.value)
41
+ ? null
42
+ : range
43
+ ? Boolean(range === null || range === void 0 ? void 0 : range.value.value)
44
+ : null,
45
+ };
46
+ };
47
+ exports.parseColorSegment = parseColorSegment;
48
+ const makeMatroskaColorBytes = ({ transferCharacteristics, matrixCoefficients, primaries, fullRange, }) => {
49
+ const rangeValue = transferCharacteristics && matrixCoefficients
50
+ ? 3
51
+ : fullRange === true
52
+ ? 2
53
+ : fullRange === false
54
+ ? 1
55
+ : 0;
56
+ // https://datatracker.ietf.org/doc/draft-ietf-cellar-matroska/
57
+ // 5.1.4.1.28.27
58
+ const primariesValue = primaries === 'bt709'
59
+ ? 1
60
+ : primaries === 'smpte170m'
61
+ ? 6
62
+ : primaries === 'bt470bg'
63
+ ? 5
64
+ : 2;
65
+ const transferChracteristicsValue = transferCharacteristics === 'bt709'
66
+ ? 1
67
+ : transferCharacteristics === 'smpte170m'
68
+ ? 6
69
+ : transferCharacteristics === 'iec61966-2-1'
70
+ ? 13
71
+ : 2;
72
+ if (matrixCoefficients === 'rgb') {
73
+ throw new Error('Cannot encode Matroska in RGB');
74
+ }
75
+ const matrixCoefficientsValue = matrixCoefficients === 'bt709'
76
+ ? 1
77
+ : matrixCoefficients === 'bt470bg'
78
+ ? 5
79
+ : matrixCoefficients === 'smpte170m'
80
+ ? 6
81
+ : 2;
82
+ return (0, make_header_1.makeMatroskaBytes)({
83
+ type: 'Colour',
84
+ minVintWidth: null,
85
+ value: [
86
+ transferChracteristicsValue === 2
87
+ ? null
88
+ : {
89
+ type: 'TransferCharacteristics',
90
+ value: {
91
+ value: transferChracteristicsValue,
92
+ byteLength: null,
93
+ },
94
+ minVintWidth: null,
95
+ },
96
+ matrixCoefficientsValue === 2
97
+ ? null
98
+ : {
99
+ type: 'MatrixCoefficients',
100
+ value: {
101
+ value: matrixCoefficientsValue,
102
+ byteLength: null,
103
+ },
104
+ minVintWidth: null,
105
+ },
106
+ primariesValue === 2
107
+ ? null
108
+ : {
109
+ type: 'Primaries',
110
+ value: {
111
+ value: primariesValue,
112
+ byteLength: null,
113
+ },
114
+ minVintWidth: null,
115
+ },
116
+ {
117
+ type: 'Range',
118
+ value: {
119
+ value: rangeValue,
120
+ byteLength: null,
121
+ },
122
+ minVintWidth: null,
123
+ },
124
+ ].filter(truthy_1.truthy),
125
+ });
126
+ };
127
+ exports.makeMatroskaColorBytes = makeMatroskaColorBytes;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAudioDescription = void 0;
4
4
  const buffer_iterator_1 = require("../../buffer-iterator");
5
- const traversal_1 = require("../../traversal");
5
+ const traversal_1 = require("./traversal");
6
6
  const getAudioDescription = (track) => {
7
7
  const codec = (0, traversal_1.getCodecSegment)(track);
8
8
  if (!codec || codec.value !== 'A_VORBIS') {
@@ -1,2 +1,2 @@
1
- export declare const measureEBMLVarInt: (value: number) => 1 | 2 | 3 | 4 | 5 | 6;
1
+ export declare const measureEBMLVarInt: (value: number) => 2 | 1 | 3 | 4 | 5 | 6;
2
2
  export declare const getVariableInt: (value: number, minWidth: number | null) => Uint8Array;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTracksFromMatroska = void 0;
4
- const traversal_1 = require("../../traversal");
5
- const get_track_1 = require("./get-track");
4
+ const make_track_1 = require("./make-track");
5
+ const traversal_1 = require("./traversal");
6
6
  const getTracksFromMatroska = (segment, timescale) => {
7
7
  const tracksSegment = (0, traversal_1.getTracksSegment)(segment);
8
8
  if (!tracksSegment) {
@@ -16,7 +16,7 @@ const getTracksFromMatroska = (segment, timescale) => {
16
16
  if (trackEntrySegment.type !== 'TrackEntry') {
17
17
  throw new Error('Expected track entry segment');
18
18
  }
19
- const track = (0, get_track_1.getTrack)({
19
+ const track = (0, make_track_1.getTrack)({
20
20
  track: trackEntrySegment,
21
21
  timescale,
22
22
  });
@@ -10,7 +10,7 @@ const getSampleFromBlock = (ebml, parserContext, offset) => {
10
10
  if (trackNumber === null) {
11
11
  throw new Error('Not enough data to get track number, should not happen');
12
12
  }
13
- const timecodeRelativeToCluster = iterator.getUint16();
13
+ const timecodeRelativeToCluster = iterator.getInt16();
14
14
  const { keyframe } = (0, block_simple_block_flags_1.parseBlockFlags)(iterator, ebml.type === 'SimpleBlock'
15
15
  ? all_segments_1.matroskaElements.SimpleBlock
16
16
  : all_segments_1.matroskaElements.Block);
@@ -0,0 +1,9 @@
1
+ import type { AudioTrack, MediaParserAudioCodec, VideoTrack } from '../../get-tracks';
2
+ import type { TrackEntry } from './segments/all-segments';
3
+ export declare const getMatroskaAudioCodecWithoutConfigString: ({ track, }: {
4
+ track: TrackEntry;
5
+ }) => MediaParserAudioCodec;
6
+ export declare const getTrack: ({ timescale, track, }: {
7
+ timescale: number;
8
+ track: TrackEntry;
9
+ }) => VideoTrack | AudioTrack | null;