@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
@@ -1,8 +1,3 @@
1
1
  import type { ColorParameterBox } from './boxes/iso-base-media/stsd/colr';
2
2
  import type { Av1BitstreamHeaderSegment } from './boxes/webm/bitstream/av1/header-segment';
3
- import type { ClusterSegment, TrackEntrySegment } from './boxes/webm/segments/track-entry';
4
3
  export declare const constructAv1CodecString: (av1BitstreamHeader: Av1BitstreamHeaderSegment, colrAtom: ColorParameterBox | null) => string;
5
- export declare const av1CodecStringToString: ({ track, clusterSegment, }: {
6
- track: TrackEntrySegment;
7
- clusterSegment: ClusterSegment;
8
- }) => string | null;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  // https://aomediacodec.github.io/av1-isobmff/#codecsparam
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.av1CodecStringToString = exports.constructAv1CodecString = void 0;
5
- const traversal_1 = require("./boxes/webm/traversal");
6
- const traversal_2 = require("./traversal");
4
+ exports.constructAv1CodecString = void 0;
7
5
  const constructAv1CodecString = (av1BitstreamHeader, colrAtom) => {
8
6
  let str = 'av01.';
9
7
  // Profile
@@ -91,18 +89,3 @@ const constructAv1CodecString = (av1BitstreamHeader, colrAtom) => {
91
89
  return str;
92
90
  };
93
91
  exports.constructAv1CodecString = constructAv1CodecString;
94
- const av1CodecStringToString = ({ track, clusterSegment, }) => {
95
- const codecSegment = (0, traversal_2.getCodecSegment)(track);
96
- if (!codecSegment) {
97
- throw new Error('Expected codec segment');
98
- }
99
- if (codecSegment.codec !== 'V_AV1') {
100
- throw new Error(`Should not call this function if it is not AV1: ${codecSegment.codec}`);
101
- }
102
- const av1BitstreamHeader = (0, traversal_1.getAv1BitstreamHeader)(clusterSegment);
103
- if (!av1BitstreamHeader) {
104
- return null;
105
- }
106
- return (0, exports.constructAv1CodecString)(av1BitstreamHeader, null);
107
- };
108
- exports.av1CodecStringToString = av1CodecStringToString;
@@ -0,0 +1,9 @@
1
+ import type { BaseBox } from './base-type';
2
+ export interface FtypBox extends BaseBox {
3
+ type: 'ftyp-box';
4
+ majorBrand: string;
5
+ minorVersion: number;
6
+ compatibleBrands: string[];
7
+ }
8
+ export declare const fourByteToNumber: (data: ArrayBuffer, from: number) => number;
9
+ export declare const parseFtyp: (data: ArrayBuffer, offset: number) => FtypBox;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFtyp = exports.fourByteToNumber = void 0;
4
+ const fourByteToNumber = (data, from) => {
5
+ const view = new DataView(data);
6
+ return ((view.getUint8(from + 0) << 24) |
7
+ (view.getUint8(from + 1) << 16) |
8
+ (view.getUint8(from + 2) << 8) |
9
+ view.getUint8(from + 3));
10
+ };
11
+ exports.fourByteToNumber = fourByteToNumber;
12
+ const parseFtyp = (data, offset) => {
13
+ const majorBrand = new TextDecoder().decode(data.slice(8, 12)).trim();
14
+ const minorVersion = (0, exports.fourByteToNumber)(data, 12);
15
+ const rest = data.slice(16);
16
+ const types = rest.byteLength / 4;
17
+ const compatibleBrands = [];
18
+ for (let i = 0; i < types; i++) {
19
+ const fourBytes = rest.slice(i * 4, i * 4 + 4);
20
+ compatibleBrands.push(new TextDecoder().decode(fourBytes).trim());
21
+ }
22
+ return {
23
+ type: 'ftyp-box',
24
+ majorBrand,
25
+ minorVersion,
26
+ compatibleBrands,
27
+ offset,
28
+ boxSize: data.byteLength,
29
+ };
30
+ };
31
+ exports.parseFtyp = parseFtyp;
@@ -0,0 +1,4 @@
1
+ import type { SamplePosition } from '../../get-sample-positions';
2
+ import type { IsoBaseMediaBox } from '../../parse-result';
3
+ import type { TrakBox } from './trak/trak';
4
+ export declare const getSamplePositionsFromTrack: (trakBox: TrakBox, moofBox: IsoBaseMediaBox | null) => SamplePosition[];
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSamplePositionsFromTrack = void 0;
4
+ const get_fps_1 = require("../../get-fps");
5
+ const get_sample_positions_1 = require("../../get-sample-positions");
6
+ const samples_from_moof_1 = require("../../samples-from-moof");
7
+ const traversal_1 = require("../../traversal");
8
+ const getSamplePositionsFromTrack = (trakBox, moofBox) => {
9
+ const stszBox = (0, traversal_1.getStszBox)(trakBox);
10
+ const stcoBox = (0, traversal_1.getStcoBox)(trakBox);
11
+ const stscBox = (0, traversal_1.getStscBox)(trakBox);
12
+ const stssBox = (0, traversal_1.getStssBox)(trakBox);
13
+ const sttsBox = (0, traversal_1.getSttsBox)(trakBox);
14
+ const tkhdBox = (0, traversal_1.getTkhdBox)(trakBox);
15
+ const cttsBox = (0, traversal_1.getCttsBox)(trakBox);
16
+ const timescaleAndDuration = (0, get_fps_1.getTimescaleAndDuration)(trakBox);
17
+ if (!tkhdBox) {
18
+ throw new Error('Expected tkhd box in trak box');
19
+ }
20
+ if (!stszBox) {
21
+ throw new Error('Expected stsz box in trak box');
22
+ }
23
+ if (!stcoBox) {
24
+ throw new Error('Expected stco box in trak box');
25
+ }
26
+ if (!stscBox) {
27
+ throw new Error('Expected stsc box in trak box');
28
+ }
29
+ if (!sttsBox) {
30
+ throw new Error('Expected stts box in trak box');
31
+ }
32
+ if (!timescaleAndDuration) {
33
+ throw new Error('Expected timescale and duration in trak box');
34
+ }
35
+ let samplePositions = (0, get_sample_positions_1.getSamplePositions)({
36
+ stcoBox,
37
+ stscBox,
38
+ stszBox,
39
+ stssBox,
40
+ sttsBox,
41
+ cttsBox,
42
+ });
43
+ if (samplePositions.length === 0 && moofBox) {
44
+ samplePositions = (0, samples_from_moof_1.getSamplesFromMoof)({ moofBox, trackId: tkhdBox.trackId });
45
+ }
46
+ return samplePositions;
47
+ };
48
+ exports.getSamplePositionsFromTrack = getSamplePositionsFromTrack;
@@ -19,13 +19,13 @@ const parseMvhd = ({ iterator, offset, size, }) => {
19
19
  const durationInUnits = iterator.getUint32();
20
20
  const durationInSeconds = durationInUnits / timeScale;
21
21
  const rateArray = iterator.getSlice(4);
22
- const rateView = (0, buffer_iterator_1.getArrayBufferIterator)(rateArray);
22
+ const rateView = (0, buffer_iterator_1.getArrayBufferIterator)(rateArray, rateArray.length);
23
23
  const rate = rateView.getInt8() * 10 +
24
24
  rateView.getInt8() +
25
25
  rateView.getInt8() * 0.1 +
26
26
  rateView.getInt8() * 0.01;
27
27
  const volumeArray = iterator.getSlice(2);
28
- const volumeView = (0, buffer_iterator_1.getArrayBufferIterator)(volumeArray);
28
+ const volumeView = (0, buffer_iterator_1.getArrayBufferIterator)(volumeArray, volumeArray.length);
29
29
  const volume = volumeView.getInt8() + volumeView.getInt8() * 0.1;
30
30
  // reserved 16bit
31
31
  iterator.discard(2);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseKeys = void 0;
4
4
  const buffer_iterator_1 = require("../../../buffer-iterator");
5
5
  const parseKeys = (data, offset) => {
6
- const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data);
6
+ const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data, data.byteLength);
7
7
  const size = iterator.getUint32();
8
8
  if (size !== data.byteLength) {
9
9
  throw new Error(`Expected keys size of ${data.byteLength}, got ${size}`);
@@ -0,0 +1,12 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ export interface TfdtBox {
3
+ type: 'tfdt-box';
4
+ version: number;
5
+ baseMediaDecodeTime: number;
6
+ offset: number;
7
+ }
8
+ export declare const parseTfdt: ({ iterator, size, offset, }: {
9
+ iterator: BufferIterator;
10
+ size: number;
11
+ offset: number;
12
+ }) => TfdtBox;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTfdt = void 0;
4
+ const parseTfdt = ({ iterator, size, offset, }) => {
5
+ const version = iterator.getUint8();
6
+ iterator.discard(3);
7
+ // Flags, discard them
8
+ const num = version === 0 ? iterator.getUint32() : Number(iterator.getUint64());
9
+ const bytesRemaining = size - (iterator.counter.getOffset() - offset);
10
+ if (bytesRemaining !== 0) {
11
+ throw new Error('expected 0 bytes ' + bytesRemaining);
12
+ }
13
+ return {
14
+ type: 'tfdt-box',
15
+ version,
16
+ baseMediaDecodeTime: num,
17
+ offset,
18
+ };
19
+ };
20
+ exports.parseTfdt = parseTfdt;
@@ -0,0 +1,16 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ export interface TfhdBox {
3
+ type: 'tfhd-box';
4
+ version: number;
5
+ trackId: number;
6
+ baseDataOffset: number;
7
+ baseSampleDescriptionIndex: number;
8
+ defaultSampleDuration: number;
9
+ defaultSampleSize: number;
10
+ defaultSampleFlags: number;
11
+ }
12
+ export declare const getTfhd: ({ iterator, offset, size, }: {
13
+ iterator: BufferIterator;
14
+ size: number;
15
+ offset: number;
16
+ }) => TfhdBox;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTfhd = void 0;
4
+ const getTfhd = ({ iterator, offset, size, }) => {
5
+ const version = iterator.getUint8();
6
+ const flags = iterator.getUint24();
7
+ const trackId = iterator.getUint32();
8
+ const baseDataOffsetPresent = flags & 0x01;
9
+ const baseDataOffset = baseDataOffsetPresent
10
+ ? Number(iterator.getUint64())
11
+ : 0;
12
+ const baseSampleDescriptionIndexPresent = flags & 0x02;
13
+ const baseSampleDescriptionIndex = baseSampleDescriptionIndexPresent
14
+ ? iterator.getUint32()
15
+ : 0;
16
+ const defaultSampleDurationPresent = flags & 0x08;
17
+ const defaultSampleDuration = defaultSampleDurationPresent
18
+ ? iterator.getUint32()
19
+ : 0;
20
+ const defaultSampleSizePresent = flags & 0x10;
21
+ const defaultSampleSize = defaultSampleSizePresent ? iterator.getUint32() : 0;
22
+ const defaultSampleFlagsPresent = flags & 0x20;
23
+ const defaultSampleFlags = defaultSampleFlagsPresent
24
+ ? iterator.getUint32()
25
+ : 0;
26
+ const bytesRemaining = size - (iterator.counter.getOffset() - offset);
27
+ if (bytesRemaining !== 0) {
28
+ throw new Error('expected 0 bytes ' + bytesRemaining);
29
+ }
30
+ return {
31
+ type: 'tfhd-box',
32
+ version,
33
+ trackId,
34
+ baseDataOffset,
35
+ baseSampleDescriptionIndex,
36
+ defaultSampleDuration,
37
+ defaultSampleSize,
38
+ defaultSampleFlags,
39
+ };
40
+ };
41
+ exports.getTfhd = getTfhd;
@@ -0,0 +1,21 @@
1
+ import type { BufferIterator } from '../../buffer-iterator';
2
+ export interface TrunBox {
3
+ type: 'trun-box';
4
+ version: number;
5
+ sampleCount: number;
6
+ dataOffset: number | null;
7
+ firstSampleFlags: number | null;
8
+ samples: TRunSample[];
9
+ }
10
+ type TRunSample = {
11
+ sampleDuration: number | null;
12
+ sampleSize: number | null;
13
+ sampleFlags: number | null;
14
+ sampleCompositionTimeOffset: number | null;
15
+ };
16
+ export declare const parseTrun: ({ iterator, offset, size, }: {
17
+ iterator: BufferIterator;
18
+ offset: number;
19
+ size: number;
20
+ }) => TrunBox;
21
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTrun = void 0;
4
+ const parseTrun = ({ iterator, offset, size, }) => {
5
+ const version = iterator.getUint8();
6
+ if (version !== 0) {
7
+ throw new Error(`Unsupported TRUN version ${version}`);
8
+ }
9
+ const flags = iterator.getUint24();
10
+ const sampleCount = iterator.getUint32();
11
+ const dataOffset = flags & 0x01 ? iterator.getInt32() : null;
12
+ const firstSampleFlags = flags & 0x04 ? iterator.getUint32() : null;
13
+ const samples = [];
14
+ for (let i = 0; i < sampleCount; i++) {
15
+ const sampleDuration = flags & 0x100 ? iterator.getUint32() : null;
16
+ const sampleSize = flags & 0x200 ? iterator.getUint32() : null;
17
+ const sampleFlags = flags & 0x400 ? iterator.getUint32() : null;
18
+ const sampleCompositionTimeOffset = flags & 0x800
19
+ ? version === 0
20
+ ? iterator.getUint32()
21
+ : iterator.getInt32Le()
22
+ : null;
23
+ samples.push({
24
+ sampleDuration,
25
+ sampleSize,
26
+ sampleFlags,
27
+ sampleCompositionTimeOffset,
28
+ });
29
+ }
30
+ const currentOffset = iterator.counter.getOffset();
31
+ const left = size - (currentOffset - offset);
32
+ if (left !== 0) {
33
+ throw new Error(`Unexpected data left in TRUN box: ${left}`);
34
+ }
35
+ return {
36
+ type: 'trun-box',
37
+ version,
38
+ sampleCount,
39
+ dataOffset,
40
+ firstSampleFlags,
41
+ samples,
42
+ };
43
+ };
44
+ exports.parseTrun = parseTrun;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseAv1PrivateData = void 0;
4
4
  const buffer_iterator_1 = require("../../buffer-iterator");
5
5
  const parseAv1PrivateData = (data, colrAtom) => {
6
- const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data);
6
+ const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(data, data.byteLength);
7
7
  iterator.startReadingBits();
8
8
  if (iterator.getBits(1) !== 1) {
9
9
  iterator.destroy();
@@ -50,15 +50,6 @@ const av1Bitstream = ({ stream, length, onVideoSample, trackNumber, context, tim
50
50
  : {
51
51
  type: 'av1-bitstream-unimplemented',
52
52
  };
53
- if (segment.type === 'av1-bitstream-header') {
54
- if (!size) {
55
- throw new Error('Expected size');
56
- }
57
- const toSample = bytesReadSoFar + size;
58
- stream.counter.decrement(stream.counter.getOffset() - address);
59
- const header = stream.getSlice(toSample);
60
- context.parserState.setAv1BitstreamHeaderSegment(segment, header);
61
- }
62
53
  if (obuType === 6) {
63
54
  const head = context.parserState.getAv1BitstreamHeaderSegment();
64
55
  if (!head) {
@@ -89,7 +80,7 @@ const av1Bitstream = ({ stream, length, onVideoSample, trackNumber, context, tim
89
80
  }
90
81
  }
91
82
  onVideoSample(trackNumber, {
92
- bytes: (0, combine_uint8array_1.combineUint8Arrays)(extraBytes, frame),
83
+ data: (0, combine_uint8array_1.combineUint8Arrays)(extraBytes, frame),
93
84
  timestamp: timecode + clusterTimestamp,
94
85
  duration: undefined,
95
86
  trackId: trackNumber,
@@ -1,2 +1,2 @@
1
- import type { TrackEntrySegment } from './segments/track-entry';
2
- export declare const getAudioDescription: (track: TrackEntrySegment) => undefined | Uint8Array;
1
+ import type { TrackEntry } from './segments/all-segments';
2
+ export declare const getAudioDescription: (track: TrackEntry) => undefined | Uint8Array;
@@ -5,7 +5,7 @@ const buffer_iterator_1 = require("../../buffer-iterator");
5
5
  const traversal_1 = require("../../traversal");
6
6
  const getAudioDescription = (track) => {
7
7
  const codec = (0, traversal_1.getCodecSegment)(track);
8
- if (!codec || codec.codec !== 'A_VORBIS') {
8
+ if (!codec || codec.value !== 'A_VORBIS') {
9
9
  return undefined;
10
10
  }
11
11
  // how to parse vorbis private
@@ -44,7 +44,7 @@ const getAudioDescription = (track) => {
44
44
  throw new Error('Error parsing vorbis codec private');
45
45
  }
46
46
  const vorbisBooks = privateData.slice(offset);
47
- const bufferIterator = (0, buffer_iterator_1.getArrayBufferIterator)(vorbisInfo.slice(0));
47
+ const bufferIterator = (0, buffer_iterator_1.getArrayBufferIterator)(vorbisInfo.slice(0), vorbisInfo.length);
48
48
  // type
49
49
  bufferIterator.getUint8();
50
50
  // vorbis
@@ -1,2 +1,2 @@
1
- export declare const measureEBMLVarInt: (value: number) => 1 | 2 | 5 | 3 | 6 | 4;
2
- export declare const getVariableInt: (value: number, width?: number) => Uint8Array;
1
+ export declare const measureEBMLVarInt: (value: number) => 2 | 3 | 1 | 4 | 5 | 6;
2
+ export declare const getVariableInt: (value: number, minWidth: number | null) => Uint8Array;
@@ -28,7 +28,8 @@ const measureEBMLVarInt = (value) => {
28
28
  throw new Error('EBML VINT size not supported ' + value);
29
29
  };
30
30
  exports.measureEBMLVarInt = measureEBMLVarInt;
31
- const getVariableInt = (value, width = (0, exports.measureEBMLVarInt)(value)) => {
31
+ const getVariableInt = (value, minWidth) => {
32
+ const width = Math.max((0, exports.measureEBMLVarInt)(value), minWidth !== null && minWidth !== void 0 ? minWidth : 0);
32
33
  switch (width) {
33
34
  case 1:
34
35
  return new Uint8Array([(1 << 7) | value]);
@@ -65,6 +66,27 @@ const getVariableInt = (value, width = (0, exports.measureEBMLVarInt)(value)) =>
65
66
  value >> 8,
66
67
  value,
67
68
  ]);
69
+ case 7:
70
+ return new Uint8Array([
71
+ (1 << 1) | ((value / 2 ** 48) & 0x1),
72
+ (value / 2 ** 40) | 0,
73
+ (value / 2 ** 32) | 0,
74
+ value >> 24,
75
+ value >> 16,
76
+ value >> 8,
77
+ value,
78
+ ]);
79
+ case 8:
80
+ return new Uint8Array([
81
+ (1 << 0) | ((value / 2 ** 56) & 0x1),
82
+ (value / 2 ** 48) | 0,
83
+ (value / 2 ** 40) | 0,
84
+ (value / 2 ** 32) | 0,
85
+ value >> 24,
86
+ value >> 16,
87
+ value >> 8,
88
+ value,
89
+ ]);
68
90
  default:
69
91
  throw new Error('Bad EBML VINT size ' + width);
70
92
  }
@@ -1,3 +1,3 @@
1
1
  import type { Track } from '../../get-tracks';
2
- import type { MainSegment } from './segments/main';
2
+ import type { MainSegment } from './segments/all-segments';
3
3
  export declare const getTracksFromMatroska: (segment: MainSegment, timescale: number) => Track[];
@@ -9,11 +9,11 @@ const getTracksFromMatroska = (segment, timescale) => {
9
9
  throw new Error('No tracks segment');
10
10
  }
11
11
  const tracks = [];
12
- for (const trackEntrySegment of tracksSegment.children) {
13
- if (trackEntrySegment.type === 'crc32-segment') {
12
+ for (const trackEntrySegment of tracksSegment.value) {
13
+ if (trackEntrySegment.type === 'Crc32') {
14
14
  continue;
15
15
  }
16
- if (trackEntrySegment.type !== 'track-entry-segment') {
16
+ if (trackEntrySegment.type !== 'TrackEntry') {
17
17
  throw new Error('Expected track entry segment');
18
18
  }
19
19
  const track = (0, get_track_1.getTrack)({
@@ -0,0 +1,17 @@
1
+ import type { ParserContext } from '../../parser-context';
2
+ import type { AudioSample, VideoSample } from '../../webcodec-sample-types';
3
+ import type { BlockSegment, SimpleBlockSegment } from './segments/all-segments';
4
+ type SampleResult = {
5
+ type: 'video-sample';
6
+ videoSample: VideoSample;
7
+ } | {
8
+ type: 'audio-sample';
9
+ audioSample: AudioSample;
10
+ } | {
11
+ type: 'partial-video-sample';
12
+ partialVideoSample: Omit<VideoSample, 'type'>;
13
+ } | {
14
+ type: 'no-sample';
15
+ };
16
+ export declare const getSampleFromBlock: (ebml: BlockSegment | SimpleBlockSegment, parserContext: ParserContext, offset: number) => SampleResult;
17
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSampleFromBlock = void 0;
4
+ const buffer_iterator_1 = require("../../buffer-iterator");
5
+ const all_segments_1 = require("./segments/all-segments");
6
+ const block_simple_block_flags_1 = require("./segments/block-simple-block-flags");
7
+ const getSampleFromBlock = (ebml, parserContext, offset) => {
8
+ const iterator = (0, buffer_iterator_1.getArrayBufferIterator)(ebml.value, ebml.value.length);
9
+ const trackNumber = iterator.getVint();
10
+ if (trackNumber === null) {
11
+ throw new Error('Not enough data to get track number, should not happen');
12
+ }
13
+ const timecodeRelativeToCluster = iterator.getUint16();
14
+ const { keyframe } = (0, block_simple_block_flags_1.parseBlockFlags)(iterator, ebml.type === 'SimpleBlock'
15
+ ? all_segments_1.matroskaElements.SimpleBlock
16
+ : all_segments_1.matroskaElements.Block);
17
+ const { codec, trackTimescale } = parserContext.parserState.getTrackInfoByNumber(trackNumber);
18
+ const clusterOffset = parserContext.parserState.getTimestampOffsetForByteOffset(offset);
19
+ const timescale = parserContext.parserState.getTimescale();
20
+ if (clusterOffset === undefined) {
21
+ throw new Error('Could not find offset for byte offset ' + offset);
22
+ }
23
+ // https://github.com/hubblec4/Matroska-Chapters-Specs/blob/master/notes.md/#timestampscale
24
+ // The TimestampScale Element is used to calculate the Raw Timestamp of a Block. The timestamp is obtained by adding the Block's timestamp to the Cluster's Timestamp Element, and then multiplying that result by the TimestampScale. The result will be the Block's Raw Timestamp in nanoseconds.
25
+ const timecodeInNanoSeconds = (timecodeRelativeToCluster + clusterOffset) *
26
+ timescale *
27
+ (trackTimescale !== null && trackTimescale !== void 0 ? trackTimescale : 1);
28
+ // Timecode should be in microseconds
29
+ const timecodeInMicroseconds = timecodeInNanoSeconds / 1000;
30
+ if (!codec) {
31
+ throw new Error(`Could not find codec for track ${trackNumber}`);
32
+ }
33
+ const remainingNow = ebml.value.length - (iterator.counter.getOffset() - 0);
34
+ if (codec.startsWith('V_')) {
35
+ const partialVideoSample = {
36
+ data: iterator.getSlice(remainingNow),
37
+ cts: null,
38
+ dts: null,
39
+ duration: undefined,
40
+ trackId: trackNumber,
41
+ timestamp: timecodeInMicroseconds,
42
+ };
43
+ if (keyframe === null) {
44
+ iterator.destroy();
45
+ return {
46
+ type: 'partial-video-sample',
47
+ partialVideoSample,
48
+ };
49
+ }
50
+ const sample = {
51
+ ...partialVideoSample,
52
+ type: keyframe ? 'key' : 'delta',
53
+ };
54
+ iterator.destroy();
55
+ return {
56
+ type: 'video-sample',
57
+ videoSample: sample,
58
+ };
59
+ }
60
+ if (codec.startsWith('A_')) {
61
+ const audioSample = {
62
+ data: iterator.getSlice(remainingNow),
63
+ trackId: trackNumber,
64
+ timestamp: timecodeInMicroseconds,
65
+ type: 'key',
66
+ };
67
+ iterator.destroy();
68
+ return {
69
+ type: 'audio-sample',
70
+ audioSample,
71
+ };
72
+ }
73
+ iterator.destroy();
74
+ return {
75
+ type: 'no-sample',
76
+ };
77
+ };
78
+ exports.getSampleFromBlock = getSampleFromBlock;
@@ -1,6 +1,6 @@
1
1
  import type { AudioTrack, VideoTrack } from '../../get-tracks';
2
- import type { TrackEntrySegment } from './segments/track-entry';
2
+ import type { TrackEntry } from './segments/all-segments';
3
3
  export declare const getTrack: ({ timescale, track, }: {
4
4
  timescale: number;
5
- track: TrackEntrySegment;
5
+ track: TrackEntry;
6
6
  }) => VideoTrack | AudioTrack | null;