@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
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMp3 = void 0;
4
+ const id3_1 = require("./id3");
5
+ const id3_v1_1 = require("./id3-v1");
6
+ const parse_mpeg_header_1 = require("./parse-mpeg-header");
7
+ const parseMp3 = async ({ iterator, state, }) => {
8
+ if (iterator.bytesRemaining() < 3) {
9
+ return {
10
+ skipTo: null,
11
+ };
12
+ }
13
+ const { returnToCheckpoint } = iterator.startCheckpoint();
14
+ const bytes = iterator.getSlice(3);
15
+ returnToCheckpoint();
16
+ // ID3 v1
17
+ if (bytes[0] === 0x54 && bytes[1] === 0x41 && bytes[2] === 0x47) {
18
+ (0, id3_v1_1.parseID3V1)(iterator);
19
+ return {
20
+ skipTo: null,
21
+ };
22
+ }
23
+ // ID3 v2 or v3
24
+ if (bytes[0] === 0x49 && bytes[1] === 0x44 && bytes[2] === 0x33) {
25
+ (0, id3_1.parseId3)({ iterator, state });
26
+ return {
27
+ skipTo: null,
28
+ };
29
+ }
30
+ if (bytes[0] === 0xff) {
31
+ await (0, parse_mpeg_header_1.parseMpegHeader)({
32
+ iterator,
33
+ state,
34
+ });
35
+ return {
36
+ skipTo: null,
37
+ };
38
+ }
39
+ throw new Error('Unknown MP3 header ' + JSON.stringify(bytes));
40
+ };
41
+ exports.parseMp3 = parseMp3;
@@ -0,0 +1,6 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParserState } from '../../state/parser-state';
3
+ export declare const parseMpegHeader: ({ iterator, state, }: {
4
+ iterator: BufferIterator;
5
+ state: ParserState;
6
+ }) => Promise<void>;
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ // spec: http://www.mp3-tech.org/programmer/frame_header.html
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.parseMpegHeader = void 0;
5
+ const register_track_1 = require("../../register-track");
6
+ const get_frame_length_1 = require("./get-frame-length");
7
+ const samples_per_mpeg_file_1 = require("./samples-per-mpeg-file");
8
+ function getSamplingFrequency({ bits, mpegVersion, }) {
9
+ const samplingTable = {
10
+ 0b00: { MPEG1: 44100, MPEG2: 22050 },
11
+ 0b01: { MPEG1: 48000, MPEG2: 24000 },
12
+ 0b10: { MPEG1: 32000, MPEG2: 16000 },
13
+ 0b11: { MPEG1: 'reserved', MPEG2: 'reserved' },
14
+ };
15
+ const key = `MPEG${mpegVersion}`;
16
+ const value = samplingTable[bits][key];
17
+ if (value === 'reserved') {
18
+ throw new Error('Reserved sampling frequency');
19
+ }
20
+ if (!value) {
21
+ throw new Error('Invalid sampling frequency for MPEG version: ' +
22
+ JSON.stringify({ bits, version: mpegVersion }));
23
+ }
24
+ return value;
25
+ }
26
+ function getBitrateKB({ bits, mpegVersion, level, }) {
27
+ const bitrateTable = {
28
+ 0b0000: {
29
+ 'V1,L1': 'free',
30
+ 'V1,L2': 'free',
31
+ 'V1,L3': 'free',
32
+ 'V2,L1': 'free',
33
+ 'V2,L2&L3': 'free',
34
+ },
35
+ 0b0001: { 'V1,L1': 32, 'V1,L2': 32, 'V1,L3': 32, 'V2,L1': 32, 'V2,L2&L3': 8 },
36
+ 0b0010: {
37
+ 'V1,L1': 64,
38
+ 'V1,L2': 48,
39
+ 'V1,L3': 40,
40
+ 'V2,L1': 48,
41
+ 'V2,L2&L3': 16,
42
+ },
43
+ 0b0011: {
44
+ 'V1,L1': 96,
45
+ 'V1,L2': 56,
46
+ 'V1,L3': 48,
47
+ 'V2,L1': 56,
48
+ 'V2,L2&L3': 24,
49
+ },
50
+ 0b0100: {
51
+ 'V1,L1': 128,
52
+ 'V1,L2': 64,
53
+ 'V1,L3': 56,
54
+ 'V2,L1': 64,
55
+ 'V2,L2&L3': 32,
56
+ },
57
+ 0b0101: {
58
+ 'V1,L1': 160,
59
+ 'V1,L2': 80,
60
+ 'V1,L3': 64,
61
+ 'V2,L1': 80,
62
+ 'V2,L2&L3': 40,
63
+ },
64
+ 0b0110: {
65
+ 'V1,L1': 192,
66
+ 'V1,L2': 96,
67
+ 'V1,L3': 80,
68
+ 'V2,L1': 96,
69
+ 'V2,L2&L3': 48,
70
+ },
71
+ 0b0111: {
72
+ 'V1,L1': 224,
73
+ 'V1,L2': 112,
74
+ 'V1,L3': 96,
75
+ 'V2,L1': 112,
76
+ 'V2,L2&L3': 56,
77
+ },
78
+ 0b1000: {
79
+ 'V1,L1': 256,
80
+ 'V1,L2': 128,
81
+ 'V1,L3': 112,
82
+ 'V2,L1': 128,
83
+ 'V2,L2&L3': 64,
84
+ },
85
+ 0b1001: {
86
+ 'V1,L1': 288,
87
+ 'V1,L2': 160,
88
+ 'V1,L3': 128,
89
+ 'V2,L1': 144,
90
+ 'V2,L2&L3': 80,
91
+ },
92
+ 0b1010: {
93
+ 'V1,L1': 320,
94
+ 'V1,L2': 192,
95
+ 'V1,L3': 160,
96
+ 'V2,L1': 160,
97
+ 'V2,L2&L3': 96,
98
+ },
99
+ 0b1011: {
100
+ 'V1,L1': 352,
101
+ 'V1,L2': 224,
102
+ 'V1,L3': 192,
103
+ 'V2,L1': 176,
104
+ 'V2,L2&L3': 112,
105
+ },
106
+ 0b1100: {
107
+ 'V1,L1': 384,
108
+ 'V1,L2': 256,
109
+ 'V1,L3': 224,
110
+ 'V2,L1': 192,
111
+ 'V2,L2&L3': 128,
112
+ },
113
+ 0b1101: {
114
+ 'V1,L1': 416,
115
+ 'V1,L2': 320,
116
+ 'V1,L3': 256,
117
+ 'V2,L1': 224,
118
+ 'V2,L2&L3': 144,
119
+ },
120
+ 0b1110: {
121
+ 'V1,L1': 448,
122
+ 'V1,L2': 384,
123
+ 'V1,L3': 320,
124
+ 'V2,L1': 256,
125
+ 'V2,L2&L3': 160,
126
+ },
127
+ 0b1111: {
128
+ 'V1,L1': 'bad',
129
+ 'V1,L2': 'bad',
130
+ 'V1,L3': 'bad',
131
+ 'V2,L1': 'bad',
132
+ 'V2,L2&L3': 'bad',
133
+ },
134
+ };
135
+ // Determine the correct key based on version and level
136
+ let key;
137
+ if (mpegVersion === 2 && (level === 2 || level === 3)) {
138
+ key = 'V2,L2&L3';
139
+ }
140
+ else {
141
+ key = `V${mpegVersion},L${level}`;
142
+ }
143
+ // Return the corresponding bitrate
144
+ return bitrateTable[bits][key];
145
+ }
146
+ const parseMpegHeader = async ({ iterator, state, }) => {
147
+ const initialOffset = iterator.counter.getOffset();
148
+ if (iterator.bytesRemaining() < 32) {
149
+ return;
150
+ }
151
+ iterator.startReadingBits();
152
+ for (let i = 0; i < 11; i++) {
153
+ const expectToBe1 = iterator.getBits(1);
154
+ if (expectToBe1 !== 1) {
155
+ throw new Error('Expected 1');
156
+ }
157
+ }
158
+ const audioVersionId = iterator.getBits(2);
159
+ /**
160
+ * 00 - MPEG Version 2.5 (later extension of MPEG 2)
161
+ 01 - reserved
162
+ 10 - MPEG Version 2 (ISO/IEC 13818-3)
163
+ 11 - MPEG Version 1 (ISO/IEC 11172-3)
164
+ */
165
+ if (audioVersionId !== 0b11 && audioVersionId !== 0b10) {
166
+ throw new Error('Expected MPEG Version 1 or 2');
167
+ }
168
+ const mpegVersion = audioVersionId === 0b11 ? 1 : 2;
169
+ const layerBits = iterator.getBits(2);
170
+ /**
171
+ * 00 - reserved
172
+ 01 - Layer III
173
+ 10 - Layer II
174
+ 11 - Layer I
175
+ */
176
+ if (layerBits === 0b00) {
177
+ throw new Error('Expected Layer I, II or III');
178
+ }
179
+ const layer = layerBits === 0b11 ? 1 : layerBits === 0b10 ? 2 : 3;
180
+ const protectionBit = iterator.getBits(1);
181
+ if (protectionBit !== 0b1) {
182
+ throw new Error('Does not support CRC yet');
183
+ }
184
+ const bitrateIndex = iterator.getBits(4);
185
+ const bitrateKbit = getBitrateKB({
186
+ bits: bitrateIndex,
187
+ mpegVersion,
188
+ level: audioVersionId,
189
+ });
190
+ if (bitrateKbit === 'bad') {
191
+ throw new Error('Invalid bitrate');
192
+ }
193
+ if (bitrateKbit === 'free') {
194
+ throw new Error('Free bitrate not supported');
195
+ }
196
+ const samplingFrequencyIndex = iterator.getBits(2);
197
+ const sampleRate = getSamplingFrequency({
198
+ bits: samplingFrequencyIndex,
199
+ mpegVersion,
200
+ });
201
+ const padding = Boolean(iterator.getBits(1));
202
+ iterator.getBits(1); // private bit
203
+ const channelMode = iterator.getBits(2); // channel mode
204
+ iterator.getBits(2); // mode extension
205
+ iterator.getBits(1); // copyright
206
+ iterator.getBits(1); // original
207
+ iterator.getBits(2); // emphasis
208
+ const numberOfChannels = channelMode === 0b11 ? 1 : 2;
209
+ const samplesPerFrame = (0, samples_per_mpeg_file_1.getSamplesPerMpegFrame)({ mpegVersion, layer });
210
+ const frameLength = (0, get_frame_length_1.getMpegFrameLength)({
211
+ bitrateKbit,
212
+ padding,
213
+ samplesPerFrame,
214
+ samplingFrequency: sampleRate,
215
+ layer,
216
+ });
217
+ iterator.stopReadingBits();
218
+ const offsetNow = iterator.counter.getOffset();
219
+ iterator.counter.decrement(offsetNow - initialOffset);
220
+ const data = iterator.getSlice(frameLength);
221
+ if (state.callbacks.tracks.getTracks().length === 0) {
222
+ state.mp3Info.setMp3Info({
223
+ layer,
224
+ mpegVersion,
225
+ sampleRate,
226
+ bitrateKbit,
227
+ startOfMpegStream: initialOffset,
228
+ });
229
+ await (0, register_track_1.registerTrack)({
230
+ container: 'mp3',
231
+ state,
232
+ track: {
233
+ type: 'audio',
234
+ codec: 'mp3',
235
+ codecPrivate: null,
236
+ codecWithoutConfig: 'mp3',
237
+ description: undefined,
238
+ numberOfChannels,
239
+ sampleRate,
240
+ timescale: 1000000,
241
+ trackId: 0,
242
+ trakBox: null,
243
+ },
244
+ });
245
+ state.callbacks.tracks.setIsDone();
246
+ }
247
+ const mp3Info = state.mp3Info.getMp3Info();
248
+ if (!mp3Info) {
249
+ throw new Error('No MP3 info by now');
250
+ }
251
+ const avgLength = (0, get_frame_length_1.getAverageMpegFrameLength)({
252
+ bitrateKbit,
253
+ layer,
254
+ samplesPerFrame,
255
+ samplingFrequency: sampleRate,
256
+ });
257
+ const nthFrame = Math.round((initialOffset - mp3Info.startOfMpegStream) / avgLength);
258
+ const durationInSeconds = samplesPerFrame / sampleRate;
259
+ const timeInSeconds = (nthFrame * samplesPerFrame) / sampleRate;
260
+ const timestamp = Math.round(timeInSeconds * 1000000);
261
+ const duration = Math.round(durationInSeconds * 1000000);
262
+ await state.callbacks.onAudioSample(0, {
263
+ data,
264
+ cts: timestamp,
265
+ dts: timestamp,
266
+ duration,
267
+ offset: initialOffset,
268
+ timescale: 1000000,
269
+ timestamp,
270
+ trackId: 0,
271
+ type: 'key',
272
+ });
273
+ };
274
+ exports.parseMpegHeader = parseMpegHeader;
@@ -0,0 +1,4 @@
1
+ export declare const getSamplesPerMpegFrame: ({ mpegVersion, layer, }: {
2
+ mpegVersion: 1 | 2;
3
+ layer: number;
4
+ }) => 384 | 1152 | 576;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSamplesPerMpegFrame = void 0;
4
+ const getSamplesPerMpegFrame = ({ mpegVersion, layer, }) => {
5
+ if (mpegVersion === 1) {
6
+ if (layer === 1) {
7
+ return 384;
8
+ }
9
+ if (layer === 2 || layer === 3) {
10
+ return 1152;
11
+ }
12
+ }
13
+ if (mpegVersion === 2) {
14
+ if (layer === 1) {
15
+ return 384;
16
+ }
17
+ if (layer === 2) {
18
+ return 1152;
19
+ }
20
+ if (layer === 3) {
21
+ return 576;
22
+ }
23
+ }
24
+ throw new Error('Invalid MPEG layer');
25
+ };
26
+ exports.getSamplesPerMpegFrame = getSamplesPerMpegFrame;
@@ -0,0 +1,13 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { Options, ParseMediaFields } from '../../options';
3
+ import type { ParseResult, RiffStructure } from '../../parse-result';
4
+ import type { ParserState } from '../../state/parser-state';
5
+ import type { RiffResult } from './expect-riff-box';
6
+ export declare const continueAfterRiffBoxResult: ({ result, structure, iterator, maxOffset, state: options, fields, }: {
7
+ result: RiffResult;
8
+ structure: RiffStructure;
9
+ iterator: BufferIterator;
10
+ maxOffset: number;
11
+ state: ParserState;
12
+ fields: Options<ParseMediaFields>;
13
+ }) => Promise<ParseResult>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.continueAfterRiffBoxResult = void 0;
4
+ const parse_riff_body_1 = require("./parse-riff-body");
5
+ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, state: options, fields, }) => {
6
+ if (result.type === 'incomplete') {
7
+ return Promise.resolve({
8
+ status: 'incomplete',
9
+ async continueParsing() {
10
+ return Promise.resolve((0, exports.continueAfterRiffBoxResult)({
11
+ result: await result.continueParsing(),
12
+ structure,
13
+ iterator,
14
+ maxOffset,
15
+ state: options,
16
+ fields,
17
+ }));
18
+ },
19
+ segments: structure,
20
+ skipTo: null,
21
+ });
22
+ }
23
+ if (result.type === 'complete' && result.box) {
24
+ structure.boxes.push(result.box);
25
+ }
26
+ return (0, parse_riff_body_1.parseRiffBody)({
27
+ iterator,
28
+ maxOffset,
29
+ state: options,
30
+ structure,
31
+ fields,
32
+ });
33
+ };
34
+ exports.continueAfterRiffBoxResult = continueAfterRiffBoxResult;
@@ -1,17 +1,11 @@
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 { RiffBox } from './riff-box';
5
4
  export type RiffResult = {
6
- type: 'incomplete';
7
- continueParsing: () => Promise<RiffResult>;
8
- } | {
9
- type: 'complete';
10
5
  box: RiffBox | null;
11
6
  skipTo: number | null;
12
7
  };
13
- export declare const expectRiffBox: ({ iterator, state, structure, }: {
8
+ export declare const expectRiffBox: ({ iterator, state, }: {
14
9
  iterator: BufferIterator;
15
10
  state: ParserState;
16
- structure: RiffStructure;
17
11
  }) => Promise<RiffResult>;
@@ -1,48 +1,71 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expectRiffBox = void 0;
4
+ const register_track_1 = require("../../register-track");
5
+ const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
4
6
  const is_movi_1 = require("./is-movi");
5
- const parse_movi_1 = require("./parse-movi");
6
7
  const parse_riff_box_1 = require("./parse-riff-box");
7
- const expectRiffBox = async ({ iterator, state, structure, }) => {
8
+ const parse_video_section_1 = require("./parse-video-section");
9
+ const expectRiffBox = async ({ iterator, state, }) => {
8
10
  // Need at least 16 bytes to read LIST,size,movi,size
9
11
  if (iterator.bytesRemaining() < 16) {
10
12
  return {
11
- type: 'incomplete',
12
- continueParsing() {
13
- return (0, exports.expectRiffBox)({ structure, iterator, state });
14
- },
13
+ box: null,
14
+ skipTo: null,
15
15
  };
16
16
  }
17
+ const checkpoint = iterator.startCheckpoint();
17
18
  const ckId = iterator.getByteString(4, false);
18
19
  const ckSize = iterator.getUint32Le();
19
20
  if ((0, is_movi_1.isMoviAtom)(iterator, ckId)) {
20
21
  iterator.discard(4);
21
- return (0, parse_movi_1.parseMovi)({
22
- iterator,
23
- maxOffset: ckSize + iterator.counter.getOffset() - 4,
24
- state,
25
- structure,
22
+ state.videoSection.setVideoSection({
23
+ start: iterator.counter.getOffset(),
24
+ size: ckSize - 4,
26
25
  });
26
+ return (0, parse_video_section_1.parseVideoSection)({ state, iterator });
27
27
  }
28
28
  if (iterator.bytesRemaining() < ckSize) {
29
- iterator.counter.decrement(8);
29
+ checkpoint.returnToCheckpoint();
30
30
  return {
31
- type: 'incomplete',
32
- continueParsing: () => {
33
- return (0, exports.expectRiffBox)({ structure, iterator, state });
34
- },
31
+ box: null,
32
+ skipTo: null,
35
33
  };
36
34
  }
35
+ const box = await (0, parse_riff_box_1.parseRiffBox)({
36
+ id: ckId,
37
+ iterator,
38
+ size: ckSize,
39
+ state,
40
+ });
41
+ if (box.type === 'strh-box') {
42
+ if (box.strf.type === 'strf-box-audio' && state.onAudioTrack) {
43
+ const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
44
+ index: state.riff.getNextTrackIndex(),
45
+ strf: box.strf,
46
+ });
47
+ await (0, register_track_1.registerTrack)({
48
+ state,
49
+ track: audioTrack,
50
+ container: 'avi',
51
+ });
52
+ }
53
+ if (state.onVideoTrack && box.strf.type === 'strf-box-video') {
54
+ const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
55
+ strh: box,
56
+ index: state.riff.getNextTrackIndex(),
57
+ strf: box.strf,
58
+ });
59
+ (0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
60
+ state,
61
+ track: videoTrack,
62
+ container: 'avi',
63
+ });
64
+ }
65
+ state.riff.incrementNextTrackIndex();
66
+ }
37
67
  return {
38
- type: 'complete',
39
- box: await (0, parse_riff_box_1.parseRiffBox)({
40
- id: ckId,
41
- iterator,
42
- size: ckSize,
43
- boxes: structure.boxes,
44
- state,
45
- }),
68
+ box,
46
69
  skipTo: null,
47
70
  };
48
71
  };
@@ -19,4 +19,4 @@ export declare const makeAviVideoTrack: ({ strh, strf, index, }: {
19
19
  index: number;
20
20
  }) => VideoTrack;
21
21
  export declare const getTracksFromAvi: (structure: RiffStructure, state: ParserState) => AllTracks;
22
- export declare const hasAllTracksFromAvi: (structure: RiffStructure, state: ParserState) => boolean;
22
+ export declare const hasAllTracksFromAvi: (state: ParserState) => boolean;
@@ -67,9 +67,6 @@ const makeAviVideoTrack = ({ strh, strf, index, }) => {
67
67
  };
68
68
  exports.makeAviVideoTrack = makeAviVideoTrack;
69
69
  const getTracksFromAvi = (structure, state) => {
70
- if (!(0, traversal_1.isRiffAvi)(structure)) {
71
- throw new Error('Not an AVI file');
72
- }
73
70
  const videoTracks = [];
74
71
  const audioTracks = [];
75
72
  const otherTracks = [];
@@ -77,10 +74,10 @@ const getTracksFromAvi = (structure, state) => {
77
74
  let i = 0;
78
75
  for (const box of boxes) {
79
76
  const strh = (0, traversal_1.getStrhBox)(box.children);
80
- const strf = (0, traversal_1.getStrfBox)(box.children);
81
- if (!strh || !strf) {
77
+ if (!strh) {
82
78
  continue;
83
79
  }
80
+ const { strf } = strh;
84
81
  if (strf.type === 'strf-box-video') {
85
82
  videoTracks.push((0, add_avc_profile_to_track_1.addAvcProfileToTrack)((0, exports.makeAviVideoTrack)({ strh, strf, index: i }), state.riff.getAvcProfile()));
86
83
  }
@@ -95,17 +92,16 @@ const getTracksFromAvi = (structure, state) => {
95
92
  return { audioTracks, otherTracks, videoTracks };
96
93
  };
97
94
  exports.getTracksFromAvi = getTracksFromAvi;
98
- const hasAllTracksFromAvi = (structure, state) => {
99
- if (!(0, traversal_1.isRiffAvi)(structure)) {
100
- throw new Error('Not an AVI file');
101
- }
95
+ const hasAllTracksFromAvi = (state) => {
102
96
  try {
97
+ const structure = state.structure.getStructure();
103
98
  const numberOfTracks = (0, exports.getNumberOfTracks)(structure);
104
99
  const tracks = (0, exports.getTracksFromAvi)(structure, state);
105
100
  return (tracks.videoTracks.length +
106
101
  tracks.audioTracks.length +
107
102
  tracks.otherTracks.length ===
108
- numberOfTracks);
103
+ numberOfTracks &&
104
+ !tracks.videoTracks.find((t) => t.codec === exports.TO_BE_OVERRIDDEN_LATER));
109
105
  }
110
106
  catch (_a) {
111
107
  return false;
@@ -1,13 +1,7 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { Options, ParseMediaFields } from '../../options';
3
- import type { ParseResult, RiffStructure } from '../../parse-result';
3
+ import type { ParseResult } from '../../parse-result';
4
4
  import type { ParserState } from '../../state/parser-state';
5
- export declare const parseRiffBody: ({ iterator, structure, maxOffset, state, }: {
6
- iterator: BufferIterator;
7
- structure: RiffStructure;
8
- maxOffset: number;
9
- state: ParserState;
10
- }) => Promise<ParseResult>;
11
5
  export declare const parseRiff: ({ iterator, state, fields, }: {
12
6
  iterator: BufferIterator;
13
7
  state: ParserState;