@remotion/media-parser 4.0.209 → 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 (213) 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 +2 -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/create/cluster-segment.js +0 -2
  39. package/dist/create/cluster.d.ts +10 -2
  40. package/dist/create/cluster.js +16 -10
  41. package/dist/create/create-media.d.ts +4 -2
  42. package/dist/create/create-media.js +76 -14
  43. package/dist/create/cues.d.ts +0 -0
  44. package/dist/create/cues.js +1 -0
  45. package/dist/create/make-duration-with-padding.d.ts +1 -1
  46. package/dist/create/make-duration-with-padding.js +3 -3
  47. package/dist/create/matroska-cues.d.ts +6 -0
  48. package/dist/create/matroska-cues.js +50 -0
  49. package/dist/create/matroska-info.js +1 -1
  50. package/dist/create/matroska-seek.d.ts +6 -0
  51. package/dist/create/matroska-seek.js +32 -0
  52. package/dist/create/matroska-segment.d.ts +1 -0
  53. package/dist/create/matroska-segment.js +3 -2
  54. package/dist/create/matroska-trackentry.d.ts +9 -14
  55. package/dist/create/matroska-trackentry.js +79 -94
  56. package/dist/emit-available-info.d.ts +12 -0
  57. package/dist/emit-available-info.js +133 -0
  58. package/dist/esm/buffer.mjs +57 -0
  59. package/dist/esm/from-fetch.mjs +72 -0
  60. package/dist/esm/from-node.mjs +48 -0
  61. package/dist/esm/from-web-file.mjs +48 -0
  62. package/dist/esm/index.mjs +6689 -0
  63. package/dist/esm/web-fs.mjs +67 -0
  64. package/dist/get-audio-codec.d.ts +5 -5
  65. package/dist/get-audio-codec.js +41 -57
  66. package/dist/get-container.d.ts +4 -0
  67. package/dist/get-container.js +26 -0
  68. package/dist/get-duration.js +1 -1
  69. package/dist/get-fps.js +1 -1
  70. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  71. package/dist/get-sample-aspect-ratio.js +19 -19
  72. package/dist/get-tracks.d.ts +13 -0
  73. package/dist/get-tracks.js +8 -8
  74. package/dist/get-video-codec.d.ts +5 -2
  75. package/dist/get-video-codec.js +111 -21
  76. package/dist/has-all-info.d.ts +2 -2
  77. package/dist/has-all-info.js +23 -9
  78. package/dist/index.d.ts +3 -1
  79. package/dist/options.d.ts +97 -30
  80. package/dist/parse-media.js +43 -62
  81. package/dist/parse-video.d.ts +2 -1
  82. package/dist/parse-video.js +3 -1
  83. package/dist/parser-state.js +1 -2
  84. package/dist/readers/from-fetch.js +24 -4
  85. package/dist/readers/from-node.js +13 -3
  86. package/dist/readers/from-web-file.js +14 -2
  87. package/dist/readers/reader.d.ts +6 -1
  88. package/dist/samples-from-moof.js +1 -1
  89. package/dist/traversal.d.ts +0 -21
  90. package/dist/traversal.js +1 -158
  91. package/dist/truthy.d.ts +3 -0
  92. package/dist/truthy.js +7 -0
  93. package/dist/writers/buffer.d.ts +2 -0
  94. package/dist/writers/buffer.js +58 -0
  95. package/dist/writers/web-fs.d.ts +1 -0
  96. package/dist/writers/web-fs.js +42 -18
  97. package/dist/writers/writer.d.ts +4 -2
  98. package/fetch.js +2 -0
  99. package/node.js +2 -0
  100. package/package.json +43 -8
  101. package/web-file.js +2 -0
  102. package/web-fs.js +2 -0
  103. package/.eslintrc +0 -8
  104. package/input.webm +0 -0
  105. package/src/add-new-matroska-tracks.ts +0 -23
  106. package/src/boxes/iso-base-media/base-type.ts +0 -4
  107. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  108. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  109. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  110. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  111. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  112. package/src/boxes/iso-base-media/make-track.ts +0 -116
  113. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  114. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  115. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  116. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  117. package/src/boxes/iso-base-media/process-box.ts +0 -748
  118. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  119. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  120. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  121. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  122. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  123. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  124. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  125. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  126. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  127. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  128. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  129. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  130. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  131. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  132. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  133. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  134. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  135. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  136. package/src/boxes/iso-base-media/to-date.ts +0 -9
  137. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  138. package/src/boxes/iso-base-media/trun.ts +0 -74
  139. package/src/boxes/iso-base-media/void-box.ts +0 -4
  140. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  141. package/src/boxes/webm/av1-codec-private.ts +0 -113
  142. package/src/boxes/webm/description.ts +0 -104
  143. package/src/boxes/webm/ebml.ts +0 -98
  144. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  145. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  146. package/src/boxes/webm/get-track.ts +0 -257
  147. package/src/boxes/webm/make-header.ts +0 -253
  148. package/src/boxes/webm/parse-ebml.ts +0 -259
  149. package/src/boxes/webm/parse-webm-header.ts +0 -18
  150. package/src/boxes/webm/segments/all-segments.ts +0 -888
  151. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  152. package/src/boxes/webm/segments/parse-children.ts +0 -144
  153. package/src/boxes/webm/segments/track-entry.ts +0 -38
  154. package/src/boxes/webm/segments.ts +0 -147
  155. package/src/boxes/webm/traversal.ts +0 -45
  156. package/src/buffer-iterator.ts +0 -555
  157. package/src/create/cluster-segment.ts +0 -62
  158. package/src/create/cluster.ts +0 -64
  159. package/src/create/create-media.ts +0 -136
  160. package/src/create/make-duration-with-padding.ts +0 -15
  161. package/src/create/matroska-header.ts +0 -63
  162. package/src/create/matroska-info.ts +0 -30
  163. package/src/create/matroska-segment.ts +0 -10
  164. package/src/create/matroska-trackentry.ts +0 -325
  165. package/src/create/timescale.ts +0 -1
  166. package/src/get-audio-codec.ts +0 -270
  167. package/src/get-dimensions.ts +0 -47
  168. package/src/get-duration.ts +0 -103
  169. package/src/get-fps.ts +0 -113
  170. package/src/get-sample-aspect-ratio.ts +0 -204
  171. package/src/get-sample-positions.ts +0 -93
  172. package/src/get-tracks.ts +0 -147
  173. package/src/get-video-codec.ts +0 -117
  174. package/src/has-all-info.ts +0 -81
  175. package/src/index.ts +0 -18
  176. package/src/make-hvc1-codec-strings.ts +0 -55
  177. package/src/options.ts +0 -118
  178. package/src/parse-media.ts +0 -183
  179. package/src/parse-result.ts +0 -79
  180. package/src/parse-video.ts +0 -83
  181. package/src/parser-context.ts +0 -10
  182. package/src/parser-state.ts +0 -178
  183. package/src/readers/from-fetch.ts +0 -90
  184. package/src/readers/from-node.ts +0 -51
  185. package/src/readers/from-web-file.ts +0 -49
  186. package/src/readers/reader.ts +0 -15
  187. package/src/samples-from-moof.ts +0 -102
  188. package/src/test/aspect-ratio.test.ts +0 -42
  189. package/src/test/av1.test.ts +0 -108
  190. package/src/test/create-matroska.test.ts +0 -287
  191. package/src/test/duration.test.ts +0 -18
  192. package/src/test/keys.test.ts +0 -47
  193. package/src/test/matroska.test.ts +0 -463
  194. package/src/test/mvhd.test.ts +0 -94
  195. package/src/test/parse-esds.test.ts +0 -98
  196. package/src/test/parse-stco.test.ts +0 -61
  197. package/src/test/parse-stsc.test.ts +0 -104
  198. package/src/test/parse-stsz.test.ts +0 -57
  199. package/src/test/parse-stts.test.ts +0 -38
  200. package/src/test/parse-video.test.ts +0 -101
  201. package/src/test/parse-webm.test.ts +0 -17
  202. package/src/test/samples-from-moof.test.ts +0 -2496
  203. package/src/test/stream-local.test.ts +0 -743
  204. package/src/test/stream-remote.test.ts +0 -59
  205. package/src/test/stream-samples.test.ts +0 -181
  206. package/src/test/stsd.test.ts +0 -265
  207. package/src/test/tkhd.test.ts +0 -87
  208. package/src/traversal.ts +0 -528
  209. package/src/webcodec-sample-types.ts +0 -29
  210. package/src/writers/web-fs.ts +0 -50
  211. package/src/writers/writer.ts +0 -12
  212. package/tsconfig.json +0 -14
  213. package/tsconfig.tsbuildinfo +0 -1
package/src/traversal.ts DELETED
@@ -1,528 +0,0 @@
1
- import type {FtypBox} from './boxes/iso-base-media/ftyp';
2
- import type {MdhdBox} from './boxes/iso-base-media/mdhd';
3
- import type {MoovBox} from './boxes/iso-base-media/moov/moov';
4
- import type {MvhdBox} from './boxes/iso-base-media/mvhd';
5
- import type {CttsBox} from './boxes/iso-base-media/stsd/ctts';
6
- import type {StcoBox} from './boxes/iso-base-media/stsd/stco';
7
- import type {StscBox} from './boxes/iso-base-media/stsd/stsc';
8
- import type {StsdBox} from './boxes/iso-base-media/stsd/stsd';
9
- import type {StssBox} from './boxes/iso-base-media/stsd/stss';
10
- import type {StszBox} from './boxes/iso-base-media/stsd/stsz';
11
- import type {SttsBox} from './boxes/iso-base-media/stsd/stts';
12
- import type {TfdtBox} from './boxes/iso-base-media/tfdt';
13
- import type {TfhdBox} from './boxes/iso-base-media/tfhd';
14
- import type {TkhdBox} from './boxes/iso-base-media/tkhd';
15
- import type {TrakBox} from './boxes/iso-base-media/trak/trak';
16
- import type {TrunBox} from './boxes/iso-base-media/trun';
17
- import type {
18
- AudioSegment,
19
- ClusterSegment,
20
- CodecIdSegment,
21
- DisplayHeightSegment,
22
- DisplayWidthSegment,
23
- HeightSegment,
24
- MainSegment,
25
- TimestampScaleSegment,
26
- TrackEntry,
27
- TrackTypeSegment,
28
- VideoSegment,
29
- WidthSegment,
30
- } from './boxes/webm/segments/all-segments';
31
- import type {AnySegment, IsoBaseMediaBox, RegularBox} from './parse-result';
32
-
33
- export const getFtypBox = (segments: AnySegment[]): FtypBox | null => {
34
- const ftypBox = segments.find((s) => s.type === 'ftyp-box');
35
- if (!ftypBox || ftypBox.type !== 'ftyp-box') {
36
- return null;
37
- }
38
-
39
- return ftypBox;
40
- };
41
-
42
- export const getMoovBox = (segments: AnySegment[]): MoovBox | null => {
43
- const moovBox = segments.find((s) => s.type === 'moov-box');
44
- if (!moovBox || moovBox.type !== 'moov-box') {
45
- return null;
46
- }
47
-
48
- return moovBox;
49
- };
50
-
51
- export const getMoofBox = (main: AnySegment[]): IsoBaseMediaBox | null => {
52
- const moofBox = main.find(
53
- (s) => s.type === 'regular-box' && s.boxType === 'moof',
54
- );
55
-
56
- if (!moofBox || moofBox.type !== 'regular-box') {
57
- return null;
58
- }
59
-
60
- return moofBox;
61
- };
62
-
63
- export const getMvhdBox = (moovBox: MoovBox): MvhdBox | null => {
64
- const mvHdBox = moovBox.children.find((s) => s.type === 'mvhd-box');
65
-
66
- if (!mvHdBox || mvHdBox.type !== 'mvhd-box') {
67
- return null;
68
- }
69
-
70
- return mvHdBox;
71
- };
72
-
73
- export const getTraks = (moovBox: MoovBox): TrakBox[] => {
74
- return moovBox.children.filter((s) => s.type === 'trak-box') as TrakBox[];
75
- };
76
-
77
- export const getTkhdBox = (trakBox: TrakBox): TkhdBox | null => {
78
- const tkhdBox = trakBox.children.find(
79
- (s) => s.type === 'tkhd-box',
80
- ) as TkhdBox | null;
81
-
82
- return tkhdBox;
83
- };
84
-
85
- export const getMdiaBox = (trakBox: TrakBox): RegularBox | null => {
86
- const mdiaBox = trakBox.children.find(
87
- (s) => s.type === 'regular-box' && s.boxType === 'mdia',
88
- );
89
-
90
- if (!mdiaBox || mdiaBox.type !== 'regular-box') {
91
- return null;
92
- }
93
-
94
- return mdiaBox;
95
- };
96
-
97
- export const getMdhdBox = (trakBox: TrakBox): MdhdBox | null => {
98
- const mdiaBox = getMdiaBox(trakBox);
99
-
100
- if (!mdiaBox) {
101
- return null;
102
- }
103
-
104
- const mdhdBox = mdiaBox.children.find(
105
- (c) => c.type === 'mdhd-box',
106
- ) as MdhdBox | null;
107
-
108
- return mdhdBox;
109
- };
110
-
111
- export const getStblBox = (trakBox: TrakBox): RegularBox | null => {
112
- const mdiaBox = getMdiaBox(trakBox);
113
-
114
- if (!mdiaBox) {
115
- return null;
116
- }
117
-
118
- const minfBox = mdiaBox.children.find(
119
- (s) => s.type === 'regular-box' && s.boxType === 'minf',
120
- );
121
-
122
- if (!minfBox || minfBox.type !== 'regular-box') {
123
- return null;
124
- }
125
-
126
- const stblBox = minfBox.children.find(
127
- (s) => s.type === 'regular-box' && s.boxType === 'stbl',
128
- );
129
-
130
- if (!stblBox || stblBox.type !== 'regular-box') {
131
- return null;
132
- }
133
-
134
- return stblBox;
135
- };
136
-
137
- export const getStsdBox = (trakBox: TrakBox): StsdBox | null => {
138
- const stblBox = getStblBox(trakBox);
139
-
140
- if (!stblBox || stblBox.type !== 'regular-box') {
141
- return null;
142
- }
143
-
144
- const stsdBox = stblBox.children.find(
145
- (s) => s.type === 'stsd-box',
146
- ) as StsdBox | null;
147
-
148
- return stsdBox;
149
- };
150
-
151
- export const getVideoDescriptors = (trakBox: TrakBox): Uint8Array | null => {
152
- const stsdBox = getStsdBox(trakBox);
153
-
154
- if (!stsdBox) {
155
- return null;
156
- }
157
-
158
- const descriptors = stsdBox.samples.map((s) => {
159
- return s.type === 'video'
160
- ? s.descriptors.map((d) => {
161
- return d.type === 'avcc-box'
162
- ? d.description
163
- : d.type === 'hvcc-box'
164
- ? d.data
165
- : null;
166
- })
167
- : [];
168
- });
169
-
170
- return descriptors.flat(1).filter(Boolean)[0] ?? null;
171
- };
172
-
173
- export const getStcoBox = (trakBox: TrakBox): StcoBox | null => {
174
- const stblBox = getStblBox(trakBox);
175
-
176
- if (!stblBox || stblBox.type !== 'regular-box') {
177
- return null;
178
- }
179
-
180
- const stcoBox = stblBox.children.find(
181
- (s) => s.type === 'stco-box',
182
- ) as StcoBox | null;
183
-
184
- return stcoBox;
185
- };
186
-
187
- export const getSttsBox = (trakBox: TrakBox): SttsBox | null => {
188
- const stblBox = getStblBox(trakBox);
189
-
190
- if (!stblBox || stblBox.type !== 'regular-box') {
191
- return null;
192
- }
193
-
194
- const sttsBox = stblBox.children.find(
195
- (s) => s.type === 'stts-box',
196
- ) as SttsBox | null;
197
-
198
- return sttsBox;
199
- };
200
-
201
- export const getCttsBox = (trakBox: TrakBox): CttsBox | null => {
202
- const stblBox = getStblBox(trakBox);
203
-
204
- if (!stblBox || stblBox.type !== 'regular-box') {
205
- return null;
206
- }
207
-
208
- const cttsBox = stblBox.children.find(
209
- (s) => s.type === 'ctts-box',
210
- ) as CttsBox | null;
211
-
212
- return cttsBox;
213
- };
214
-
215
- export const getStszBox = (trakBox: TrakBox): StszBox | null => {
216
- const stblBox = getStblBox(trakBox);
217
-
218
- if (!stblBox || stblBox.type !== 'regular-box') {
219
- return null;
220
- }
221
-
222
- const stszBox = stblBox.children.find(
223
- (s) => s.type === 'stsz-box',
224
- ) as StszBox | null;
225
-
226
- return stszBox;
227
- };
228
-
229
- export const getStscBox = (trakBox: TrakBox): StscBox | null => {
230
- const stblBox = getStblBox(trakBox);
231
-
232
- if (!stblBox || stblBox.type !== 'regular-box') {
233
- return null;
234
- }
235
-
236
- const stcoBox = stblBox.children.find(
237
- (b) => b.type === 'stsc-box',
238
- ) as StscBox | null;
239
-
240
- return stcoBox;
241
- };
242
-
243
- export const getStssBox = (trakBox: TrakBox): StssBox | null => {
244
- const stblBox = getStblBox(trakBox);
245
-
246
- if (!stblBox || stblBox.type !== 'regular-box') {
247
- return null;
248
- }
249
-
250
- const stssBox = stblBox.children.find(
251
- (b) => b.type === 'stss-box',
252
- ) as StssBox | null;
253
-
254
- return stssBox;
255
- };
256
-
257
- export const getTfdtBox = (segment: IsoBaseMediaBox): TfdtBox | null => {
258
- if (segment.type !== 'regular-box' || segment.boxType !== 'traf') {
259
- throw new Error('Expected traf-box');
260
- }
261
-
262
- const tfhdBox = segment.children.find((c) => c.type === 'tfdt-box');
263
-
264
- if (!tfhdBox || tfhdBox.type !== 'tfdt-box') {
265
- throw new Error('Expected tfhd-box');
266
- }
267
-
268
- return tfhdBox;
269
- };
270
-
271
- export const getTfhdBox = (segment: IsoBaseMediaBox): TfhdBox | null => {
272
- if (segment.type !== 'regular-box' || segment.boxType !== 'traf') {
273
- throw new Error('Expected traf-box');
274
- }
275
-
276
- const tfhdBox = segment.children.find(
277
- (c) => c.type === 'tfhd-box',
278
- ) as TfhdBox;
279
-
280
- if (!tfhdBox || tfhdBox.type !== 'tfhd-box') {
281
- throw new Error('Expected tfhd-box');
282
- }
283
-
284
- return tfhdBox;
285
- };
286
-
287
- export const getTrunBoxes = (segment: IsoBaseMediaBox): TrunBox[] => {
288
- if (segment.type !== 'regular-box' || segment.boxType !== 'traf') {
289
- throw new Error('Expected traf-box');
290
- }
291
-
292
- const trunBoxes = segment.children.filter((c) => c.type === 'trun-box');
293
-
294
- return trunBoxes as TrunBox[];
295
- };
296
-
297
- export const getClusterSegment = (
298
- segment: MainSegment,
299
- ): ClusterSegment | null => {
300
- const clusterSegment = segment.value.find((b) => b.type === 'Cluster') as
301
- | ClusterSegment
302
- | undefined;
303
-
304
- return clusterSegment ?? null;
305
- };
306
-
307
- export const getTracksSegment = (segment: MainSegment) => {
308
- const tracksSegment = segment.value.find((b) => b.type === 'Tracks');
309
- if (!tracksSegment || tracksSegment.type !== 'Tracks') {
310
- return null;
311
- }
312
-
313
- return tracksSegment;
314
- };
315
-
316
- export const getTimescaleSegment = (
317
- segment: MainSegment,
318
- ): TimestampScaleSegment | null => {
319
- const infoSegment = segment.value.find((b) => b.type === 'Info');
320
-
321
- if (!infoSegment || infoSegment.type !== 'Info') {
322
- return null;
323
- }
324
-
325
- const timescale = infoSegment.value.find((b) => b.type === 'TimestampScale');
326
-
327
- if (!timescale || timescale.type !== 'TimestampScale') {
328
- return null;
329
- }
330
-
331
- return timescale as TimestampScaleSegment;
332
- };
333
-
334
- export const getVideoSegment = (track: TrackEntry): VideoSegment | null => {
335
- const videoSegment = track.value.find((b) => b.type === 'Video');
336
- if (!videoSegment || videoSegment.type !== 'Video') {
337
- return null;
338
- }
339
-
340
- return videoSegment ?? null;
341
- };
342
-
343
- export const getAudioSegment = (track: TrackEntry): AudioSegment | null => {
344
- const audioSegment = track.value.find((b) => b.type === 'Audio');
345
- if (!audioSegment || audioSegment.type !== 'Audio') {
346
- return null;
347
- }
348
-
349
- return audioSegment ?? null;
350
- };
351
-
352
- export const getSampleRate = (track: TrackEntry): number | null => {
353
- const audioSegment = getAudioSegment(track);
354
- if (!audioSegment) {
355
- return null;
356
- }
357
-
358
- const samplingFrequency = audioSegment.value.find(
359
- (b) => b.type === 'SamplingFrequency',
360
- );
361
-
362
- if (!samplingFrequency || samplingFrequency.type !== 'SamplingFrequency') {
363
- return null;
364
- }
365
-
366
- return samplingFrequency.value.value;
367
- };
368
-
369
- export const getNumberOfChannels = (track: TrackEntry): number => {
370
- const audioSegment = getAudioSegment(track);
371
- if (!audioSegment) {
372
- throw new Error('Could not find audio segment');
373
- }
374
-
375
- const channels = audioSegment.value.find((b) => b.type === 'Channels');
376
-
377
- if (!channels || channels.type !== 'Channels') {
378
- return 1;
379
- }
380
-
381
- return channels.value.value;
382
- };
383
-
384
- export const getBitDepth = (track: TrackEntry): number | null => {
385
- const audioSegment = getAudioSegment(track);
386
- if (!audioSegment) {
387
- return null;
388
- }
389
-
390
- const bitDepth = audioSegment.value.find((b) => b.type === 'BitDepth');
391
-
392
- if (!bitDepth || bitDepth.type !== 'BitDepth') {
393
- return null;
394
- }
395
-
396
- return bitDepth.value.value;
397
- };
398
-
399
- export const getPrivateData = (track: TrackEntry): Uint8Array | null => {
400
- const privateData = track.value.find((b) => b.type === 'CodecPrivate');
401
-
402
- if (!privateData || privateData.type !== 'CodecPrivate') {
403
- return null;
404
- }
405
-
406
- return privateData.value;
407
- };
408
-
409
- export const getWidthSegment = (track: TrackEntry): WidthSegment | null => {
410
- const videoSegment = getVideoSegment(track);
411
- if (!videoSegment) {
412
- return null;
413
- }
414
-
415
- const width = videoSegment.value.find((b) => b.type === 'PixelWidth');
416
-
417
- if (!width || width.type !== 'PixelWidth') {
418
- return null;
419
- }
420
-
421
- return width;
422
- };
423
-
424
- export const getHeightSegment = (track: TrackEntry): HeightSegment | null => {
425
- const videoSegment = getVideoSegment(track);
426
- if (!videoSegment) {
427
- return null;
428
- }
429
-
430
- const height = videoSegment.value.find((b) => b.type === 'PixelHeight');
431
-
432
- if (!height || height.type !== 'PixelHeight') {
433
- return null;
434
- }
435
-
436
- return height;
437
- };
438
-
439
- export const getDisplayWidthSegment = (
440
- track: TrackEntry,
441
- ): DisplayWidthSegment | null => {
442
- const videoSegment = getVideoSegment(track);
443
- if (!videoSegment) {
444
- return null;
445
- }
446
-
447
- const displayWidth = videoSegment.value.find(
448
- (b) => b.type === 'DisplayWidth',
449
- );
450
-
451
- if (!displayWidth || displayWidth.type !== 'DisplayWidth') {
452
- return null;
453
- }
454
-
455
- return displayWidth;
456
- };
457
-
458
- export const getDisplayHeightSegment = (
459
- track: TrackEntry,
460
- ): DisplayHeightSegment | null => {
461
- const videoSegment = getVideoSegment(track);
462
- if (!videoSegment) {
463
- return null;
464
- }
465
-
466
- const displayHeight = videoSegment.value.find(
467
- (b) => b.type === 'DisplayHeight',
468
- );
469
-
470
- if (!displayHeight || displayHeight.type !== 'DisplayHeight') {
471
- return null;
472
- }
473
-
474
- return displayHeight;
475
- };
476
-
477
- export const getTrackTypeSegment = (
478
- track: TrackEntry,
479
- ): TrackTypeSegment | null => {
480
- const trackType = track.value.find((b) => b.type === 'TrackType');
481
- if (!trackType || trackType.type !== 'TrackType') {
482
- return null;
483
- }
484
-
485
- return trackType;
486
- };
487
-
488
- export const getTrackId = (track: TrackEntry): number => {
489
- const trackId = track.value.find((b) => b.type === 'TrackNumber');
490
- if (!trackId || trackId.type !== 'TrackNumber') {
491
- throw new Error('Expected track number segment');
492
- }
493
-
494
- return trackId.value.value;
495
- };
496
-
497
- export const getCodecSegment = (track: TrackEntry): CodecIdSegment | null => {
498
- const codec = track.value.find((b) => b.type === 'CodecID');
499
- if (!codec || codec.type !== 'CodecID') {
500
- return null;
501
- }
502
-
503
- return codec;
504
- };
505
-
506
- export const hasSkippedMdatProcessing = (anySegment: AnySegment[]) => {
507
- const mdat = anySegment.find((b) => b.type === 'mdat-box');
508
- if (!mdat) {
509
- return {
510
- skipped: false as const,
511
- };
512
- }
513
-
514
- if (mdat.type !== 'mdat-box') {
515
- throw new Error('Expected mdat-box');
516
- }
517
-
518
- if (mdat.samplesProcessed) {
519
- return {
520
- skipped: false as const,
521
- };
522
- }
523
-
524
- return {
525
- skipped: true,
526
- fileOffset: mdat.fileOffset,
527
- };
528
- };
@@ -1,29 +0,0 @@
1
- import type {AudioTrack, VideoTrack} from './get-tracks';
2
-
3
- export type AudioSample = {
4
- data: Uint8Array;
5
- timestamp: number;
6
- trackId: number;
7
- type: 'key' | 'delta';
8
- };
9
-
10
- export type VideoSample = {
11
- data: Uint8Array;
12
- timestamp: number;
13
- duration: number | undefined;
14
- trackId: number;
15
- type: 'key' | 'delta';
16
- cts: number | null;
17
- dts: number | null;
18
- };
19
-
20
- export type OnAudioSample = (sample: AudioSample) => void | Promise<void>;
21
- export type OnVideoSample = (sample: VideoSample) => void | Promise<void>;
22
-
23
- export type OnAudioTrack = (
24
- track: AudioTrack,
25
- ) => OnAudioSample | Promise<OnAudioSample | null> | null;
26
-
27
- export type OnVideoTrack = (
28
- track: VideoTrack,
29
- ) => OnVideoSample | Promise<OnVideoSample | null> | null;
@@ -1,50 +0,0 @@
1
- import type {Writer, WriterInterface} from './writer';
2
-
3
- const createContent = async () => {
4
- const directoryHandle = await navigator.storage.getDirectory();
5
- const filename = `media-parser-${Math.random().toString().replace('0.', '')}.webm`;
6
-
7
- const fileHandle = await directoryHandle.getFileHandle(filename, {
8
- create: true,
9
- });
10
- const writable = await fileHandle.createWritable();
11
-
12
- let written = 0;
13
-
14
- const writer: Writer = {
15
- write: async (arr: Uint8Array) => {
16
- await writable.write(arr);
17
- written += arr.byteLength;
18
- },
19
- save: async () => {
20
- await writable.close();
21
- const picker = await window.showSaveFilePicker({
22
- suggestedName: `${Math.random().toString().replace('.', '')}.webm`,
23
- });
24
-
25
- const newHandle = await directoryHandle.getFileHandle(filename, {
26
- create: true,
27
- });
28
- const newFile = await newHandle.getFile();
29
- const pickerWriteable = await picker.createWritable();
30
- const stream = newFile.stream();
31
- await stream.pipeTo(pickerWriteable);
32
-
33
- await directoryHandle.removeEntry(filename, {
34
- recursive: true,
35
- });
36
- },
37
- getWrittenByteCount: () => written,
38
- updateDataAt: async (position: number, vint: Uint8Array) => {
39
- await writable.seek(position);
40
- await writable.write(vint);
41
- await writable.seek(written);
42
- },
43
- };
44
-
45
- return writer;
46
- };
47
-
48
- export const webFsWriter: WriterInterface = {
49
- createContent,
50
- };
@@ -1,12 +0,0 @@
1
- export type Writer = {
2
- write: (arr: Uint8Array) => Promise<void>;
3
- save: () => Promise<void>;
4
- getWrittenByteCount: () => number;
5
- updateDataAt: (position: number, vint: Uint8Array) => Promise<void>;
6
- };
7
-
8
- type CreateContent = () => Promise<Writer>;
9
-
10
- export type WriterInterface = {
11
- createContent: CreateContent;
12
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../tsconfig.settings.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "./dist",
6
- "skipLibCheck": true
7
- },
8
- "references": [
9
- {
10
- "path": "../renderer"
11
- }
12
- ],
13
- "include": ["src"]
14
- }