@remotion/media-parser 4.0.201 → 4.0.204

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 (144) hide show
  1. package/dist/av1-codec-string.d.ts +0 -5
  2. package/dist/av1-codec-string.js +1 -18
  3. package/dist/boxes/iso-base-media/ftype.d.ts +9 -0
  4. package/dist/boxes/iso-base-media/ftype.js +31 -0
  5. package/dist/boxes/iso-base-media/get-sample-positions-from-track.d.ts +4 -0
  6. package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +48 -0
  7. package/dist/boxes/iso-base-media/mvhd.js +2 -2
  8. package/dist/boxes/iso-base-media/stsd/keys.js +1 -1
  9. package/dist/boxes/iso-base-media/tfdt.d.ts +12 -0
  10. package/dist/boxes/iso-base-media/tfdt.js +20 -0
  11. package/dist/boxes/iso-base-media/tfhd.d.ts +16 -0
  12. package/dist/boxes/iso-base-media/tfhd.js +41 -0
  13. package/dist/boxes/iso-base-media/trun.d.ts +21 -0
  14. package/dist/boxes/iso-base-media/trun.js +44 -0
  15. package/dist/boxes/webm/av1-codec-private.js +1 -1
  16. package/dist/boxes/webm/bitstream/av1.js +1 -10
  17. package/dist/boxes/webm/description.d.ts +2 -2
  18. package/dist/boxes/webm/description.js +2 -2
  19. package/dist/boxes/webm/ebml.d.ts +2 -2
  20. package/dist/boxes/webm/ebml.js +23 -1
  21. package/dist/boxes/webm/get-ready-tracks.d.ts +1 -1
  22. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  23. package/dist/boxes/webm/get-sample-from-block.d.ts +17 -0
  24. package/dist/boxes/webm/get-sample-from-block.js +78 -0
  25. package/dist/boxes/webm/get-track.d.ts +2 -2
  26. package/dist/boxes/webm/get-track.js +26 -25
  27. package/dist/boxes/webm/make-header.d.ts +3 -8
  28. package/dist/boxes/webm/make-header.js +43 -20
  29. package/dist/boxes/webm/parse-ebml.d.ts +9 -4
  30. package/dist/boxes/webm/parse-ebml.js +122 -13
  31. package/dist/boxes/webm/segments/all-segments.d.ts +421 -107
  32. package/dist/boxes/webm/segments/all-segments.js +260 -33
  33. package/dist/boxes/webm/segments/track-entry.d.ts +3 -191
  34. package/dist/boxes/webm/segments/track-entry.js +2 -456
  35. package/dist/boxes/webm/segments.d.ts +3 -16
  36. package/dist/boxes/webm/segments.js +12 -196
  37. package/dist/boxes/webm/tracks.d.ts +8 -0
  38. package/dist/boxes/webm/tracks.js +21 -0
  39. package/dist/boxes/webm/traversal.d.ts +5 -6
  40. package/dist/boxes/webm/traversal.js +6 -6
  41. package/dist/buffer-iterator.d.ts +1 -1
  42. package/dist/buffer-iterator.js +3 -3
  43. package/dist/from-web.js +6 -15
  44. package/dist/get-audio-codec.d.ts +1 -1
  45. package/dist/get-audio-codec.js +13 -13
  46. package/dist/get-duration.js +12 -14
  47. package/dist/get-tracks.js +2 -2
  48. package/dist/get-video-codec.js +13 -13
  49. package/dist/get-video-metadata.d.ts +2 -0
  50. package/dist/get-video-metadata.js +44 -0
  51. package/dist/parse-media.js +4 -1
  52. package/dist/parser-context.d.ts +1 -0
  53. package/dist/parser-state.js +3 -2
  54. package/dist/read-and-increment-offset.d.ts +28 -0
  55. package/dist/read-and-increment-offset.js +177 -0
  56. package/dist/samples-from-moof.d.ts +6 -0
  57. package/dist/samples-from-moof.js +74 -0
  58. package/dist/traversal.d.ts +19 -17
  59. package/dist/traversal.js +38 -39
  60. package/dist/understand-vorbis.d.ts +1 -0
  61. package/dist/understand-vorbis.js +12 -0
  62. package/input.webm +0 -0
  63. package/package.json +2 -2
  64. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +69 -0
  65. package/src/boxes/iso-base-media/make-track.ts +4 -45
  66. package/src/boxes/iso-base-media/mdat/mdat.ts +33 -24
  67. package/src/boxes/iso-base-media/mdhd.ts +10 -7
  68. package/src/boxes/iso-base-media/mvhd.ts +17 -16
  69. package/src/boxes/iso-base-media/process-box.ts +42 -0
  70. package/src/boxes/iso-base-media/stsd/keys.ts +1 -1
  71. package/src/boxes/iso-base-media/tfdt.ts +37 -0
  72. package/src/boxes/iso-base-media/tfhd.ts +66 -0
  73. package/src/boxes/iso-base-media/tkhd.ts +11 -13
  74. package/src/boxes/iso-base-media/trun.ts +74 -0
  75. package/src/boxes/webm/av1-codec-private.ts +1 -1
  76. package/src/boxes/webm/description.ts +7 -4
  77. package/src/boxes/webm/ebml.ts +24 -4
  78. package/src/boxes/webm/get-ready-tracks.ts +4 -4
  79. package/src/boxes/webm/get-sample-from-block.ts +125 -0
  80. package/src/boxes/webm/get-track.ts +40 -33
  81. package/src/boxes/webm/make-header.ts +58 -51
  82. package/src/boxes/webm/parse-ebml.ts +170 -16
  83. package/src/boxes/webm/segments/all-segments.ts +379 -62
  84. package/src/boxes/webm/segments/track-entry.ts +3 -846
  85. package/src/boxes/webm/segments.ts +18 -410
  86. package/src/boxes/webm/traversal.ts +17 -17
  87. package/src/buffer-iterator.ts +8 -6
  88. package/src/get-audio-codec.ts +14 -16
  89. package/src/get-duration.ts +55 -21
  90. package/src/get-tracks.ts +6 -6
  91. package/src/get-video-codec.ts +13 -15
  92. package/src/has-all-info.ts +1 -1
  93. package/src/parse-media.ts +7 -2
  94. package/src/parse-result.ts +7 -1
  95. package/src/parser-context.ts +1 -0
  96. package/src/parser-state.ts +2 -2
  97. package/src/samples-from-moof.ts +101 -0
  98. package/src/test/create-matroska.test.ts +237 -23
  99. package/src/test/matroska.test.ts +283 -348
  100. package/src/test/mvhd.test.ts +1 -1
  101. package/src/test/parse-esds.test.ts +2 -2
  102. package/src/test/parse-stco.test.ts +2 -2
  103. package/src/test/parse-stsc.test.ts +2 -2
  104. package/src/test/parse-stsz.test.ts +2 -2
  105. package/src/test/parse-stts.test.ts +1 -1
  106. package/src/test/samples-from-moof.test.ts +2496 -0
  107. package/src/test/stream-local.test.ts +28 -30
  108. package/src/test/stream-samples.test.ts +153 -231
  109. package/src/test/stsd.test.ts +4 -2
  110. package/src/test/tkhd.test.ts +1 -1
  111. package/src/traversal.ts +118 -86
  112. package/tsconfig.tsbuildinfo +1 -1
  113. package/dist/bitstream/av1.d.ts +0 -2
  114. package/dist/bitstream/av1.js +0 -12
  115. package/dist/boxes/iso-base-media/avcc-hvcc.d.ts +0 -20
  116. package/dist/boxes/iso-base-media/avcc-hvcc.js +0 -73
  117. package/dist/boxes/iso-base-media/avcc.d.ts +0 -18
  118. package/dist/boxes/iso-base-media/avcc.js +0 -27
  119. package/dist/boxes/iso-base-media/esds-descriptors.d.ts +0 -21
  120. package/dist/boxes/iso-base-media/esds-descriptors.js +0 -62
  121. package/dist/boxes/iso-base-media/esds.d.ts +0 -15
  122. package/dist/boxes/iso-base-media/esds.js +0 -27
  123. package/dist/from-input-type-file.d.ts +0 -2
  124. package/dist/from-input-type-file.js +0 -37
  125. package/dist/get-codec.d.ts +0 -4
  126. package/dist/get-codec.js +0 -22
  127. package/dist/web-file.d.ts +0 -2
  128. package/dist/web-file.js +0 -37
  129. package/src/boxes/webm/segments/duration.ts +0 -29
  130. package/src/boxes/webm/segments/info.ts +0 -34
  131. package/src/boxes/webm/segments/main.ts +0 -6
  132. package/src/boxes/webm/segments/muxing.ts +0 -18
  133. package/src/boxes/webm/segments/seek-head.ts +0 -34
  134. package/src/boxes/webm/segments/seek-position.ts +0 -18
  135. package/src/boxes/webm/segments/seek.ts +0 -55
  136. package/src/boxes/webm/segments/timestamp-scale.ts +0 -17
  137. package/src/boxes/webm/segments/tracks.ts +0 -32
  138. package/src/boxes/webm/segments/void.ts +0 -18
  139. package/src/boxes/webm/segments/writing.ts +0 -18
  140. package/src/combine-uint8array.ts +0 -13
  141. /package/dist/{get-samples.d.ts → boxes/webm/bitstream/av1/frame.d.ts} +0 -0
  142. /package/dist/{get-samples.js → boxes/webm/bitstream/av1/frame.js} +0 -0
  143. /package/dist/{sample-aspect-ratio.d.ts → boxes/webm/bitstream/h264/get-h264-descriptor.d.ts} +0 -0
  144. /package/dist/{sample-aspect-ratio.js → boxes/webm/bitstream/h264/get-h264-descriptor.js} +0 -0
@@ -0,0 +1,28 @@
1
+ export declare class OffsetCounter {
2
+ #private;
3
+ constructor(initial: number);
4
+ increment(amount: number): void;
5
+ getOffset(): number;
6
+ }
7
+ export declare const getArrayBufferIterator: (data: ArrayBuffer, initialOffset: number) => {
8
+ view: DataView;
9
+ counter: OffsetCounter;
10
+ data: ArrayBuffer;
11
+ discard: (length: number) => void;
12
+ getSlice: (amount: number) => ArrayBuffer;
13
+ getAtom: () => string;
14
+ getMatroskaSegmentId: () => string;
15
+ getVint: (bytes: number) => number;
16
+ getUint8: () => number;
17
+ getEBML: () => number;
18
+ getInt8: () => number;
19
+ getUint16: () => number;
20
+ getInt16: () => number;
21
+ getUint32: () => number;
22
+ getFixedPoint1616Number: () => number;
23
+ getPascalString: () => number[];
24
+ getDecimalBytes(length: number): number;
25
+ getByteString(length: number): string;
26
+ getFloat64: () => number;
27
+ };
28
+ export type BufferIterator = ReturnType<typeof getArrayBufferIterator>;
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _OffsetCounter_offset;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getArrayBufferIterator = exports.OffsetCounter = void 0;
16
+ class OffsetCounter {
17
+ constructor(initial) {
18
+ _OffsetCounter_offset.set(this, void 0);
19
+ __classPrivateFieldSet(this, _OffsetCounter_offset, initial, "f");
20
+ }
21
+ increment(amount) {
22
+ if (amount < 0) {
23
+ throw new Error('Cannot increment by a negative amount');
24
+ }
25
+ __classPrivateFieldSet(this, _OffsetCounter_offset, __classPrivateFieldGet(this, _OffsetCounter_offset, "f") + amount, "f");
26
+ }
27
+ getOffset() {
28
+ return __classPrivateFieldGet(this, _OffsetCounter_offset, "f");
29
+ }
30
+ }
31
+ exports.OffsetCounter = OffsetCounter;
32
+ _OffsetCounter_offset = new WeakMap();
33
+ const makeOffsetCounter = (initial) => {
34
+ return new OffsetCounter(initial);
35
+ };
36
+ const getArrayBufferIterator = (data, initialOffset) => {
37
+ const view = new DataView(data);
38
+ const counter = makeOffsetCounter(initialOffset);
39
+ const getSlice = (amount) => {
40
+ const value = data.slice(counter.getOffset(), counter.getOffset() + amount);
41
+ counter.increment(amount);
42
+ return value;
43
+ };
44
+ const getUint8 = () => {
45
+ const val = view.getUint8(counter.getOffset());
46
+ counter.increment(1);
47
+ return val;
48
+ };
49
+ const getUint32 = () => {
50
+ const val = view.getUint32(counter.getOffset());
51
+ counter.increment(4);
52
+ return val;
53
+ };
54
+ return {
55
+ view,
56
+ counter,
57
+ data,
58
+ discard: (length) => {
59
+ counter.increment(length);
60
+ },
61
+ getSlice,
62
+ getAtom: () => {
63
+ const atom = getSlice(4);
64
+ return new TextDecoder().decode(atom);
65
+ },
66
+ getMatroskaSegmentId: () => {
67
+ const first = getSlice(1);
68
+ const firstOneString = `0x${Array.from(new Uint8Array(first))
69
+ .map((b) => {
70
+ return b.toString(16).padStart(2, '0');
71
+ })
72
+ .join('')}`;
73
+ // Catch void block
74
+ const knownIdsWithOneLength = ['0xec', '0xae'];
75
+ if (knownIdsWithOneLength.includes(firstOneString)) {
76
+ return firstOneString;
77
+ }
78
+ const firstTwo = getSlice(1);
79
+ const knownIdsWithTwoLength = ['0x4dbb', '0x53ac', '0xec01'];
80
+ const firstTwoString = `${firstOneString}${Array.from(new Uint8Array(firstTwo))
81
+ .map((b) => {
82
+ return b.toString(16).padStart(2, '0');
83
+ })
84
+ .join('')}`;
85
+ if (knownIdsWithTwoLength.includes(firstTwoString)) {
86
+ return firstTwoString;
87
+ }
88
+ const knownIdsWithThreeLength = ['0x4d808c', '0x57418c', '0x448988'];
89
+ const firstThree = getSlice(1);
90
+ const firstThreeString = `${firstTwoString}${Array.from(new Uint8Array(firstThree))
91
+ .map((b) => {
92
+ return b.toString(16).padStart(2, '0');
93
+ })
94
+ .join('')}`;
95
+ if (knownIdsWithThreeLength.includes(firstThreeString)) {
96
+ return firstThreeString;
97
+ }
98
+ const segmentId = getSlice(1);
99
+ return `${firstThreeString}${Array.from(new Uint8Array(segmentId))
100
+ .map((b) => {
101
+ return b.toString(16).padStart(2, '0');
102
+ })
103
+ .join('')}`;
104
+ },
105
+ getVint: (bytes) => {
106
+ const slice = getSlice(bytes);
107
+ const d = [...Array.from(new Uint8Array(slice))];
108
+ const totalLength = d[0];
109
+ if (totalLength === 0) {
110
+ return 0;
111
+ }
112
+ // Calculate the actual length of the data based on the first set bit
113
+ let actualLength = 0;
114
+ while (((totalLength >> (7 - actualLength)) & 0x01) === 0) {
115
+ actualLength++;
116
+ }
117
+ actualLength += 1; // Include the first byte set as 1
118
+ // Combine the numbers to form the integer value
119
+ let value = 0;
120
+ // Mask the first byte properly then start combining
121
+ value = totalLength & (0xff >> actualLength);
122
+ for (let i = 1; i < actualLength; i++) {
123
+ value = (value << 8) | d[i];
124
+ }
125
+ return value;
126
+ },
127
+ getUint8,
128
+ getEBML: () => {
129
+ const val = getUint8();
130
+ // https://darkcoding.net/software/reading-mediarecorders-webm-opus-output/#:~:text=The%20first%20four%20bytes%20(%201A,%E2%80%93%20read%20on%20for%20why).
131
+ // You drop the initial 0 bits and the first 1 bit to get the value. 0x81 is 0b10000001, so there are zero inital 0 bits, meaning length one byte, and the value is 1. The 0x9F value for length of the EBML header we saw earlier is 0b10011111, still one byte, value is 0b0011111, which is 31 (the python repl is very helpful for these conversions).
132
+ const actualValue = val & 0x7f; // 0x7F is binary 01111111, which masks out the first bit
133
+ return actualValue;
134
+ },
135
+ getInt8: () => {
136
+ const val = view.getInt8(counter.getOffset());
137
+ counter.increment(1);
138
+ return val;
139
+ },
140
+ getUint16: () => {
141
+ const val = view.getUint16(counter.getOffset());
142
+ counter.increment(2);
143
+ return val;
144
+ },
145
+ getInt16: () => {
146
+ const val = view.getInt16(counter.getOffset());
147
+ counter.increment(2);
148
+ return val;
149
+ },
150
+ getUint32,
151
+ // https://developer.apple.com/documentation/quicktime-file-format/sound_sample_description_version_1
152
+ // A 32-bit unsigned fixed-point number (16.16) that indicates the rate at which the sound samples were obtained.
153
+ getFixedPoint1616Number: () => {
154
+ const val = getUint32();
155
+ return val / 2 ** 16;
156
+ },
157
+ getPascalString: () => {
158
+ const val = getSlice(32);
159
+ return [...Array.from(new Uint8Array(val))];
160
+ },
161
+ getDecimalBytes(length) {
162
+ const bytes = getSlice(length);
163
+ const numbers = [...Array.from(new Uint8Array(bytes))];
164
+ return numbers.reduce((acc, byte, index) => acc + (byte << (8 * (numbers.length - index - 1))), 0);
165
+ },
166
+ getByteString(length) {
167
+ const bytes = getSlice(length);
168
+ return new TextDecoder().decode(bytes);
169
+ },
170
+ getFloat64: () => {
171
+ const val = view.getFloat64(counter.getOffset());
172
+ counter.increment(8);
173
+ return val;
174
+ },
175
+ };
176
+ };
177
+ exports.getArrayBufferIterator = getArrayBufferIterator;
@@ -0,0 +1,6 @@
1
+ import type { SamplePosition } from './get-sample-positions';
2
+ import type { AnySegment } from './parse-result';
3
+ export declare const getSamplesFromMoof: ({ moofBox, trackId, }: {
4
+ moofBox: AnySegment;
5
+ trackId: number;
6
+ }) => SamplePosition[];
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSamplesFromMoof = void 0;
4
+ const traversal_1 = require("./traversal");
5
+ const getSamplesFromTraf = (trafSegment, moofOffset) => {
6
+ var _a, _b, _c, _d, _e, _f;
7
+ if (trafSegment.type !== 'regular-box' || trafSegment.boxType !== 'traf') {
8
+ throw new Error('Expected traf-box');
9
+ }
10
+ const tfhdBox = (0, traversal_1.getTfhdBox)(trafSegment);
11
+ const defaultSampleDuration = (_a = tfhdBox === null || tfhdBox === void 0 ? void 0 : tfhdBox.defaultSampleDuration) !== null && _a !== void 0 ? _a : null;
12
+ const defaultSampleSize = (_b = tfhdBox === null || tfhdBox === void 0 ? void 0 : tfhdBox.defaultSampleSize) !== null && _b !== void 0 ? _b : null;
13
+ const defaultSampleFlags = (_c = tfhdBox === null || tfhdBox === void 0 ? void 0 : tfhdBox.defaultSampleFlags) !== null && _c !== void 0 ? _c : null;
14
+ const tfdtBox = (0, traversal_1.getTfdtBox)(trafSegment);
15
+ const trunBoxes = (0, traversal_1.getTrunBoxes)(trafSegment);
16
+ let time = 0;
17
+ let offset = 0;
18
+ let dataOffset = 0;
19
+ const samples = [];
20
+ for (const trunBox of trunBoxes) {
21
+ let i = -1;
22
+ if (dataOffset === 0 && trunBox.dataOffset) {
23
+ dataOffset = trunBox.dataOffset;
24
+ }
25
+ for (const sample of trunBox.samples) {
26
+ i++;
27
+ const duration = (_d = sample.sampleDuration) !== null && _d !== void 0 ? _d : defaultSampleDuration;
28
+ if (duration === null) {
29
+ throw new Error('Expected duration');
30
+ }
31
+ const size = (_e = sample.sampleSize) !== null && _e !== void 0 ? _e : defaultSampleSize;
32
+ if (size === null) {
33
+ throw new Error('Expected size');
34
+ }
35
+ const isFirstSample = i === 0;
36
+ const sampleFlags = sample.sampleFlags
37
+ ? sample.sampleFlags
38
+ : isFirstSample && trunBox.firstSampleFlags !== null
39
+ ? trunBox.firstSampleFlags
40
+ : defaultSampleFlags;
41
+ if (sampleFlags === null) {
42
+ throw new Error('Expected sample flags');
43
+ }
44
+ const keyframe = !((sampleFlags >> 16) & 0x1);
45
+ const dts = time + ((_f = tfdtBox === null || tfdtBox === void 0 ? void 0 : tfdtBox.baseMediaDecodeTime) !== null && _f !== void 0 ? _f : 0);
46
+ const samplePosition = {
47
+ offset: offset + (moofOffset !== null && moofOffset !== void 0 ? moofOffset : 0) + (dataOffset !== null && dataOffset !== void 0 ? dataOffset : 0),
48
+ dts,
49
+ cts: dts,
50
+ duration,
51
+ isKeyframe: keyframe,
52
+ size,
53
+ };
54
+ samples.push(samplePosition);
55
+ offset += size;
56
+ time += duration;
57
+ }
58
+ }
59
+ return samples;
60
+ };
61
+ const getSamplesFromMoof = ({ moofBox, trackId, }) => {
62
+ if (moofBox.type !== 'regular-box') {
63
+ throw new Error('Expected moof-box');
64
+ }
65
+ const trafs = moofBox.children.filter((c) => c.type === 'regular-box' && c.boxType === 'traf');
66
+ const mapped = trafs.map((traf) => {
67
+ const tfhdBox = (0, traversal_1.getTfhdBox)(traf);
68
+ return (tfhdBox === null || tfhdBox === void 0 ? void 0 : tfhdBox.trackId) === trackId
69
+ ? getSamplesFromTraf(traf, moofBox.offset)
70
+ : [];
71
+ });
72
+ return mapped.flat(1);
73
+ };
74
+ exports.getSamplesFromMoof = getSamplesFromMoof;
@@ -11,9 +11,7 @@ import type { StszBox } from './boxes/iso-base-media/stsd/stsz';
11
11
  import type { SttsBox } from './boxes/iso-base-media/stsd/stts';
12
12
  import type { TkhdBox } from './boxes/iso-base-media/tkhd';
13
13
  import type { TrakBox } from './boxes/iso-base-media/trak/trak';
14
- import type { MainSegment } from './boxes/webm/segments/main';
15
- import type { TimestampScaleSegment } from './boxes/webm/segments/timestamp-scale';
16
- import type { AudioSegment, ClusterSegment, CodecSegment, DisplayHeightSegment, DisplayWidthSegment, HeightSegment, TrackEntrySegment, TrackTypeSegment, VideoSegment, WidthSegment } from './boxes/webm/segments/track-entry';
14
+ import type { AudioSegment, ClusterSegment, CodecIdSegment, DisplayHeightSegment, DisplayWidthSegment, HeightSegment, MainSegment, TimestampScaleSegment, TrackEntry, TrackTypeSegment, VideoSegment, WidthSegment } from './boxes/webm/segments/all-segments';
17
15
  import type { AnySegment, RegularBox } from './parse-result';
18
16
  export declare const getFtypBox: (segments: AnySegment[]) => FtypBox | null;
19
17
  export declare const getMoovBox: (segments: AnySegment[]) => MoovBox | null;
@@ -32,21 +30,25 @@ export declare const getStszBox: (trakBox: TrakBox) => StszBox | null;
32
30
  export declare const getStscBox: (trakBox: TrakBox) => StscBox | null;
33
31
  export declare const getStssBox: (trakBox: TrakBox) => StssBox | null;
34
32
  export declare const getClusterSegment: (segment: MainSegment) => ClusterSegment | null;
35
- export declare const getTracksSegment: (segment: MainSegment) => import("./boxes/webm/segments/tracks").TracksSegment | null;
33
+ export declare const getTracksSegment: (segment: MainSegment) => {
34
+ type: "Tracks";
35
+ value: import("./boxes/webm/segments/all-segments").PossibleEbml[];
36
+ minVintWidth: number;
37
+ } | null;
36
38
  export declare const getTimescaleSegment: (segment: MainSegment) => TimestampScaleSegment | null;
37
- export declare const getVideoSegment: (track: TrackEntrySegment) => VideoSegment | null;
38
- export declare const getAudioSegment: (track: TrackEntrySegment) => AudioSegment | null;
39
- export declare const getSampleRate: (track: TrackEntrySegment) => number | null;
40
- export declare const getNumberOfChannels: (track: TrackEntrySegment) => number;
41
- export declare const getBitDepth: (track: TrackEntrySegment) => number | null;
42
- export declare const getPrivateData: (track: TrackEntrySegment) => Uint8Array | null;
43
- export declare const getWidthSegment: (track: TrackEntrySegment) => WidthSegment | null;
44
- export declare const getHeightSegment: (track: TrackEntrySegment) => HeightSegment | null;
45
- export declare const getDisplayWidthSegment: (track: TrackEntrySegment) => DisplayWidthSegment | null;
46
- export declare const getDisplayHeightSegment: (track: TrackEntrySegment) => DisplayHeightSegment | null;
47
- export declare const getTrackTypeSegment: (track: TrackEntrySegment) => TrackTypeSegment | null;
48
- export declare const getTrackId: (track: TrackEntrySegment) => number;
49
- export declare const getCodecSegment: (track: TrackEntrySegment) => CodecSegment | null;
39
+ export declare const getVideoSegment: (track: TrackEntry) => VideoSegment | null;
40
+ export declare const getAudioSegment: (track: TrackEntry) => AudioSegment | null;
41
+ export declare const getSampleRate: (track: TrackEntry) => number | null;
42
+ export declare const getNumberOfChannels: (track: TrackEntry) => number;
43
+ export declare const getBitDepth: (track: TrackEntry) => number | null;
44
+ export declare const getPrivateData: (track: TrackEntry) => Uint8Array | null;
45
+ export declare const getWidthSegment: (track: TrackEntry) => WidthSegment | null;
46
+ export declare const getHeightSegment: (track: TrackEntry) => HeightSegment | null;
47
+ export declare const getDisplayWidthSegment: (track: TrackEntry) => DisplayWidthSegment | null;
48
+ export declare const getDisplayHeightSegment: (track: TrackEntry) => DisplayHeightSegment | null;
49
+ export declare const getTrackTypeSegment: (track: TrackEntry) => TrackTypeSegment | null;
50
+ export declare const getTrackId: (track: TrackEntry) => number;
51
+ export declare const getCodecSegment: (track: TrackEntry) => CodecIdSegment | null;
50
52
  export declare const hasSkippedMdatProcessing: (anySegment: AnySegment[]) => {
51
53
  skipped: false;
52
54
  fileOffset?: undefined;
package/dist/traversal.js CHANGED
@@ -151,41 +151,41 @@ const getStssBox = (trakBox) => {
151
151
  };
152
152
  exports.getStssBox = getStssBox;
153
153
  const getClusterSegment = (segment) => {
154
- const clusterSegment = segment.children.find((b) => b.type === 'cluster-segment');
154
+ const clusterSegment = segment.value.find((b) => b.type === 'Cluster');
155
155
  return clusterSegment !== null && clusterSegment !== void 0 ? clusterSegment : null;
156
156
  };
157
157
  exports.getClusterSegment = getClusterSegment;
158
158
  const getTracksSegment = (segment) => {
159
- const tracksSegment = segment.children.find((b) => b.type === 'tracks-segment');
160
- if (!tracksSegment || tracksSegment.type !== 'tracks-segment') {
159
+ const tracksSegment = segment.value.find((b) => b.type === 'Tracks');
160
+ if (!tracksSegment || tracksSegment.type !== 'Tracks') {
161
161
  return null;
162
162
  }
163
163
  return tracksSegment;
164
164
  };
165
165
  exports.getTracksSegment = getTracksSegment;
166
166
  const getTimescaleSegment = (segment) => {
167
- const infoSegment = segment.children.find((b) => b.type === 'info-segment');
168
- if (!infoSegment || infoSegment.type !== 'info-segment') {
167
+ const infoSegment = segment.value.find((b) => b.type === 'Info');
168
+ if (!infoSegment || infoSegment.type !== 'Info') {
169
169
  return null;
170
170
  }
171
- const timescale = infoSegment.children.find((b) => b.type === 'timestamp-scale-segment');
172
- if (!timescale || timescale.type !== 'timestamp-scale-segment') {
171
+ const timescale = infoSegment.value.find((b) => b.type === 'TimestampScale');
172
+ if (!timescale || timescale.type !== 'TimestampScale') {
173
173
  return null;
174
174
  }
175
175
  return timescale;
176
176
  };
177
177
  exports.getTimescaleSegment = getTimescaleSegment;
178
178
  const getVideoSegment = (track) => {
179
- const videoSegment = track.children.find((b) => b.type === 'video-segment');
180
- if (!videoSegment || videoSegment.type !== 'video-segment') {
179
+ const videoSegment = track.value.find((b) => b.type === 'Video');
180
+ if (!videoSegment || videoSegment.type !== 'Video') {
181
181
  return null;
182
182
  }
183
183
  return videoSegment !== null && videoSegment !== void 0 ? videoSegment : null;
184
184
  };
185
185
  exports.getVideoSegment = getVideoSegment;
186
186
  const getAudioSegment = (track) => {
187
- const audioSegment = track.children.find((b) => b.type === 'audio-segment');
188
- if (!audioSegment || audioSegment.type !== 'audio-segment') {
187
+ const audioSegment = track.value.find((b) => b.type === 'Audio');
188
+ if (!audioSegment || audioSegment.type !== 'Audio') {
189
189
  return null;
190
190
  }
191
191
  return audioSegment !== null && audioSegment !== void 0 ? audioSegment : null;
@@ -196,12 +196,11 @@ const getSampleRate = (track) => {
196
196
  if (!audioSegment) {
197
197
  return null;
198
198
  }
199
- const samplingFrequency = audioSegment.children.find((b) => b.type === 'sampling-frequency-segment');
200
- if (!samplingFrequency ||
201
- samplingFrequency.type !== 'sampling-frequency-segment') {
199
+ const samplingFrequency = audioSegment.value.find((b) => b.type === 'SamplingFrequency');
200
+ if (!samplingFrequency || samplingFrequency.type !== 'SamplingFrequency') {
202
201
  return null;
203
202
  }
204
- return samplingFrequency.samplingFrequency;
203
+ return samplingFrequency.value.value;
205
204
  };
206
205
  exports.getSampleRate = getSampleRate;
207
206
  const getNumberOfChannels = (track) => {
@@ -209,11 +208,11 @@ const getNumberOfChannels = (track) => {
209
208
  if (!audioSegment) {
210
209
  throw new Error('Could not find audio segment');
211
210
  }
212
- const channels = audioSegment.children.find((b) => b.type === 'channels-segment');
213
- if (!channels || channels.type !== 'channels-segment') {
211
+ const channels = audioSegment.value.find((b) => b.type === 'Channels');
212
+ if (!channels || channels.type !== 'Channels') {
214
213
  return 1;
215
214
  }
216
- return channels.channels;
215
+ return channels.value.value;
217
216
  };
218
217
  exports.getNumberOfChannels = getNumberOfChannels;
219
218
  const getBitDepth = (track) => {
@@ -221,19 +220,19 @@ const getBitDepth = (track) => {
221
220
  if (!audioSegment) {
222
221
  return null;
223
222
  }
224
- const bitDepth = audioSegment.children.find((b) => b.type === 'bit-depth-segment');
225
- if (!bitDepth || bitDepth.type !== 'bit-depth-segment') {
223
+ const bitDepth = audioSegment.value.find((b) => b.type === 'BitDepth');
224
+ if (!bitDepth || bitDepth.type !== 'BitDepth') {
226
225
  return null;
227
226
  }
228
- return bitDepth.bitDepth;
227
+ return bitDepth.value.value;
229
228
  };
230
229
  exports.getBitDepth = getBitDepth;
231
230
  const getPrivateData = (track) => {
232
- const privateData = track.children.find((b) => b.type === 'codec-private-segment');
233
- if (!privateData || privateData.type !== 'codec-private-segment') {
231
+ const privateData = track.value.find((b) => b.type === 'CodecPrivate');
232
+ if (!privateData || privateData.type !== 'CodecPrivate') {
234
233
  return null;
235
234
  }
236
- return privateData.codecPrivateData;
235
+ return privateData.value;
237
236
  };
238
237
  exports.getPrivateData = getPrivateData;
239
238
  const getWidthSegment = (track) => {
@@ -241,8 +240,8 @@ const getWidthSegment = (track) => {
241
240
  if (!videoSegment) {
242
241
  return null;
243
242
  }
244
- const width = videoSegment.children.find((b) => b.type === 'width-segment');
245
- if (!width || width.type !== 'width-segment') {
243
+ const width = videoSegment.value.find((b) => b.type === 'PixelWidth');
244
+ if (!width || width.type !== 'PixelWidth') {
246
245
  return null;
247
246
  }
248
247
  return width;
@@ -253,8 +252,8 @@ const getHeightSegment = (track) => {
253
252
  if (!videoSegment) {
254
253
  return null;
255
254
  }
256
- const height = videoSegment.children.find((b) => b.type === 'height-segment');
257
- if (!height || height.type !== 'height-segment') {
255
+ const height = videoSegment.value.find((b) => b.type === 'PixelHeight');
256
+ if (!height || height.type !== 'PixelHeight') {
258
257
  return null;
259
258
  }
260
259
  return height;
@@ -265,8 +264,8 @@ const getDisplayWidthSegment = (track) => {
265
264
  if (!videoSegment) {
266
265
  return null;
267
266
  }
268
- const displayWidth = videoSegment.children.find((b) => b.type === 'display-width-segment');
269
- if (!displayWidth || displayWidth.type !== 'display-width-segment') {
267
+ const displayWidth = videoSegment.value.find((b) => b.type === 'DisplayWidth');
268
+ if (!displayWidth || displayWidth.type !== 'DisplayWidth') {
270
269
  return null;
271
270
  }
272
271
  return displayWidth;
@@ -277,32 +276,32 @@ const getDisplayHeightSegment = (track) => {
277
276
  if (!videoSegment) {
278
277
  return null;
279
278
  }
280
- const displayHeight = videoSegment.children.find((b) => b.type === 'display-height-segment');
281
- if (!displayHeight || displayHeight.type !== 'display-height-segment') {
279
+ const displayHeight = videoSegment.value.find((b) => b.type === 'DisplayHeight');
280
+ if (!displayHeight || displayHeight.type !== 'DisplayHeight') {
282
281
  return null;
283
282
  }
284
283
  return displayHeight;
285
284
  };
286
285
  exports.getDisplayHeightSegment = getDisplayHeightSegment;
287
286
  const getTrackTypeSegment = (track) => {
288
- const trackType = track.children.find((b) => b.type === 'track-type-segment');
289
- if (!trackType || trackType.type !== 'track-type-segment') {
287
+ const trackType = track.value.find((b) => b.type === 'TrackType');
288
+ if (!trackType || trackType.type !== 'TrackType') {
290
289
  return null;
291
290
  }
292
291
  return trackType;
293
292
  };
294
293
  exports.getTrackTypeSegment = getTrackTypeSegment;
295
294
  const getTrackId = (track) => {
296
- const trackId = track.children.find((b) => b.type === 'track-number-segment');
297
- if (!trackId || trackId.type !== 'track-number-segment') {
295
+ const trackId = track.value.find((b) => b.type === 'TrackNumber');
296
+ if (!trackId || trackId.type !== 'TrackNumber') {
298
297
  throw new Error('Expected track number segment');
299
298
  }
300
- return trackId.trackNumber;
299
+ return trackId.value.value;
301
300
  };
302
301
  exports.getTrackId = getTrackId;
303
302
  const getCodecSegment = (track) => {
304
- const codec = track.children.find((b) => b.type === 'codec-segment');
305
- if (!codec || codec.type !== 'codec-segment') {
303
+ const codec = track.value.find((b) => b.type === 'CodecID');
304
+ if (!codec || codec.type !== 'CodecID') {
306
305
  return null;
307
306
  }
308
307
  return codec;
@@ -0,0 +1 @@
1
+ declare const understand: (src: string) => Promise<void>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ const understand = async (src) => {
3
+ const content = await Bun.file(src).arrayBuffer();
4
+ const firstBit = new DataView(content).getUint8(0);
5
+ const offset = new DataView(content).getUint8(1);
6
+ const offset2 = new DataView(content).getUint8(2);
7
+ const globalOffset = firstBit + 1;
8
+ const header = new TextDecoder().decode(content.slice(globalOffset, globalOffset + offset));
9
+ const comment = new TextDecoder().decode(content.slice(globalOffset + offset, globalOffset + offset2));
10
+ const rest = new TextDecoder().decode(content.slice(globalOffset + offset2 + offset, globalOffset + offset2 + offset + 50));
11
+ console.log({ firstBit, offset, offset2, header, comment, rest });
12
+ };
package/input.webm ADDED
Binary file
package/package.json CHANGED
@@ -3,11 +3,11 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/media-parser"
4
4
  },
5
5
  "name": "@remotion/media-parser",
6
- "version": "4.0.201",
6
+ "version": "4.0.204",
7
7
  "main": "dist/index.js",
8
8
  "sideEffects": false,
9
9
  "devDependencies": {
10
- "@remotion/renderer": "4.0.201"
10
+ "@remotion/renderer": "4.0.204"
11
11
  },
12
12
  "publishConfig": {
13
13
  "access": "public"
@@ -0,0 +1,69 @@
1
+ import {getTimescaleAndDuration} from '../../get-fps';
2
+ import type {SamplePosition} from '../../get-sample-positions';
3
+ import {getSamplePositions} from '../../get-sample-positions';
4
+ import type {IsoBaseMediaBox} from '../../parse-result';
5
+ import {getSamplesFromMoof} from '../../samples-from-moof';
6
+ import {
7
+ getCttsBox,
8
+ getStcoBox,
9
+ getStscBox,
10
+ getStssBox,
11
+ getStszBox,
12
+ getSttsBox,
13
+ getTkhdBox,
14
+ } from '../../traversal';
15
+ import type {TrakBox} from './trak/trak';
16
+
17
+ export const getSamplePositionsFromTrack = (
18
+ trakBox: TrakBox,
19
+ moofBox: IsoBaseMediaBox | null,
20
+ ): SamplePosition[] => {
21
+ const stszBox = getStszBox(trakBox);
22
+ const stcoBox = getStcoBox(trakBox);
23
+ const stscBox = getStscBox(trakBox);
24
+ const stssBox = getStssBox(trakBox);
25
+ const sttsBox = getSttsBox(trakBox);
26
+ const tkhdBox = getTkhdBox(trakBox);
27
+ const cttsBox = getCttsBox(trakBox);
28
+
29
+ const timescaleAndDuration = getTimescaleAndDuration(trakBox);
30
+
31
+ if (!tkhdBox) {
32
+ throw new Error('Expected tkhd box in trak box');
33
+ }
34
+
35
+ if (!stszBox) {
36
+ throw new Error('Expected stsz box in trak box');
37
+ }
38
+
39
+ if (!stcoBox) {
40
+ throw new Error('Expected stco box in trak box');
41
+ }
42
+
43
+ if (!stscBox) {
44
+ throw new Error('Expected stsc box in trak box');
45
+ }
46
+
47
+ if (!sttsBox) {
48
+ throw new Error('Expected stts box in trak box');
49
+ }
50
+
51
+ if (!timescaleAndDuration) {
52
+ throw new Error('Expected timescale and duration in trak box');
53
+ }
54
+
55
+ let samplePositions = getSamplePositions({
56
+ stcoBox,
57
+ stscBox,
58
+ stszBox,
59
+ stssBox,
60
+ sttsBox,
61
+ cttsBox,
62
+ });
63
+
64
+ if (samplePositions.length === 0 && moofBox) {
65
+ samplePositions = getSamplesFromMoof({moofBox, trackId: tkhdBox.trackId});
66
+ }
67
+
68
+ return samplePositions;
69
+ };