@remotion/media-parser 4.0.231 → 4.0.233

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 (115) 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/esds/decoder-specific-config.d.ts +1 -2
  8. package/dist/boxes/iso-base-media/esds/decoder-specific-config.js +1 -5
  9. package/dist/boxes/iso-base-media/esds/esds-descriptors.d.ts +2 -4
  10. package/dist/boxes/iso-base-media/esds/esds-descriptors.js +3 -4
  11. package/dist/boxes/iso-base-media/esds/esds.d.ts +1 -3
  12. package/dist/boxes/iso-base-media/esds/esds.js +2 -2
  13. package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +7 -1
  14. package/dist/boxes/iso-base-media/make-track.js +3 -3
  15. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -2
  16. package/dist/boxes/iso-base-media/mdat/mdat.js +5 -2
  17. package/dist/boxes/iso-base-media/moov/moov.js +2 -2
  18. package/dist/boxes/iso-base-media/process-box.d.ts +5 -5
  19. package/dist/boxes/iso-base-media/process-box.js +38 -38
  20. package/dist/boxes/iso-base-media/stsd/mebx.js +2 -2
  21. package/dist/boxes/iso-base-media/stsd/samples.d.ts +2 -2
  22. package/dist/boxes/iso-base-media/stsd/samples.js +15 -14
  23. package/dist/boxes/iso-base-media/trak/trak.js +2 -2
  24. package/dist/boxes/iso-base-media/traversal.d.ts +1 -1
  25. package/dist/boxes/riff/expect-riff-box.d.ts +16 -0
  26. package/dist/boxes/riff/expect-riff-box.js +49 -0
  27. package/dist/boxes/riff/get-tracks-from-avi.d.ts +21 -0
  28. package/dist/boxes/riff/get-tracks-from-avi.js +108 -0
  29. package/dist/boxes/riff/is-movi.d.ts +2 -0
  30. package/dist/boxes/riff/is-movi.js +12 -0
  31. package/dist/boxes/riff/parse-avih.d.ts +6 -0
  32. package/dist/boxes/riff/parse-avih.js +32 -0
  33. package/dist/boxes/riff/parse-box.d.ts +13 -0
  34. package/dist/boxes/riff/parse-box.js +113 -0
  35. package/dist/boxes/riff/parse-fmt-box.d.ts +7 -0
  36. package/dist/boxes/riff/parse-fmt-box.js +33 -0
  37. package/dist/boxes/riff/parse-list-box.d.ts +8 -0
  38. package/dist/boxes/riff/parse-list-box.js +30 -0
  39. package/dist/boxes/riff/parse-movi.d.ts +17 -0
  40. package/dist/boxes/riff/parse-movi.js +122 -0
  41. package/dist/boxes/riff/parse-riff-box.d.ts +10 -0
  42. package/dist/boxes/riff/parse-riff-box.js +33 -0
  43. package/dist/boxes/riff/parse-strf.d.ts +7 -0
  44. package/dist/boxes/riff/parse-strf.js +67 -0
  45. package/dist/boxes/riff/parse-strh.d.ts +6 -0
  46. package/dist/boxes/riff/parse-strh.js +46 -0
  47. package/dist/boxes/riff/riff-box.d.ts +81 -0
  48. package/dist/boxes/riff/riff-box.js +2 -0
  49. package/dist/boxes/riff/strf.d.ts +7 -0
  50. package/dist/boxes/riff/strf.js +67 -0
  51. package/dist/boxes/riff/timescale.d.ts +1 -0
  52. package/dist/boxes/riff/timescale.js +4 -0
  53. package/dist/boxes/riff/traversal.d.ts +8 -0
  54. package/dist/boxes/riff/traversal.js +36 -0
  55. package/dist/boxes/webm/parse-ebml.js +2 -2
  56. package/dist/boxes/webm/parse-webm-header.d.ts +2 -2
  57. package/dist/boxes/webm/parse-webm-header.js +7 -7
  58. package/dist/boxes/webm/traversal.d.ts +2 -2
  59. package/dist/buffer-iterator.d.ts +6 -1
  60. package/dist/buffer-iterator.js +24 -5
  61. package/dist/create/event-emitter.d.ts +31 -0
  62. package/dist/create/event-emitter.js +25 -0
  63. package/dist/create/iso-base-media/create-iso-base-media.d.ts +1 -1
  64. package/dist/create/iso-base-media/create-iso-base-media.js +3 -5
  65. package/dist/create/matroska/cluster.js +1 -1
  66. package/dist/create/matroska/create-matroska-media.d.ts +1 -1
  67. package/dist/create/matroska/create-matroska-media.js +7 -14
  68. package/dist/create/media-fn.d.ts +2 -1
  69. package/dist/create/mp3/create-mp3.d.ts +2 -0
  70. package/dist/create/mp3/create-mp3.js +49 -0
  71. package/dist/create/progress-tracker.d.ts +7 -0
  72. package/dist/create/progress-tracker.js +43 -0
  73. package/dist/create/wav/create-wav.d.ts +2 -0
  74. package/dist/create/wav/create-wav.js +110 -0
  75. package/dist/create/with-resolvers.d.ts +10 -0
  76. package/dist/create/with-resolvers.js +28 -0
  77. package/dist/emit-available-info.d.ts +2 -2
  78. package/dist/emit-available-info.js +17 -6
  79. package/dist/esm/from-node.mjs +2 -1
  80. package/dist/esm/index.mjs +1828 -605
  81. package/dist/get-audio-codec.d.ts +4 -3
  82. package/dist/get-audio-codec.js +17 -3
  83. package/dist/get-container.d.ts +3 -3
  84. package/dist/get-container.js +9 -7
  85. package/dist/get-dimensions.d.ts +3 -3
  86. package/dist/get-duration.d.ts +3 -3
  87. package/dist/get-duration.js +32 -14
  88. package/dist/get-fps.d.ts +3 -3
  89. package/dist/get-fps.js +31 -4
  90. package/dist/get-is-hdr.d.ts +4 -0
  91. package/dist/get-is-hdr.js +18 -0
  92. package/dist/get-sample-positions-from-lpcm.d.ts +3 -0
  93. package/dist/get-sample-positions-from-lpcm.js +46 -0
  94. package/dist/get-tracks.d.ts +7 -10
  95. package/dist/get-tracks.js +55 -27
  96. package/dist/get-video-codec.d.ts +5 -4
  97. package/dist/get-video-codec.js +47 -13
  98. package/dist/has-all-info.d.ts +2 -2
  99. package/dist/has-all-info.js +10 -5
  100. package/dist/index.d.ts +23 -3
  101. package/dist/index.js +9 -0
  102. package/dist/options.d.ts +16 -9
  103. package/dist/parse-media.js +3 -1
  104. package/dist/parse-result.d.ts +20 -6
  105. package/dist/parse-video.d.ts +2 -2
  106. package/dist/parse-video.js +5 -16
  107. package/dist/parser-context.d.ts +1 -0
  108. package/dist/parser-state.d.ts +11 -0
  109. package/dist/parser-state.js +30 -0
  110. package/dist/readers/from-node.js +2 -1
  111. package/dist/register-track.d.ts +13 -0
  112. package/dist/register-track.js +25 -0
  113. package/dist/version.d.ts +1 -1
  114. package/dist/version.js +1 -1
  115. package/package.json +3 -3
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRiff = exports.parseRiffBody = void 0;
4
+ const register_track_1 = require("../../register-track");
5
+ const expect_riff_box_1 = require("./expect-riff-box");
6
+ const get_tracks_from_avi_1 = require("./get-tracks-from-avi");
7
+ const traversal_1 = require("./traversal");
8
+ const continueAfterRiffBoxResult = ({ result, structure, iterator, maxOffset, options, }) => {
9
+ if (result.type === 'incomplete') {
10
+ return Promise.resolve({
11
+ status: 'incomplete',
12
+ async continueParsing() {
13
+ return Promise.resolve(continueAfterRiffBoxResult({
14
+ result: await result.continueParsing(),
15
+ structure,
16
+ iterator,
17
+ maxOffset,
18
+ options,
19
+ }));
20
+ },
21
+ segments: structure,
22
+ skipTo: null,
23
+ });
24
+ }
25
+ if (result.type === 'complete') {
26
+ if (result.box) {
27
+ structure.boxes.push(result.box);
28
+ }
29
+ }
30
+ return (0, exports.parseRiffBody)({ iterator, maxOffset, options, structure });
31
+ };
32
+ const parseRiffBody = async ({ iterator, structure, maxOffset, options, }) => {
33
+ while (iterator.bytesRemaining() > 0 &&
34
+ iterator.counter.getOffset() < maxOffset) {
35
+ const result = await (0, expect_riff_box_1.expectRiffBox)({
36
+ iterator,
37
+ options,
38
+ structure,
39
+ });
40
+ if (result.type === 'incomplete') {
41
+ return {
42
+ status: 'incomplete',
43
+ async continueParsing() {
44
+ return Promise.resolve(continueAfterRiffBoxResult({
45
+ iterator,
46
+ maxOffset,
47
+ options,
48
+ result: await result.continueParsing(),
49
+ structure,
50
+ }));
51
+ },
52
+ segments: structure,
53
+ skipTo: null,
54
+ };
55
+ }
56
+ if (result.box === null) {
57
+ continue;
58
+ }
59
+ structure.boxes.push(result.box);
60
+ if (result.box.type === 'strf-box-video' ||
61
+ result.box.type === 'strf-box-audio') {
62
+ const strh = (0, traversal_1.getStrhBox)(structure.boxes);
63
+ const strf = (0, traversal_1.getStrfBox)(structure.boxes);
64
+ if (!strh || !strf) {
65
+ throw new Error('strh or strf box missing');
66
+ }
67
+ if (strf.type === 'strf-box-audio' && options.onAudioTrack) {
68
+ const audioTrack = (0, get_tracks_from_avi_1.makeAviAudioTrack)({
69
+ index: options.nextTrackIndex,
70
+ strf,
71
+ });
72
+ await (0, register_track_1.registerTrack)({
73
+ options,
74
+ state: options.parserState,
75
+ track: audioTrack,
76
+ });
77
+ }
78
+ if (options.onVideoTrack && strf.type === 'strf-box-video') {
79
+ const videoTrack = (0, get_tracks_from_avi_1.makeAviVideoTrack)({
80
+ strh,
81
+ index: options.nextTrackIndex,
82
+ strf,
83
+ });
84
+ (0, register_track_1.registerVideoTrackWhenProfileIsAvailable)({
85
+ options,
86
+ state: options.parserState,
87
+ track: videoTrack,
88
+ });
89
+ }
90
+ options.nextTrackIndex++;
91
+ }
92
+ }
93
+ return {
94
+ status: 'done',
95
+ segments: structure,
96
+ };
97
+ };
98
+ exports.parseRiffBody = parseRiffBody;
99
+ const parseRiff = ({ iterator, options, }) => {
100
+ const structure = { type: 'riff', boxes: [] };
101
+ const riff = iterator.getByteString(4);
102
+ if (riff !== 'RIFF') {
103
+ throw new Error('Not a RIFF file');
104
+ }
105
+ const size = iterator.getUint32Le();
106
+ const fileType = iterator.getByteString(4);
107
+ if (fileType !== 'WAVE' && fileType !== 'AVI') {
108
+ throw new Error(`File type ${fileType} not supported`);
109
+ }
110
+ structure.boxes.push({ type: 'riff-header', fileSize: size, fileType });
111
+ return (0, exports.parseRiffBody)({ iterator, structure, maxOffset: Infinity, options });
112
+ };
113
+ exports.parseRiff = parseRiff;
@@ -0,0 +1,7 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { RiffBox } from './riff-box';
3
+ export declare const parseFmtBox: ({ iterator, boxes, size, }: {
4
+ iterator: BufferIterator;
5
+ boxes: RiffBox[];
6
+ size: number;
7
+ }) => RiffBox;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFmtBox = void 0;
4
+ const parseFmtBox = ({ iterator, boxes, size, }) => {
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');
9
+ }
10
+ if (header.fileType !== 'WAVE') {
11
+ throw new Error('Only supporting WAVE type');
12
+ }
13
+ const wFormatTag = iterator.getUint16Le();
14
+ if (wFormatTag !== 1) {
15
+ throw new Error('Expected wFormatTag to be 1, only supporting this');
16
+ }
17
+ const numberOfChannels = iterator.getUint16Le();
18
+ const sampleRate = iterator.getUint32Le();
19
+ const byteRate = iterator.getUint32Le();
20
+ const blockAlign = iterator.getUint16Le();
21
+ const bitsPerSample = iterator.getUint16Le();
22
+ box.expectNoMoreBytes();
23
+ return {
24
+ type: 'wave-format-box',
25
+ formatTag: wFormatTag,
26
+ numberOfChannels,
27
+ sampleRate,
28
+ blockAlign,
29
+ byteRate,
30
+ bitsPerSample,
31
+ };
32
+ };
33
+ exports.parseFmtBox = parseFmtBox;
@@ -0,0 +1,8 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParserContext } from '../../parser-context';
3
+ import type { RiffBox } from './riff-box';
4
+ export declare const parseListBox: ({ iterator, size, options, }: {
5
+ iterator: BufferIterator;
6
+ size: number;
7
+ options: ParserContext;
8
+ }) => Promise<RiffBox>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseListBox = void 0;
4
+ const parse_box_1 = require("./parse-box");
5
+ const parseListBox = async ({ iterator, size, options, }) => {
6
+ const counter = iterator.counter.getOffset();
7
+ const listType = iterator.getByteString(4);
8
+ if (listType === 'movi') {
9
+ throw new Error('should not be handled here');
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
+ options,
20
+ });
21
+ if (result.status === 'incomplete') {
22
+ throw new Error(`Should only parse complete boxes (${listType})`);
23
+ }
24
+ return {
25
+ type: 'list-box',
26
+ listType,
27
+ children: structure.boxes,
28
+ };
29
+ };
30
+ exports.parseListBox = parseListBox;
@@ -0,0 +1,17 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { RiffStructure } from '../../parse-result';
3
+ import type { ParserContext } from '../../parser-context';
4
+ import type { RiffResult } from './expect-riff-box';
5
+ export declare const handleChunk: ({ iterator, options, structure, ckId, ckSize, }: {
6
+ iterator: BufferIterator;
7
+ options: ParserContext;
8
+ structure: RiffStructure;
9
+ ckId: string;
10
+ ckSize: number;
11
+ }) => Promise<void>;
12
+ export declare const parseMovi: ({ iterator, maxOffset, options, structure, }: {
13
+ iterator: BufferIterator;
14
+ maxOffset: number;
15
+ options: ParserContext;
16
+ structure: RiffStructure;
17
+ }) => Promise<RiffResult>;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMovi = exports.handleChunk = void 0;
4
+ const parse_avc_1 = require("../avc/parse-avc");
5
+ const timescale_1 = require("./timescale");
6
+ const traversal_1 = require("./traversal");
7
+ const getStrhForIndex = (structure, trackId) => {
8
+ const boxes = (0, traversal_1.getStrlBoxes)(structure);
9
+ const box = boxes[trackId];
10
+ if (!box) {
11
+ throw new Error('Expected box');
12
+ }
13
+ const strh = (0, traversal_1.getStrhBox)(box.children);
14
+ if (!strh) {
15
+ throw new Error('strh');
16
+ }
17
+ return strh;
18
+ };
19
+ const handleChunk = async ({ iterator, options, structure, ckId, ckSize, }) => {
20
+ const videoChunk = ckId.match(/^([0-9]{2})dc$/);
21
+ if (videoChunk) {
22
+ const trackId = parseInt(videoChunk[1], 10);
23
+ const strh = getStrhForIndex(structure, trackId);
24
+ const samplesPerSecond = strh.rate / strh.scale;
25
+ const nthSample = options.parserState.getSamplesForTrack(trackId);
26
+ const timeInSec = nthSample / samplesPerSecond;
27
+ const timestamp = Math.floor(timeInSec * timescale_1.MEDIA_PARSER_RIFF_TIMESCALE);
28
+ const duration = Math.floor((1 / samplesPerSecond) * timescale_1.MEDIA_PARSER_RIFF_TIMESCALE);
29
+ const data = iterator.getSlice(ckSize);
30
+ const infos = (0, parse_avc_1.parseAvc)(data);
31
+ const keyOrDelta = infos.find((i) => i.type === 'keyframe' || i.type === 'delta-frame');
32
+ if (!keyOrDelta) {
33
+ throw new Error('expected avc to contain info about key or delta');
34
+ }
35
+ const avcProfile = infos.find((i) => i.type === 'avc-profile');
36
+ const ppsProfile = infos.find((i) => i.type === 'avc-pps');
37
+ if (avcProfile && ppsProfile) {
38
+ await options.parserState.onProfile({ pps: ppsProfile, sps: avcProfile });
39
+ }
40
+ await options.parserState.onVideoSample(trackId, {
41
+ cts: timestamp,
42
+ dts: timestamp,
43
+ data,
44
+ duration,
45
+ timestamp,
46
+ trackId,
47
+ type: keyOrDelta.type === 'keyframe' ? 'key' : 'delta',
48
+ });
49
+ }
50
+ else {
51
+ const audioChunk = ckId.match(/^([0-9]{2})wb$/);
52
+ if (audioChunk) {
53
+ const trackId = parseInt(audioChunk[1], 10);
54
+ const strh = getStrhForIndex(structure, trackId);
55
+ const samplesPerSecond = strh.rate / strh.scale;
56
+ const nthSample = options.parserState.getSamplesForTrack(trackId);
57
+ const timeInSec = nthSample / samplesPerSecond;
58
+ const timestamp = timeInSec * timescale_1.MEDIA_PARSER_RIFF_TIMESCALE;
59
+ const duration = (1 / samplesPerSecond) * timescale_1.MEDIA_PARSER_RIFF_TIMESCALE;
60
+ await options.parserState.onAudioSample(trackId, {
61
+ cts: timestamp,
62
+ dts: timestamp,
63
+ data: iterator.getSlice(ckSize),
64
+ duration,
65
+ timestamp,
66
+ trackId,
67
+ type: 'key',
68
+ });
69
+ }
70
+ }
71
+ };
72
+ exports.handleChunk = handleChunk;
73
+ const parseMovi = async ({ iterator, maxOffset, options, structure, }) => {
74
+ while (iterator.counter.getOffset() < maxOffset) {
75
+ if (iterator.bytesRemaining() < 8) {
76
+ return {
77
+ type: 'incomplete',
78
+ continueParsing: () => {
79
+ return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, options, structure }));
80
+ },
81
+ };
82
+ }
83
+ const ckId = iterator.getByteString(4);
84
+ const ckSize = iterator.getUint32Le();
85
+ if (iterator.bytesRemaining() < ckSize) {
86
+ iterator.counter.decrement(8);
87
+ return {
88
+ type: 'incomplete',
89
+ continueParsing: () => {
90
+ return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, options, structure }));
91
+ },
92
+ };
93
+ }
94
+ await (0, exports.handleChunk)({ iterator, options, structure, ckId, ckSize });
95
+ // Discard added zeroes
96
+ while (iterator.counter.getOffset() < maxOffset &&
97
+ iterator.bytesRemaining() > 0) {
98
+ if (iterator.getUint8() !== 0) {
99
+ iterator.counter.decrement(1);
100
+ break;
101
+ }
102
+ }
103
+ }
104
+ if (iterator.counter.getOffset() === maxOffset) {
105
+ return {
106
+ type: 'complete',
107
+ box: {
108
+ type: 'movi-box',
109
+ },
110
+ };
111
+ }
112
+ if (iterator.counter.getOffset() > maxOffset) {
113
+ throw new Error('Oops, this should not happen!');
114
+ }
115
+ return {
116
+ type: 'incomplete',
117
+ continueParsing: () => {
118
+ return Promise.resolve((0, exports.parseMovi)({ iterator, maxOffset, options, structure }));
119
+ },
120
+ };
121
+ };
122
+ exports.parseMovi = parseMovi;
@@ -0,0 +1,10 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { ParserContext } from '../../parser-context';
3
+ import type { RiffBox } from './riff-box';
4
+ export declare const parseRiffBox: ({ iterator, size, id, boxes, options, }: {
5
+ iterator: BufferIterator;
6
+ size: number;
7
+ id: string;
8
+ boxes: RiffBox[];
9
+ options: ParserContext;
10
+ }) => Promise<RiffBox>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRiffBox = void 0;
4
+ const parse_avih_1 = require("./parse-avih");
5
+ const parse_fmt_box_1 = require("./parse-fmt-box");
6
+ const parse_list_box_1 = require("./parse-list-box");
7
+ const parse_strf_1 = require("./parse-strf");
8
+ const parse_strh_1 = require("./parse-strh");
9
+ const parseRiffBox = ({ iterator, size, id, boxes, options, }) => {
10
+ if (id === 'fmt') {
11
+ return Promise.resolve((0, parse_fmt_box_1.parseFmtBox)({ iterator, boxes, size }));
12
+ }
13
+ if (id === 'LIST') {
14
+ return (0, parse_list_box_1.parseListBox)({ iterator, size, options });
15
+ }
16
+ if (id === 'avih') {
17
+ return Promise.resolve((0, parse_avih_1.parseAvih)({ iterator, size }));
18
+ }
19
+ if (id === 'strh') {
20
+ return Promise.resolve((0, parse_strh_1.parseStrh)({ iterator, size }));
21
+ }
22
+ if (id === 'strf') {
23
+ return Promise.resolve((0, parse_strf_1.parseStrf)({ iterator, size, boxes }));
24
+ }
25
+ iterator.discard(size);
26
+ const box = {
27
+ type: 'riff-box',
28
+ size,
29
+ id,
30
+ };
31
+ return Promise.resolve(box);
32
+ };
33
+ exports.parseRiffBox = parseRiffBox;
@@ -0,0 +1,7 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { RiffBox } from './riff-box';
3
+ export declare const parseStrf: ({ iterator, size, boxes, }: {
4
+ iterator: BufferIterator;
5
+ size: number;
6
+ boxes: RiffBox[];
7
+ }) => RiffBox;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStrf = void 0;
4
+ const parseStrfAudio = ({ iterator, size, }) => {
5
+ const box = iterator.startBox(size);
6
+ const formatTag = iterator.getUint16Le();
7
+ const numberOfChannels = iterator.getUint16Le();
8
+ const samplesPerSec = iterator.getUint32Le();
9
+ const avgBytesPerSec = iterator.getUint32Le();
10
+ const blockAlign = iterator.getUint16Le();
11
+ const bitsPerSample = iterator.getUint16Le();
12
+ const cbSize = iterator.getUint16Le();
13
+ box.expectNoMoreBytes();
14
+ return {
15
+ type: 'strf-box-audio',
16
+ avgBytesPerSecond: avgBytesPerSec,
17
+ bitsPerSample,
18
+ blockAlign,
19
+ cbSize,
20
+ formatTag,
21
+ numberOfChannels,
22
+ sampleRate: samplesPerSec,
23
+ };
24
+ };
25
+ const parseStrfVideo = ({ iterator, size, }) => {
26
+ const box = iterator.startBox(size);
27
+ const biSize = iterator.getUint32Le();
28
+ const width = iterator.getInt32Le();
29
+ const height = iterator.getInt32Le();
30
+ const planes = iterator.getUint16Le();
31
+ const bitCount = iterator.getUint16Le();
32
+ const compression = iterator.getByteString(4);
33
+ const sizeImage = iterator.getUint32Le();
34
+ const xPelsPerMeter = iterator.getInt32Le();
35
+ const yPelsPerMeter = iterator.getInt32Le();
36
+ const clrUsed = iterator.getUint32Le();
37
+ const clrImportant = iterator.getUint32Le();
38
+ box.expectNoMoreBytes();
39
+ return {
40
+ type: 'strf-box-video',
41
+ biSize,
42
+ bitCount,
43
+ clrImportant,
44
+ clrUsed,
45
+ compression,
46
+ height,
47
+ planes,
48
+ sizeImage,
49
+ width,
50
+ xPelsPerMeter,
51
+ yPelsPerMeter,
52
+ };
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') {
60
+ return parseStrfVideo({ iterator, size });
61
+ }
62
+ if (strh.fccType === 'auds') {
63
+ return parseStrfAudio({ iterator, size });
64
+ }
65
+ throw new Error(`Unsupported fccType: ${strh.fccType}`);
66
+ };
67
+ exports.parseStrf = parseStrf;
@@ -0,0 +1,6 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { RiffBox } from './riff-box';
3
+ export declare const parseStrh: ({ iterator, size, }: {
4
+ iterator: BufferIterator;
5
+ size: number;
6
+ }) => RiffBox;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStrh = void 0;
4
+ const parseStrh = ({ iterator, size, }) => {
5
+ const box = iterator.startBox(size);
6
+ const fccType = iterator.getByteString(4);
7
+ if (fccType !== 'vids' && fccType !== 'auds') {
8
+ throw new Error('Expected AVI handler to be vids / auds');
9
+ }
10
+ const handler = fccType === 'vids' ? iterator.getByteString(4) : iterator.getUint32Le();
11
+ if (typeof handler === 'string' && handler !== 'H264') {
12
+ throw new Error(`Only H264 is supported as a stream type in .avi, got ${handler}`);
13
+ }
14
+ if (fccType === 'auds' && handler !== 1) {
15
+ throw new Error(`Only "1" is supported as a stream type in .avi, got ${handler}`);
16
+ }
17
+ const flags = iterator.getUint32Le();
18
+ const priority = iterator.getUint16Le();
19
+ const language = iterator.getUint16Le();
20
+ const initialFrames = iterator.getUint32Le();
21
+ const scale = iterator.getUint32Le();
22
+ const rate = iterator.getUint32Le();
23
+ const start = iterator.getUint32Le();
24
+ const length = iterator.getUint32Le();
25
+ const suggestedBufferSize = iterator.getUint32Le();
26
+ const quality = iterator.getUint32Le();
27
+ const sampleSize = iterator.getUint32Le();
28
+ box.discardRest();
29
+ return {
30
+ type: 'strh-box',
31
+ fccType,
32
+ handler,
33
+ flags,
34
+ priority,
35
+ initialFrames,
36
+ length,
37
+ quality,
38
+ rate,
39
+ sampleSize,
40
+ scale,
41
+ start,
42
+ suggestedBufferSize,
43
+ language,
44
+ };
45
+ };
46
+ exports.parseStrh = parseStrh;
@@ -0,0 +1,81 @@
1
+ export type WaveFormatBox = {
2
+ type: 'wave-format-box';
3
+ formatTag: 1;
4
+ numberOfChannels: number;
5
+ sampleRate: number;
6
+ blockAlign: number;
7
+ byteRate: number;
8
+ bitsPerSample: number;
9
+ };
10
+ export type ListBox = {
11
+ type: 'list-box';
12
+ listType: string;
13
+ children: RiffBox[];
14
+ };
15
+ export type RiffRegularBox = {
16
+ type: 'riff-box';
17
+ size: number;
18
+ id: string;
19
+ };
20
+ export type AvihBox = {
21
+ type: 'avih-box';
22
+ microSecPerFrame: number;
23
+ maxBytesPerSecond: number;
24
+ paddingGranularity: number;
25
+ flags: number;
26
+ totalFrames: number;
27
+ initialFrames: number;
28
+ streams: number;
29
+ suggestedBufferSize: number;
30
+ width: number;
31
+ height: number;
32
+ };
33
+ export type StrhBox = {
34
+ type: 'strh-box';
35
+ fccType: 'vids' | 'auds';
36
+ handler: 'H264' | number;
37
+ flags: number;
38
+ priority: number;
39
+ initialFrames: number;
40
+ scale: number;
41
+ rate: number;
42
+ start: number;
43
+ length: number;
44
+ suggestedBufferSize: number;
45
+ quality: number;
46
+ sampleSize: number;
47
+ language: number;
48
+ };
49
+ export type StrfBoxVideo = {
50
+ type: 'strf-box-video';
51
+ biSize: number;
52
+ width: number;
53
+ height: number;
54
+ planes: number;
55
+ bitCount: number;
56
+ compression: string;
57
+ sizeImage: number;
58
+ xPelsPerMeter: number;
59
+ yPelsPerMeter: number;
60
+ clrUsed: number;
61
+ clrImportant: number;
62
+ };
63
+ export type StrfBoxAudio = {
64
+ type: 'strf-box-audio';
65
+ formatTag: number;
66
+ numberOfChannels: number;
67
+ sampleRate: number;
68
+ avgBytesPerSecond: number;
69
+ blockAlign: number;
70
+ bitsPerSample: number;
71
+ cbSize: number;
72
+ };
73
+ export type RiffHeader = {
74
+ type: 'riff-header';
75
+ fileSize: number;
76
+ fileType: string;
77
+ };
78
+ export type MoviBox = {
79
+ type: 'movi-box';
80
+ };
81
+ export type RiffBox = RiffRegularBox | WaveFormatBox | RiffHeader | ListBox | AvihBox | StrhBox | StrfBoxVideo | StrfBoxAudio | MoviBox;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ import type { RiffBox } from './riff-box';
3
+ export declare const parseStrf: ({ iterator, size, boxes, }: {
4
+ iterator: BufferIterator;
5
+ size: number;
6
+ boxes: RiffBox[];
7
+ }) => RiffBox;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStrf = void 0;
4
+ const parseStrfAudio = ({ iterator, size, }) => {
5
+ const box = iterator.startBox(size);
6
+ const formatTag = iterator.getUint16Le();
7
+ const numberOfChannels = iterator.getUint16Le();
8
+ const samplesPerSec = iterator.getUint32Le();
9
+ const avgBytesPerSec = iterator.getUint32Le();
10
+ const blockAlign = iterator.getUint16Le();
11
+ const bitsPerSample = iterator.getUint16Le();
12
+ const cbSize = iterator.getUint16Le();
13
+ box.expectNoMoreBytes();
14
+ return {
15
+ type: 'strf-box-audio',
16
+ avgBytesPerSecond: avgBytesPerSec,
17
+ bitsPerSample,
18
+ blockAlign,
19
+ cbSize,
20
+ formatTag,
21
+ numberOfChannels,
22
+ sampleRate: samplesPerSec,
23
+ };
24
+ };
25
+ const parseStrfVideo = ({ iterator, size, }) => {
26
+ const box = iterator.startBox(size);
27
+ const biSize = iterator.getUint32Le();
28
+ const width = iterator.getInt32Le();
29
+ const height = iterator.getInt32Le();
30
+ const planes = iterator.getUint16Le();
31
+ const bitCount = iterator.getUint16Le();
32
+ const compression = iterator.getByteString(4);
33
+ const sizeImage = iterator.getUint32Le();
34
+ const xPelsPerMeter = iterator.getInt32Le();
35
+ const yPelsPerMeter = iterator.getInt32Le();
36
+ const clrUsed = iterator.getUint32Le();
37
+ const clrImportant = iterator.getUint32Le();
38
+ box.expectNoMoreBytes();
39
+ return {
40
+ type: 'strf-box-video',
41
+ biSize,
42
+ bitCount,
43
+ clrImportant,
44
+ clrUsed,
45
+ compression,
46
+ height,
47
+ planes,
48
+ sizeImage,
49
+ width,
50
+ xPelsPerMeter,
51
+ yPelsPerMeter,
52
+ };
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') {
60
+ return parseStrfVideo({ iterator, size });
61
+ }
62
+ if (strh.fccType === 'auds') {
63
+ return parseStrfAudio({ iterator, size });
64
+ }
65
+ throw new Error(`Unsupported fccType: ${strh.fccType}`);
66
+ };
67
+ exports.parseStrf = parseStrf;
@@ -0,0 +1 @@
1
+ export declare const MEDIA_PARSER_RIFF_TIMESCALE = 1000000;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MEDIA_PARSER_RIFF_TIMESCALE = void 0;
4
+ exports.MEDIA_PARSER_RIFF_TIMESCALE = 1000000;