@remotion/media-parser 4.0.231 → 4.0.232

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 (95) hide show
  1. package/dist/add-avc-profile-to-track.d.ts +3 -0
  2. package/dist/add-avc-profile-to-track.js +35 -0
  3. package/dist/add-new-matroska-tracks.d.ts +6 -1
  4. package/dist/add-new-matroska-tracks.js +16 -1
  5. package/dist/boxes/avc/parse-avc.d.ts +18 -0
  6. package/dist/boxes/avc/parse-avc.js +96 -0
  7. package/dist/boxes/iso-base-media/make-track.js +3 -3
  8. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -2
  9. package/dist/boxes/iso-base-media/mdat/mdat.js +5 -2
  10. package/dist/boxes/iso-base-media/moov/moov.js +2 -2
  11. package/dist/boxes/iso-base-media/process-box.d.ts +5 -5
  12. package/dist/boxes/iso-base-media/process-box.js +38 -37
  13. package/dist/boxes/iso-base-media/stsd/mebx.js +2 -2
  14. package/dist/boxes/iso-base-media/stsd/samples.d.ts +2 -2
  15. package/dist/boxes/iso-base-media/stsd/samples.js +9 -9
  16. package/dist/boxes/iso-base-media/trak/trak.js +2 -2
  17. package/dist/boxes/iso-base-media/traversal.d.ts +1 -1
  18. package/dist/boxes/riff/expect-riff-box.d.ts +16 -0
  19. package/dist/boxes/riff/expect-riff-box.js +49 -0
  20. package/dist/boxes/riff/get-tracks-from-avi.d.ts +21 -0
  21. package/dist/boxes/riff/get-tracks-from-avi.js +108 -0
  22. package/dist/boxes/riff/is-movi.d.ts +2 -0
  23. package/dist/boxes/riff/is-movi.js +12 -0
  24. package/dist/boxes/riff/parse-avih.d.ts +6 -0
  25. package/dist/boxes/riff/parse-avih.js +32 -0
  26. package/dist/boxes/riff/parse-box.d.ts +13 -0
  27. package/dist/boxes/riff/parse-box.js +113 -0
  28. package/dist/boxes/riff/parse-fmt-box.d.ts +7 -0
  29. package/dist/boxes/riff/parse-fmt-box.js +33 -0
  30. package/dist/boxes/riff/parse-list-box.d.ts +8 -0
  31. package/dist/boxes/riff/parse-list-box.js +30 -0
  32. package/dist/boxes/riff/parse-movi.d.ts +17 -0
  33. package/dist/boxes/riff/parse-movi.js +122 -0
  34. package/dist/boxes/riff/parse-riff-box.d.ts +10 -0
  35. package/dist/boxes/riff/parse-riff-box.js +33 -0
  36. package/dist/boxes/riff/parse-strf.d.ts +7 -0
  37. package/dist/boxes/riff/parse-strf.js +67 -0
  38. package/dist/boxes/riff/parse-strh.d.ts +6 -0
  39. package/dist/boxes/riff/parse-strh.js +46 -0
  40. package/dist/boxes/riff/riff-box.d.ts +81 -0
  41. package/dist/boxes/riff/riff-box.js +2 -0
  42. package/dist/boxes/riff/strf.d.ts +7 -0
  43. package/dist/boxes/riff/strf.js +67 -0
  44. package/dist/boxes/riff/timescale.d.ts +1 -0
  45. package/dist/boxes/riff/timescale.js +4 -0
  46. package/dist/boxes/riff/traversal.d.ts +8 -0
  47. package/dist/boxes/riff/traversal.js +36 -0
  48. package/dist/boxes/webm/parse-ebml.js +2 -2
  49. package/dist/boxes/webm/parse-webm-header.d.ts +2 -2
  50. package/dist/boxes/webm/parse-webm-header.js +7 -7
  51. package/dist/boxes/webm/traversal.d.ts +2 -2
  52. package/dist/buffer-iterator.d.ts +6 -1
  53. package/dist/buffer-iterator.js +24 -5
  54. package/dist/create/iso-base-media/create-iso-base-media.js +0 -4
  55. package/dist/create/matroska/create-matroska-media.js +0 -4
  56. package/dist/create/media-fn.d.ts +0 -1
  57. package/dist/create/mp3/create-mp3.d.ts +2 -0
  58. package/dist/create/mp3/create-mp3.js +49 -0
  59. package/dist/create/wav/create-wav.d.ts +2 -0
  60. package/dist/create/wav/create-wav.js +108 -0
  61. package/dist/emit-available-info.d.ts +2 -2
  62. package/dist/emit-available-info.js +6 -4
  63. package/dist/esm/from-node.mjs +2 -1
  64. package/dist/esm/index.mjs +1487 -431
  65. package/dist/get-audio-codec.d.ts +3 -3
  66. package/dist/get-audio-codec.js +2 -2
  67. package/dist/get-container.d.ts +3 -3
  68. package/dist/get-container.js +9 -7
  69. package/dist/get-dimensions.d.ts +3 -3
  70. package/dist/get-duration.d.ts +3 -3
  71. package/dist/get-duration.js +32 -14
  72. package/dist/get-fps.d.ts +3 -3
  73. package/dist/get-fps.js +31 -4
  74. package/dist/get-tracks.d.ts +4 -7
  75. package/dist/get-tracks.js +55 -27
  76. package/dist/get-video-codec.d.ts +5 -4
  77. package/dist/get-video-codec.js +38 -10
  78. package/dist/has-all-info.d.ts +2 -2
  79. package/dist/has-all-info.js +4 -4
  80. package/dist/index.d.ts +1 -0
  81. package/dist/index.js +2 -0
  82. package/dist/options.d.ts +9 -9
  83. package/dist/parse-media.js +2 -0
  84. package/dist/parse-result.d.ts +20 -6
  85. package/dist/parse-video.d.ts +2 -2
  86. package/dist/parse-video.js +5 -16
  87. package/dist/parser-context.d.ts +1 -0
  88. package/dist/parser-state.d.ts +11 -0
  89. package/dist/parser-state.js +30 -0
  90. package/dist/readers/from-node.js +2 -1
  91. package/dist/register-track.d.ts +13 -0
  92. package/dist/register-track.js +25 -0
  93. package/dist/version.d.ts +1 -1
  94. package/dist/version.js +1 -1
  95. package/package.json +3 -3
@@ -0,0 +1,3 @@
1
+ import type { VideoTrack } from './get-tracks';
2
+ import type { SpsAndPps } from './parser-state';
3
+ export declare const addAvcProfileToTrack: (track: VideoTrack, avc1Profile: SpsAndPps | null) => VideoTrack;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAvcProfileToTrack = void 0;
4
+ const make_header_1 = require("./boxes/webm/make-header");
5
+ const addAvcProfileToTrack = (track, avc1Profile) => {
6
+ if (avc1Profile === null) {
7
+ return track;
8
+ }
9
+ return {
10
+ ...track,
11
+ codec: `avc1.${avc1Profile.sps.profile.toString(16).padStart(2, '0')}${avc1Profile.sps.compatibility.toString(16).padStart(2, '0')}${avc1Profile.sps.level.toString(16).padStart(2, '0')}`,
12
+ codecPrivate: (0, make_header_1.combineUint8Arrays)([
13
+ new Uint8Array([
14
+ // https://gist.github.com/uupaa/8493378ec15f644a3d2b
15
+ 1,
16
+ avc1Profile.sps.level,
17
+ avc1Profile.sps.compatibility,
18
+ avc1Profile.sps.profile,
19
+ 0xff,
20
+ 0xe1,
21
+ ]),
22
+ // sequence parameter set length
23
+ (0, make_header_1.serializeUint16)(avc1Profile.sps.sps.length),
24
+ // sequence parameter set
25
+ avc1Profile.sps.sps,
26
+ // num of PPS
27
+ new Uint8Array([0x01]),
28
+ // picture parameter set length
29
+ (0, make_header_1.serializeUint16)(avc1Profile.pps.pps.length),
30
+ // PPS
31
+ avc1Profile.pps.pps,
32
+ ]),
33
+ };
34
+ };
35
+ exports.addAvcProfileToTrack = addAvcProfileToTrack;
@@ -1,4 +1,4 @@
1
- import type { Track } from './get-tracks';
1
+ import type { Track, VideoTrack } from './get-tracks';
2
2
  import type { ParserContext } from './parser-context';
3
3
  import type { ParserState } from './parser-state';
4
4
  export declare const registerTrack: ({ state, options, track, }: {
@@ -6,3 +6,8 @@ export declare const registerTrack: ({ state, options, track, }: {
6
6
  options: ParserContext;
7
7
  track: Track;
8
8
  }) => Promise<void>;
9
+ export declare const registerVideoTrackWhenProfileIsAvailable: ({ options, state, track, }: {
10
+ state: ParserState;
11
+ options: ParserContext;
12
+ track: VideoTrack;
13
+ }) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerTrack = void 0;
3
+ exports.registerVideoTrackWhenProfileIsAvailable = exports.registerTrack = void 0;
4
4
  const registerTrack = async ({ state, options, track, }) => {
5
5
  if (track.type === 'video' && options.onVideoTrack) {
6
6
  const callback = await options.onVideoTrack(track);
@@ -12,3 +12,18 @@ const registerTrack = async ({ state, options, track, }) => {
12
12
  }
13
13
  };
14
14
  exports.registerTrack = registerTrack;
15
+ const registerVideoTrackWhenProfileIsAvailable = ({ options, state, track, }) => {
16
+ state.registerOnAvcProfileCallback(async (profile) => {
17
+ const newTrack = {
18
+ ...track,
19
+ codec: 'avc1...',
20
+ };
21
+ console.log(profile, newTrack);
22
+ await (0, exports.registerTrack)({
23
+ options,
24
+ state,
25
+ track: newTrack,
26
+ });
27
+ });
28
+ };
29
+ exports.registerVideoTrackWhenProfileIsAvailable = registerVideoTrackWhenProfileIsAvailable;
@@ -0,0 +1,18 @@
1
+ export type AvcProfileInfo = {
2
+ profile: number;
3
+ level: number;
4
+ compatibility: number;
5
+ sps: Uint8Array;
6
+ type: 'avc-profile';
7
+ };
8
+ export type AvcPPs = {
9
+ type: 'avc-pps';
10
+ pps: Uint8Array;
11
+ };
12
+ type AvcInfo = AvcProfileInfo | AvcPPs | {
13
+ type: 'keyframe';
14
+ } | {
15
+ type: 'delta-frame';
16
+ };
17
+ export declare const parseAvc: (buffer: Uint8Array) => AvcInfo[];
18
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAvc = void 0;
4
+ const buffer_iterator_1 = require("../../buffer-iterator");
5
+ const readSps = (iterator) => {
6
+ const profile = iterator.getUint8();
7
+ const compatibility = iterator.getUint8();
8
+ const level = iterator.getUint8();
9
+ return {
10
+ profile,
11
+ compatibility,
12
+ level,
13
+ };
14
+ };
15
+ const findEnd = (buffer) => {
16
+ let zeroesInARow = 0;
17
+ for (let i = 0; i < buffer.length; i++) {
18
+ const val = buffer[i];
19
+ if (val === 0) {
20
+ zeroesInARow++;
21
+ continue;
22
+ }
23
+ if (zeroesInARow >= 2 && val === 1) {
24
+ return i - zeroesInARow;
25
+ }
26
+ zeroesInARow = 0;
27
+ }
28
+ return null;
29
+ };
30
+ const inspect = (buffer) => {
31
+ const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(buffer, buffer.byteLength);
32
+ iterator.startReadingBits();
33
+ iterator.getBits(1);
34
+ iterator.getBits(2);
35
+ const type = iterator.getBits(5);
36
+ iterator.stopReadingBits();
37
+ if (type === 7) {
38
+ const end = findEnd(buffer);
39
+ const data = readSps(iterator);
40
+ const sps = buffer.slice(1, end === null ? Infinity : end);
41
+ return {
42
+ level: data.level,
43
+ profile: data.profile,
44
+ compatibility: data.compatibility,
45
+ sps,
46
+ type: 'avc-profile',
47
+ };
48
+ }
49
+ if (type === 5) {
50
+ return {
51
+ type: 'keyframe',
52
+ };
53
+ }
54
+ if (type === 8) {
55
+ const end = findEnd(buffer);
56
+ const pps = buffer.slice(0, end === null ? Infinity : end);
57
+ return {
58
+ type: 'avc-pps',
59
+ pps,
60
+ };
61
+ }
62
+ if (type === 1) {
63
+ return {
64
+ type: 'delta-frame',
65
+ };
66
+ }
67
+ iterator.destroy();
68
+ return null;
69
+ };
70
+ // https://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream
71
+ const parseAvc = (buffer) => {
72
+ let zeroesInARow = 0;
73
+ const infos = [];
74
+ for (let i = 0; i < buffer.length; i++) {
75
+ const val = buffer[i];
76
+ if (val === 0) {
77
+ zeroesInARow++;
78
+ continue;
79
+ }
80
+ if (zeroesInARow >= 2 && val === 1) {
81
+ zeroesInARow = 0;
82
+ const info = inspect(buffer.slice(i + 1, i + 100));
83
+ if (info) {
84
+ infos.push(info);
85
+ if (info.type === 'keyframe' || info.type === 'delta-frame') {
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ if (val !== 1) {
91
+ zeroesInARow = 0;
92
+ }
93
+ }
94
+ return infos;
95
+ };
96
+ exports.parseAvc = parseAvc;
@@ -7,7 +7,7 @@ const get_sample_aspect_ratio_1 = require("../../get-sample-aspect-ratio");
7
7
  const get_video_codec_1 = require("../../get-video-codec");
8
8
  const traversal_1 = require("./traversal");
9
9
  const makeBaseMediaTrack = (trakBox) => {
10
- var _a;
10
+ var _a, _b, _c;
11
11
  const tkhdBox = (0, traversal_1.getTkhdBox)(trakBox);
12
12
  const videoDescriptors = (0, traversal_1.getVideoDescriptors)(trakBox);
13
13
  const timescaleAndDuration = (0, get_fps_1.getTimescaleAndDuration)(trakBox);
@@ -36,7 +36,7 @@ const makeBaseMediaTrack = (trakBox) => {
36
36
  sampleRate,
37
37
  description,
38
38
  trakBox,
39
- codecPrivate: (0, get_audio_codec_1.getCodecPrivateFromTrak)(trakBox),
39
+ codecPrivate: (_b = (_a = (0, get_audio_codec_1.getCodecPrivateFromTrak)(trakBox)) !== null && _a !== void 0 ? _a : description) !== null && _b !== void 0 ? _b : null,
40
40
  codecWithoutConfig: (0, get_audio_codec_1.getAudioCodecFromTrack)(trakBox),
41
41
  };
42
42
  }
@@ -84,7 +84,7 @@ const makeBaseMediaTrack = (trakBox) => {
84
84
  rotation,
85
85
  trakBox,
86
86
  codecPrivate: privateData,
87
- color: (_a = (0, get_video_codec_1.getIsoBmColrConfig)(trakBox)) !== null && _a !== void 0 ? _a : {
87
+ color: (_c = (0, get_video_codec_1.getIsoBmColrConfig)(trakBox)) !== null && _c !== void 0 ? _c : {
88
88
  fullRange: null,
89
89
  matrixCoefficients: null,
90
90
  primaries: null,
@@ -1,5 +1,5 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
- import type { AnySegment } from '../../../parse-result';
2
+ import type { IsoBaseMediaBox } from '../../../parse-result';
3
3
  import type { ParserContext } from '../../../parser-context';
4
4
  type MdatStatus = {
5
5
  status: 'samples-buffered';
@@ -17,7 +17,7 @@ export declare const parseMdat: ({ data, size, fileOffset, existingBoxes, option
17
17
  data: BufferIterator;
18
18
  size: number;
19
19
  fileOffset: number;
20
- existingBoxes: AnySegment[];
20
+ existingBoxes: IsoBaseMediaBox[];
21
21
  options: ParserContext;
22
22
  signal: AbortSignal | null;
23
23
  maySkipSampleProcessing: boolean;
@@ -5,7 +5,10 @@ const get_tracks_1 = require("../../../get-tracks");
5
5
  const get_sample_positions_from_track_1 = require("../get-sample-positions-from-track");
6
6
  const traversal_1 = require("../traversal");
7
7
  const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signal, maySkipSampleProcessing, }) => {
8
- const alreadyHas = (0, get_tracks_1.hasTracks)(existingBoxes);
8
+ const alreadyHas = (0, get_tracks_1.hasTracks)({
9
+ type: 'iso-base-media',
10
+ boxes: existingBoxes,
11
+ }, options.parserState);
9
12
  if (!alreadyHas) {
10
13
  if (maySkipSampleProcessing) {
11
14
  data.discard(size - (data.counter.getOffset() - fileOffset));
@@ -25,7 +28,7 @@ const parseMdat = async ({ data, size, fileOffset, existingBoxes, options, signa
25
28
  fileOffset,
26
29
  });
27
30
  }
28
- const tracks = (0, get_tracks_1.getTracks)(existingBoxes, options.parserState);
31
+ const tracks = (0, get_tracks_1.getTracks)({ type: 'iso-base-media', boxes: existingBoxes }, options.parserState);
29
32
  const allTracks = [
30
33
  ...tracks.videoTracks,
31
34
  ...tracks.audioTracks,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMoov = void 0;
4
4
  const process_box_1 = require("../process-box");
5
5
  const parseMoov = async ({ iterator, offset, size, options, signal, logLevel, }) => {
6
- const children = await (0, process_box_1.parseBoxes)({
6
+ const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
7
7
  iterator,
8
8
  maxBytes: size - (iterator.counter.getOffset() - offset),
9
9
  allowIncompleteBoxes: false,
@@ -20,7 +20,7 @@ const parseMoov = async ({ iterator, offset, size, options, signal, logLevel, })
20
20
  offset,
21
21
  boxSize: size,
22
22
  type: 'moov-box',
23
- children: children.segments,
23
+ children: children.segments.boxes,
24
24
  };
25
25
  };
26
26
  exports.parseMoov = parseMoov;
@@ -1,25 +1,25 @@
1
1
  import type { BufferIterator } from '../../buffer-iterator';
2
2
  import type { LogLevel } from '../../log';
3
- import type { AnySegment, IsoBaseMediaBox, ParseResult } from '../../parse-result';
3
+ import type { IsoBaseMediaBox, IsoBaseMediaStructure, ParseResult } from '../../parse-result';
4
4
  import type { BoxAndNext, PartialMdatBox } from '../../parse-video';
5
5
  import type { ParserContext } from '../../parser-context';
6
6
  export declare const parseMdatPartially: ({ iterator, boxSize, fileOffset, parsedBoxes, options, signal, }: {
7
7
  iterator: BufferIterator;
8
8
  boxSize: number;
9
9
  fileOffset: number;
10
- parsedBoxes: AnySegment[];
10
+ parsedBoxes: IsoBaseMediaBox[];
11
11
  options: ParserContext;
12
12
  signal: AbortSignal | null;
13
13
  }) => Promise<BoxAndNext>;
14
14
  export declare const processBox: ({ iterator, allowIncompleteBoxes, parsedBoxes, options, signal, logLevel, }: {
15
15
  iterator: BufferIterator;
16
16
  allowIncompleteBoxes: boolean;
17
- parsedBoxes: AnySegment[];
17
+ parsedBoxes: IsoBaseMediaBox[];
18
18
  options: ParserContext;
19
19
  signal: AbortSignal | null;
20
20
  logLevel: LogLevel;
21
21
  }) => Promise<BoxAndNext>;
22
- export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, signal, logLevel, }: {
22
+ export declare const parseIsoBaseMediaBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, signal, logLevel, }: {
23
23
  iterator: BufferIterator;
24
24
  maxBytes: number;
25
25
  allowIncompleteBoxes: boolean;
@@ -28,4 +28,4 @@ export declare const parseBoxes: ({ iterator, maxBytes, allowIncompleteBoxes, in
28
28
  continueMdat: false | PartialMdatBox;
29
29
  signal: AbortSignal | null;
30
30
  logLevel: LogLevel;
31
- }) => Promise<ParseResult>;
31
+ }) => Promise<ParseResult<IsoBaseMediaStructure>>;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseBoxes = exports.processBox = exports.parseMdatPartially = void 0;
3
+ exports.parseIsoBaseMediaBoxes = exports.processBox = exports.parseMdatPartially = void 0;
4
4
  const get_tracks_1 = require("../../get-tracks");
5
+ const register_track_1 = require("../../register-track");
5
6
  const esds_1 = require("./esds/esds");
6
7
  const ftyp_1 = require("./ftyp");
7
8
  const make_track_1 = require("./make-track");
@@ -39,7 +40,7 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
39
40
  boxType === 'stsb';
40
41
  if (parseChildren) {
41
42
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
42
- const parsed = await (0, exports.parseBoxes)({
43
+ const parsed = await (0, exports.parseIsoBaseMediaBoxes)({
43
44
  iterator,
44
45
  maxBytes: bytesRemainingInBox,
45
46
  allowIncompleteBoxes: false,
@@ -52,7 +53,7 @@ const getChildren = async ({ boxType, iterator, bytesRemainingInBox, options, si
52
53
  if (parsed.status === 'incomplete') {
53
54
  throw new Error('Incomplete boxes are not allowed');
54
55
  }
55
- return parsed.segments;
56
+ return parsed.segments.boxes;
56
57
  }
57
58
  if (bytesRemainingInBox < 0) {
58
59
  throw new Error('Box size is too big ' + JSON.stringify({ boxType }));
@@ -87,7 +88,6 @@ const parseMdatPartially = async ({ iterator, boxSize, fileOffset, parsedBoxes,
87
88
  };
88
89
  exports.parseMdatPartially = parseMdatPartially;
89
90
  const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options, signal, logLevel, }) => {
90
- var _a, _b;
91
91
  const fileOffset = iterator.counter.getOffset();
92
92
  const bytesRemaining = iterator.bytesRemaining();
93
93
  const boxSizeRaw = iterator.getFourByteNumber();
@@ -117,7 +117,8 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
117
117
  const boxSize = boxSizeRaw === 1 ? iterator.getEightByteNumber() : boxSizeRaw;
118
118
  if (bytesRemaining < boxSize) {
119
119
  if (boxType === 'mdat') {
120
- const shouldSkip = (options.canSkipVideoData || !(0, get_tracks_1.hasTracks)(parsedBoxes)) &&
120
+ const shouldSkip = (options.canSkipVideoData ||
121
+ !(0, get_tracks_1.hasTracks)({ type: 'iso-base-media', boxes: parsedBoxes }, options.parserState)) &&
121
122
  options.supportsContentRange;
122
123
  if (shouldSkip) {
123
124
  const skipTo = fileOffset + boxSize;
@@ -349,14 +350,11 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
349
350
  });
350
351
  const transformedTrack = (0, make_track_1.makeBaseMediaTrack)(box);
351
352
  if (transformedTrack) {
352
- if (transformedTrack.type === 'audio') {
353
- const callback = await ((_a = options.onAudioTrack) === null || _a === void 0 ? void 0 : _a.call(options, transformedTrack));
354
- await options.parserState.registerAudioSampleCallback(transformedTrack.trackId, callback !== null && callback !== void 0 ? callback : null);
355
- }
356
- if (transformedTrack.type === 'video') {
357
- const callback = await ((_b = options.onVideoTrack) === null || _b === void 0 ? void 0 : _b.call(options, transformedTrack));
358
- await options.parserState.registerVideoSampleCallback(transformedTrack.trackId, callback !== null && callback !== void 0 ? callback : null);
359
- }
353
+ await (0, register_track_1.registerTrack)({
354
+ options,
355
+ state: options.parserState,
356
+ track: transformedTrack,
357
+ });
360
358
  }
361
359
  return {
362
360
  type: 'complete',
@@ -498,10 +496,13 @@ const processBox = async ({ iterator, allowIncompleteBoxes, parsedBoxes, options
498
496
  };
499
497
  };
500
498
  exports.processBox = processBox;
501
- const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, signal, logLevel, }) => {
502
- let boxes = initialBoxes;
499
+ const parseIsoBaseMediaBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBoxes, options, continueMdat, signal, logLevel, }) => {
500
+ const structure = {
501
+ type: 'iso-base-media',
502
+ boxes: initialBoxes,
503
+ };
503
504
  const initialOffset = iterator.counter.getOffset();
504
- const alreadyHasMdat = boxes.find((b) => b.type === 'mdat-box');
505
+ const alreadyHasMdat = structure.boxes.find((b) => b.type === 'mdat-box');
505
506
  while (iterator.bytesRemaining() > 0 &&
506
507
  iterator.counter.getOffset() - initialOffset < maxBytes) {
507
508
  const result = continueMdat
@@ -527,13 +528,13 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
527
528
  }
528
529
  return {
529
530
  status: 'incomplete',
530
- segments: boxes,
531
+ segments: structure,
531
532
  continueParsing: () => {
532
- return (0, exports.parseBoxes)({
533
+ return (0, exports.parseIsoBaseMediaBoxes)({
533
534
  iterator,
534
535
  maxBytes,
535
536
  allowIncompleteBoxes,
536
- initialBoxes: boxes,
537
+ initialBoxes: structure.boxes,
537
538
  options,
538
539
  continueMdat: false,
539
540
  signal,
@@ -546,13 +547,13 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
546
547
  if (result.type === 'partial-mdat-box') {
547
548
  return {
548
549
  status: 'incomplete',
549
- segments: boxes,
550
+ segments: structure,
550
551
  continueParsing: () => {
551
- return Promise.resolve((0, exports.parseBoxes)({
552
+ return Promise.resolve((0, exports.parseIsoBaseMediaBoxes)({
552
553
  iterator,
553
554
  maxBytes,
554
555
  allowIncompleteBoxes,
555
- initialBoxes: boxes,
556
+ initialBoxes: structure.boxes,
556
557
  options,
557
558
  continueMdat: result,
558
559
  signal,
@@ -563,8 +564,8 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
563
564
  };
564
565
  }
565
566
  if (result.box.type === 'mdat-box' && alreadyHasMdat) {
566
- boxes = boxes.filter((b) => b.type !== 'mdat-box');
567
- boxes.push(result.box);
567
+ structure.boxes = structure.boxes.filter((b) => b.type !== 'mdat-box');
568
+ structure.boxes.push(result.box);
568
569
  iterator.allowDiscard();
569
570
  if (result.box.status !== 'samples-processed') {
570
571
  throw new Error('unexpected');
@@ -572,7 +573,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
572
573
  break;
573
574
  }
574
575
  else {
575
- boxes.push(result.box);
576
+ structure.boxes.push(result.box);
576
577
  }
577
578
  if (result.skipTo !== null) {
578
579
  if (!options.supportsContentRange) {
@@ -580,13 +581,13 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
580
581
  }
581
582
  return {
582
583
  status: 'incomplete',
583
- segments: boxes,
584
+ segments: structure,
584
585
  continueParsing: () => {
585
- return (0, exports.parseBoxes)({
586
+ return (0, exports.parseIsoBaseMediaBoxes)({
586
587
  iterator,
587
588
  maxBytes,
588
589
  allowIncompleteBoxes,
589
- initialBoxes: boxes,
590
+ initialBoxes: structure.boxes,
590
591
  options,
591
592
  continueMdat: false,
592
593
  signal,
@@ -599,13 +600,13 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
599
600
  if (iterator.bytesRemaining() < 0) {
600
601
  return {
601
602
  status: 'incomplete',
602
- segments: boxes,
603
+ segments: structure,
603
604
  continueParsing: () => {
604
- return (0, exports.parseBoxes)({
605
+ return (0, exports.parseIsoBaseMediaBoxes)({
605
606
  iterator,
606
607
  maxBytes,
607
608
  allowIncompleteBoxes,
608
- initialBoxes: boxes,
609
+ initialBoxes: structure.boxes,
609
610
  options,
610
611
  continueMdat: false,
611
612
  signal,
@@ -617,7 +618,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
617
618
  }
618
619
  iterator.removeBytesRead();
619
620
  }
620
- const mdatState = (0, traversal_1.getMdatBox)(boxes);
621
+ const mdatState = (0, traversal_1.getMdatBox)(structure.boxes);
621
622
  const skipped = (mdatState === null || mdatState === void 0 ? void 0 : mdatState.status) === 'samples-skipped' &&
622
623
  !options.canSkipVideoData &&
623
624
  options.supportsContentRange;
@@ -625,16 +626,16 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
625
626
  if (skipped || buffered) {
626
627
  return {
627
628
  status: 'incomplete',
628
- segments: boxes,
629
+ segments: structure,
629
630
  continueParsing: () => {
630
631
  if (buffered) {
631
632
  iterator.skipTo(mdatState.fileOffset, false);
632
633
  }
633
- return (0, exports.parseBoxes)({
634
+ return (0, exports.parseIsoBaseMediaBoxes)({
634
635
  iterator,
635
636
  maxBytes,
636
637
  allowIncompleteBoxes: false,
637
- initialBoxes: boxes,
638
+ initialBoxes: structure.boxes,
638
639
  options,
639
640
  continueMdat: false,
640
641
  signal,
@@ -646,7 +647,7 @@ const parseBoxes = async ({ iterator, maxBytes, allowIncompleteBoxes, initialBox
646
647
  }
647
648
  return {
648
649
  status: 'done',
649
- segments: boxes,
650
+ segments: structure,
650
651
  };
651
652
  };
652
- exports.parseBoxes = parseBoxes;
653
+ exports.parseIsoBaseMediaBoxes = parseIsoBaseMediaBoxes;
@@ -6,7 +6,7 @@ const parseMebx = async ({ iterator, offset, size, options, signal, }) => {
6
6
  // reserved, 6 bit
7
7
  iterator.discard(6);
8
8
  const dataReferenceIndex = iterator.getUint16();
9
- const children = await (0, process_box_1.parseBoxes)({
9
+ const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
10
10
  iterator,
11
11
  maxBytes: iterator.counter.getOffset() - offset,
12
12
  allowIncompleteBoxes: false,
@@ -25,7 +25,7 @@ const parseMebx = async ({ iterator, offset, size, options, signal, }) => {
25
25
  offset,
26
26
  dataReferenceIndex,
27
27
  format: 'mebx',
28
- children: children.segments,
28
+ children: children.segments.boxes,
29
29
  };
30
30
  };
31
31
  exports.parseMebx = parseMebx;
@@ -1,6 +1,6 @@
1
1
  import type { BufferIterator } from '../../../buffer-iterator';
2
2
  import type { LogLevel } from '../../../log';
3
- import type { AnySegment } from '../../../parse-result';
3
+ import type { AnySegment, IsoBaseMediaBox } from '../../../parse-result';
4
4
  import type { ParserContext } from '../../../parser-context';
5
5
  type SampleBase = {
6
6
  format: string;
@@ -37,7 +37,7 @@ export type VideoSample = SampleBase & {
37
37
  frameCountPerSample: number;
38
38
  depth: number;
39
39
  colorTableId: number;
40
- descriptors: AnySegment[];
40
+ descriptors: IsoBaseMediaBox[];
41
41
  version: number;
42
42
  revisionLevel: number;
43
43
  vendor: number[];
@@ -98,7 +98,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
98
98
  const packetSize = iterator.getUint16();
99
99
  const sampleRate = iterator.getFixedPointUnsigned1616Number();
100
100
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
101
- const children = await (0, process_box_1.parseBoxes)({
101
+ const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
102
102
  iterator,
103
103
  allowIncompleteBoxes: false,
104
104
  maxBytes: bytesRemainingInBox,
@@ -130,7 +130,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
130
130
  bytesPerPacket: null,
131
131
  bytesPerFrame: null,
132
132
  bitsPerSample: null,
133
- children: children.segments,
133
+ children: children.segments.boxes,
134
134
  },
135
135
  };
136
136
  }
@@ -145,7 +145,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
145
145
  const bytesPerFrame = iterator.getUint32();
146
146
  const bytesPerSample = iterator.getUint32();
147
147
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
148
- const children = await (0, process_box_1.parseBoxes)({
148
+ const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
149
149
  iterator,
150
150
  allowIncompleteBoxes: false,
151
151
  maxBytes: bytesRemainingInBox,
@@ -177,7 +177,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
177
177
  bytesPerPacket,
178
178
  bytesPerFrame,
179
179
  bitsPerSample: bytesPerSample,
180
- children: children.segments,
180
+ children: children.segments.boxes,
181
181
  },
182
182
  };
183
183
  }
@@ -196,7 +196,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
196
196
  const bytesPerFrame = iterator.getUint32();
197
197
  const samplesPerPacket = iterator.getUint32();
198
198
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
199
- const children = await (0, process_box_1.parseBoxes)({
199
+ const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
200
200
  iterator,
201
201
  allowIncompleteBoxes: false,
202
202
  maxBytes: bytesRemainingInBox,
@@ -228,7 +228,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
228
228
  bytesPerPacket: null,
229
229
  bytesPerFrame,
230
230
  bitsPerSample: bitsPerCodedSample,
231
- children: children.segments,
231
+ children: children.segments.boxes,
232
232
  },
233
233
  };
234
234
  }
@@ -251,7 +251,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
251
251
  const colorTableId = iterator.getInt16();
252
252
  const bytesRemainingInBox = boxSize - (iterator.counter.getOffset() - fileOffset);
253
253
  const children = bytesRemainingInBox > 8
254
- ? await (0, process_box_1.parseBoxes)({
254
+ ? await (0, process_box_1.parseIsoBaseMediaBoxes)({
255
255
  iterator,
256
256
  allowIncompleteBoxes: false,
257
257
  maxBytes: bytesRemainingInBox,
@@ -262,7 +262,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
262
262
  logLevel,
263
263
  })
264
264
  : (iterator.discard(bytesRemainingInBox),
265
- { status: 'done', segments: [] });
265
+ { status: 'done', segments: { boxes: [], type: 'iso-base-media' } });
266
266
  if (children.status === 'incomplete') {
267
267
  throw new Error('Incomplete boxes are not allowed');
268
268
  }
@@ -287,7 +287,7 @@ const processSample = async ({ iterator, options, signal, logLevel, }) => {
287
287
  compressorName,
288
288
  depth,
289
289
  colorTableId,
290
- descriptors: children.segments,
290
+ descriptors: children.segments.boxes,
291
291
  },
292
292
  };
293
293
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTrak = void 0;
4
4
  const process_box_1 = require("../process-box");
5
5
  const parseTrak = async ({ data, size, offsetAtStart, options, signal, logLevel, }) => {
6
- const children = await (0, process_box_1.parseBoxes)({
6
+ const children = await (0, process_box_1.parseIsoBaseMediaBoxes)({
7
7
  iterator: data,
8
8
  maxBytes: size - (data.counter.getOffset() - offsetAtStart),
9
9
  allowIncompleteBoxes: false,
@@ -20,7 +20,7 @@ const parseTrak = async ({ data, size, offsetAtStart, options, signal, logLevel,
20
20
  offset: offsetAtStart,
21
21
  boxSize: size,
22
22
  type: 'trak-box',
23
- children: children.segments,
23
+ children: children.segments.boxes,
24
24
  };
25
25
  };
26
26
  exports.parseTrak = parseTrak;