@remotion/media-parser 4.0.248 → 4.0.250

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 (162) hide show
  1. package/dist/boxes/avc/key.d.ts +1 -1
  2. package/dist/boxes/iso-base-media/continue-mdat-routine.d.ts +14 -0
  3. package/dist/boxes/iso-base-media/continue-mdat-routine.js +74 -0
  4. package/dist/boxes/iso-base-media/get-children.d.ts +8 -0
  5. package/dist/boxes/iso-base-media/get-children.js +23 -0
  6. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +3 -22
  7. package/dist/boxes/iso-base-media/mdat/mdat.js +80 -121
  8. package/dist/boxes/iso-base-media/moov/moov.d.ts +1 -6
  9. package/dist/boxes/iso-base-media/moov/moov.js +5 -15
  10. package/dist/boxes/iso-base-media/parse-all-children.d.ts +8 -0
  11. package/dist/boxes/iso-base-media/parse-all-children.js +20 -0
  12. package/dist/boxes/iso-base-media/parse-boxes.d.ts +7 -0
  13. package/dist/boxes/iso-base-media/parse-boxes.js +46 -0
  14. package/dist/boxes/iso-base-media/parse-mdat-partially.d.ts +9 -0
  15. package/dist/boxes/iso-base-media/parse-mdat-partially.js +24 -0
  16. package/dist/boxes/iso-base-media/process-box.d.ts +2 -29
  17. package/dist/boxes/iso-base-media/process-box.js +56 -367
  18. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +1 -4
  19. package/dist/boxes/iso-base-media/stsd/mebx.js +5 -15
  20. package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -12
  21. package/dist/boxes/iso-base-media/stsd/samples.js +24 -70
  22. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +1 -4
  23. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -5
  24. package/dist/boxes/iso-base-media/trak/trak.d.ts +1 -6
  25. package/dist/boxes/iso-base-media/trak/trak.js +5 -15
  26. package/dist/boxes/iso-base-media/traversal.d.ts +0 -2
  27. package/dist/boxes/iso-base-media/traversal.js +1 -12
  28. package/dist/boxes/mp3/get-duration.d.ts +2 -0
  29. package/dist/boxes/mp3/get-duration.js +30 -0
  30. package/dist/boxes/mp3/get-frame-length.d.ts +13 -0
  31. package/dist/boxes/mp3/get-frame-length.js +33 -0
  32. package/dist/boxes/mp3/get-metadata-from-mp3.d.ts +3 -0
  33. package/dist/boxes/mp3/get-metadata-from-mp3.js +8 -0
  34. package/dist/boxes/mp3/get-tracks-from-mp3.d.ts +4 -0
  35. package/dist/boxes/mp3/get-tracks-from-mp3.js +25 -0
  36. package/dist/boxes/mp3/id3-v1.d.ts +2 -0
  37. package/dist/boxes/mp3/id3-v1.js +12 -0
  38. package/dist/boxes/mp3/id3-v2.d.ts +0 -0
  39. package/dist/boxes/mp3/id3-v2.js +1 -0
  40. package/dist/boxes/mp3/id3.d.ts +6 -0
  41. package/dist/boxes/mp3/id3.js +80 -0
  42. package/dist/boxes/mp3/parse-mp3.d.ts +7 -0
  43. package/dist/boxes/mp3/parse-mp3.js +41 -0
  44. package/dist/boxes/mp3/parse-mpeg-header.d.ts +6 -0
  45. package/dist/boxes/mp3/parse-mpeg-header.js +274 -0
  46. package/dist/boxes/mp3/samples-per-mpeg-file.d.ts +4 -0
  47. package/dist/boxes/mp3/samples-per-mpeg-file.js +26 -0
  48. package/dist/boxes/riff/continue-after-riff-result.d.ts +13 -0
  49. package/dist/boxes/riff/continue-after-riff-result.js +34 -0
  50. package/dist/boxes/riff/expect-riff-box.d.ts +1 -7
  51. package/dist/boxes/riff/expect-riff-box.js +47 -24
  52. package/dist/boxes/riff/get-tracks-from-avi.d.ts +1 -1
  53. package/dist/boxes/riff/get-tracks-from-avi.js +6 -10
  54. package/dist/boxes/riff/parse-box.d.ts +1 -7
  55. package/dist/boxes/riff/parse-box.js +4 -120
  56. package/dist/boxes/riff/parse-fmt-box.d.ts +3 -2
  57. package/dist/boxes/riff/parse-fmt-box.js +7 -5
  58. package/dist/boxes/riff/parse-list-box.js +15 -14
  59. package/dist/boxes/riff/parse-movi.d.ts +2 -5
  60. package/dist/boxes/riff/parse-movi.js +34 -56
  61. package/dist/boxes/riff/parse-riff-body.d.ts +7 -0
  62. package/dist/boxes/riff/parse-riff-body.js +25 -0
  63. package/dist/boxes/riff/parse-riff-box.d.ts +1 -2
  64. package/dist/boxes/riff/parse-riff-box.js +2 -6
  65. package/dist/boxes/riff/parse-riff-header.d.ts +7 -0
  66. package/dist/boxes/riff/parse-riff-header.js +23 -0
  67. package/dist/boxes/riff/parse-riff.d.ts +7 -0
  68. package/dist/boxes/riff/parse-riff.js +15 -0
  69. package/dist/boxes/riff/parse-strf.d.ts +4 -4
  70. package/dist/boxes/riff/parse-strf.js +4 -8
  71. package/dist/boxes/riff/parse-strh.js +11 -0
  72. package/dist/boxes/riff/parse-video-section.d.ts +6 -0
  73. package/dist/boxes/riff/parse-video-section.js +20 -0
  74. package/dist/boxes/riff/riff-box.d.ts +4 -5
  75. package/dist/boxes/riff/traversal.d.ts +1 -2
  76. package/dist/boxes/riff/traversal.js +1 -6
  77. package/dist/boxes/transport-stream/get-tracks.d.ts +2 -3
  78. package/dist/boxes/transport-stream/get-tracks.js +4 -3
  79. package/dist/boxes/transport-stream/parse-packet.d.ts +1 -7
  80. package/dist/boxes/transport-stream/parse-packet.js +3 -4
  81. package/dist/boxes/transport-stream/parse-stream-packet.d.ts +1 -5
  82. package/dist/boxes/transport-stream/parse-stream-packet.js +10 -12
  83. package/dist/boxes/transport-stream/parse-transport-stream.d.ts +1 -7
  84. package/dist/boxes/transport-stream/parse-transport-stream.js +19 -49
  85. package/dist/boxes/transport-stream/process-stream-buffers.d.ts +1 -2
  86. package/dist/boxes/transport-stream/process-stream-buffers.js +3 -3
  87. package/dist/boxes/webm/parse-ebml.js +3 -0
  88. package/dist/boxes/webm/parse-webm-header.d.ts +2 -4
  89. package/dist/boxes/webm/parse-webm-header.js +41 -25
  90. package/dist/boxes/webm/segments/parse-children.d.ts +2 -16
  91. package/dist/boxes/webm/segments/parse-children.js +7 -130
  92. package/dist/boxes/webm/segments.d.ts +4 -8
  93. package/dist/boxes/webm/segments.js +41 -123
  94. package/dist/buffer-iterator.d.ts +6 -3
  95. package/dist/buffer-iterator.js +27 -16
  96. package/dist/bun-reader.d.ts +1 -0
  97. package/dist/bun-reader.js +17 -0
  98. package/dist/continue-mdat-routine.d.ts +17 -0
  99. package/dist/continue-mdat-routine.js +92 -0
  100. package/dist/emit-available-info.js +42 -28
  101. package/dist/esm/from-node.mjs +8 -9
  102. package/dist/esm/index.mjs +5133 -5085
  103. package/dist/file-types/detect-file-type.js +6 -2
  104. package/dist/get-audio-codec.d.ts +1 -1
  105. package/dist/get-audio-codec.js +3 -3
  106. package/dist/get-container.js +5 -1
  107. package/dist/get-dimensions.d.ts +1 -1
  108. package/dist/get-dimensions.js +4 -1
  109. package/dist/get-duration.js +6 -2
  110. package/dist/get-fields-from-callbacks.js +1 -0
  111. package/dist/get-fps.js +3 -0
  112. package/dist/get-is-hdr.d.ts +1 -1
  113. package/dist/get-is-hdr.js +3 -3
  114. package/dist/get-keyframes.js +1 -1
  115. package/dist/get-tracks.d.ts +2 -2
  116. package/dist/get-tracks.js +23 -15
  117. package/dist/get-video-codec.d.ts +1 -1
  118. package/dist/get-video-codec.js +3 -3
  119. package/dist/has-all-info.js +4 -3
  120. package/dist/index.d.ts +65 -21
  121. package/dist/index.js +1 -1
  122. package/dist/may-skip-video-data/may-skip-video-data.js +6 -2
  123. package/dist/may-skip-video-data/need-samples-for-fields.js +1 -0
  124. package/dist/metadata/get-metadata.d.ts +1 -0
  125. package/dist/metadata/get-metadata.js +16 -1
  126. package/dist/options.d.ts +12 -5
  127. package/dist/parse-media.js +88 -68
  128. package/dist/parse-result.d.ts +17 -19
  129. package/dist/parse-video.d.ts +3 -17
  130. package/dist/parse-video.js +52 -40
  131. package/dist/readers/from-node.js +7 -8
  132. package/dist/state/can-skip-tracks.d.ts +8 -1
  133. package/dist/state/can-skip-tracks.js +38 -26
  134. package/dist/state/emitted-fields.js +1 -0
  135. package/dist/state/images.d.ts +9 -0
  136. package/dist/state/images.js +14 -0
  137. package/dist/state/iso-base-media/cached-sample-positions.d.ts +15 -0
  138. package/dist/state/iso-base-media/cached-sample-positions.js +42 -0
  139. package/dist/state/iso-base-media/iso-state.d.ts +8 -0
  140. package/dist/state/iso-base-media/iso-state.js +15 -0
  141. package/dist/state/iso-state.d.ts +4 -0
  142. package/dist/state/iso-state.js +13 -0
  143. package/dist/state/mp3.d.ts +11 -0
  144. package/dist/state/mp3.js +13 -0
  145. package/dist/state/parser-state.d.ts +57 -11
  146. package/dist/state/parser-state.js +17 -2
  147. package/dist/state/sample-callbacks.d.ts +5 -1
  148. package/dist/state/sample-callbacks.js +8 -2
  149. package/dist/state/slow-duration-fps.d.ts +2 -1
  150. package/dist/state/slow-duration-fps.js +52 -18
  151. package/dist/state/transport-stream.d.ts +8 -0
  152. package/dist/state/transport-stream.js +11 -0
  153. package/dist/state/video-section.d.ts +16 -0
  154. package/dist/state/video-section.js +37 -0
  155. package/dist/state/webm.d.ts +15 -0
  156. package/dist/state/webm.js +32 -0
  157. package/dist/throttled-progress.d.ts +14 -0
  158. package/dist/throttled-progress.js +44 -0
  159. package/dist/version.d.ts +1 -1
  160. package/dist/version.js +1 -1
  161. package/package.json +3 -3
  162. package/test.json +663 -0
@@ -1,125 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRiff = exports.parseRiffBody = void 0;
4
- const get_tracks_1 = require("../../get-tracks");
3
+ exports.parseRiff = void 0;
5
4
  const has_all_info_1 = require("../../has-all-info");
6
- const register_track_1 = require("../../register-track");
7
- const expect_riff_box_1 = require("./expect-riff-box");
8
- const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
9
- const traversal_1 = require("./traversal");
10
- const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, state: options, }) => {
11
- if (result.type === 'incomplete') {
12
- return Promise.resolve({
13
- status: 'incomplete',
14
- async continueParsing() {
15
- return Promise.resolve(continueAfterRiffBoxResult({
16
- result: await result.continueParsing(),
17
- structure,
18
- iterator,
19
- maxOffset,
20
- state: options,
21
- }));
22
- },
23
- segments: structure,
24
- skipTo: null,
25
- });
26
- }
27
- if (result.type === 'complete' && result.box) {
28
- structure.boxes.push(result.box);
29
- }
30
- return (0, exports.parseRiffBody)({ iterator, maxOffset, state: options, structure });
31
- };
32
- const parseRiffBody = async ({ iterator, structure, maxOffset, state, }) => {
33
- while (iterator.bytesRemaining() > 0 &&
34
- iterator.counter.getOffset() < maxOffset) {
35
- const result = await (0, expect_riff_box_1.expectRiffBox)({
36
- iterator,
37
- state,
38
- structure,
39
- });
40
- if (result.type === 'complete' && result.skipTo !== null) {
41
- return {
42
- status: 'incomplete',
43
- skipTo: result.skipTo,
44
- continueParsing() {
45
- return Promise.resolve(continueAfterRiffBoxResult({
46
- iterator,
47
- maxOffset,
48
- state,
49
- result,
50
- structure,
51
- }));
52
- },
53
- };
54
- }
55
- if (result.type === 'incomplete') {
56
- return {
57
- status: 'incomplete',
58
- async continueParsing() {
59
- return Promise.resolve(continueAfterRiffBoxResult({
60
- iterator,
61
- maxOffset,
62
- state,
63
- result: await result.continueParsing(),
64
- structure,
65
- }));
66
- },
67
- skipTo: null,
68
- };
69
- }
70
- if (result.box === null) {
71
- continue;
72
- }
73
- structure.boxes.push(result.box);
74
- // When parsing an AVI
75
- if (result.box.type === 'list-box' && result.box.listType === 'hdrl') {
76
- const tracks = (0, get_tracks_1.getTracks)(structure, state);
77
- if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
78
- state.callbacks.tracks.setIsDone();
79
- }
80
- }
81
- // When parsing a WAV
82
- if (result.box.type === 'wave-format-box') {
83
- state.callbacks.tracks.setIsDone();
84
- }
85
- if (result.box.type === 'strf-box-video' ||
86
- result.box.type === 'strf-box-audio') {
87
- const strh = (0, traversal_1.getStrhBox)(structure.boxes);
88
- const strf = (0, traversal_1.getStrfBox)(structure.boxes);
89
- if (!strh || !strf) {
90
- throw new Error('strh or strf box missing');
91
- }
92
- if (strf.type === 'strf-box-audio' && state.onAudioTrack) {
93
- const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
94
- index: state.riff.getNextTrackIndex(),
95
- strf,
96
- });
97
- await (0, register_track_1.registerTrack)({
98
- state,
99
- track: audioTrack,
100
- container: 'avi',
101
- });
102
- }
103
- if (state.onVideoTrack && strf.type === 'strf-box-video') {
104
- const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
105
- strh,
106
- index: state.riff.getNextTrackIndex(),
107
- strf,
108
- });
109
- (0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
110
- state,
111
- track: videoTrack,
112
- container: 'avi',
113
- });
114
- }
115
- state.riff.incrementNextTrackIndex();
116
- }
117
- }
118
- return {
119
- status: 'done',
120
- };
121
- };
122
- exports.parseRiffBody = parseRiffBody;
5
+ const parse_riff_body_1 = require("./parse-riff-body");
123
6
  const parseRiff = ({ iterator, state, fields, }) => {
124
7
  const riff = iterator.getByteString(4, false);
125
8
  if (riff !== 'RIFF') {
@@ -141,11 +24,12 @@ const parseRiff = ({ iterator, state, fields, }) => {
141
24
  segments: structure,
142
25
  });
143
26
  }
144
- return (0, exports.parseRiffBody)({
27
+ return (0, parse_riff_body_1.parseRiffBody)({
145
28
  iterator,
146
29
  maxOffset: Infinity,
147
30
  state,
148
31
  structure,
32
+ fields,
149
33
  });
150
34
  };
151
35
  exports.parseRiff = parseRiff;
@@ -1,7 +1,8 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParserState } from '../../state/parser-state';
2
3
  import type { RiffBox } from './riff-box';
3
- export declare const parseFmtBox: ({ iterator, boxes, size, }: {
4
+ export declare const parseFmtBox: ({ iterator, size, state, }: {
4
5
  iterator: BufferIterator;
5
- boxes: RiffBox[];
6
6
  size: number;
7
+ state: ParserState;
7
8
  }) => RiffBox;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseFmtBox = void 0;
4
- const parseFmtBox = ({ iterator, boxes, size, }) => {
4
+ const parseFmtBox = ({ iterator, size, state, }) => {
5
5
  const box = iterator.startBox(size);
6
- const header = boxes.find((b) => b.type === 'riff-header');
7
- if (!header) {
8
- throw new Error('Expected RIFF header');
6
+ const structure = state.structure.getStructure();
7
+ const riffHeader = structure.boxes.find((b) => b.type === 'riff-header');
8
+ if (!riffHeader) {
9
+ throw new Error('Expected RIFF header to be parsed before fmt');
9
10
  }
10
- if (header.fileType !== 'WAVE') {
11
+ // TODO: Can we delete this?
12
+ if (riffHeader.fileType !== 'WAVE') {
11
13
  throw new Error('Only supporting WAVE type');
12
14
  }
13
15
  const wFormatTag = iterator.getUint16Le();
@@ -1,30 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseListBox = void 0;
4
- const parse_box_1 = require("./parse-box");
4
+ const expect_riff_box_1 = require("./expect-riff-box");
5
5
  const parseListBox = async ({ iterator, size, state, }) => {
6
6
  const counter = iterator.counter.getOffset();
7
7
  const listType = iterator.getByteString(4, false);
8
8
  if (listType === 'movi') {
9
9
  throw new Error('should not be handled here');
10
10
  }
11
- const structure = {
12
- type: 'riff',
13
- boxes: [],
14
- };
15
- const result = await (0, parse_box_1.parseRiffBody)({
16
- structure,
17
- iterator,
18
- maxOffset: counter + size,
19
- state,
20
- });
21
- if (result.status === 'incomplete') {
22
- throw new Error(`Should only parse complete boxes (${listType})`);
11
+ const boxes = [];
12
+ const maxOffset = counter + size;
13
+ while (iterator.counter.getOffset() < maxOffset) {
14
+ const result = await (0, expect_riff_box_1.expectRiffBox)({
15
+ iterator,
16
+ state,
17
+ });
18
+ if (result.box !== null) {
19
+ boxes.push(result.box);
20
+ }
21
+ else {
22
+ throw new Error('Unexpected result');
23
+ }
23
24
  }
24
25
  return {
25
26
  type: 'list-box',
26
27
  listType,
27
- children: structure.boxes,
28
+ children: boxes,
28
29
  };
29
30
  };
30
31
  exports.parseListBox = parseListBox;
@@ -1,17 +1,14 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { RiffStructure } from '../../parse-result';
3
2
  import type { ParserState } from '../../state/parser-state';
4
3
  import type { RiffResult } from './expect-riff-box';
5
- export declare const handleChunk: ({ iterator, state, structure, ckId, ckSize, }: {
4
+ export declare const handleChunk: ({ iterator, state, ckId, ckSize, }: {
6
5
  iterator: BufferIterator;
7
6
  state: ParserState;
8
- structure: RiffStructure;
9
7
  ckId: string;
10
8
  ckSize: number;
11
9
  }) => Promise<void>;
12
- export declare const parseMovi: ({ iterator, maxOffset, state, structure, }: {
10
+ export declare const parseMovi: ({ iterator, maxOffset, state, }: {
13
11
  iterator: BufferIterator;
14
12
  maxOffset: number;
15
13
  state: ParserState;
16
- structure: RiffStructure;
17
14
  }) => Promise<RiffResult>;
@@ -18,12 +18,12 @@ const getStrhForIndex = (structure, trackId) => {
18
18
  }
19
19
  return strh;
20
20
  };
21
- const handleChunk = async ({ iterator, state, structure, ckId, ckSize, }) => {
21
+ const handleChunk = async ({ iterator, state, ckId, ckSize, }) => {
22
22
  const offset = iterator.counter.getOffset();
23
23
  const videoChunk = ckId.match(/^([0-9]{2})dc$/);
24
24
  if (videoChunk) {
25
25
  const trackId = parseInt(videoChunk[1], 10);
26
- const strh = getStrhForIndex(structure, trackId);
26
+ const strh = getStrhForIndex(state.structure.getStructure(), trackId);
27
27
  const samplesPerSecond = strh.rate / strh.scale;
28
28
  const nthSample = state.callbacks.getSamplesForTrack(trackId);
29
29
  const timeInSec = nthSample / samplesPerSecond;
@@ -56,7 +56,7 @@ const handleChunk = async ({ iterator, state, structure, ckId, ckSize, }) => {
56
56
  const audioChunk = ckId.match(/^([0-9]{2})wb$/);
57
57
  if (audioChunk) {
58
58
  const trackId = parseInt(audioChunk[1], 10);
59
- const strh = getStrhForIndex(structure, trackId);
59
+ const strh = getStrhForIndex(state.structure.getStructure(), trackId);
60
60
  const samplesPerSecond = strh.rate / strh.scale;
61
61
  const nthSample = state.callbacks.getSamplesForTrack(trackId);
62
62
  const timeInSec = nthSample / samplesPerSecond;
@@ -81,66 +81,44 @@ const handleChunk = async ({ iterator, state, structure, ckId, ckSize, }) => {
81
81
  }
82
82
  };
83
83
  exports.handleChunk = handleChunk;
84
- const parseMovi = async ({ iterator, maxOffset, state, structure, }) => {
85
- while (iterator.counter.getOffset() < maxOffset) {
86
- if (iterator.bytesRemaining() < 8) {
87
- return {
88
- type: 'incomplete',
89
- continueParsing: () => {
90
- return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
91
- },
92
- };
93
- }
94
- const ckId = iterator.getByteString(4, false);
95
- const ckSize = iterator.getUint32Le();
96
- if ((0, may_skip_video_data_1.maySkipVideoData)({
97
- state,
98
- }) &&
99
- state.riff.getAvcProfile()) {
100
- return {
101
- type: 'complete',
102
- box: {
103
- type: 'movi-box',
104
- },
105
- skipTo: maxOffset,
106
- };
107
- }
108
- if (iterator.bytesRemaining() < ckSize) {
109
- iterator.counter.decrement(8);
110
- return {
111
- type: 'incomplete',
112
- continueParsing: () => {
113
- return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
114
- },
115
- };
116
- }
117
- await (0, exports.handleChunk)({ iterator, state, structure, ckId, ckSize });
118
- // Discard added zeroes
119
- while (iterator.counter.getOffset() < maxOffset &&
120
- iterator.bytesRemaining() > 0) {
121
- if (iterator.getUint8() !== 0) {
122
- iterator.counter.decrement(1);
123
- break;
124
- }
125
- }
84
+ const parseMovi = async ({ iterator, maxOffset, state, }) => {
85
+ if ((0, may_skip_video_data_1.maySkipVideoData)({
86
+ state,
87
+ }) &&
88
+ state.riff.getAvcProfile()) {
89
+ return {
90
+ box: null,
91
+ skipTo: maxOffset,
92
+ };
126
93
  }
127
- if (iterator.counter.getOffset() === maxOffset) {
94
+ if (iterator.bytesRemaining() < 8) {
128
95
  return {
129
- type: 'complete',
130
- box: {
131
- type: 'movi-box',
132
- },
96
+ box: null,
133
97
  skipTo: null,
134
98
  };
135
99
  }
136
- if (iterator.counter.getOffset() > maxOffset) {
137
- throw new Error('Oops, this should not happen!');
100
+ const checkpoint = iterator.startCheckpoint();
101
+ const ckId = iterator.getByteString(4, false);
102
+ const ckSize = iterator.getUint32Le();
103
+ if (iterator.bytesRemaining() < ckSize) {
104
+ checkpoint.returnToCheckpoint();
105
+ return {
106
+ box: null,
107
+ skipTo: null,
108
+ };
109
+ }
110
+ await (0, exports.handleChunk)({ iterator, state, ckId, ckSize });
111
+ // Discard added zeroes
112
+ while (iterator.counter.getOffset() < maxOffset &&
113
+ iterator.bytesRemaining() > 0) {
114
+ if (iterator.getUint8() !== 0) {
115
+ iterator.counter.decrement(1);
116
+ break;
117
+ }
138
118
  }
139
119
  return {
140
- type: 'incomplete',
141
- continueParsing: () => {
142
- return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, state, structure }));
143
- },
120
+ box: null,
121
+ skipTo: null,
144
122
  };
145
123
  };
146
124
  exports.parseMovi = parseMovi;
@@ -0,0 +1,7 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParseResult } from '../../parse-result';
3
+ import type { ParserState } from '../../state/parser-state';
4
+ export declare const parseRiffBody: ({ iterator, state, }: {
5
+ iterator: BufferIterator;
6
+ state: ParserState;
7
+ }) => Promise<ParseResult>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRiffBody = void 0;
4
+ const expect_riff_box_1 = require("./expect-riff-box");
5
+ const parse_video_section_1 = require("./parse-video-section");
6
+ const parseRiffBody = async ({ iterator, state, }) => {
7
+ if (state.videoSection.isInVideoSectionState(iterator) === 'in-section') {
8
+ const videoSec = await (0, parse_video_section_1.parseVideoSection)({ state, iterator });
9
+ return {
10
+ skipTo: videoSec.skipTo,
11
+ };
12
+ }
13
+ const result = await (0, expect_riff_box_1.expectRiffBox)({
14
+ iterator,
15
+ state,
16
+ });
17
+ if (result.box !== null) {
18
+ const structure = state.structure.getStructure();
19
+ structure.boxes.push(result.box);
20
+ }
21
+ return {
22
+ skipTo: result.skipTo,
23
+ };
24
+ };
25
+ exports.parseRiffBody = parseRiffBody;
@@ -1,10 +1,9 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { ParserState } from '../../state/parser-state';
3
3
  import type { RiffBox } from './riff-box';
4
- export declare const parseRiffBox: ({ iterator, size, id, boxes, state, }: {
4
+ export declare const parseRiffBox: ({ iterator, size, id, state, }: {
5
5
  iterator: BufferIterator;
6
6
  size: number;
7
7
  id: string;
8
- boxes: RiffBox[];
9
8
  state: ParserState;
10
9
  }) => Promise<RiffBox>;
@@ -5,11 +5,10 @@ const parse_avih_1 = require("./parse-avih");
5
5
  const parse_fmt_box_1 = require("./parse-fmt-box");
6
6
  const parse_isft_1 = require("./parse-isft");
7
7
  const parse_list_box_1 = require("./parse-list-box");
8
- const parse_strf_1 = require("./parse-strf");
9
8
  const parse_strh_1 = require("./parse-strh");
10
- const parseRiffBox = ({ iterator, size, id, boxes, state, }) => {
9
+ const parseRiffBox = ({ iterator, size, id, state, }) => {
11
10
  if (id === 'fmt') {
12
- return Promise.resolve((0, parse_fmt_box_1.parseFmtBox)({ iterator, boxes, size }));
11
+ return Promise.resolve((0, parse_fmt_box_1.parseFmtBox)({ iterator, size, state }));
13
12
  }
14
13
  if (id === 'LIST') {
15
14
  return (0, parse_list_box_1.parseListBox)({ iterator, size, state });
@@ -23,9 +22,6 @@ const parseRiffBox = ({ iterator, size, id, boxes, state, }) => {
23
22
  if (id === 'strh') {
24
23
  return Promise.resolve((0, parse_strh_1.parseStrh)({ iterator, size }));
25
24
  }
26
- if (id === 'strf') {
27
- return Promise.resolve((0, parse_strf_1.parseStrf)({ iterator, size, boxes }));
28
- }
29
25
  iterator.discard(size);
30
26
  const box = {
31
27
  type: 'riff-box',
@@ -0,0 +1,7 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParseResult } from '../../parse-result';
3
+ import type { ParserState } from '../../state/parser-state';
4
+ export declare const parseRiffHeader: ({ iterator, state, }: {
5
+ iterator: BufferIterator;
6
+ state: ParserState;
7
+ }) => ParseResult;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRiffHeader = void 0;
4
+ const parseRiffHeader = ({ iterator, state, }) => {
5
+ const riff = iterator.getByteString(4, false);
6
+ if (riff !== 'RIFF') {
7
+ throw new Error('Not a RIFF file');
8
+ }
9
+ const structure = state.structure.getStructure();
10
+ if (structure.type !== 'riff') {
11
+ throw new Error('Structure is not a RIFF structure');
12
+ }
13
+ const size = iterator.getUint32Le();
14
+ const fileType = iterator.getByteString(4, false);
15
+ if (fileType !== 'WAVE' && fileType !== 'AVI') {
16
+ throw new Error(`File type ${fileType} not supported`);
17
+ }
18
+ structure.boxes.push({ type: 'riff-header', fileSize: size, fileType });
19
+ return {
20
+ skipTo: null,
21
+ };
22
+ };
23
+ exports.parseRiffHeader = parseRiffHeader;
@@ -0,0 +1,7 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParseResult } from '../../parse-result';
3
+ import type { ParserState } from '../../state/parser-state';
4
+ export declare const parseRiff: ({ iterator, state, }: {
5
+ iterator: BufferIterator;
6
+ state: ParserState;
7
+ }) => Promise<ParseResult>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRiff = void 0;
4
+ const parse_riff_body_1 = require("./parse-riff-body");
5
+ const parse_riff_header_1 = require("./parse-riff-header");
6
+ const parseRiff = ({ iterator, state, }) => {
7
+ if (iterator.counter.getOffset() === 0) {
8
+ return Promise.resolve((0, parse_riff_header_1.parseRiffHeader)({ iterator, state }));
9
+ }
10
+ return (0, parse_riff_body_1.parseRiffBody)({
11
+ iterator,
12
+ state,
13
+ });
14
+ };
15
+ exports.parseRiff = parseRiff;
@@ -1,7 +1,7 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
- import type { RiffBox } from './riff-box';
3
- export declare const parseStrf: ({ iterator, size, boxes, }: {
2
+ import type { FccType, StrfBoxAudio, StrfBoxVideo } from './riff-box';
3
+ export declare const parseStrf: ({ iterator, size, fccType, }: {
4
4
  iterator: BufferIterator;
5
5
  size: number;
6
- boxes: RiffBox[];
7
- }) => RiffBox;
6
+ fccType: FccType;
7
+ }) => StrfBoxAudio | StrfBoxVideo;
@@ -51,17 +51,13 @@ const parseStrfVideo = ({ iterator, size, }) => {
51
51
  yPelsPerMeter,
52
52
  };
53
53
  };
54
- const parseStrf = ({ iterator, size, boxes, }) => {
55
- const strh = boxes.find((b) => b.type === 'strh-box');
56
- if (!strh) {
57
- throw new Error('strh box not found');
58
- }
59
- if (strh.fccType === 'vids') {
54
+ const parseStrf = ({ iterator, size, fccType, }) => {
55
+ if (fccType === 'vids') {
60
56
  return parseStrfVideo({ iterator, size });
61
57
  }
62
- if (strh.fccType === 'auds') {
58
+ if (fccType === 'auds') {
63
59
  return parseStrfAudio({ iterator, size });
64
60
  }
65
- throw new Error(`Unsupported fccType: ${strh.fccType}`);
61
+ throw new Error(`Unsupported fccType: ${fccType}`);
66
62
  };
67
63
  exports.parseStrf = parseStrf;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseStrh = void 0;
4
+ const parse_strf_1 = require("./parse-strf");
4
5
  const parseStrh = ({ iterator, size, }) => {
5
6
  const box = iterator.startBox(size);
6
7
  const fccType = iterator.getByteString(4, false);
@@ -28,6 +29,15 @@ const parseStrh = ({ iterator, size, }) => {
28
29
  const quality = iterator.getUint32Le();
29
30
  const sampleSize = iterator.getUint32Le();
30
31
  box.discardRest();
32
+ const ckId = iterator.getByteString(4, false);
33
+ const ckSize = iterator.getUint32Le();
34
+ if (ckId !== 'strf') {
35
+ throw new Error(`Expected strf, got ${JSON.stringify(ckId)}`);
36
+ }
37
+ if (iterator.bytesRemaining() < ckSize) {
38
+ throw new Error('Expected strf to be complete');
39
+ }
40
+ const strf = (0, parse_strf_1.parseStrf)({ iterator, size: ckSize, fccType });
31
41
  return {
32
42
  type: 'strh-box',
33
43
  fccType,
@@ -43,6 +53,7 @@ const parseStrh = ({ iterator, size, }) => {
43
53
  start,
44
54
  suggestedBufferSize,
45
55
  language,
56
+ strf,
46
57
  };
47
58
  };
48
59
  exports.parseStrh = parseStrh;
@@ -0,0 +1,6 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParserState } from '../../state/parser-state';
3
+ export declare const parseVideoSection: ({ state, iterator, }: {
4
+ state: ParserState;
5
+ iterator: BufferIterator;
6
+ }) => Promise<import("./expect-riff-box").RiffResult>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseVideoSection = void 0;
4
+ const get_tracks_1 = require("../../get-tracks");
5
+ const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
6
+ const parse_movi_1 = require("./parse-movi");
7
+ const parseVideoSection = ({ state, iterator, }) => {
8
+ const videoSection = state.videoSection.getVideoSection();
9
+ const movi = (0, parse_movi_1.parseMovi)({
10
+ iterator,
11
+ maxOffset: videoSection.start + videoSection.size,
12
+ state,
13
+ });
14
+ const tracks = (0, get_tracks_1.getTracks)(state);
15
+ if (!tracks.videoTracks.some((t) => t.codec === get_tracks_from_avi_1.TO_BE_OVERRIDDEN_LATER)) {
16
+ state.callbacks.tracks.setIsDone();
17
+ }
18
+ return movi;
19
+ };
20
+ exports.parseVideoSection = parseVideoSection;
@@ -30,9 +30,10 @@ export type AvihBox = {
30
30
  width: number;
31
31
  height: number;
32
32
  };
33
+ export type FccType = 'vids' | 'auds';
33
34
  export type StrhBox = {
34
35
  type: 'strh-box';
35
- fccType: 'vids' | 'auds';
36
+ fccType: FccType;
36
37
  handler: 'H264' | number;
37
38
  flags: number;
38
39
  priority: number;
@@ -45,6 +46,7 @@ export type StrhBox = {
45
46
  quality: number;
46
47
  sampleSize: number;
47
48
  language: number;
49
+ strf: StrfBoxVideo | StrfBoxAudio;
48
50
  };
49
51
  export type StrfBoxVideo = {
50
52
  type: 'strf-box-video';
@@ -75,11 +77,8 @@ export type RiffHeader = {
75
77
  fileSize: number;
76
78
  fileType: string;
77
79
  };
78
- export type MoviBox = {
79
- type: 'movi-box';
80
- };
81
80
  export type IsftBox = {
82
81
  type: 'isft-box';
83
82
  software: string;
84
83
  };
85
- export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox | AvihBox | StrhBox | StrfBoxVideo | StrfBoxAudio | MoviBox | IsftBox;
84
+ export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox | AvihBox | StrhBox | StrfBoxVideo | StrfBoxAudio | IsftBox;
@@ -1,8 +1,7 @@
1
1
  import type { RiffStructure } from '../../parse-result';
2
- import type { AvihBox, ListBox, RiffBox, StrfBoxAudio, StrfBoxVideo, StrhBox } from './riff-box';
2
+ import type { AvihBox, ListBox, RiffBox, StrhBox } from './riff-box';
3
3
  export declare const isRiffAvi: (structure: RiffStructure) => boolean;
4
4
  export declare const getHdlrBox: (structure: RiffStructure) => ListBox | null;
5
5
  export declare const getAvihBox: (structure: RiffStructure) => AvihBox | null;
6
6
  export declare const getStrlBoxes: (structure: RiffStructure) => ListBox[];
7
7
  export declare const getStrhBox: (strlBoxChildren: RiffBox[]) => StrhBox | null;
8
- export declare const getStrfBox: (strlBoxChildren: RiffBox[]) => StrfBoxAudio | StrfBoxVideo | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStrfBox = exports.getStrhBox = exports.getStrlBoxes = exports.getAvihBox = exports.getHdlrBox = exports.isRiffAvi = void 0;
3
+ exports.getStrhBox = exports.getStrlBoxes = exports.getAvihBox = exports.getHdlrBox = exports.isRiffAvi = void 0;
4
4
  const isRiffAvi = (structure) => {
5
5
  return structure.boxes.some((box) => box.type === 'riff-header' && box.fileType === 'AVI');
6
6
  };
@@ -29,8 +29,3 @@ const getStrhBox = (strlBoxChildren) => {
29
29
  return strlBoxChildren.find((box) => box.type === 'strh-box');
30
30
  };
31
31
  exports.getStrhBox = getStrhBox;
32
- const getStrfBox = (strlBoxChildren) => {
33
- var _a;
34
- return ((_a = strlBoxChildren.find((box) => box.type === 'strf-box-audio' || box.type === 'strf-box-video')) !== null && _a !== void 0 ? _a : null);
35
- };
36
- exports.getStrfBox = getStrfBox;