@remotion/media-parser 4.0.251 → 4.0.253

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 (148) hide show
  1. package/dist/aac-codecprivate.d.ts +2 -1
  2. package/dist/aac-codecprivate.js +28 -7
  3. package/dist/abort.d.ts +1 -0
  4. package/dist/abort.js +7 -0
  5. package/dist/buffer-iterator.d.ts +5 -1
  6. package/dist/buffer-iterator.js +5 -5
  7. package/dist/containers/aac/parse-aac.js +3 -2
  8. package/dist/containers/flac/get-channel-count.d.ts +1 -1
  9. package/dist/containers/flac/get-duration-from-flac.js +1 -4
  10. package/dist/containers/flac/get-sample-rate.js +1 -1
  11. package/dist/containers/flac/parse-flac-frame.js +3 -9
  12. package/dist/containers/flac/parse-flac.js +2 -7
  13. package/dist/containers/flac/parse-header.js +2 -2
  14. package/dist/containers/flac/parse-metadata.js +2 -2
  15. package/dist/containers/flac/parse-streaminfo.js +3 -3
  16. package/dist/containers/flac/parse-unknown-block.js +2 -2
  17. package/dist/containers/iso-base-media/base-media-box.d.ts +1 -4
  18. package/dist/containers/iso-base-media/get-actual-number-of-channels.js +1 -1
  19. package/dist/containers/iso-base-media/get-children.js +2 -2
  20. package/dist/containers/iso-base-media/get-keyframes.d.ts +2 -2
  21. package/dist/containers/iso-base-media/get-keyframes.js +8 -4
  22. package/dist/containers/iso-base-media/get-moov-atom.d.ts +6 -0
  23. package/dist/containers/iso-base-media/get-moov-atom.js +73 -0
  24. package/dist/containers/iso-base-media/get-sample-positions-from-track.d.ts +4 -1
  25. package/dist/containers/iso-base-media/get-sample-positions-from-track.js +7 -3
  26. package/dist/containers/iso-base-media/get-video-codec-from-iso-track.js +1 -1
  27. package/dist/containers/iso-base-media/mdat/mdat.d.ts +2 -1
  28. package/dist/containers/iso-base-media/mdat/mdat.js +16 -11
  29. package/dist/containers/iso-base-media/parse-boxes.js +4 -26
  30. package/dist/containers/iso-base-media/process-box.js +50 -163
  31. package/dist/containers/iso-base-media/stsd/samples.js +1 -0
  32. package/dist/containers/iso-base-media/traversal.d.ts +3 -2
  33. package/dist/containers/iso-base-media/traversal.js +11 -10
  34. package/dist/containers/mp3/get-duration.js +0 -3
  35. package/dist/containers/mp3/id3.js +1 -1
  36. package/dist/containers/mp3/parse-mp3.js +4 -12
  37. package/dist/containers/mp3/parse-mpeg-header.js +1 -1
  38. package/dist/containers/riff/expect-riff-box.d.ts +1 -2
  39. package/dist/containers/riff/expect-riff-box.js +4 -14
  40. package/dist/containers/riff/get-tracks-from-avi.js +1 -1
  41. package/dist/containers/riff/parse-list-box.js +3 -5
  42. package/dist/containers/riff/parse-movi.d.ts +2 -4
  43. package/dist/containers/riff/parse-movi.js +9 -27
  44. package/dist/containers/riff/parse-riff-body.js +17 -11
  45. package/dist/containers/riff/parse-riff-header.js +2 -7
  46. package/dist/containers/riff/parse-video-section.d.ts +1 -1
  47. package/dist/containers/riff/parse-video-section.js +5 -7
  48. package/dist/containers/transport-stream/adts-header.js +1 -0
  49. package/dist/containers/transport-stream/get-tracks.js +1 -1
  50. package/dist/containers/transport-stream/parse-packet.js +1 -1
  51. package/dist/containers/transport-stream/parse-transport-stream.js +3 -10
  52. package/dist/containers/transport-stream/process-stream-buffers.js +1 -1
  53. package/dist/containers/wav/get-duration-from-wav.js +1 -4
  54. package/dist/containers/wav/parse-data.js +6 -6
  55. package/dist/containers/wav/parse-fmt.js +2 -2
  56. package/dist/containers/wav/parse-header.js +2 -2
  57. package/dist/containers/wav/parse-id3.js +2 -4
  58. package/dist/containers/wav/parse-list.js +2 -2
  59. package/dist/containers/wav/parse-video-section.js +2 -5
  60. package/dist/containers/webm/av1-codec-private.js +1 -1
  61. package/dist/containers/webm/parse-ebml.js +1 -1
  62. package/dist/containers/webm/parse-webm-header.js +3 -10
  63. package/dist/controller.d.ts +17 -0
  64. package/dist/controller.js +31 -0
  65. package/dist/download-and-parse-media.d.ts +2 -0
  66. package/dist/download-and-parse-media.js +72 -0
  67. package/dist/emit-available-info.d.ts +2 -3
  68. package/dist/emit-available-info.js +36 -36
  69. package/dist/emitter.d.ts +20 -0
  70. package/dist/emitter.js +29 -0
  71. package/dist/errors.d.ts +4 -0
  72. package/dist/errors.js +13 -1
  73. package/dist/esm/from-fetch.mjs +134 -8
  74. package/dist/esm/from-node.mjs +8 -8
  75. package/dist/esm/from-web-file.mjs +14 -14
  76. package/dist/esm/index.mjs +3051 -2836
  77. package/dist/esm/node.mjs +113 -0
  78. package/dist/get-audio-codec.js +3 -0
  79. package/dist/get-dimensions.js +2 -2
  80. package/dist/get-duration.js +8 -8
  81. package/dist/get-fps.d.ts +4 -4
  82. package/dist/get-fps.js +16 -11
  83. package/dist/get-keyframes.d.ts +1 -2
  84. package/dist/get-keyframes.js +4 -3
  85. package/dist/get-location.d.ts +2 -2
  86. package/dist/get-location.js +2 -2
  87. package/dist/get-tracks.d.ts +3 -5
  88. package/dist/get-tracks.js +8 -14
  89. package/dist/has-all-info.js +3 -3
  90. package/dist/index.d.ts +132 -104
  91. package/dist/index.js +9 -1
  92. package/dist/init-video.d.ts +1 -1
  93. package/dist/init-video.js +8 -8
  94. package/dist/internal-parse-media.d.ts +2 -0
  95. package/dist/internal-parse-media.js +231 -0
  96. package/dist/make-hvc1-codec-strings.js +4 -4
  97. package/dist/media-parser-controller.d.ts +17 -0
  98. package/dist/media-parser-controller.js +31 -0
  99. package/dist/metadata/get-metadata.d.ts +2 -1
  100. package/dist/metadata/get-metadata.js +3 -2
  101. package/dist/metadata/metadata-from-iso.d.ts +2 -2
  102. package/dist/metadata/metadata-from-iso.js +2 -2
  103. package/dist/options.d.ts +60 -34
  104. package/dist/parse-and-download-media.d.ts +2 -0
  105. package/dist/parse-and-download-media.js +57 -0
  106. package/dist/parse-media.js +8 -202
  107. package/dist/parse-result.d.ts +2 -6
  108. package/dist/pause-signal.d.ts +11 -0
  109. package/dist/pause-signal.js +38 -0
  110. package/dist/perform-seek.d.ts +5 -8
  111. package/dist/perform-seek.js +17 -9
  112. package/dist/readers/from-fetch.js +11 -8
  113. package/dist/readers/from-node.js +8 -8
  114. package/dist/readers/from-web-file.js +16 -16
  115. package/dist/readers/reader.d.ts +8 -2
  116. package/dist/register-track.js +5 -0
  117. package/dist/remotion-license-acknowledge.d.ts +6 -0
  118. package/dist/remotion-license-acknowledge.js +17 -0
  119. package/dist/run-parse-iteration.d.ts +1 -1
  120. package/dist/run-parse-iteration.js +2 -2
  121. package/dist/skip.d.ts +5 -0
  122. package/dist/skip.js +8 -0
  123. package/dist/state/has-tracks-section.d.ts +3 -1
  124. package/dist/state/has-tracks-section.js +7 -1
  125. package/dist/state/iso-base-media/cached-sample-positions.d.ts +2 -2
  126. package/dist/state/iso-base-media/cached-sample-positions.js +12 -6
  127. package/dist/state/iso-base-media/iso-state.d.ts +6 -4
  128. package/dist/state/iso-base-media/iso-state.js +2 -5
  129. package/dist/state/iso-base-media/moov-box.d.ts +5 -0
  130. package/dist/state/iso-base-media/moov-box.js +13 -0
  131. package/dist/state/last-eventloop-break.d.ts +4 -0
  132. package/dist/state/last-eventloop-break.js +18 -0
  133. package/dist/state/parser-state.d.ts +124 -102
  134. package/dist/state/parser-state.js +22 -4
  135. package/dist/state/sample-callbacks.d.ts +5 -3
  136. package/dist/state/sample-callbacks.js +3 -3
  137. package/dist/state/structure.d.ts +7 -0
  138. package/dist/state/structure.js +56 -6
  139. package/dist/throttled-progress.d.ts +3 -2
  140. package/dist/throttled-progress.js +3 -3
  141. package/dist/version.d.ts +1 -1
  142. package/dist/version.js +1 -1
  143. package/dist/writers/node.d.ts +4 -0
  144. package/dist/writers/node.js +81 -0
  145. package/dist/writers/writer.d.ts +17 -0
  146. package/dist/writers/writer.js +2 -0
  147. package/package.json +12 -9
  148. package/LICENSE.md +0 -49
@@ -14,16 +14,16 @@ const get_sample_rate_1 = require("./get-sample-rate");
14
14
  const get_tracks_1 = require("./get-tracks");
15
15
  const get_video_codec_1 = require("./get-video-codec");
16
16
  const get_metadata_1 = require("./metadata/get-metadata");
17
- const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLength, name, mimeType, fieldsInReturnValue, }) => {
17
+ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name, mimeType, fieldsInReturnValue, }) => {
18
18
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
19
19
  const keys = Object.keys(hasInfo);
20
20
  const { emittedFields } = state;
21
21
  for (const key of keys) {
22
22
  if (key === 'structure') {
23
23
  if (hasInfo.structure && !emittedFields.structure) {
24
- (_a = callbacks.onStructure) === null || _a === void 0 ? void 0 : _a.call(callbacks, state.structure.getStructure());
24
+ await ((_a = callbacks.onStructure) === null || _a === void 0 ? void 0 : _a.call(callbacks, state.getStructure()));
25
25
  if (fieldsInReturnValue.structure) {
26
- returnValue.structure = state.structure.getStructure();
26
+ returnValue.structure = state.getStructure();
27
27
  }
28
28
  emittedFields.structure = true;
29
29
  }
@@ -33,7 +33,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
33
33
  if (hasInfo.durationInSeconds) {
34
34
  if (!emittedFields.durationInSeconds) {
35
35
  const durationInSeconds = (0, get_duration_1.getDuration)(state);
36
- (_b = callbacks.onDurationInSeconds) === null || _b === void 0 ? void 0 : _b.call(callbacks, durationInSeconds);
36
+ await ((_b = callbacks.onDurationInSeconds) === null || _b === void 0 ? void 0 : _b.call(callbacks, durationInSeconds));
37
37
  if (fieldsInReturnValue.durationInSeconds) {
38
38
  returnValue.durationInSeconds = durationInSeconds;
39
39
  }
@@ -46,7 +46,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
46
46
  if (hasInfo.slowDurationInSeconds &&
47
47
  !emittedFields.slowDurationInSeconds) {
48
48
  const slowDurationInSeconds = (_c = (0, get_duration_1.getDuration)(state)) !== null && _c !== void 0 ? _c : state.slowDurationAndFps.getSlowDurationInSeconds();
49
- (_d = callbacks.onSlowDurationInSeconds) === null || _d === void 0 ? void 0 : _d.call(callbacks, slowDurationInSeconds);
49
+ await ((_d = callbacks.onSlowDurationInSeconds) === null || _d === void 0 ? void 0 : _d.call(callbacks, slowDurationInSeconds));
50
50
  if (fieldsInReturnValue.slowDurationInSeconds) {
51
51
  returnValue.slowDurationInSeconds = slowDurationInSeconds;
52
52
  }
@@ -57,17 +57,17 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
57
57
  if (key === 'fps') {
58
58
  if (hasInfo.fps) {
59
59
  if (!emittedFields.fps) {
60
- const fps = (0, get_fps_1.getFps)(state.structure.getStructure());
61
- (_e = callbacks.onFps) === null || _e === void 0 ? void 0 : _e.call(callbacks, fps);
60
+ const fps = (0, get_fps_1.getFps)(state);
61
+ await ((_e = callbacks.onFps) === null || _e === void 0 ? void 0 : _e.call(callbacks, fps));
62
62
  if (fieldsInReturnValue.fps) {
63
63
  returnValue.fps = fps;
64
64
  }
65
65
  emittedFields.fps = true;
66
66
  }
67
67
  if (!emittedFields.slowFps) {
68
- const fps = (0, get_fps_1.getFps)(state.structure.getStructure());
68
+ const fps = (0, get_fps_1.getFps)(state);
69
69
  if (fps) {
70
- (_f = callbacks.onSlowFps) === null || _f === void 0 ? void 0 : _f.call(callbacks, fps);
70
+ await ((_f = callbacks.onSlowFps) === null || _f === void 0 ? void 0 : _f.call(callbacks, fps));
71
71
  if (fieldsInReturnValue.slowFps) {
72
72
  returnValue.slowFps = fps;
73
73
  }
@@ -81,7 +81,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
81
81
  if (key === 'slowFps') {
82
82
  if (hasInfo.slowFps && !emittedFields.slowFps) {
83
83
  const slowFps = state.slowDurationAndFps.getFps();
84
- (_g = callbacks.onSlowFps) === null || _g === void 0 ? void 0 : _g.call(callbacks, slowFps);
84
+ await ((_g = callbacks.onSlowFps) === null || _g === void 0 ? void 0 : _g.call(callbacks, slowFps));
85
85
  if (fieldsInReturnValue.slowFps) {
86
86
  returnValue.slowFps = slowFps;
87
87
  }
@@ -98,7 +98,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
98
98
  height: dimensionsQueried.height,
99
99
  width: dimensionsQueried.width,
100
100
  };
101
- (_h = callbacks.onDimensions) === null || _h === void 0 ? void 0 : _h.call(callbacks, dimensions);
101
+ await ((_h = callbacks.onDimensions) === null || _h === void 0 ? void 0 : _h.call(callbacks, dimensions));
102
102
  if (fieldsInReturnValue.dimensions) {
103
103
  returnValue.dimensions = dimensions;
104
104
  }
@@ -115,7 +115,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
115
115
  height: dimensionsQueried.unrotatedHeight,
116
116
  width: dimensionsQueried.unrotatedWidth,
117
117
  };
118
- (_j = callbacks.onUnrotatedDimensions) === null || _j === void 0 ? void 0 : _j.call(callbacks, unrotatedDimensions);
118
+ await ((_j = callbacks.onUnrotatedDimensions) === null || _j === void 0 ? void 0 : _j.call(callbacks, unrotatedDimensions));
119
119
  if (fieldsInReturnValue.unrotatedDimensions) {
120
120
  returnValue.unrotatedDimensions = unrotatedDimensions;
121
121
  }
@@ -127,7 +127,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
127
127
  if (hasInfo.rotation && !emittedFields.rotation) {
128
128
  const dimensionsQueried = (0, get_dimensions_1.getDimensions)(state);
129
129
  const rotation = (_k = dimensionsQueried === null || dimensionsQueried === void 0 ? void 0 : dimensionsQueried.rotation) !== null && _k !== void 0 ? _k : 0;
130
- (_l = callbacks.onRotation) === null || _l === void 0 ? void 0 : _l.call(callbacks, rotation);
130
+ await ((_l = callbacks.onRotation) === null || _l === void 0 ? void 0 : _l.call(callbacks, rotation));
131
131
  if (fieldsInReturnValue.rotation) {
132
132
  returnValue.rotation = rotation;
133
133
  }
@@ -138,7 +138,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
138
138
  if (key === 'videoCodec') {
139
139
  if (!emittedFields.videoCodec && hasInfo.videoCodec) {
140
140
  const videoCodec = (0, get_video_codec_1.getVideoCodec)(state);
141
- (_m = callbacks.onVideoCodec) === null || _m === void 0 ? void 0 : _m.call(callbacks, videoCodec);
141
+ await ((_m = callbacks.onVideoCodec) === null || _m === void 0 ? void 0 : _m.call(callbacks, videoCodec));
142
142
  if (fieldsInReturnValue.videoCodec) {
143
143
  returnValue.videoCodec = videoCodec;
144
144
  }
@@ -149,7 +149,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
149
149
  if (key === 'audioCodec') {
150
150
  if (!emittedFields.audioCodec && hasInfo.audioCodec) {
151
151
  const audioCodec = (0, get_audio_codec_1.getAudioCodec)(state);
152
- (_o = callbacks.onAudioCodec) === null || _o === void 0 ? void 0 : _o.call(callbacks, audioCodec);
152
+ await ((_o = callbacks.onAudioCodec) === null || _o === void 0 ? void 0 : _o.call(callbacks, audioCodec));
153
153
  if (fieldsInReturnValue.audioCodec) {
154
154
  returnValue.audioCodec = audioCodec;
155
155
  }
@@ -160,7 +160,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
160
160
  if (key === 'tracks') {
161
161
  if (!emittedFields.tracks && hasInfo.tracks) {
162
162
  const { videoTracks, audioTracks } = (0, get_tracks_1.getTracks)(state);
163
- (_p = callbacks.onTracks) === null || _p === void 0 ? void 0 : _p.call(callbacks, { videoTracks, audioTracks });
163
+ await ((_p = callbacks.onTracks) === null || _p === void 0 ? void 0 : _p.call(callbacks, { videoTracks, audioTracks }));
164
164
  if (fieldsInReturnValue.tracks) {
165
165
  returnValue.tracks = { videoTracks, audioTracks };
166
166
  }
@@ -181,9 +181,9 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
181
181
  }
182
182
  if (key === 'size') {
183
183
  if (!emittedFields.size && hasInfo.size) {
184
- (_q = callbacks.onSize) === null || _q === void 0 ? void 0 : _q.call(callbacks, contentLength);
184
+ await ((_q = callbacks.onSize) === null || _q === void 0 ? void 0 : _q.call(callbacks, state.contentLength));
185
185
  if (fieldsInReturnValue.size) {
186
- returnValue.size = contentLength;
186
+ returnValue.size = state.contentLength;
187
187
  }
188
188
  emittedFields.size = true;
189
189
  }
@@ -191,7 +191,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
191
191
  }
192
192
  if (key === 'mimeType') {
193
193
  if (!emittedFields.mimeType && hasInfo.mimeType) {
194
- (_r = callbacks.onMimeType) === null || _r === void 0 ? void 0 : _r.call(callbacks, mimeType);
194
+ await ((_r = callbacks.onMimeType) === null || _r === void 0 ? void 0 : _r.call(callbacks, mimeType));
195
195
  if (fieldsInReturnValue.mimeType) {
196
196
  returnValue.mimeType = mimeType;
197
197
  }
@@ -201,7 +201,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
201
201
  }
202
202
  if (key === 'name') {
203
203
  if (!emittedFields.name && hasInfo.name) {
204
- (_s = callbacks.onName) === null || _s === void 0 ? void 0 : _s.call(callbacks, name);
204
+ await ((_s = callbacks.onName) === null || _s === void 0 ? void 0 : _s.call(callbacks, name));
205
205
  if (fieldsInReturnValue.name) {
206
206
  returnValue.name = name;
207
207
  }
@@ -212,7 +212,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
212
212
  if (key === 'isHdr') {
213
213
  if (!returnValue.isHdr && hasInfo.isHdr) {
214
214
  const isHdr = (0, get_is_hdr_1.getIsHdr)(state);
215
- (_t = callbacks.onIsHdr) === null || _t === void 0 ? void 0 : _t.call(callbacks, isHdr);
215
+ await ((_t = callbacks.onIsHdr) === null || _t === void 0 ? void 0 : _t.call(callbacks, isHdr));
216
216
  if (fieldsInReturnValue.isHdr) {
217
217
  returnValue.isHdr = isHdr;
218
218
  }
@@ -222,8 +222,8 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
222
222
  }
223
223
  if (key === 'container') {
224
224
  if (!returnValue.container && hasInfo.container) {
225
- const container = (0, get_container_1.getContainer)(state.structure.getStructure());
226
- (_u = callbacks.onContainer) === null || _u === void 0 ? void 0 : _u.call(callbacks, container);
225
+ const container = (0, get_container_1.getContainer)(state.getStructure());
226
+ await ((_u = callbacks.onContainer) === null || _u === void 0 ? void 0 : _u.call(callbacks, container));
227
227
  if (fieldsInReturnValue.container) {
228
228
  returnValue.container = container;
229
229
  }
@@ -233,8 +233,8 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
233
233
  }
234
234
  if (key === 'metadata') {
235
235
  if (!emittedFields.metadata && hasInfo.metadata) {
236
- const metadata = (0, get_metadata_1.getMetadata)(state.structure.getStructure());
237
- (_v = callbacks.onMetadata) === null || _v === void 0 ? void 0 : _v.call(callbacks, metadata);
236
+ const metadata = (0, get_metadata_1.getMetadata)(state);
237
+ await ((_v = callbacks.onMetadata) === null || _v === void 0 ? void 0 : _v.call(callbacks, metadata));
238
238
  if (fieldsInReturnValue.metadata) {
239
239
  returnValue.metadata = metadata;
240
240
  }
@@ -244,8 +244,8 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
244
244
  }
245
245
  if (key === 'location') {
246
246
  if (!emittedFields.location && hasInfo.location) {
247
- const location = (0, get_location_1.getLocation)(state.structure.getStructure());
248
- (_w = callbacks.onLocation) === null || _w === void 0 ? void 0 : _w.call(callbacks, location);
247
+ const location = (0, get_location_1.getLocation)(state);
248
+ await ((_w = callbacks.onLocation) === null || _w === void 0 ? void 0 : _w.call(callbacks, location));
249
249
  if (fieldsInReturnValue.location) {
250
250
  returnValue.location = location;
251
251
  }
@@ -255,7 +255,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
255
255
  }
256
256
  if (key === 'slowKeyframes') {
257
257
  if (!emittedFields.slowKeyframes && hasInfo.slowKeyframes) {
258
- (_x = callbacks.onSlowKeyframes) === null || _x === void 0 ? void 0 : _x.call(callbacks, state.keyframes.getKeyframes());
258
+ await ((_x = callbacks.onSlowKeyframes) === null || _x === void 0 ? void 0 : _x.call(callbacks, state.keyframes.getKeyframes()));
259
259
  if (fieldsInReturnValue.slowKeyframes) {
260
260
  returnValue.slowKeyframes = state.keyframes.getKeyframes();
261
261
  }
@@ -265,7 +265,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
265
265
  }
266
266
  if (key === 'slowNumberOfFrames') {
267
267
  if (!emittedFields.slowNumberOfFrames && hasInfo.slowNumberOfFrames) {
268
- (_y = callbacks.onSlowNumberOfFrames) === null || _y === void 0 ? void 0 : _y.call(callbacks, state.slowDurationAndFps.getSlowNumberOfFrames());
268
+ await ((_y = callbacks.onSlowNumberOfFrames) === null || _y === void 0 ? void 0 : _y.call(callbacks, state.slowDurationAndFps.getSlowNumberOfFrames()));
269
269
  if (fieldsInReturnValue.slowNumberOfFrames) {
270
270
  returnValue.slowNumberOfFrames =
271
271
  state.slowDurationAndFps.getSlowNumberOfFrames();
@@ -276,7 +276,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
276
276
  }
277
277
  if (key === 'slowAudioBitrate') {
278
278
  if (!emittedFields.slowAudioBitrate && hasInfo.slowAudioBitrate) {
279
- (_z = callbacks.onSlowAudioBitrate) === null || _z === void 0 ? void 0 : _z.call(callbacks, state.slowDurationAndFps.getAudioBitrate());
279
+ await ((_z = callbacks.onSlowAudioBitrate) === null || _z === void 0 ? void 0 : _z.call(callbacks, state.slowDurationAndFps.getAudioBitrate()));
280
280
  if (fieldsInReturnValue.slowAudioBitrate) {
281
281
  returnValue.slowAudioBitrate =
282
282
  state.slowDurationAndFps.getAudioBitrate();
@@ -287,7 +287,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
287
287
  }
288
288
  if (key === 'slowVideoBitrate') {
289
289
  if (!emittedFields.slowVideoBitrate && hasInfo.slowVideoBitrate) {
290
- (_0 = callbacks.onSlowVideoBitrate) === null || _0 === void 0 ? void 0 : _0.call(callbacks, state.slowDurationAndFps.getVideoBitrate());
290
+ await ((_0 = callbacks.onSlowVideoBitrate) === null || _0 === void 0 ? void 0 : _0.call(callbacks, state.slowDurationAndFps.getVideoBitrate()));
291
291
  if (fieldsInReturnValue.slowVideoBitrate) {
292
292
  returnValue.slowVideoBitrate =
293
293
  state.slowDurationAndFps.getVideoBitrate();
@@ -298,9 +298,9 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
298
298
  }
299
299
  if (key === 'keyframes') {
300
300
  if (!emittedFields.keyframes && hasInfo.keyframes) {
301
- (_1 = callbacks.onKeyframes) === null || _1 === void 0 ? void 0 : _1.call(callbacks, (0, get_keyframes_1.getKeyframes)(state.structure.getStructure()));
301
+ await ((_1 = callbacks.onKeyframes) === null || _1 === void 0 ? void 0 : _1.call(callbacks, (0, get_keyframes_1.getKeyframes)(state)));
302
302
  if (fieldsInReturnValue.keyframes) {
303
- returnValue.keyframes = (0, get_keyframes_1.getKeyframes)(state.structure.getStructure());
303
+ returnValue.keyframes = (0, get_keyframes_1.getKeyframes)(state);
304
304
  }
305
305
  emittedFields.keyframes = true;
306
306
  }
@@ -308,7 +308,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
308
308
  }
309
309
  if (key === 'images') {
310
310
  if (!emittedFields.images && hasInfo.images) {
311
- (_2 = callbacks.onImages) === null || _2 === void 0 ? void 0 : _2.call(callbacks, state.images.images);
311
+ await ((_2 = callbacks.onImages) === null || _2 === void 0 ? void 0 : _2.call(callbacks, state.images.images));
312
312
  if (fieldsInReturnValue.images) {
313
313
  returnValue.images = state.images.images;
314
314
  }
@@ -319,7 +319,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
319
319
  if (key === 'sampleRate') {
320
320
  if (!emittedFields.sampleRate && hasInfo.sampleRate) {
321
321
  const sampleRate = (0, get_sample_rate_1.getSampleRate)(state);
322
- (_3 = callbacks.onSampleRate) === null || _3 === void 0 ? void 0 : _3.call(callbacks, sampleRate);
322
+ await ((_3 = callbacks.onSampleRate) === null || _3 === void 0 ? void 0 : _3.call(callbacks, sampleRate));
323
323
  if (fieldsInReturnValue.sampleRate) {
324
324
  returnValue.sampleRate = sampleRate;
325
325
  }
@@ -331,7 +331,7 @@ const emitAvailableInfo = ({ hasInfo, callbacks, state, returnValue, contentLeng
331
331
  if (!emittedFields.numberOfAudioChannels &&
332
332
  hasInfo.numberOfAudioChannels) {
333
333
  const numberOfAudioChannels = (0, get_number_of_audio_channels_1.getNumberOfAudioChannels)(state);
334
- (_4 = callbacks.onNumberOfAudioChannels) === null || _4 === void 0 ? void 0 : _4.call(callbacks, numberOfAudioChannels);
334
+ await ((_4 = callbacks.onNumberOfAudioChannels) === null || _4 === void 0 ? void 0 : _4.call(callbacks, numberOfAudioChannels));
335
335
  if (fieldsInReturnValue.numberOfAudioChannels) {
336
336
  returnValue.numberOfAudioChannels = numberOfAudioChannels;
337
337
  }
@@ -0,0 +1,20 @@
1
+ type MediaParserEventMap = {
2
+ pause: undefined;
3
+ resume: undefined;
4
+ };
5
+ export type MediaParserEventTypes = keyof MediaParserEventMap;
6
+ export type CallbackListener<T extends MediaParserEventTypes> = (data: {
7
+ detail: MediaParserEventMap[T];
8
+ }) => void;
9
+ type MediaParserListeners = {
10
+ [EventType in MediaParserEventTypes]: CallbackListener<EventType>[];
11
+ };
12
+ export declare class MediaParserEmitter {
13
+ listeners: MediaParserListeners;
14
+ addEventListener: <Q extends MediaParserEventTypes>(name: Q, callback: CallbackListener<Q>) => void;
15
+ removeEventListener: <Q extends MediaParserEventTypes>(name: Q, callback: CallbackListener<Q>) => void;
16
+ private dispatchEvent;
17
+ dispatchPause: () => void;
18
+ dispatchResume: () => void;
19
+ }
20
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaParserEmitter = void 0;
4
+ class MediaParserEmitter {
5
+ constructor() {
6
+ this.listeners = {
7
+ pause: [],
8
+ resume: [],
9
+ };
10
+ this.addEventListener = (name, callback) => {
11
+ this.listeners[name].push(callback);
12
+ };
13
+ this.removeEventListener = (name, callback) => {
14
+ this.listeners[name] = this.listeners[name].filter((l) => l !== callback);
15
+ };
16
+ this.dispatchPause = () => {
17
+ this.dispatchEvent('pause', undefined);
18
+ };
19
+ this.dispatchResume = () => {
20
+ this.dispatchEvent('resume', undefined);
21
+ };
22
+ }
23
+ dispatchEvent(dispatchName, context) {
24
+ this.listeners[dispatchName].forEach((callback) => {
25
+ callback({ detail: context });
26
+ });
27
+ }
28
+ }
29
+ exports.MediaParserEmitter = MediaParserEmitter;
package/dist/errors.d.ts CHANGED
@@ -65,4 +65,8 @@ export declare class IsAnUnsupportedAudioTypeError extends Error {
65
65
  audioType: UnsupportedAudioType | null;
66
66
  });
67
67
  }
68
+ export declare class MediaParserAbortError extends Error {
69
+ constructor(message: string);
70
+ }
71
+ export declare const hasBeenAborted: (error: unknown) => error is MediaParserAbortError;
68
72
  export {};
package/dist/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsAnUnsupportedAudioTypeError = exports.IsAnUnsupportedFileTypeError = exports.IsAPdfError = exports.IsAnImageError = exports.IsAGifError = void 0;
3
+ exports.hasBeenAborted = exports.MediaParserAbortError = exports.IsAnUnsupportedAudioTypeError = exports.IsAnUnsupportedFileTypeError = exports.IsAPdfError = exports.IsAnImageError = exports.IsAGifError = void 0;
4
4
  class IsAGifError extends Error {
5
5
  constructor({ message, mimeType, sizeInBytes, fileName, }) {
6
6
  super(message);
@@ -69,3 +69,15 @@ class IsAnUnsupportedAudioTypeError extends Error {
69
69
  }
70
70
  }
71
71
  exports.IsAnUnsupportedAudioTypeError = IsAnUnsupportedAudioTypeError;
72
+ class MediaParserAbortError extends Error {
73
+ constructor(message) {
74
+ super(message);
75
+ this.name = 'MediaParserAbortError';
76
+ this.cause = undefined;
77
+ }
78
+ }
79
+ exports.MediaParserAbortError = MediaParserAbortError;
80
+ const hasBeenAborted = (error) => {
81
+ return error instanceof MediaParserAbortError;
82
+ };
83
+ exports.hasBeenAborted = hasBeenAborted;
@@ -1,3 +1,129 @@
1
+ // src/errors.ts
2
+ class IsAGifError extends Error {
3
+ mimeType;
4
+ sizeInBytes;
5
+ fileName;
6
+ constructor({
7
+ message,
8
+ mimeType,
9
+ sizeInBytes,
10
+ fileName
11
+ }) {
12
+ super(message);
13
+ this.fileName = "IsAGifError";
14
+ this.mimeType = mimeType;
15
+ this.sizeInBytes = sizeInBytes;
16
+ this.fileName = fileName;
17
+ if (Error.captureStackTrace) {
18
+ Error.captureStackTrace(this, IsAGifError);
19
+ }
20
+ }
21
+ }
22
+
23
+ class IsAnImageError extends Error {
24
+ imageType;
25
+ dimensions;
26
+ mimeType;
27
+ sizeInBytes;
28
+ fileName;
29
+ constructor({
30
+ dimensions,
31
+ imageType,
32
+ message,
33
+ mimeType,
34
+ sizeInBytes,
35
+ fileName
36
+ }) {
37
+ super(message);
38
+ this.name = "IsAnImageError";
39
+ this.imageType = imageType;
40
+ this.dimensions = dimensions;
41
+ this.mimeType = mimeType;
42
+ this.sizeInBytes = sizeInBytes;
43
+ this.fileName = fileName;
44
+ if (Error.captureStackTrace) {
45
+ Error.captureStackTrace(this, IsAnImageError);
46
+ }
47
+ }
48
+ }
49
+
50
+ class IsAPdfError extends Error {
51
+ mimeType;
52
+ sizeInBytes;
53
+ fileName;
54
+ constructor({
55
+ message,
56
+ mimeType,
57
+ sizeInBytes,
58
+ fileName
59
+ }) {
60
+ super(message);
61
+ this.name = "IsAPdfError";
62
+ this.mimeType = mimeType;
63
+ this.sizeInBytes = sizeInBytes;
64
+ this.fileName = fileName;
65
+ if (Error.captureStackTrace) {
66
+ Error.captureStackTrace(this, IsAPdfError);
67
+ }
68
+ }
69
+ }
70
+
71
+ class IsAnUnsupportedFileTypeError extends Error {
72
+ mimeType;
73
+ sizeInBytes;
74
+ fileName;
75
+ constructor({
76
+ message,
77
+ mimeType,
78
+ sizeInBytes,
79
+ fileName
80
+ }) {
81
+ super(message);
82
+ this.name = "IsAnUnsupportedFileTypeError";
83
+ this.mimeType = mimeType;
84
+ this.sizeInBytes = sizeInBytes;
85
+ this.fileName = fileName;
86
+ if (Error.captureStackTrace) {
87
+ Error.captureStackTrace(this, IsAnUnsupportedFileTypeError);
88
+ }
89
+ }
90
+ }
91
+
92
+ class IsAnUnsupportedAudioTypeError extends Error {
93
+ mimeType;
94
+ sizeInBytes;
95
+ fileName;
96
+ audioType;
97
+ constructor({
98
+ message,
99
+ mimeType,
100
+ sizeInBytes,
101
+ fileName,
102
+ audioType
103
+ }) {
104
+ super(message);
105
+ this.name = "IsAnUnsupportedAudioTypeError";
106
+ this.mimeType = mimeType;
107
+ this.sizeInBytes = sizeInBytes;
108
+ this.fileName = fileName;
109
+ this.audioType = audioType;
110
+ if (Error.captureStackTrace) {
111
+ Error.captureStackTrace(this, IsAnUnsupportedAudioTypeError);
112
+ }
113
+ }
114
+ }
115
+
116
+ class MediaParserAbortError extends Error {
117
+ constructor(message) {
118
+ super(message);
119
+ this.name = "MediaParserAbortError";
120
+ this.cause = undefined;
121
+ }
122
+ }
123
+ var hasBeenAborted = (error) => {
124
+ return error instanceof MediaParserAbortError;
125
+ };
126
+
1
127
  // src/readers/from-fetch.ts
2
128
  function parseContentRange(input) {
3
129
  const matches = input.match(/^(\w+) ((\d+)-(\d+)|\*)\/(\d+|\*)$/);
@@ -31,7 +157,7 @@ var validateContentRangeAndDetectIfSupported = (actualRange, parsedContentRange,
31
157
  return { supportsContentRange: true };
32
158
  };
33
159
  var fetchReader = {
34
- read: async (src, range, signal) => {
160
+ read: async ({ src, range, controller }) => {
35
161
  if (typeof src !== "string") {
36
162
  throw new Error("src must be a string when using `fetchReader`");
37
163
  }
@@ -39,7 +165,7 @@ var fetchReader = {
39
165
  if (!resolvedUrl.startsWith("https://") && !resolvedUrl.startsWith("blob:") && !resolvedUrl.startsWith("http://")) {
40
166
  return Promise.reject(new Error(resolvedUrl + " is not a URL - needs to start with http:// or https:// or blob:. If you want to read a local file, pass `reader: nodeReader` to parseMedia()."));
41
167
  }
42
- const controller = new AbortController;
168
+ const ownController = new AbortController;
43
169
  const cache = typeof navigator !== "undefined" && navigator.userAgent.includes("Cloudflare-Workers") ? undefined : "no-store";
44
170
  const actualRange = range === null ? 0 : range;
45
171
  const res = await fetch(resolvedUrl, {
@@ -48,14 +174,14 @@ var fetchReader = {
48
174
  } : {
49
175
  Range: `bytes=${`${actualRange[0]}-${actualRange[1]}`}`
50
176
  },
51
- signal: controller.signal,
177
+ signal: ownController.signal,
52
178
  cache
53
179
  });
54
180
  const contentRange = res.headers.get("content-range");
55
181
  const parsedContentRange = contentRange ? parseContentRange(contentRange) : null;
56
182
  const { supportsContentRange } = validateContentRangeAndDetectIfSupported(actualRange, parsedContentRange, res.status);
57
- signal?.addEventListener("abort", () => {
58
- controller.abort(new Error("Aborted by user"));
183
+ controller._internals.signal.addEventListener("abort", () => {
184
+ ownController.abort(new MediaParserAbortError("Aborted by user"));
59
185
  }, { once: true });
60
186
  if (res.status.toString().startsWith("4") || res.status.toString().startsWith("5")) {
61
187
  throw new Error(`Server returned status code ${res.status} for ${src} and range ${actualRange}`);
@@ -69,8 +195,8 @@ var fetchReader = {
69
195
  const name = contentDisposition?.match(/filename="([^"]+)"/)?.[1];
70
196
  const fallbackName = src.split("/").pop();
71
197
  const reader = res.body.getReader();
72
- if (signal) {
73
- signal.addEventListener("abort", () => {
198
+ if (controller) {
199
+ controller._internals.signal.addEventListener("abort", () => {
74
200
  reader.cancel().catch(() => {
75
201
  });
76
202
  }, { once: true });
@@ -79,7 +205,7 @@ var fetchReader = {
79
205
  reader: {
80
206
  reader,
81
207
  abort: () => {
82
- controller.abort();
208
+ ownController.abort();
83
209
  }
84
210
  },
85
211
  contentLength,
@@ -3,23 +3,23 @@ import { createReadStream, statSync } from "fs";
3
3
  import { sep } from "path";
4
4
  import { Readable } from "stream";
5
5
  var nodeReader = {
6
- read: (src, range, signal) => {
6
+ read: ({ src, range, controller }) => {
7
7
  if (typeof src !== "string") {
8
8
  throw new Error("src must be a string when using `nodeReader`");
9
9
  }
10
- const controller = new AbortController;
10
+ const ownController = new AbortController;
11
11
  const stream = createReadStream(src, {
12
12
  start: range === null ? 0 : typeof range === "number" ? range : range[0],
13
13
  end: range === null ? Infinity : typeof range === "number" ? Infinity : range[1],
14
- signal: controller.signal
14
+ signal: ownController.signal
15
15
  });
16
- signal?.addEventListener("abort", () => {
17
- controller.abort();
16
+ controller._internals.signal.addEventListener("abort", () => {
17
+ ownController.abort();
18
18
  }, { once: true });
19
19
  const stats = statSync(src);
20
20
  const reader = Readable.toWeb(stream).getReader();
21
- if (signal) {
22
- signal.addEventListener("abort", () => {
21
+ if (controller) {
22
+ controller._internals.signal.addEventListener("abort", () => {
23
23
  reader.cancel().catch(() => {
24
24
  });
25
25
  }, { once: true });
@@ -28,7 +28,7 @@ var nodeReader = {
28
28
  reader: {
29
29
  reader,
30
30
  abort: () => {
31
- controller.abort();
31
+ ownController.abort();
32
32
  }
33
33
  },
34
34
  contentLength: stats.size,
@@ -1,21 +1,21 @@
1
1
  // src/readers/from-web-file.ts
2
2
  var webFileReader = {
3
- read: (file, range, signal) => {
4
- if (typeof file === "string") {
3
+ read: ({ src, range, controller }) => {
4
+ if (typeof src === "string") {
5
5
  throw new Error("`inputTypeFileReader` only supports `File` objects");
6
6
  }
7
- const part = range === null ? file : typeof range === "number" ? file.slice(range) : file.slice(range[0], range[1]);
7
+ const part = range === null ? src : typeof range === "number" ? src.slice(range) : src.slice(range[0], range[1]);
8
8
  const reader = new FileReader;
9
- reader.readAsArrayBuffer(file);
10
- const controller = new AbortController;
11
- if (controller) {
12
- controller.signal.addEventListener("abort", () => {
9
+ reader.readAsArrayBuffer(src);
10
+ const ownController = new AbortController;
11
+ if (ownController) {
12
+ ownController.signal.addEventListener("abort", () => {
13
13
  reader.abort();
14
14
  }, { once: true });
15
15
  }
16
- if (signal) {
17
- signal.addEventListener("abort", () => {
18
- controller.abort();
16
+ if (controller) {
17
+ controller._internals.signal.addEventListener("abort", () => {
18
+ ownController.abort();
19
19
  }, { once: true });
20
20
  }
21
21
  return new Promise((resolve, reject) => {
@@ -27,13 +27,13 @@ var webFileReader = {
27
27
  reader: streamReader,
28
28
  abort() {
29
29
  streamReader.cancel();
30
- controller.abort();
30
+ ownController.abort();
31
31
  }
32
32
  },
33
- contentLength: file.size,
34
- name: file.name,
33
+ contentLength: src.size,
34
+ name: src.name,
35
35
  supportsContentRange: true,
36
- contentType: file.type
36
+ contentType: src.type
37
37
  });
38
38
  };
39
39
  reader.onerror = (error) => {