@remotion/media-parser 4.0.201 → 4.0.202

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 (113) hide show
  1. package/dist/boxes/iso-base-media/mvhd.js +2 -2
  2. package/dist/boxes/iso-base-media/stsd/keys.js +1 -1
  3. package/dist/boxes/webm/av1-codec-private.js +1 -1
  4. package/dist/boxes/webm/description.d.ts +2 -2
  5. package/dist/boxes/webm/description.js +2 -2
  6. package/dist/boxes/webm/ebml.d.ts +2 -2
  7. package/dist/boxes/webm/ebml.js +23 -1
  8. package/dist/boxes/webm/get-ready-tracks.d.ts +1 -1
  9. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  10. package/dist/boxes/webm/get-sample-from-block.d.ts +17 -0
  11. package/dist/boxes/webm/get-sample-from-block.js +78 -0
  12. package/dist/boxes/webm/get-track.d.ts +2 -2
  13. package/dist/boxes/webm/get-track.js +26 -25
  14. package/dist/boxes/webm/make-header.d.ts +3 -8
  15. package/dist/boxes/webm/make-header.js +43 -20
  16. package/dist/boxes/webm/parse-ebml.d.ts +9 -4
  17. package/dist/boxes/webm/parse-ebml.js +122 -13
  18. package/dist/boxes/webm/segments/all-segments.d.ts +421 -107
  19. package/dist/boxes/webm/segments/all-segments.js +260 -33
  20. package/dist/boxes/webm/segments/seek-position.js +1 -1
  21. package/dist/boxes/webm/segments/seek.d.ts +1 -1
  22. package/dist/boxes/webm/segments/seek.js +2 -8
  23. package/dist/boxes/webm/segments/timestamp-scale.js +1 -1
  24. package/dist/boxes/webm/segments/track-entry.d.ts +3 -191
  25. package/dist/boxes/webm/segments/track-entry.js +2 -456
  26. package/dist/boxes/webm/segments.d.ts +3 -16
  27. package/dist/boxes/webm/segments.js +12 -196
  28. package/dist/boxes/webm/traversal.d.ts +5 -6
  29. package/dist/boxes/webm/traversal.js +6 -6
  30. package/dist/buffer-iterator.d.ts +1 -1
  31. package/dist/buffer-iterator.js +3 -3
  32. package/dist/create/create-media.d.ts +2 -0
  33. package/dist/create/create-media.js +36 -0
  34. package/dist/create/matroska-header.d.ts +1 -0
  35. package/dist/create/matroska-header.js +66 -0
  36. package/dist/create/matroska-info.d.ts +4 -0
  37. package/dist/create/matroska-info.js +39 -0
  38. package/dist/create/matroska-segment.d.ts +1 -0
  39. package/dist/create/matroska-segment.js +12 -0
  40. package/dist/create/matroska-trackentry.d.ts +21 -0
  41. package/dist/create/matroska-trackentry.js +191 -0
  42. package/dist/create-media.d.ts +1 -0
  43. package/dist/create-media.js +78 -0
  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/parse-media.js +4 -1
  50. package/dist/parser-context.d.ts +1 -0
  51. package/dist/parser-state.js +3 -2
  52. package/dist/readers/from-fetch.d.ts +2 -0
  53. package/dist/readers/from-fetch.js +64 -0
  54. package/dist/readers/from-node.d.ts +2 -0
  55. package/dist/readers/from-node.js +40 -0
  56. package/dist/readers/from-web-file.d.ts +2 -0
  57. package/dist/readers/from-web-file.js +39 -0
  58. package/dist/readers/reader.d.ts +11 -0
  59. package/dist/readers/reader.js +2 -0
  60. package/dist/traversal.d.ts +19 -17
  61. package/dist/traversal.js +38 -39
  62. package/dist/writers/web-fs.d.ts +2 -0
  63. package/dist/writers/web-fs.js +28 -0
  64. package/dist/writers/writer.d.ts +9 -0
  65. package/dist/writers/writer.js +2 -0
  66. package/input.webm +0 -0
  67. package/package.json +2 -2
  68. package/src/boxes/iso-base-media/mvhd.ts +2 -2
  69. package/src/boxes/iso-base-media/stsd/keys.ts +1 -1
  70. package/src/boxes/webm/av1-codec-private.ts +1 -1
  71. package/src/boxes/webm/description.ts +7 -4
  72. package/src/boxes/webm/ebml.ts +24 -4
  73. package/src/boxes/webm/get-ready-tracks.ts +4 -4
  74. package/src/boxes/webm/get-sample-from-block.ts +125 -0
  75. package/src/boxes/webm/get-track.ts +38 -31
  76. package/src/boxes/webm/make-header.ts +58 -51
  77. package/src/boxes/webm/parse-ebml.ts +170 -16
  78. package/src/boxes/webm/segments/all-segments.ts +379 -62
  79. package/src/boxes/webm/segments/track-entry.ts +3 -846
  80. package/src/boxes/webm/segments.ts +18 -410
  81. package/src/boxes/webm/traversal.ts +17 -17
  82. package/src/buffer-iterator.ts +5 -4
  83. package/src/get-audio-codec.ts +14 -16
  84. package/src/get-duration.ts +15 -16
  85. package/src/get-tracks.ts +2 -2
  86. package/src/get-video-codec.ts +13 -15
  87. package/src/parse-media.ts +6 -1
  88. package/src/parser-context.ts +1 -0
  89. package/src/parser-state.ts +2 -2
  90. package/src/test/create-matroska.test.ts +237 -23
  91. package/src/test/matroska.test.ts +283 -348
  92. package/src/test/mvhd.test.ts +1 -1
  93. package/src/test/parse-esds.test.ts +2 -2
  94. package/src/test/parse-stco.test.ts +2 -2
  95. package/src/test/parse-stsc.test.ts +2 -2
  96. package/src/test/parse-stsz.test.ts +2 -2
  97. package/src/test/parse-stts.test.ts +1 -1
  98. package/src/test/stsd.test.ts +4 -2
  99. package/src/test/tkhd.test.ts +1 -1
  100. package/src/traversal.ts +62 -85
  101. package/tsconfig.tsbuildinfo +1 -1
  102. package/src/boxes/webm/segments/duration.ts +0 -29
  103. package/src/boxes/webm/segments/info.ts +0 -34
  104. package/src/boxes/webm/segments/main.ts +0 -6
  105. package/src/boxes/webm/segments/muxing.ts +0 -18
  106. package/src/boxes/webm/segments/seek-head.ts +0 -34
  107. package/src/boxes/webm/segments/seek-position.ts +0 -18
  108. package/src/boxes/webm/segments/seek.ts +0 -55
  109. package/src/boxes/webm/segments/timestamp-scale.ts +0 -17
  110. package/src/boxes/webm/segments/tracks.ts +0 -32
  111. package/src/boxes/webm/segments/void.ts +0 -18
  112. package/src/boxes/webm/segments/writing.ts +0 -18
  113. package/src/combine-uint8array.ts +0 -13
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEbml = void 0;
3
+ exports.postprocessEbml = exports.parseEbml = void 0;
4
+ const add_new_matroska_tracks_1 = require("../../add-new-matroska-tracks");
5
+ const get_sample_from_block_1 = require("./get-sample-from-block");
6
+ const get_track_1 = require("./get-track");
4
7
  const all_segments_1 = require("./segments/all-segments");
5
- const parseEbml = (iterator) => {
8
+ const parseEbml = async (iterator, parserContext) => {
6
9
  const hex = iterator.getMatroskaSegmentId();
7
10
  if (hex === null) {
8
11
  throw new Error('Not enough bytes left to parse EBML - this should not happen');
@@ -11,36 +14,58 @@ const parseEbml = (iterator) => {
11
14
  if (!hasInMap) {
12
15
  throw new Error(`Don't know how to parse EBML hex ID ${JSON.stringify(hex)}`);
13
16
  }
17
+ const off = iterator.counter.getOffset();
14
18
  const size = iterator.getVint();
19
+ const minVintWidth = iterator.counter.getOffset() - off;
15
20
  if (size === null) {
16
21
  throw new Error('Not enough bytes left to parse EBML - this should not happen');
17
22
  }
18
23
  if (hasInMap.type === 'uint') {
24
+ const beforeUintOffset = iterator.counter.getOffset();
19
25
  const value = iterator.getUint(size);
20
- return { type: hasInMap.name, value, hex };
26
+ return {
27
+ type: hasInMap.name,
28
+ value: {
29
+ value,
30
+ byteLength: iterator.counter.getOffset() - beforeUintOffset,
31
+ },
32
+ minVintWidth,
33
+ };
21
34
  }
22
35
  if (hasInMap.type === 'string') {
23
36
  const value = iterator.getByteString(size);
24
37
  return {
25
38
  type: hasInMap.name,
26
39
  value,
27
- hex,
40
+ minVintWidth,
28
41
  };
29
42
  }
30
43
  if (hasInMap.type === 'float') {
31
44
  const value = size === 4 ? iterator.getFloat32() : iterator.getFloat64();
32
45
  return {
33
46
  type: hasInMap.name,
34
- value,
35
- hex,
47
+ value: {
48
+ value,
49
+ size: size === 4 ? '32' : '64',
50
+ },
51
+ minVintWidth,
36
52
  };
37
53
  }
38
- if (hasInMap.type === 'void') {
39
- iterator.discard(size);
54
+ if (hasInMap.type === 'hex-string') {
40
55
  return {
41
56
  type: hasInMap.name,
42
- value: undefined,
43
- hex,
57
+ value: '0x' +
58
+ [...iterator.getSlice(size)]
59
+ .map((b) => b.toString(16).padStart(2, '0'))
60
+ .join(''),
61
+ minVintWidth,
62
+ };
63
+ }
64
+ if (hasInMap.type === 'uint8array') {
65
+ return {
66
+ type: hasInMap.name,
67
+ value: iterator.getSlice(size),
68
+ minVintWidth,
44
69
  };
45
70
  }
46
71
  if (hasInMap.type === 'children') {
@@ -48,8 +73,14 @@ const parseEbml = (iterator) => {
48
73
  const startOffset = iterator.counter.getOffset();
49
74
  // eslint-disable-next-line no-constant-condition
50
75
  while (true) {
51
- const value = (0, exports.parseEbml)(iterator);
52
- children.push(value);
76
+ const offset = iterator.counter.getOffset();
77
+ const value = await (0, exports.parseEbml)(iterator, parserContext);
78
+ const remapped = await (0, exports.postprocessEbml)({
79
+ offset,
80
+ ebml: value,
81
+ parserContext,
82
+ });
83
+ children.push(remapped);
53
84
  const offsetNow = iterator.counter.getOffset();
54
85
  if (offsetNow - startOffset > size) {
55
86
  throw new Error(`Offset ${offsetNow - startOffset} is larger than the length of the hex ${size}`);
@@ -58,9 +89,87 @@ const parseEbml = (iterator) => {
58
89
  break;
59
90
  }
60
91
  }
61
- return { type: hasInMap.name, value: children, hex };
92
+ return { type: hasInMap.name, value: children, minVintWidth };
62
93
  }
63
94
  // @ts-expect-error
64
95
  throw new Error(`Unknown segment type ${hasInMap.type}`);
65
96
  };
66
97
  exports.parseEbml = parseEbml;
98
+ const postprocessEbml = async ({ offset, ebml, parserContext, }) => {
99
+ if (ebml.type === 'TimestampScale') {
100
+ parserContext.parserState.setTimescale(ebml.value.value);
101
+ }
102
+ if (ebml.type === 'TrackEntry') {
103
+ parserContext.parserState.onTrackEntrySegment(ebml);
104
+ const track = (0, get_track_1.getTrack)({
105
+ track: ebml,
106
+ timescale: parserContext.parserState.getTimescale(),
107
+ });
108
+ if (track) {
109
+ await (0, add_new_matroska_tracks_1.registerTrack)({
110
+ state: parserContext.parserState,
111
+ options: parserContext,
112
+ track,
113
+ });
114
+ }
115
+ }
116
+ if (ebml.type === 'Timestamp') {
117
+ parserContext.parserState.setTimestampOffset(offset, ebml.value.value);
118
+ }
119
+ if (ebml.type === 'Block' || ebml.type === 'SimpleBlock') {
120
+ const sample = (0, get_sample_from_block_1.getSampleFromBlock)(ebml, parserContext, offset);
121
+ if (sample.type === 'video-sample' && parserContext.nullifySamples) {
122
+ await parserContext.parserState.onVideoSample(sample.videoSample.trackId, sample.videoSample);
123
+ return {
124
+ type: 'Block',
125
+ value: new Uint8Array([]),
126
+ minVintWidth: ebml.minVintWidth,
127
+ };
128
+ }
129
+ if (sample.type === 'audio-sample' && parserContext.nullifySamples) {
130
+ await parserContext.parserState.onAudioSample(sample.audioSample.trackId, sample.audioSample);
131
+ return {
132
+ type: 'Block',
133
+ value: new Uint8Array([]),
134
+ minVintWidth: ebml.minVintWidth,
135
+ };
136
+ }
137
+ if (sample.type === 'no-sample' && parserContext.nullifySamples) {
138
+ return {
139
+ type: 'Block',
140
+ value: new Uint8Array([]),
141
+ minVintWidth: ebml.minVintWidth,
142
+ };
143
+ }
144
+ }
145
+ if (ebml.type === 'BlockGroup') {
146
+ // Blocks don't have information about keyframes.
147
+ // https://ffmpeg.org/pipermail/ffmpeg-devel/2015-June/173825.html
148
+ // "For Blocks, keyframes is
149
+ // inferred by the absence of ReferenceBlock element (as done by matroskadec).""
150
+ const block = ebml.value.find((c) => c.type === 'SimpleBlock' || c.type === 'Block');
151
+ if (!block || (block.type !== 'SimpleBlock' && block.type !== 'Block')) {
152
+ throw new Error('Expected block segment');
153
+ }
154
+ const hasReferenceBlock = ebml.value.find((c) => c.type === 'ReferenceBlock');
155
+ const sample = block.value.length === 0
156
+ ? null
157
+ : (0, get_sample_from_block_1.getSampleFromBlock)(block, parserContext, offset);
158
+ if (sample && sample.type === 'partial-video-sample') {
159
+ const completeFrame = {
160
+ ...sample.partialVideoSample,
161
+ type: hasReferenceBlock ? 'delta' : 'key',
162
+ };
163
+ await parserContext.parserState.onVideoSample(sample.partialVideoSample.trackId, completeFrame);
164
+ }
165
+ if (parserContext.nullifySamples) {
166
+ return {
167
+ type: 'BlockGroup',
168
+ value: [],
169
+ minVintWidth: ebml.minVintWidth,
170
+ };
171
+ }
172
+ }
173
+ return ebml;
174
+ };
175
+ exports.postprocessEbml = postprocessEbml;