@remotion/media-parser 4.0.209 → 4.0.211

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 (290) 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 +13 -4
  5. package/dist/boxes/iso-base-media/mdat/mdat.js +20 -5
  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 +66 -12
  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 +39 -0
  24. package/dist/boxes/iso-base-media/traversal.js +201 -0
  25. package/dist/boxes/webm/color.d.ts +4 -0
  26. package/dist/boxes/webm/color.js +127 -0
  27. package/dist/boxes/webm/description.js +1 -1
  28. package/dist/boxes/webm/ebml.d.ts +1 -1
  29. package/dist/boxes/webm/get-ready-tracks.js +3 -3
  30. package/dist/boxes/webm/get-sample-from-block.js +1 -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/segments/parse-children.js +6 -0
  37. package/dist/boxes/webm/traversal.d.ts +26 -1
  38. package/dist/boxes/webm/traversal.js +214 -1
  39. package/dist/buffer-iterator.d.ts +4 -1
  40. package/dist/buffer-iterator.js +31 -5
  41. package/dist/create/cluster-segment.js +0 -2
  42. package/dist/create/cluster.d.ts +16 -2
  43. package/dist/create/cluster.js +17 -10
  44. package/dist/create/create-media.d.ts +4 -2
  45. package/dist/create/create-media.js +101 -22
  46. package/dist/create/make-duration-with-padding.d.ts +1 -1
  47. package/dist/create/make-duration-with-padding.js +3 -3
  48. package/dist/create/matroska-cues.d.ts +6 -0
  49. package/dist/create/matroska-cues.js +49 -0
  50. package/dist/create/matroska-info.js +1 -1
  51. package/dist/create/matroska-seek.d.ts +6 -0
  52. package/dist/create/matroska-seek.js +32 -0
  53. package/dist/create/matroska-segment.d.ts +1 -0
  54. package/dist/create/matroska-segment.js +3 -2
  55. package/dist/create/matroska-trackentry.d.ts +9 -14
  56. package/dist/create/matroska-trackentry.js +79 -102
  57. package/dist/emit-available-info.d.ts +12 -0
  58. package/dist/emit-available-info.js +133 -0
  59. package/dist/esm/buffer.mjs +57 -0
  60. package/dist/esm/from-fetch.mjs +107 -0
  61. package/dist/esm/from-node.mjs +49 -0
  62. package/dist/esm/from-web-file.mjs +49 -0
  63. package/dist/esm/index.mjs +6822 -0
  64. package/dist/esm/web-fs.mjs +67 -0
  65. package/dist/get-audio-codec.d.ts +5 -5
  66. package/dist/get-audio-codec.js +44 -57
  67. package/dist/get-container.d.ts +4 -0
  68. package/dist/get-container.js +26 -0
  69. package/dist/get-duration.js +1 -1
  70. package/dist/get-fps.js +1 -1
  71. package/dist/get-sample-aspect-ratio.d.ts +1 -1
  72. package/dist/get-sample-aspect-ratio.js +19 -19
  73. package/dist/get-tracks.d.ts +13 -0
  74. package/dist/get-tracks.js +8 -8
  75. package/dist/get-video-codec.d.ts +5 -2
  76. package/dist/get-video-codec.js +111 -21
  77. package/dist/has-all-info.d.ts +2 -2
  78. package/dist/has-all-info.js +23 -9
  79. package/dist/index.d.ts +4 -1
  80. package/dist/options.d.ts +97 -30
  81. package/dist/parse-media.js +59 -69
  82. package/dist/parse-video.d.ts +2 -1
  83. package/dist/parse-video.js +3 -1
  84. package/dist/parser-context.d.ts +1 -0
  85. package/dist/parser-state.js +1 -2
  86. package/dist/readers/from-fetch.d.ts +12 -0
  87. package/dist/readers/from-fetch.js +83 -17
  88. package/dist/readers/from-node.js +14 -3
  89. package/dist/readers/from-web-file.js +15 -2
  90. package/dist/readers/reader.d.ts +7 -1
  91. package/dist/samples-from-moof.js +1 -1
  92. package/dist/truthy.d.ts +3 -0
  93. package/dist/truthy.js +7 -0
  94. package/dist/writers/buffer.d.ts +2 -0
  95. package/dist/writers/buffer.js +58 -0
  96. package/dist/writers/web-fs.d.ts +1 -0
  97. package/dist/writers/web-fs.js +42 -18
  98. package/dist/writers/writer.d.ts +4 -2
  99. package/fetch.js +2 -0
  100. package/node.js +2 -0
  101. package/package.json +43 -8
  102. package/web-file.js +2 -0
  103. package/web-fs.js +2 -0
  104. package/.eslintrc +0 -8
  105. package/dist/av1-codec-string.d.ts +0 -3
  106. package/dist/av1-codec-string.js +0 -91
  107. package/dist/boxes/iso-base-media/ftype.d.ts +0 -9
  108. package/dist/boxes/iso-base-media/ftype.js +0 -31
  109. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.d.ts +0 -20
  110. package/dist/boxes/iso-base-media/stsd/avcc-hvcc.js +0 -73
  111. package/dist/boxes/iso-base-media/stts/stts.d.ts +0 -15
  112. package/dist/boxes/iso-base-media/stts/stts.js +0 -35
  113. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.d.ts +0 -14
  114. package/dist/boxes/webm/bitstream/av1/bitstream-frame-header.js +0 -67
  115. package/dist/boxes/webm/bitstream/av1/bitstream-frame.d.ts +0 -11
  116. package/dist/boxes/webm/bitstream/av1/bitstream-frame.js +0 -14
  117. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.d.ts +0 -6
  118. package/dist/boxes/webm/bitstream/av1/chroma-sample-position.js +0 -9
  119. package/dist/boxes/webm/bitstream/av1/color-config.d.ts +0 -16
  120. package/dist/boxes/webm/bitstream/av1/color-config.js +0 -103
  121. package/dist/boxes/webm/bitstream/av1/color-primaries.d.ts +0 -14
  122. package/dist/boxes/webm/bitstream/av1/color-primaries.js +0 -17
  123. package/dist/boxes/webm/bitstream/av1/decoder-model-info.d.ts +0 -9
  124. package/dist/boxes/webm/bitstream/av1/decoder-model-info.js +0 -17
  125. package/dist/boxes/webm/bitstream/av1/frame.d.ts +0 -0
  126. package/dist/boxes/webm/bitstream/av1/frame.js +0 -1
  127. package/dist/boxes/webm/bitstream/av1/header-segment.d.ts +0 -51
  128. package/dist/boxes/webm/bitstream/av1/header-segment.js +0 -183
  129. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.d.ts +0 -17
  130. package/dist/boxes/webm/bitstream/av1/matrix-coefficients.js +0 -20
  131. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.d.ts +0 -10
  132. package/dist/boxes/webm/bitstream/av1/operating-parameters-info.js +0 -15
  133. package/dist/boxes/webm/bitstream/av1/temporal-point-info.d.ts +0 -5
  134. package/dist/boxes/webm/bitstream/av1/temporal-point-info.js +0 -8
  135. package/dist/boxes/webm/bitstream/av1/timing-info.d.ts +0 -8
  136. package/dist/boxes/webm/bitstream/av1/timing-info.js +0 -20
  137. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.d.ts +0 -21
  138. package/dist/boxes/webm/bitstream/av1/transfer-characteristics.js +0 -24
  139. package/dist/boxes/webm/bitstream/av1/uvlc.d.ts +0 -2
  140. package/dist/boxes/webm/bitstream/av1/uvlc.js +0 -20
  141. package/dist/boxes/webm/bitstream/av1.d.ts +0 -20
  142. package/dist/boxes/webm/bitstream/av1.js +0 -118
  143. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.d.ts +0 -0
  144. package/dist/boxes/webm/bitstream/h264/get-h264-descriptor.js +0 -1
  145. package/dist/boxes/webm/segments/duration.d.ts +0 -6
  146. package/dist/boxes/webm/segments/duration.js +0 -19
  147. package/dist/boxes/webm/segments/info.d.ts +0 -9
  148. package/dist/boxes/webm/segments/info.js +0 -22
  149. package/dist/boxes/webm/segments/main.d.ts +0 -5
  150. package/dist/boxes/webm/segments/main.js +0 -2
  151. package/dist/boxes/webm/segments/muxing.d.ts +0 -6
  152. package/dist/boxes/webm/segments/muxing.js +0 -11
  153. package/dist/boxes/webm/segments/seek-head.d.ts +0 -9
  154. package/dist/boxes/webm/segments/seek-head.js +0 -22
  155. package/dist/boxes/webm/segments/seek-position.d.ts +0 -6
  156. package/dist/boxes/webm/segments/seek-position.js +0 -11
  157. package/dist/boxes/webm/segments/seek.d.ts +0 -13
  158. package/dist/boxes/webm/segments/seek.js +0 -35
  159. package/dist/boxes/webm/segments/timestamp-scale.d.ts +0 -6
  160. package/dist/boxes/webm/segments/timestamp-scale.js +0 -11
  161. package/dist/boxes/webm/segments/tracks.d.ts +0 -8
  162. package/dist/boxes/webm/segments/tracks.js +0 -21
  163. package/dist/boxes/webm/segments/unknown.d.ts +0 -6
  164. package/dist/boxes/webm/segments/unknown.js +0 -11
  165. package/dist/boxes/webm/segments/void.d.ts +0 -6
  166. package/dist/boxes/webm/segments/void.js +0 -11
  167. package/dist/boxes/webm/segments/writing.d.ts +0 -6
  168. package/dist/boxes/webm/segments/writing.js +0 -11
  169. package/dist/boxes/webm/tracks.d.ts +0 -8
  170. package/dist/boxes/webm/tracks.js +0 -21
  171. package/dist/combine-uint8array.d.ts +0 -1
  172. package/dist/combine-uint8array.js +0 -13
  173. package/dist/from-web.d.ts +0 -2
  174. package/dist/from-web.js +0 -45
  175. package/dist/get-video-metadata.d.ts +0 -2
  176. package/dist/get-video-metadata.js +0 -44
  177. package/dist/read-and-increment-offset.d.ts +0 -28
  178. package/dist/read-and-increment-offset.js +0 -177
  179. package/dist/understand-vorbis.d.ts +0 -1
  180. package/dist/understand-vorbis.js +0 -12
  181. package/input.webm +0 -0
  182. package/src/add-new-matroska-tracks.ts +0 -23
  183. package/src/boxes/iso-base-media/base-type.ts +0 -4
  184. package/src/boxes/iso-base-media/esds/decoder-specific-config.ts +0 -68
  185. package/src/boxes/iso-base-media/esds/esds-descriptors.ts +0 -135
  186. package/src/boxes/iso-base-media/esds/esds.ts +0 -49
  187. package/src/boxes/iso-base-media/ftyp.ts +0 -39
  188. package/src/boxes/iso-base-media/get-sample-positions-from-track.ts +0 -69
  189. package/src/boxes/iso-base-media/make-track.ts +0 -116
  190. package/src/boxes/iso-base-media/mdat/mdat.ts +0 -140
  191. package/src/boxes/iso-base-media/mdhd.ts +0 -59
  192. package/src/boxes/iso-base-media/moov/moov.ts +0 -43
  193. package/src/boxes/iso-base-media/mvhd.ts +0 -114
  194. package/src/boxes/iso-base-media/process-box.ts +0 -748
  195. package/src/boxes/iso-base-media/stsd/av1c.ts +0 -19
  196. package/src/boxes/iso-base-media/stsd/avcc.ts +0 -36
  197. package/src/boxes/iso-base-media/stsd/colr.ts +0 -49
  198. package/src/boxes/iso-base-media/stsd/ctts.ts +0 -64
  199. package/src/boxes/iso-base-media/stsd/hvcc.ts +0 -32
  200. package/src/boxes/iso-base-media/stsd/keys.ts +0 -27
  201. package/src/boxes/iso-base-media/stsd/mebx.ts +0 -54
  202. package/src/boxes/iso-base-media/stsd/pasp.ts +0 -32
  203. package/src/boxes/iso-base-media/stsd/samples.ts +0 -359
  204. package/src/boxes/iso-base-media/stsd/stco.ts +0 -52
  205. package/src/boxes/iso-base-media/stsd/stsc.ts +0 -61
  206. package/src/boxes/iso-base-media/stsd/stsd.ts +0 -55
  207. package/src/boxes/iso-base-media/stsd/stss.ts +0 -47
  208. package/src/boxes/iso-base-media/stsd/stsz.ts +0 -75
  209. package/src/boxes/iso-base-media/stsd/stts.ts +0 -62
  210. package/src/boxes/iso-base-media/tfdt.ts +0 -37
  211. package/src/boxes/iso-base-media/tfhd.ts +0 -66
  212. package/src/boxes/iso-base-media/tkhd.ts +0 -150
  213. package/src/boxes/iso-base-media/to-date.ts +0 -9
  214. package/src/boxes/iso-base-media/trak/trak.ts +0 -43
  215. package/src/boxes/iso-base-media/trun.ts +0 -74
  216. package/src/boxes/iso-base-media/void-box.ts +0 -4
  217. package/src/boxes/webm/allowed-partial-segments.ts +0 -1
  218. package/src/boxes/webm/av1-codec-private.ts +0 -113
  219. package/src/boxes/webm/description.ts +0 -104
  220. package/src/boxes/webm/ebml.ts +0 -98
  221. package/src/boxes/webm/get-ready-tracks.ts +0 -36
  222. package/src/boxes/webm/get-sample-from-block.ts +0 -125
  223. package/src/boxes/webm/get-track.ts +0 -257
  224. package/src/boxes/webm/make-header.ts +0 -253
  225. package/src/boxes/webm/parse-ebml.ts +0 -259
  226. package/src/boxes/webm/parse-webm-header.ts +0 -18
  227. package/src/boxes/webm/segments/all-segments.ts +0 -888
  228. package/src/boxes/webm/segments/block-simple-block-flags.ts +0 -52
  229. package/src/boxes/webm/segments/parse-children.ts +0 -144
  230. package/src/boxes/webm/segments/track-entry.ts +0 -38
  231. package/src/boxes/webm/segments.ts +0 -147
  232. package/src/boxes/webm/traversal.ts +0 -45
  233. package/src/buffer-iterator.ts +0 -555
  234. package/src/create/cluster-segment.ts +0 -62
  235. package/src/create/cluster.ts +0 -64
  236. package/src/create/create-media.ts +0 -136
  237. package/src/create/make-duration-with-padding.ts +0 -15
  238. package/src/create/matroska-header.ts +0 -63
  239. package/src/create/matroska-info.ts +0 -30
  240. package/src/create/matroska-segment.ts +0 -10
  241. package/src/create/matroska-trackentry.ts +0 -325
  242. package/src/create/timescale.ts +0 -1
  243. package/src/get-audio-codec.ts +0 -270
  244. package/src/get-dimensions.ts +0 -47
  245. package/src/get-duration.ts +0 -103
  246. package/src/get-fps.ts +0 -113
  247. package/src/get-sample-aspect-ratio.ts +0 -204
  248. package/src/get-sample-positions.ts +0 -93
  249. package/src/get-tracks.ts +0 -147
  250. package/src/get-video-codec.ts +0 -117
  251. package/src/has-all-info.ts +0 -81
  252. package/src/index.ts +0 -18
  253. package/src/make-hvc1-codec-strings.ts +0 -55
  254. package/src/options.ts +0 -118
  255. package/src/parse-media.ts +0 -183
  256. package/src/parse-result.ts +0 -79
  257. package/src/parse-video.ts +0 -83
  258. package/src/parser-context.ts +0 -10
  259. package/src/parser-state.ts +0 -178
  260. package/src/readers/from-fetch.ts +0 -90
  261. package/src/readers/from-node.ts +0 -51
  262. package/src/readers/from-web-file.ts +0 -49
  263. package/src/readers/reader.ts +0 -15
  264. package/src/samples-from-moof.ts +0 -102
  265. package/src/test/aspect-ratio.test.ts +0 -42
  266. package/src/test/av1.test.ts +0 -108
  267. package/src/test/create-matroska.test.ts +0 -287
  268. package/src/test/duration.test.ts +0 -18
  269. package/src/test/keys.test.ts +0 -47
  270. package/src/test/matroska.test.ts +0 -463
  271. package/src/test/mvhd.test.ts +0 -94
  272. package/src/test/parse-esds.test.ts +0 -98
  273. package/src/test/parse-stco.test.ts +0 -61
  274. package/src/test/parse-stsc.test.ts +0 -104
  275. package/src/test/parse-stsz.test.ts +0 -57
  276. package/src/test/parse-stts.test.ts +0 -38
  277. package/src/test/parse-video.test.ts +0 -101
  278. package/src/test/parse-webm.test.ts +0 -17
  279. package/src/test/samples-from-moof.test.ts +0 -2496
  280. package/src/test/stream-local.test.ts +0 -743
  281. package/src/test/stream-remote.test.ts +0 -59
  282. package/src/test/stream-samples.test.ts +0 -181
  283. package/src/test/stsd.test.ts +0 -265
  284. package/src/test/tkhd.test.ts +0 -87
  285. package/src/traversal.ts +0 -528
  286. package/src/webcodec-sample-types.ts +0 -29
  287. package/src/writers/web-fs.ts +0 -50
  288. package/src/writers/writer.ts +0 -12
  289. package/tsconfig.json +0 -14
  290. 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
- }