@remotion/media-parser 4.0.208 → 4.0.210

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 (215) hide show
  1. package/buffer.js +2 -0
  2. package/dist/boxes/iso-base-media/get-sample-positions-from-track.js +1 -1
  3. package/dist/boxes/iso-base-media/make-track.js +14 -2
  4. package/dist/boxes/iso-base-media/mdat/mdat.d.ts +2 -1
  5. package/dist/boxes/iso-base-media/mdat/mdat.js +8 -3
  6. package/dist/boxes/iso-base-media/moov/moov.d.ts +2 -1
  7. package/dist/boxes/iso-base-media/moov/moov.js +2 -1
  8. package/dist/boxes/iso-base-media/process-box.d.ts +6 -3
  9. package/dist/boxes/iso-base-media/process-box.js +20 -5
  10. package/dist/boxes/iso-base-media/stsd/avcc.d.ts +1 -1
  11. package/dist/boxes/iso-base-media/stsd/avcc.js +2 -2
  12. package/dist/boxes/iso-base-media/stsd/ctts.js +2 -5
  13. package/dist/boxes/iso-base-media/stsd/hvcc.d.ts +1 -1
  14. package/dist/boxes/iso-base-media/stsd/hvcc.js +2 -2
  15. package/dist/boxes/iso-base-media/stsd/mebx.d.ts +2 -1
  16. package/dist/boxes/iso-base-media/stsd/mebx.js +2 -1
  17. package/dist/boxes/iso-base-media/stsd/samples.d.ts +4 -2
  18. package/dist/boxes/iso-base-media/stsd/samples.js +69 -11
  19. package/dist/boxes/iso-base-media/stsd/stsd.d.ts +2 -1
  20. package/dist/boxes/iso-base-media/stsd/stsd.js +2 -1
  21. package/dist/boxes/iso-base-media/trak/trak.d.ts +2 -1
  22. package/dist/boxes/iso-base-media/trak/trak.js +2 -1
  23. package/dist/boxes/iso-base-media/traversal.d.ts +44 -0
  24. package/dist/boxes/iso-base-media/traversal.js +211 -0
  25. package/dist/boxes/webm/color.d.ts +4 -0
  26. package/dist/boxes/webm/color.js +120 -0
  27. package/dist/boxes/webm/description.js +1 -1
  28. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  29. package/dist/boxes/webm/get-sample-from-block.js +1 -1
  30. package/dist/boxes/webm/get-track.js +16 -1
  31. package/dist/boxes/webm/make-track.d.ts +9 -0
  32. package/dist/boxes/webm/make-track.js +260 -0
  33. package/dist/boxes/webm/parse-ebml.js +5 -2
  34. package/dist/boxes/webm/segments/all-segments.d.ts +36 -3
  35. package/dist/boxes/webm/segments/all-segments.js +34 -6
  36. package/dist/boxes/webm/traversal.d.ts +26 -1
  37. package/dist/boxes/webm/traversal.js +214 -1
  38. package/dist/buffer-iterator.js +6 -0
  39. package/dist/create/cluster-segment.d.ts +1 -1
  40. package/dist/create/cluster-segment.js +3 -5
  41. package/dist/create/cluster.d.ts +13 -0
  42. package/dist/create/cluster.js +54 -0
  43. package/dist/create/create-media.d.ts +4 -2
  44. package/dist/create/create-media.js +87 -47
  45. package/dist/create/cues.d.ts +0 -0
  46. package/dist/create/cues.js +1 -0
  47. package/dist/create/make-duration-with-padding.d.ts +1 -0
  48. package/dist/create/make-duration-with-padding.js +15 -0
  49. package/dist/create/matroska-cues.d.ts +6 -0
  50. package/dist/create/matroska-cues.js +50 -0
  51. package/dist/create/matroska-info.d.ts +1 -2
  52. package/dist/create/matroska-info.js +3 -11
  53. package/dist/create/matroska-seek.d.ts +6 -0
  54. package/dist/create/matroska-seek.js +32 -0
  55. package/dist/create/matroska-segment.d.ts +1 -0
  56. package/dist/create/matroska-segment.js +3 -2
  57. package/dist/create/matroska-trackentry.d.ts +9 -14
  58. package/dist/create/matroska-trackentry.js +79 -94
  59. package/dist/create/timescale.d.ts +1 -0
  60. package/dist/create/timescale.js +4 -0
  61. package/dist/emit-available-info.d.ts +12 -0
  62. package/dist/emit-available-info.js +133 -0
  63. package/dist/esm/buffer.mjs +57 -0
  64. package/dist/esm/from-fetch.mjs +72 -0
  65. package/dist/esm/from-node.mjs +48 -0
  66. package/dist/esm/from-web-file.mjs +48 -0
  67. package/dist/esm/index.mjs +6689 -0
  68. package/dist/esm/web-fs.mjs +67 -0
  69. package/dist/get-audio-codec.d.ts +5 -5
  70. package/dist/get-audio-codec.js +41 -57
  71. package/dist/get-container.d.ts +4 -0
  72. package/dist/get-container.js +26 -0
  73. package/dist/get-duration.js +1 -1
  74. package/dist/get-fps.js +1 -1
  75. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  76. package/dist/get-sample-aspect-ratio.js +19 -19
  77. package/dist/get-tracks.d.ts +13 -0
  78. package/dist/get-tracks.js +8 -8
  79. package/dist/get-video-codec.d.ts +5 -2
  80. package/dist/get-video-codec.js +111 -21
  81. package/dist/has-all-info.d.ts +2 -2
  82. package/dist/has-all-info.js +23 -9
  83. package/dist/index.d.ts +3 -1
  84. package/dist/options.d.ts +97 -30
  85. package/dist/parse-media.js +43 -62
  86. package/dist/parse-video.d.ts +2 -1
  87. package/dist/parse-video.js +3 -1
  88. package/dist/parser-state.js +1 -2
  89. package/dist/readers/from-fetch.js +24 -4
  90. package/dist/readers/from-node.js +13 -3
  91. package/dist/readers/from-web-file.js +14 -2
  92. package/dist/readers/reader.d.ts +6 -1
  93. package/dist/samples-from-moof.js +1 -1
  94. package/dist/traversal.d.ts +0 -21
  95. package/dist/traversal.js +1 -158
  96. package/dist/truthy.d.ts +3 -0
  97. package/dist/truthy.js +7 -0
  98. package/dist/writers/buffer.d.ts +2 -0
  99. package/dist/writers/buffer.js +58 -0
  100. package/dist/writers/web-fs.d.ts +1 -0
  101. package/dist/writers/web-fs.js +42 -18
  102. package/dist/writers/writer.d.ts +4 -2
  103. package/fetch.js +2 -0
  104. package/node.js +2 -0
  105. package/package.json +43 -8
  106. package/web-file.js +2 -0
  107. package/web-fs.js +2 -0
  108. package/.eslintrc +0 -8
  109. package/input.webm +0 -0
  110. package/src/add-new-matroska-tracks.ts +0 -23
  111. package/src/boxes/iso-base-media/base-type.ts +0 -4
  112. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  113. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  114. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  115. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  116. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  117. package/src/boxes/iso-base-media/make-track.ts +0 -116
  118. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  119. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  120. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  121. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  122. package/src/boxes/iso-base-media/process-box.ts +0 -748
  123. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  124. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  125. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  126. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  127. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  128. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  129. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  130. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  131. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  132. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  133. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  134. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  135. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  136. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  137. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  138. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  139. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  140. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  141. package/src/boxes/iso-base-media/to-date.ts +0 -9
  142. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  143. package/src/boxes/iso-base-media/trun.ts +0 -74
  144. package/src/boxes/iso-base-media/void-box.ts +0 -4
  145. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  146. package/src/boxes/webm/av1-codec-private.ts +0 -113
  147. package/src/boxes/webm/description.ts +0 -104
  148. package/src/boxes/webm/ebml.ts +0 -98
  149. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  150. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  151. package/src/boxes/webm/get-track.ts +0 -257
  152. package/src/boxes/webm/make-header.ts +0 -253
  153. package/src/boxes/webm/parse-ebml.ts +0 -255
  154. package/src/boxes/webm/parse-webm-header.ts +0 -18
  155. package/src/boxes/webm/segments/all-segments.ts +0 -888
  156. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  157. package/src/boxes/webm/segments/parse-children.ts +0 -144
  158. package/src/boxes/webm/segments/track-entry.ts +0 -38
  159. package/src/boxes/webm/segments.ts +0 -147
  160. package/src/boxes/webm/traversal.ts +0 -45
  161. package/src/buffer-iterator.ts +0 -548
  162. package/src/create/cluster-segment.ts +0 -62
  163. package/src/create/create-media.ts +0 -172
  164. package/src/create/matroska-header.ts +0 -63
  165. package/src/create/matroska-info.ts +0 -46
  166. package/src/create/matroska-segment.ts +0 -10
  167. package/src/create/matroska-trackentry.ts +0 -325
  168. package/src/get-audio-codec.ts +0 -270
  169. package/src/get-dimensions.ts +0 -47
  170. package/src/get-duration.ts +0 -103
  171. package/src/get-fps.ts +0 -113
  172. package/src/get-sample-aspect-ratio.ts +0 -204
  173. package/src/get-sample-positions.ts +0 -93
  174. package/src/get-tracks.ts +0 -147
  175. package/src/get-video-codec.ts +0 -117
  176. package/src/has-all-info.ts +0 -81
  177. package/src/index.ts +0 -18
  178. package/src/make-hvc1-codec-strings.ts +0 -55
  179. package/src/options.ts +0 -118
  180. package/src/parse-media.ts +0 -183
  181. package/src/parse-result.ts +0 -79
  182. package/src/parse-video.ts +0 -83
  183. package/src/parser-context.ts +0 -10
  184. package/src/parser-state.ts +0 -178
  185. package/src/readers/from-fetch.ts +0 -90
  186. package/src/readers/from-node.ts +0 -51
  187. package/src/readers/from-web-file.ts +0 -49
  188. package/src/readers/reader.ts +0 -15
  189. package/src/samples-from-moof.ts +0 -102
  190. package/src/test/aspect-ratio.test.ts +0 -42
  191. package/src/test/av1.test.ts +0 -108
  192. package/src/test/create-matroska.test.ts +0 -287
  193. package/src/test/duration.test.ts +0 -18
  194. package/src/test/keys.test.ts +0 -47
  195. package/src/test/matroska.test.ts +0 -463
  196. package/src/test/mvhd.test.ts +0 -94
  197. package/src/test/parse-esds.test.ts +0 -98
  198. package/src/test/parse-stco.test.ts +0 -61
  199. package/src/test/parse-stsc.test.ts +0 -104
  200. package/src/test/parse-stsz.test.ts +0 -57
  201. package/src/test/parse-stts.test.ts +0 -38
  202. package/src/test/parse-video.test.ts +0 -101
  203. package/src/test/parse-webm.test.ts +0 -17
  204. package/src/test/samples-from-moof.test.ts +0 -2496
  205. package/src/test/stream-local.test.ts +0 -743
  206. package/src/test/stream-remote.test.ts +0 -59
  207. package/src/test/stream-samples.test.ts +0 -181
  208. package/src/test/stsd.test.ts +0 -265
  209. package/src/test/tkhd.test.ts +0 -87
  210. package/src/traversal.ts +0 -528
  211. package/src/webcodec-sample-types.ts +0 -29
  212. package/src/writers/web-fs.ts +0 -50
  213. package/src/writers/writer.ts +0 -12
  214. package/tsconfig.json +0 -14
  215. package/tsconfig.tsbuildinfo +0 -1
@@ -1,255 +0,0 @@
1
- import {registerTrack} from '../../add-new-matroska-tracks';
2
- import {type BufferIterator} from '../../buffer-iterator';
3
- import type {ParserContext} from '../../parser-context';
4
- import type {VideoSample} from '../../webcodec-sample-types';
5
- import {getSampleFromBlock} from './get-sample-from-block';
6
- import {getTrack} from './get-track';
7
- import type {PossibleEbml} from './segments/all-segments';
8
- import {ebmlMap} from './segments/all-segments';
9
-
10
- export type Prettify<T> = {
11
- [K in keyof T]: T[K];
12
- } & {};
13
-
14
- export const parseEbml = async (
15
- iterator: BufferIterator,
16
- parserContext: ParserContext,
17
- ): Promise<Prettify<PossibleEbml>> => {
18
- const hex = iterator.getMatroskaSegmentId();
19
- if (hex === null) {
20
- throw new Error(
21
- 'Not enough bytes left to parse EBML - this should not happen',
22
- );
23
- }
24
-
25
- const hasInMap = ebmlMap[hex as keyof typeof ebmlMap];
26
- if (!hasInMap) {
27
- throw new Error(
28
- `Don't know how to parse EBML hex ID ${JSON.stringify(hex)}`,
29
- );
30
- }
31
-
32
- const off = iterator.counter.getOffset();
33
- const size = iterator.getVint();
34
- const minVintWidth = iterator.counter.getOffset() - off;
35
-
36
- if (size === null) {
37
- throw new Error(
38
- 'Not enough bytes left to parse EBML - this should not happen',
39
- );
40
- }
41
-
42
- if (hasInMap.type === 'uint') {
43
- const beforeUintOffset = iterator.counter.getOffset();
44
- const value = size === 0 ? 0 : iterator.getUint(size);
45
-
46
- const {name} = hasInMap;
47
-
48
- return {
49
- // To work around TS limit
50
- type: name as 'SeekPosition',
51
- value: {
52
- value,
53
- byteLength: iterator.counter.getOffset() - beforeUintOffset,
54
- },
55
- minVintWidth,
56
- };
57
- }
58
-
59
- if (hasInMap.type === 'string') {
60
- const value = iterator.getByteString(size);
61
-
62
- return {
63
- type: hasInMap.name,
64
- value,
65
- minVintWidth,
66
- };
67
- }
68
-
69
- if (hasInMap.type === 'float') {
70
- const value =
71
- size === 0
72
- ? 0.0
73
- : size === 4
74
- ? iterator.getFloat32()
75
- : iterator.getFloat64();
76
-
77
- return {
78
- type: hasInMap.name,
79
- value: {
80
- value,
81
- size: size === 4 ? '32' : '64',
82
- },
83
- minVintWidth,
84
- };
85
- }
86
-
87
- if (hasInMap.type === 'hex-string') {
88
- return {
89
- type: hasInMap.name,
90
- value:
91
- '0x' +
92
- [...iterator.getSlice(size)]
93
- .map((b) => b.toString(16).padStart(2, '0'))
94
- .join(''),
95
- minVintWidth,
96
- };
97
- }
98
-
99
- if (hasInMap.type === 'uint8array') {
100
- return {
101
- type: hasInMap.name,
102
- value: iterator.getSlice(size),
103
- minVintWidth,
104
- };
105
- }
106
-
107
- if (hasInMap.type === 'children') {
108
- const children: PossibleEbml[] = [];
109
- const startOffset = iterator.counter.getOffset();
110
-
111
- // eslint-disable-next-line no-constant-condition
112
- while (true) {
113
- const offset = iterator.counter.getOffset();
114
- const value = await parseEbml(iterator, parserContext);
115
- const remapped = await postprocessEbml({
116
- offset,
117
- ebml: value,
118
- parserContext,
119
- });
120
- children.push(remapped);
121
-
122
- const offsetNow = iterator.counter.getOffset();
123
-
124
- if (offsetNow - startOffset > size) {
125
- throw new Error(
126
- `Offset ${offsetNow - startOffset} is larger than the length of the hex ${size}`,
127
- );
128
- }
129
-
130
- if (offsetNow - startOffset === size) {
131
- break;
132
- }
133
- }
134
-
135
- return {type: hasInMap.name, value: children, minVintWidth};
136
- }
137
-
138
- // @ts-expect-error
139
- throw new Error(`Unknown segment type ${hasInMap.type}`);
140
- };
141
-
142
- export const postprocessEbml = async ({
143
- offset,
144
- ebml,
145
- parserContext,
146
- }: {
147
- offset: number;
148
- ebml: Prettify<PossibleEbml>;
149
- parserContext: ParserContext;
150
- }): Promise<Prettify<PossibleEbml>> => {
151
- if (ebml.type === 'TimestampScale') {
152
- parserContext.parserState.setTimescale(ebml.value.value);
153
- }
154
-
155
- if (ebml.type === 'TrackEntry') {
156
- parserContext.parserState.onTrackEntrySegment(ebml);
157
-
158
- const track = getTrack({
159
- track: ebml,
160
- timescale: parserContext.parserState.getTimescale(),
161
- });
162
-
163
- if (track) {
164
- await registerTrack({
165
- state: parserContext.parserState,
166
- options: parserContext,
167
- track,
168
- });
169
- }
170
- }
171
-
172
- if (ebml.type === 'Timestamp') {
173
- parserContext.parserState.setTimestampOffset(offset, ebml.value.value);
174
- }
175
-
176
- if (ebml.type === 'Block' || ebml.type === 'SimpleBlock') {
177
- const sample = getSampleFromBlock(ebml, parserContext, offset);
178
-
179
- if (sample.type === 'video-sample' && parserContext.nullifySamples) {
180
- await parserContext.parserState.onVideoSample(
181
- sample.videoSample.trackId,
182
- sample.videoSample,
183
- );
184
- return {
185
- type: 'Block',
186
- value: new Uint8Array([]),
187
- minVintWidth: ebml.minVintWidth,
188
- };
189
- }
190
-
191
- if (sample.type === 'audio-sample' && parserContext.nullifySamples) {
192
- await parserContext.parserState.onAudioSample(
193
- sample.audioSample.trackId,
194
- sample.audioSample,
195
- );
196
- return {
197
- type: 'Block',
198
- value: new Uint8Array([]),
199
- minVintWidth: ebml.minVintWidth,
200
- };
201
- }
202
-
203
- if (sample.type === 'no-sample' && parserContext.nullifySamples) {
204
- return {
205
- type: 'Block',
206
- value: new Uint8Array([]),
207
- minVintWidth: ebml.minVintWidth,
208
- };
209
- }
210
- }
211
-
212
- if (ebml.type === 'BlockGroup') {
213
- // Blocks don't have information about keyframes.
214
- // https://ffmpeg.org/pipermail/ffmpeg-devel/2015-June/173825.html
215
- // "For Blocks, keyframes is
216
- // inferred by the absence of ReferenceBlock element (as done by matroskadec).""
217
-
218
- const block = ebml.value.find(
219
- (c) => c.type === 'SimpleBlock' || c.type === 'Block',
220
- );
221
- if (!block || (block.type !== 'SimpleBlock' && block.type !== 'Block')) {
222
- throw new Error('Expected block segment');
223
- }
224
-
225
- const hasReferenceBlock = ebml.value.find(
226
- (c) => c.type === 'ReferenceBlock',
227
- );
228
-
229
- const sample =
230
- block.value.length === 0
231
- ? null
232
- : getSampleFromBlock(block, parserContext, offset);
233
-
234
- if (sample && sample.type === 'partial-video-sample') {
235
- const completeFrame: VideoSample = {
236
- ...sample.partialVideoSample,
237
- type: hasReferenceBlock ? 'delta' : 'key',
238
- };
239
- await parserContext.parserState.onVideoSample(
240
- sample.partialVideoSample.trackId,
241
- completeFrame,
242
- );
243
- }
244
-
245
- if (parserContext.nullifySamples) {
246
- return {
247
- type: 'BlockGroup',
248
- value: [],
249
- minVintWidth: ebml.minVintWidth,
250
- };
251
- }
252
- }
253
-
254
- return ebml;
255
- };
@@ -1,18 +0,0 @@
1
- import type {BufferIterator} from '../../buffer-iterator';
2
- import type {ParseResult} from '../../parse-result';
3
- import type {ParserContext} from '../../parser-context';
4
- import {expectChildren} from './segments/parse-children';
5
-
6
- // Parsing according to https://darkcoding.net/software/reading-mediarecorders-webm-opus-output/
7
- export const parseWebm = (
8
- counter: BufferIterator,
9
- parserContext: ParserContext,
10
- ): Promise<ParseResult> => {
11
- return expectChildren({
12
- iterator: counter,
13
- length: Infinity,
14
- initialChildren: [],
15
- wrap: null,
16
- parserContext,
17
- });
18
- };