@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
@@ -1,74 +0,0 @@
1
- import type {BufferIterator} from '../../buffer-iterator';
2
-
3
- export interface TrunBox {
4
- type: 'trun-box';
5
- version: number;
6
- sampleCount: number;
7
- dataOffset: number | null;
8
- firstSampleFlags: number | null;
9
- samples: TRunSample[];
10
- }
11
-
12
- type TRunSample = {
13
- sampleDuration: number | null;
14
- sampleSize: number | null;
15
- sampleFlags: number | null;
16
- sampleCompositionTimeOffset: number | null;
17
- };
18
-
19
- export const parseTrun = ({
20
- iterator,
21
- offset,
22
- size,
23
- }: {
24
- iterator: BufferIterator;
25
- offset: number;
26
- size: number;
27
- }): TrunBox => {
28
- const version = iterator.getUint8();
29
- if (version !== 0) {
30
- throw new Error(`Unsupported TRUN version ${version}`);
31
- }
32
-
33
- const flags = iterator.getUint24();
34
- const sampleCount = iterator.getUint32();
35
-
36
- const dataOffset = flags & 0x01 ? iterator.getInt32() : null;
37
- const firstSampleFlags = flags & 0x04 ? iterator.getUint32() : null;
38
-
39
- const samples: TRunSample[] = [];
40
-
41
- for (let i = 0; i < sampleCount; i++) {
42
- const sampleDuration = flags & 0x100 ? iterator.getUint32() : null;
43
- const sampleSize = flags & 0x200 ? iterator.getUint32() : null;
44
- const sampleFlags = flags & 0x400 ? iterator.getUint32() : null;
45
- const sampleCompositionTimeOffset =
46
- flags & 0x800
47
- ? version === 0
48
- ? iterator.getUint32()
49
- : iterator.getInt32Le()
50
- : null;
51
-
52
- samples.push({
53
- sampleDuration,
54
- sampleSize,
55
- sampleFlags,
56
- sampleCompositionTimeOffset,
57
- });
58
- }
59
-
60
- const currentOffset = iterator.counter.getOffset();
61
- const left = size - (currentOffset - offset);
62
- if (left !== 0) {
63
- throw new Error(`Unexpected data left in TRUN box: ${left}`);
64
- }
65
-
66
- return {
67
- type: 'trun-box',
68
- version,
69
- sampleCount,
70
- dataOffset,
71
- firstSampleFlags,
72
- samples,
73
- };
74
- };
@@ -1,4 +0,0 @@
1
- export interface VoidBox {
2
- type: 'void-box';
3
- boxSize: number;
4
- }
@@ -1 +0,0 @@
1
- export const allowedPartialSegments = ['0x1f43b675', '0x18538067'];
@@ -1,113 +0,0 @@
1
- import {getArrayBufferIterator} from '../../buffer-iterator';
2
- import type {ColorParameterBox} from '../iso-base-media/stsd/colr';
3
-
4
- export const parseAv1PrivateData = (
5
- data: Uint8Array,
6
- colrAtom: ColorParameterBox | null,
7
- ) => {
8
- const iterator = getArrayBufferIterator(data, data.byteLength);
9
- iterator.startReadingBits();
10
- if (iterator.getBits(1) !== 1) {
11
- iterator.destroy();
12
- throw new Error('Expected av1 private data to be version 1');
13
- }
14
-
15
- const version = iterator.getBits(7);
16
- if (version !== 1) {
17
- iterator.destroy();
18
- throw new Error(
19
- `Expected av1 private data to be version 1, got ${version}`,
20
- );
21
- }
22
-
23
- let str = 'av01.';
24
-
25
- // https://aomediacodec.github.io/av1-isobmff/#codecsparam
26
-
27
- const seqProfile = iterator.getBits(3);
28
- // Profile
29
- str += seqProfile;
30
- str += '.';
31
-
32
- const seq_level_idx = iterator.getBits(5);
33
- const seq_tier_0 = iterator.getBits(1);
34
- // Level
35
- // The level parameter value SHALL equal the first level value indicated by seq_level_idx in the Sequence Header OBU
36
- str += seq_level_idx.toString(16).padStart(2, '0');
37
- str += seq_tier_0 ? 'H' : 'M';
38
- str += '.';
39
-
40
- // bitDepth
41
- // The bitDepth parameter value SHALL equal the value of BitDepth variable as defined in [AV1] derived from the Sequence Header OBU
42
- const high_bitdepth = iterator.getBits(1);
43
- const twelve_bit = iterator.getBits(1);
44
- const bitDepth =
45
- high_bitdepth && seqProfile === 2
46
- ? twelve_bit
47
- ? 12
48
- : 10
49
- : high_bitdepth
50
- ? 10
51
- : 8;
52
- str += bitDepth.toString().padStart(2, '0');
53
- str += '.';
54
-
55
- // monochrome
56
- // The monochrome parameter value, represented by a single digit decimal, SHALL equal the value of mono_chrome in the Sequence Header OBU
57
- const mono_chrome = iterator.getBits(1);
58
- str += mono_chrome ? '1' : '0';
59
- str += '.';
60
-
61
- // The chromaSubsampling parameter value, represented by a three-digit decimal,
62
- // SHALL have its first digit equal to subsampling_x
63
- const subsampling_x = iterator.getBits(1);
64
- str += subsampling_x ? '1' : '0';
65
-
66
- // and its second digit equal to subsampling_y.
67
- const subsampling_y = iterator.getBits(1);
68
- str += subsampling_y ? '1' : '0';
69
-
70
- // If both subsampling_x and subsampling_y are set to 1, then the third digit SHALL be equal to chroma_sample_position, otherwise it SHALL be set to 0
71
- const chroma_sample_position = iterator.getBits(2);
72
- str +=
73
- subsampling_x && subsampling_y
74
- ? chroma_sample_position === 1
75
- ? '1'
76
- : '0'
77
- : '0';
78
- str += '.';
79
-
80
- if (colrAtom) {
81
- str += colrAtom.primaries.toString().padStart(2, '0');
82
- str += '.';
83
- str += colrAtom.transfer.toString().padStart(2, '0');
84
- str += '.';
85
- str += colrAtom.matrixIndex.toString().padStart(2, '0');
86
- str += '.';
87
- str += colrAtom.fullRangeFlag ? '1' : '0';
88
- } else {
89
- // Otherwise, the color_description_present_flag is set to 0 in the Sequence Header OBU. The colorPrimaries, transferCharacteristics, and matrixCoefficients parameter values SHOULD be set to the default values below.
90
- // colorPrimaries 01 (ITU-R BT.709)
91
- str += '01';
92
- str += '.';
93
- // transferCharacteristics 01 (ITU-R BT.709)
94
- str += '01';
95
- str += '.';
96
- // matrixCoefficients 00 (ITU-R BT.709)
97
- str += '01';
98
- str += '.';
99
- // videoFullRangeFlag 0 (studio swing representation)
100
- str += '0';
101
- }
102
-
103
- // If the codecs parameter string ends with ".0.110.01.01.01.0" (containing all the default values below), that trailing part of the string SHOULD be omitted.
104
- const suffix = '.0.110.01.01.01.0';
105
-
106
- if (str.endsWith(suffix)) {
107
- str = str.slice(0, -suffix.length);
108
- }
109
-
110
- iterator.destroy();
111
-
112
- return str;
113
- };
@@ -1,104 +0,0 @@
1
- import {getArrayBufferIterator} from '../../buffer-iterator';
2
- import {getCodecSegment, getPrivateData} from '../../traversal';
3
- import type {TrackEntry} from './segments/all-segments';
4
-
5
- export const getAudioDescription = (
6
- track: TrackEntry,
7
- ): undefined | Uint8Array => {
8
- const codec = getCodecSegment(track);
9
- if (!codec || codec.value !== 'A_VORBIS') {
10
- return undefined;
11
- }
12
-
13
- // how to parse vorbis private
14
- // https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java#L2466
15
- const privateData = getPrivateData(track);
16
- if (!privateData) {
17
- return undefined;
18
- }
19
-
20
- if (privateData[0] !== 2) {
21
- throw new Error('Expected vorbis private data version 2');
22
- }
23
-
24
- let offset = 1;
25
- let vorbisInfoLength = 0;
26
- let vorbisSkipLength = 0;
27
-
28
- while ((privateData[offset] & 0xff) === 0xff) {
29
- vorbisInfoLength += 0xff;
30
- offset++;
31
- }
32
-
33
- vorbisInfoLength += privateData[offset++] & 0xff;
34
-
35
- while ((privateData[offset] & 0xff) === 0xff) {
36
- vorbisSkipLength += 0xff;
37
- offset++;
38
- }
39
-
40
- vorbisSkipLength += privateData[offset++] & 0xff;
41
-
42
- if (privateData[offset] !== 0x01) {
43
- throw new Error('Error parsing vorbis codec private');
44
- }
45
-
46
- const vorbisInfo = privateData.slice(offset, offset + vorbisInfoLength);
47
- offset += vorbisInfoLength;
48
-
49
- if (privateData[offset] !== 0x03) {
50
- throw new Error('Error parsing vorbis codec private');
51
- }
52
-
53
- const vorbisComments = privateData.slice(offset, offset + vorbisSkipLength);
54
- offset += vorbisSkipLength;
55
-
56
- if (privateData[offset] !== 0x05) {
57
- throw new Error('Error parsing vorbis codec private');
58
- }
59
-
60
- const vorbisBooks = privateData.slice(offset);
61
-
62
- const bufferIterator = getArrayBufferIterator(
63
- vorbisInfo.slice(0),
64
- vorbisInfo.length,
65
- );
66
-
67
- // type
68
- bufferIterator.getUint8();
69
- // vorbis
70
- const vorbis = bufferIterator.getByteString(6);
71
- if (vorbis !== 'vorbis') {
72
- throw new Error('Error parsing vorbis codec private');
73
- }
74
-
75
- const vorbisVersion = bufferIterator.getUint32Le();
76
- if (vorbisVersion !== 0) {
77
- throw new Error('Error parsing vorbis codec private');
78
- }
79
-
80
- const vorbisDescription = new Uint8Array([
81
- // constructing the vorbis description
82
- // This format consists in the page_segments field
83
- /**
84
- * The number of segment entries to appear in the segment table.
85
- * The maximum number of 255 segments (255 bytes each) sets the maximum possible physical page size at 65307 bytes or just under 64kB (thus we know that a header corrupted so as destroy sizing/alignment information will not cause a runaway bitstream.
86
- * We'll read in the page according to the corrupted size information that's guaranteed to be a reasonable size regardless, notice the checksum mismatch, drop sync and then look for recapture).
87
- */
88
- 2,
89
- // followed by the segment_table field
90
- // offset of the comments table
91
- vorbisInfo.length,
92
- // offset of the codebooks table
93
- vorbisComments.length,
94
- // followed by the three Vorbis header packets,
95
- // respectively the identification header,
96
- ...vorbisInfo,
97
- // the comments header,
98
- ...vorbisComments,
99
- // and the setup header, in this order, as described in section 4.2 of [VORBIS].
100
- ...vorbisBooks,
101
- ]);
102
-
103
- return vorbisDescription;
104
- };
@@ -1,98 +0,0 @@
1
- // https://github.com/Vanilagy/webm-muxer/blob/main/src/ebml.ts#L101
2
-
3
- export const measureEBMLVarInt = (value: number) => {
4
- if (value < (1 << 7) - 1) {
5
- /** Top bit is set, leaving 7 bits to hold the integer, but we can't store
6
- * 127 because "all bits set to one" is a reserved value. Same thing for the
7
- * other cases below:
8
- */
9
- return 1;
10
- }
11
-
12
- if (value < (1 << 14) - 1) {
13
- return 2;
14
- }
15
-
16
- if (value < (1 << 21) - 1) {
17
- return 3;
18
- }
19
-
20
- if (value < (1 << 28) - 1) {
21
- return 4;
22
- }
23
-
24
- if (value < 2 ** 35 - 1) {
25
- return 5;
26
- }
27
-
28
- if (value < 2 ** 42 - 1) {
29
- return 6;
30
- }
31
-
32
- throw new Error('EBML VINT size not supported ' + value);
33
- };
34
-
35
- export const getVariableInt = (value: number, minWidth: number | null) => {
36
- const width = Math.max(measureEBMLVarInt(value), minWidth ?? 0);
37
-
38
- switch (width) {
39
- case 1:
40
- return new Uint8Array([(1 << 7) | value]);
41
- case 2:
42
- return new Uint8Array([(1 << 6) | (value >> 8), value]);
43
- case 3:
44
- return new Uint8Array([(1 << 5) | (value >> 16), value >> 8, value]);
45
- case 4:
46
- return new Uint8Array([
47
- (1 << 4) | (value >> 24),
48
- value >> 16,
49
- value >> 8,
50
- value,
51
- ]);
52
- case 5:
53
- /**
54
- * JavaScript converts its doubles to 32-bit integers for bitwise
55
- * operations, so we need to do a division by 2^32 instead of a
56
- * right-shift of 32 to retain those top 3 bits
57
- */
58
- return new Uint8Array([
59
- (1 << 3) | ((value / 2 ** 32) & 0x7),
60
- value >> 24,
61
- value >> 16,
62
- value >> 8,
63
- value,
64
- ]);
65
- case 6:
66
- return new Uint8Array([
67
- (1 << 2) | ((value / 2 ** 40) & 0x3),
68
- (value / 2 ** 32) | 0,
69
- value >> 24,
70
- value >> 16,
71
- value >> 8,
72
- value,
73
- ]);
74
- case 7:
75
- return new Uint8Array([
76
- (1 << 1) | ((value / 2 ** 48) & 0x1),
77
- (value / 2 ** 40) | 0,
78
- (value / 2 ** 32) | 0,
79
- value >> 24,
80
- value >> 16,
81
- value >> 8,
82
- value,
83
- ]);
84
- case 8:
85
- return new Uint8Array([
86
- (1 << 0) | ((value / 2 ** 56) & 0x1),
87
- (value / 2 ** 48) | 0,
88
- (value / 2 ** 40) | 0,
89
- (value / 2 ** 32) | 0,
90
- value >> 24,
91
- value >> 16,
92
- value >> 8,
93
- value,
94
- ]);
95
- default:
96
- throw new Error('Bad EBML VINT size ' + width);
97
- }
98
- };
@@ -1,36 +0,0 @@
1
- import type {Track} from '../../get-tracks';
2
- import {getTracksSegment} from '../../traversal';
3
- import {getTrack} from './get-track';
4
- import type {MainSegment} from './segments/all-segments';
5
-
6
- export const getTracksFromMatroska = (
7
- segment: MainSegment,
8
- timescale: number,
9
- ): Track[] => {
10
- const tracksSegment = getTracksSegment(segment);
11
- if (!tracksSegment) {
12
- throw new Error('No tracks segment');
13
- }
14
-
15
- const tracks: Track[] = [];
16
-
17
- for (const trackEntrySegment of tracksSegment.value) {
18
- if (trackEntrySegment.type === 'Crc32') {
19
- continue;
20
- }
21
-
22
- if (trackEntrySegment.type !== 'TrackEntry') {
23
- throw new Error('Expected track entry segment');
24
- }
25
-
26
- const track = getTrack({
27
- track: trackEntrySegment,
28
- timescale,
29
- });
30
- if (track) {
31
- tracks.push(track);
32
- }
33
- }
34
-
35
- return tracks;
36
- };
@@ -1,125 +0,0 @@
1
- import {getArrayBufferIterator} from '../../buffer-iterator';
2
- import type {ParserContext} from '../../parser-context';
3
- import type {AudioSample, VideoSample} from '../../webcodec-sample-types';
4
- import type {BlockSegment, SimpleBlockSegment} from './segments/all-segments';
5
- import {matroskaElements} from './segments/all-segments';
6
- import {parseBlockFlags} from './segments/block-simple-block-flags';
7
-
8
- type SampleResult =
9
- | {
10
- type: 'video-sample';
11
- videoSample: VideoSample;
12
- }
13
- | {
14
- type: 'audio-sample';
15
- audioSample: AudioSample;
16
- }
17
- | {
18
- type: 'partial-video-sample';
19
- partialVideoSample: Omit<VideoSample, 'type'>;
20
- }
21
- | {
22
- type: 'no-sample';
23
- };
24
-
25
- export const getSampleFromBlock = (
26
- ebml: BlockSegment | SimpleBlockSegment,
27
- parserContext: ParserContext,
28
- offset: number,
29
- ): SampleResult => {
30
- const iterator = getArrayBufferIterator(ebml.value, ebml.value.length);
31
- const trackNumber = iterator.getVint();
32
- if (trackNumber === null) {
33
- throw new Error('Not enough data to get track number, should not happen');
34
- }
35
-
36
- const timecodeRelativeToCluster = iterator.getUint16();
37
-
38
- const {keyframe} = parseBlockFlags(
39
- iterator,
40
- ebml.type === 'SimpleBlock'
41
- ? matroskaElements.SimpleBlock
42
- : matroskaElements.Block,
43
- );
44
-
45
- const {codec, trackTimescale} =
46
- parserContext.parserState.getTrackInfoByNumber(trackNumber);
47
-
48
- const clusterOffset =
49
- parserContext.parserState.getTimestampOffsetForByteOffset(offset);
50
-
51
- const timescale = parserContext.parserState.getTimescale();
52
-
53
- if (clusterOffset === undefined) {
54
- throw new Error('Could not find offset for byte offset ' + offset);
55
- }
56
-
57
- // https://github.com/hubblec4/Matroska-Chapters-Specs/blob/master/notes.md/#timestampscale
58
- // The TimestampScale Element is used to calculate the Raw Timestamp of a Block. The timestamp is obtained by adding the Block's timestamp to the Cluster's Timestamp Element, and then multiplying that result by the TimestampScale. The result will be the Block's Raw Timestamp in nanoseconds.
59
- const timecodeInNanoSeconds =
60
- (timecodeRelativeToCluster + clusterOffset) *
61
- timescale *
62
- (trackTimescale ?? 1);
63
-
64
- // Timecode should be in microseconds
65
- const timecodeInMicroseconds = timecodeInNanoSeconds / 1000;
66
-
67
- if (!codec) {
68
- throw new Error(`Could not find codec for track ${trackNumber}`);
69
- }
70
-
71
- const remainingNow = ebml.value.length - (iterator.counter.getOffset() - 0);
72
-
73
- if (codec.startsWith('V_')) {
74
- const partialVideoSample: Omit<VideoSample, 'type'> = {
75
- data: iterator.getSlice(remainingNow),
76
- cts: null,
77
- dts: null,
78
- duration: undefined,
79
- trackId: trackNumber,
80
- timestamp: timecodeInMicroseconds,
81
- };
82
-
83
- if (keyframe === null) {
84
- iterator.destroy();
85
-
86
- return {
87
- type: 'partial-video-sample',
88
- partialVideoSample,
89
- };
90
- }
91
-
92
- const sample: VideoSample = {
93
- ...partialVideoSample,
94
- type: keyframe ? 'key' : 'delta',
95
- };
96
-
97
- iterator.destroy();
98
-
99
- return {
100
- type: 'video-sample',
101
- videoSample: sample,
102
- };
103
- }
104
-
105
- if (codec.startsWith('A_')) {
106
- const audioSample: AudioSample = {
107
- data: iterator.getSlice(remainingNow),
108
- trackId: trackNumber,
109
- timestamp: timecodeInMicroseconds,
110
- type: 'key',
111
- };
112
-
113
- iterator.destroy();
114
-
115
- return {
116
- type: 'audio-sample',
117
- audioSample,
118
- };
119
- }
120
-
121
- iterator.destroy();
122
- return {
123
- type: 'no-sample',
124
- };
125
- };