@remotion/media-parser 4.0.209 → 4.0.210

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 (213) 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 +2 -1
  5. package/dist/boxes/iso-base-media/mdat/mdat.js +8 -3
  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 +20 -5
  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 +44 -0
  24. package/dist/boxes/iso-base-media/traversal.js +211 -0
  25. package/dist/boxes/webm/color.d.ts +4 -0
  26. package/dist/boxes/webm/color.js +120 -0
  27. package/dist/boxes/webm/description.js +1 -1
  28. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  29. package/dist/boxes/webm/get-sample-from-block.js +1 -1
  30. package/dist/boxes/webm/get-track.js +16 -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/traversal.d.ts +26 -1
  37. package/dist/boxes/webm/traversal.js +214 -1
  38. package/dist/create/cluster-segment.js +0 -2
  39. package/dist/create/cluster.d.ts +10 -2
  40. package/dist/create/cluster.js +16 -10
  41. package/dist/create/create-media.d.ts +4 -2
  42. package/dist/create/create-media.js +76 -14
  43. package/dist/create/cues.d.ts +0 -0
  44. package/dist/create/cues.js +1 -0
  45. package/dist/create/make-duration-with-padding.d.ts +1 -1
  46. package/dist/create/make-duration-with-padding.js +3 -3
  47. package/dist/create/matroska-cues.d.ts +6 -0
  48. package/dist/create/matroska-cues.js +50 -0
  49. package/dist/create/matroska-info.js +1 -1
  50. package/dist/create/matroska-seek.d.ts +6 -0
  51. package/dist/create/matroska-seek.js +32 -0
  52. package/dist/create/matroska-segment.d.ts +1 -0
  53. package/dist/create/matroska-segment.js +3 -2
  54. package/dist/create/matroska-trackentry.d.ts +9 -14
  55. package/dist/create/matroska-trackentry.js +79 -94
  56. package/dist/emit-available-info.d.ts +12 -0
  57. package/dist/emit-available-info.js +133 -0
  58. package/dist/esm/buffer.mjs +57 -0
  59. package/dist/esm/from-fetch.mjs +72 -0
  60. package/dist/esm/from-node.mjs +48 -0
  61. package/dist/esm/from-web-file.mjs +48 -0
  62. package/dist/esm/index.mjs +6689 -0
  63. package/dist/esm/web-fs.mjs +67 -0
  64. package/dist/get-audio-codec.d.ts +5 -5
  65. package/dist/get-audio-codec.js +41 -57
  66. package/dist/get-container.d.ts +4 -0
  67. package/dist/get-container.js +26 -0
  68. package/dist/get-duration.js +1 -1
  69. package/dist/get-fps.js +1 -1
  70. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  71. package/dist/get-sample-aspect-ratio.js +19 -19
  72. package/dist/get-tracks.d.ts +13 -0
  73. package/dist/get-tracks.js +8 -8
  74. package/dist/get-video-codec.d.ts +5 -2
  75. package/dist/get-video-codec.js +111 -21
  76. package/dist/has-all-info.d.ts +2 -2
  77. package/dist/has-all-info.js +23 -9
  78. package/dist/index.d.ts +3 -1
  79. package/dist/options.d.ts +97 -30
  80. package/dist/parse-media.js +43 -62
  81. package/dist/parse-video.d.ts +2 -1
  82. package/dist/parse-video.js +3 -1
  83. package/dist/parser-state.js +1 -2
  84. package/dist/readers/from-fetch.js +24 -4
  85. package/dist/readers/from-node.js +13 -3
  86. package/dist/readers/from-web-file.js +14 -2
  87. package/dist/readers/reader.d.ts +6 -1
  88. package/dist/samples-from-moof.js +1 -1
  89. package/dist/traversal.d.ts +0 -21
  90. package/dist/traversal.js +1 -158
  91. package/dist/truthy.d.ts +3 -0
  92. package/dist/truthy.js +7 -0
  93. package/dist/writers/buffer.d.ts +2 -0
  94. package/dist/writers/buffer.js +58 -0
  95. package/dist/writers/web-fs.d.ts +1 -0
  96. package/dist/writers/web-fs.js +42 -18
  97. package/dist/writers/writer.d.ts +4 -2
  98. package/fetch.js +2 -0
  99. package/node.js +2 -0
  100. package/package.json +43 -8
  101. package/web-file.js +2 -0
  102. package/web-fs.js +2 -0
  103. package/.eslintrc +0 -8
  104. package/input.webm +0 -0
  105. package/src/add-new-matroska-tracks.ts +0 -23
  106. package/src/boxes/iso-base-media/base-type.ts +0 -4
  107. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  108. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  109. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  110. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  111. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  112. package/src/boxes/iso-base-media/make-track.ts +0 -116
  113. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  114. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  115. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  116. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  117. package/src/boxes/iso-base-media/process-box.ts +0 -748
  118. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  119. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  120. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  121. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  122. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  123. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  124. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  125. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  126. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  127. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  128. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  129. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  130. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  131. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  132. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  133. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  134. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  135. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  136. package/src/boxes/iso-base-media/to-date.ts +0 -9
  137. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  138. package/src/boxes/iso-base-media/trun.ts +0 -74
  139. package/src/boxes/iso-base-media/void-box.ts +0 -4
  140. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  141. package/src/boxes/webm/av1-codec-private.ts +0 -113
  142. package/src/boxes/webm/description.ts +0 -104
  143. package/src/boxes/webm/ebml.ts +0 -98
  144. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  145. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  146. package/src/boxes/webm/get-track.ts +0 -257
  147. package/src/boxes/webm/make-header.ts +0 -253
  148. package/src/boxes/webm/parse-ebml.ts +0 -259
  149. package/src/boxes/webm/parse-webm-header.ts +0 -18
  150. package/src/boxes/webm/segments/all-segments.ts +0 -888
  151. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  152. package/src/boxes/webm/segments/parse-children.ts +0 -144
  153. package/src/boxes/webm/segments/track-entry.ts +0 -38
  154. package/src/boxes/webm/segments.ts +0 -147
  155. package/src/boxes/webm/traversal.ts +0 -45
  156. package/src/buffer-iterator.ts +0 -555
  157. package/src/create/cluster-segment.ts +0 -62
  158. package/src/create/cluster.ts +0 -64
  159. package/src/create/create-media.ts +0 -136
  160. package/src/create/make-duration-with-padding.ts +0 -15
  161. package/src/create/matroska-header.ts +0 -63
  162. package/src/create/matroska-info.ts +0 -30
  163. package/src/create/matroska-segment.ts +0 -10
  164. package/src/create/matroska-trackentry.ts +0 -325
  165. package/src/create/timescale.ts +0 -1
  166. package/src/get-audio-codec.ts +0 -270
  167. package/src/get-dimensions.ts +0 -47
  168. package/src/get-duration.ts +0 -103
  169. package/src/get-fps.ts +0 -113
  170. package/src/get-sample-aspect-ratio.ts +0 -204
  171. package/src/get-sample-positions.ts +0 -93
  172. package/src/get-tracks.ts +0 -147
  173. package/src/get-video-codec.ts +0 -117
  174. package/src/has-all-info.ts +0 -81
  175. package/src/index.ts +0 -18
  176. package/src/make-hvc1-codec-strings.ts +0 -55
  177. package/src/options.ts +0 -118
  178. package/src/parse-media.ts +0 -183
  179. package/src/parse-result.ts +0 -79
  180. package/src/parse-video.ts +0 -83
  181. package/src/parser-context.ts +0 -10
  182. package/src/parser-state.ts +0 -178
  183. package/src/readers/from-fetch.ts +0 -90
  184. package/src/readers/from-node.ts +0 -51
  185. package/src/readers/from-web-file.ts +0 -49
  186. package/src/readers/reader.ts +0 -15
  187. package/src/samples-from-moof.ts +0 -102
  188. package/src/test/aspect-ratio.test.ts +0 -42
  189. package/src/test/av1.test.ts +0 -108
  190. package/src/test/create-matroska.test.ts +0 -287
  191. package/src/test/duration.test.ts +0 -18
  192. package/src/test/keys.test.ts +0 -47
  193. package/src/test/matroska.test.ts +0 -463
  194. package/src/test/mvhd.test.ts +0 -94
  195. package/src/test/parse-esds.test.ts +0 -98
  196. package/src/test/parse-stco.test.ts +0 -61
  197. package/src/test/parse-stsc.test.ts +0 -104
  198. package/src/test/parse-stsz.test.ts +0 -57
  199. package/src/test/parse-stts.test.ts +0 -38
  200. package/src/test/parse-video.test.ts +0 -101
  201. package/src/test/parse-webm.test.ts +0 -17
  202. package/src/test/samples-from-moof.test.ts +0 -2496
  203. package/src/test/stream-local.test.ts +0 -743
  204. package/src/test/stream-remote.test.ts +0 -59
  205. package/src/test/stream-samples.test.ts +0 -181
  206. package/src/test/stsd.test.ts +0 -265
  207. package/src/test/tkhd.test.ts +0 -87
  208. package/src/traversal.ts +0 -528
  209. package/src/webcodec-sample-types.ts +0 -29
  210. package/src/writers/web-fs.ts +0 -50
  211. package/src/writers/writer.ts +0 -12
  212. package/tsconfig.json +0 -14
  213. package/tsconfig.tsbuildinfo +0 -1
package/buffer.js ADDED
@@ -0,0 +1,2 @@
1
+ // For backwards compatibility when you use Metro
2
+ module.exports = require('./dist/writers/buffer');
@@ -4,7 +4,7 @@ exports.getSamplePositionsFromTrack = void 0;
4
4
  const get_fps_1 = require("../../get-fps");
5
5
  const get_sample_positions_1 = require("../../get-sample-positions");
6
6
  const samples_from_moof_1 = require("../../samples-from-moof");
7
- const traversal_1 = require("../../traversal");
7
+ const traversal_1 = require("./traversal");
8
8
  const getSamplePositionsFromTrack = (trakBox, moofBox) => {
9
9
  const stszBox = (0, traversal_1.getStszBox)(trakBox);
10
10
  const stcoBox = (0, traversal_1.getStcoBox)(trakBox);
@@ -5,8 +5,9 @@ const get_audio_codec_1 = require("../../get-audio-codec");
5
5
  const get_fps_1 = require("../../get-fps");
6
6
  const get_sample_aspect_ratio_1 = require("../../get-sample-aspect-ratio");
7
7
  const get_video_codec_1 = require("../../get-video-codec");
8
- const traversal_1 = require("../../traversal");
8
+ const traversal_1 = require("./traversal");
9
9
  const makeBaseMediaTrack = (trakBox) => {
10
+ var _a;
10
11
  const tkhdBox = (0, traversal_1.getTkhdBox)(trakBox);
11
12
  const videoDescriptors = (0, traversal_1.getVideoDescriptors)(trakBox);
12
13
  const timescaleAndDuration = (0, get_fps_1.getTimescaleAndDuration)(trakBox);
@@ -35,6 +36,8 @@ const makeBaseMediaTrack = (trakBox) => {
35
36
  sampleRate,
36
37
  description,
37
38
  trakBox,
39
+ codecPrivate: null,
40
+ codecWithoutConfig: (0, get_audio_codec_1.getAudioCodecFromTrack)(trakBox),
38
41
  };
39
42
  }
40
43
  if (!(0, get_fps_1.trakBoxContainsVideo)(trakBox)) {
@@ -45,7 +48,7 @@ const makeBaseMediaTrack = (trakBox) => {
45
48
  trakBox,
46
49
  };
47
50
  }
48
- const videoSample = (0, get_sample_aspect_ratio_1.getVideoSample)(trakBox);
51
+ const videoSample = (0, get_sample_aspect_ratio_1.getStsdVideoConfig)(trakBox);
49
52
  if (!videoSample) {
50
53
  throw new Error('No video sample');
51
54
  }
@@ -63,6 +66,7 @@ const makeBaseMediaTrack = (trakBox) => {
63
66
  if (!codec) {
64
67
  throw new Error('Could not find video codec');
65
68
  }
69
+ const privateData = (0, get_video_codec_1.getVideoPrivateData)(trakBox);
66
70
  const track = {
67
71
  type: 'video',
68
72
  trackId: tkhdBox.trackId,
@@ -79,6 +83,14 @@ const makeBaseMediaTrack = (trakBox) => {
79
83
  displayAspectHeight,
80
84
  rotation,
81
85
  trakBox,
86
+ codecPrivate: privateData,
87
+ color: (_a = (0, get_video_codec_1.getIsoBmColrConfig)(trakBox)) !== null && _a !== void 0 ? _a : {
88
+ fullRange: null,
89
+ matrixCoefficients: null,
90
+ primaries: null,
91
+ transferCharacteristics: null,
92
+ },
93
+ codecWithoutConfig: (0, get_video_codec_1.getVideoCodecFromIsoTrak)(trakBox),
82
94
  };
83
95
  return track;
84
96
  };
@@ -7,10 +7,11 @@ export interface MdatBox {
7
7
  boxSize: number;
8
8
  fileOffset: number;
9
9
  }
10
- export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, options, }: {
10
+ export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, options, signal, }: {
11
11
  data: BufferIterator;
12
12
  size: number;
13
13
  fileOffset: number;
14
14
  existingBoxes: AnySegment[];
15
15
  options: ParserContext;
16
+ signal: AbortSignal | null;
16
17
  }) => Promise<MdatBox>;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMdat = void 0;
4
4
  const get_tracks_1 = require("../../../get-tracks");
5
- const traversal_1 = require("../../../traversal");
6
5
  const get_sample_positions_from_track_1 = require("../get-sample-positions-from-track");
7
- const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, }) => {
6
+ const traversal_1 = require("../traversal");
7
+ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signal, }) => {
8
8
  const alreadyHas = (0, get_tracks_1.hasTracks)(existingBoxes);
9
9
  if (!alreadyHas) {
10
10
  data.discard(size - (data.counter.getOffset() - fileOffset));
@@ -37,6 +37,9 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, }) =>
37
37
  .flat(1);
38
38
  // eslint-disable-next-line no-constant-condition
39
39
  while (true) {
40
+ if (signal && signal.aborted) {
41
+ break;
42
+ }
40
43
  const samplesWithIndex = flatSamples.find((sample) => {
41
44
  return sample.samplePosition.offset === data.counter.getOffset();
42
45
  });
@@ -62,9 +65,11 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, }) =>
62
65
  }
63
66
  const bytes = data.getSlice(samplesWithIndex.samplePosition.size);
64
67
  if (samplesWithIndex.track.type === 'audio') {
68
+ const timestamp = Math.floor((samplesWithIndex.samplePosition.cts * 1000000) /
69
+ samplesWithIndex.track.timescale);
65
70
  await options.parserState.onAudioSample(samplesWithIndex.track.trackId, {
66
71
  data: bytes,
67
- timestamp: samplesWithIndex.samplePosition.offset,
72
+ timestamp,
68
73
  trackId: samplesWithIndex.track.trackId,
69
74
  type: samplesWithIndex.samplePosition.isKeyframe ? 'key' : 'delta',
70
75
  });
@@ -6,9 +6,10 @@ export interface MoovBox extends BaseBox {
6
6
  type: 'moov-box';
7
7
  children: AnySegment[];
8
8
  }
9
- export declare const parseMoov: ({ iterator, offset, size, options, }: {
9
+ export declare const parseMoov: ({ iterator, offset, size, options, signal, }: {
10
10
  iterator: BufferIterator;
11
11
  offset: number;
12
12
  size: number;
13
13
  options: ParserContext;
14
+ signal: AbortSignal | null;
14
15
  }) => Promise<MoovBox>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMoov = void 0;
4
4
  const process_box_1 = require("../process-box");
5
- const parseMoov = async ({ iterator, offset, size, options, }) => {
5
+ const parseMoov = async ({ iterator, offset, size, options, signal, }) => {
6
6
  const children = await (0, process_box_1.parseBoxes)({
7
7
  iterator,
8
8
  maxBytes: size - (iterator.counter.getOffset() - offset),
@@ -11,6 +11,7 @@ const parseMoov = async ({ iterator, offset, size, 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');
@@ -2,21 +2,23 @@ import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { AnySegment, IsoBaseMediaBox, ParseResult } from '../../parse-result';
3
3
  import type { BoxAndNext, PartialMdatBox } from '../../parse-video';
4
4
  import type { ParserContext } from '../../parser-context';
5
- export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, options, }: {
5
+ export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, options, signal, }: {
6
6
  iterator: BufferIterator;
7
7
  boxSize: number;
8
8
  fileOffset: number;
9
9
  parsedBoxes: AnySegment[];
10
10
  options: ParserContext;
11
+ signal: AbortSignal | null;
11
12
  }) => Promise<BoxAndNext>;
12
- export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, options, littleEndian, }: {
13
+ export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, options, littleEndian, signal, }: {
13
14
  iterator: BufferIterator;
14
15
  allowIncompleteBoxes: boolean;
15
16
  parsedBoxes: AnySegment[];
16
17
  options: ParserContext;
17
18
  littleEndian: boolean;
19
+ signal: AbortSignal | null;
18
20
  }) => Promise<BoxAndNext>;
19
- export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, littleEndian, }: {
21
+ export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, littleEndian, signal, }: {
20
22
  iterator: BufferIterator;
21
23
  maxBytes: number;
22
24
  allowIncompleteBoxes: boolean;
@@ -24,4 +26,5 @@ export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, in
24
26
  options: ParserContext;
25
27
  continueMdat: false | PartialMdatBox;
26
28
  littleEndian: boolean;
29
+ signal: AbortSignal | null;
27
30
  }) => Promise<ParseResult>;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBoxes = exports.processBox = exports.parseMdatPartially = void 0;
4
4
  const get_tracks_1 = require("../../get-tracks");
5
- const traversal_1 = require("../../traversal");
6
5
  const esds_1 = require("./esds/esds");
7
6
  const ftyp_1 = require("./ftyp");
8
7
  const make_track_1 = require("./make-track");
@@ -27,8 +26,9 @@ const tfdt_1 = require("./tfdt");
27
26
  const tfhd_1 = require("./tfhd");
28
27
  const tkhd_1 = require("./tkhd");
29
28
  const trak_1 = require("./trak/trak");
29
+ const traversal_1 = require("./traversal");
30
30
  const trun_1 = require("./trun");
31
- const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, littleEndian, }) => {
31
+ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, littleEndian, signal, }) => {
32
32
  const parseChildren = boxType === 'mdia' ||
33
33
  boxType === 'minf' ||
34
34
  boxType === 'stbl' ||
@@ -46,6 +46,7 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, li
46
46
  options,
47
47
  continueMdat: false,
48
48
  littleEndian,
49
+ signal,
49
50
  });
50
51
  if (parsed.status === 'incomplete') {
51
52
  throw new Error('Incomplete boxes are not allowed');
@@ -58,13 +59,14 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, li
58
59
  iterator.discard(bytesRemainingInBox);
59
60
  return [];
60
61
  };
61
- const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes, options, }) => {
62
+ const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes, options, signal, }) => {
62
63
  const box = await (0, mdat_1.parseMdat)({
63
64
  data: iterator,
64
65
  size: boxSize,
65
66
  fileOffset,
66
67
  existingBoxes: parsedBoxes,
67
68
  options,
69
+ signal,
68
70
  });
69
71
  if (box.samplesProcessed &&
70
72
  box.fileOffset + boxSize === iterator.counter.getOffset()) {
@@ -82,7 +84,7 @@ const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes,
82
84
  };
83
85
  };
84
86
  exports.parseMdatPartially = parseMdatPartially;
85
- const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options, littleEndian, }) => {
87
+ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options, littleEndian, signal, }) => {
86
88
  var _a, _b;
87
89
  const fileOffset = iterator.counter.getOffset();
88
90
  const bytesRemaining = iterator.bytesRemaining();
@@ -139,6 +141,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
139
141
  fileOffset,
140
142
  parsedBoxes,
141
143
  options,
144
+ signal,
142
145
  });
143
146
  }
144
147
  }
@@ -212,6 +215,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
212
215
  offset: fileOffset,
213
216
  size: boxSize,
214
217
  options,
218
+ signal,
215
219
  });
216
220
  return {
217
221
  type: 'complete',
@@ -306,6 +310,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
306
310
  size: boxSize,
307
311
  options,
308
312
  littleEndian,
313
+ signal,
309
314
  });
310
315
  return {
311
316
  type: 'complete',
@@ -320,6 +325,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
320
325
  offset: fileOffset,
321
326
  size: boxSize,
322
327
  options,
328
+ signal,
323
329
  });
324
330
  return {
325
331
  type: 'complete',
@@ -334,6 +340,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
334
340
  size: boxSize,
335
341
  offsetAtStart: fileOffset,
336
342
  options,
343
+ signal,
337
344
  });
338
345
  const transformedTrack = (0, make_track_1.makeBaseMediaTrack)(box);
339
346
  if (transformedTrack) {
@@ -449,6 +456,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
449
456
  fileOffset,
450
457
  existingBoxes: parsedBoxes,
451
458
  options,
459
+ signal,
452
460
  });
453
461
  return {
454
462
  type: 'complete',
@@ -464,6 +472,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
464
472
  bytesRemainingInBox,
465
473
  options,
466
474
  littleEndian,
475
+ signal,
467
476
  });
468
477
  return {
469
478
  type: 'complete',
@@ -479,7 +488,7 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
479
488
  };
480
489
  };
481
490
  exports.processBox = processBox;
482
- const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, littleEndian, }) => {
491
+ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, littleEndian, signal, }) => {
483
492
  let boxes = initialBoxes;
484
493
  const initialOffset = iterator.counter.getOffset();
485
494
  const alreadyHasMdat = boxes.find((b) => b.type === 'mdat-box');
@@ -492,6 +501,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
492
501
  fileOffset: continueMdat.fileOffset,
493
502
  parsedBoxes: initialBoxes,
494
503
  options,
504
+ signal,
495
505
  })
496
506
  : await (0, exports.processBox)({
497
507
  iterator,
@@ -499,6 +509,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
499
509
  parsedBoxes: initialBoxes,
500
510
  options,
501
511
  littleEndian,
512
+ signal,
502
513
  });
503
514
  if (result.type === 'incomplete') {
504
515
  if (Number.isFinite(maxBytes)) {
@@ -516,6 +527,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
516
527
  options,
517
528
  continueMdat: false,
518
529
  littleEndian,
530
+ signal,
519
531
  });
520
532
  },
521
533
  skipTo: null,
@@ -534,6 +546,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
534
546
  options,
535
547
  continueMdat: result,
536
548
  littleEndian,
549
+ signal,
537
550
  }));
538
551
  },
539
552
  skipTo: null,
@@ -560,6 +573,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
560
573
  options,
561
574
  continueMdat: false,
562
575
  littleEndian,
576
+ signal,
563
577
  });
564
578
  },
565
579
  skipTo: result.skipTo,
@@ -581,6 +595,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
581
595
  options,
582
596
  continueMdat: false,
583
597
  littleEndian,
598
+ signal,
584
599
  });
585
600
  },
586
601
  skipTo: mdatState.fileOffset,
@@ -1,7 +1,7 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  export interface AvccBox {
3
3
  type: 'avcc-box';
4
- description: Uint8Array;
4
+ privateData: Uint8Array;
5
5
  configurationString: string;
6
6
  }
7
7
  export declare const parseAvcc: ({ data, size, }: {
@@ -11,10 +11,10 @@ const parseAvcc = ({ data, size, }) => {
11
11
  const level = data.getUint8();
12
12
  const str = `${profile.toString(16).padStart(2, '0')}${profileCompatibility.toString(16).padStart(2, '0')}${level.toString(16).padStart(2, '0')}`;
13
13
  data.counter.decrement(4);
14
- const description = data.getSlice(size - 8);
14
+ const privateData = data.getSlice(size - 8);
15
15
  return {
16
16
  type: 'avcc-box',
17
- description,
17
+ privateData,
18
18
  configurationString: str,
19
19
  };
20
20
  };
@@ -13,12 +13,9 @@ const parseCtts = ({ iterator, offset, size, }) => {
13
13
  const sampleCount = iterator.getUint32();
14
14
  // V1 = signed, V0 = unsigned
15
15
  // however some files are buggy
16
- // Let's do the same thing as mp4box but uint32, based on our test set of videos
16
+ // Let's do the same thing as mp4box
17
17
  // https://github.com/gpac/mp4box.js/blob/c6cc468145bc5b031b866446111f29c8b620dbe6/src/parsing/ctts.js#L2
18
- const sampleOffset = iterator.getUint32();
19
- if (sampleOffset < 0) {
20
- throw new Error('ctts box uses negative values without using version 1');
21
- }
18
+ const sampleOffset = iterator.getInt32();
22
19
  entries.push({
23
20
  sampleCount,
24
21
  sampleOffset,
@@ -1,7 +1,7 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  export interface HvccBox {
3
3
  type: 'hvcc-box';
4
- data: Uint8Array;
4
+ privateData: Uint8Array;
5
5
  configurationString: string;
6
6
  }
7
7
  export declare const parseHvcc: ({ data, size, offset, }: {
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHvcc = void 0;
4
4
  const make_hvc1_codec_strings_1 = require("../../../make-hvc1-codec-strings");
5
5
  const parseHvcc = ({ data, size, offset, }) => {
6
- const raw = data.getSlice(size - 8);
6
+ const privateData = data.getSlice(size - 8);
7
7
  data.counter.decrement(size - 8);
8
8
  const constraintString = (0, make_hvc1_codec_strings_1.getHvc1CodecString)(data);
9
9
  const remaining = size - (data.counter.getOffset() - offset);
10
10
  data.discard(remaining);
11
11
  return {
12
12
  type: 'hvcc-box',
13
- data: raw,
13
+ privateData,
14
14
  configurationString: constraintString,
15
15
  };
16
16
  };
@@ -8,10 +8,11 @@ export interface MebxBox extends BaseBox {
8
8
  format: string;
9
9
  children: AnySegment[];
10
10
  }
11
- export declare const parseMebx: ({ iterator, offset, size, options, littleEndian, }: {
11
+ export declare const parseMebx: ({ iterator, offset, size, options, littleEndian, signal, }: {
12
12
  iterator: BufferIterator;
13
13
  offset: number;
14
14
  size: number;
15
15
  options: ParserContext;
16
16
  littleEndian: boolean;
17
+ signal: AbortSignal | null;
17
18
  }) => Promise<MebxBox>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMebx = void 0;
4
4
  const process_box_1 = require("../process-box");
5
- const parseMebx = async ({ iterator, offset, size, options, littleEndian, }) => {
5
+ const parseMebx = async ({ iterator, offset, size, options, littleEndian, signal, }) => {
6
6
  // reserved, 6 bit
7
7
  iterator.discard(6);
8
8
  const dataReferenceIndex = iterator.getUint16();
@@ -14,6 +14,7 @@ const parseMebx = async ({ iterator, offset, size, options, littleEndian, }) =>
14
14
  options,
15
15
  continueMdat: false,
16
16
  littleEndian,
17
+ signal,
17
18
  });
18
19
  if (children.status === 'incomplete') {
19
20
  throw new Error('Incomplete boxes are not allowed');
@@ -48,13 +48,15 @@ export type Sample = AudioSample | VideoSample | UnknownSample;
48
48
  type SampleAndNext = {
49
49
  sample: Sample | null;
50
50
  };
51
- export declare const processSample: ({ iterator, options, }: {
51
+ export declare const processSample: ({ iterator, options, signal, }: {
52
52
  iterator: BufferIterator;
53
53
  options: ParserContext;
54
+ signal: AbortSignal | null;
54
55
  }) => Promise<SampleAndNext>;
55
- export declare const parseSamples: ({ iterator, maxBytes, options, }: {
56
+ export declare const parseSamples: ({ iterator, maxBytes, options, signal, }: {
56
57
  iterator: BufferIterator;
57
58
  maxBytes: number;
58
59
  options: ParserContext;
60
+ signal: AbortSignal | null;
59
61
  }) => Promise<Sample[]>;
60
62
  export {};
@@ -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');