@kenzuya/mediabunny 1.26.0 → 1.28.5

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 (237) hide show
  1. package/README.md +1 -1
  2. package/dist/bundles/{mediabunny.mjs → mediabunny.js} +21963 -21388
  3. package/dist/bundles/mediabunny.min.js +490 -0
  4. package/dist/modules/shared/mp3-misc.d.ts.map +1 -1
  5. package/dist/modules/src/adts/adts-demuxer.d.ts +6 -6
  6. package/dist/modules/src/adts/adts-demuxer.d.ts.map +1 -1
  7. package/dist/modules/src/adts/adts-muxer.d.ts +4 -4
  8. package/dist/modules/src/adts/adts-muxer.d.ts.map +1 -1
  9. package/dist/modules/src/adts/adts-reader.d.ts +1 -1
  10. package/dist/modules/src/adts/adts-reader.d.ts.map +1 -1
  11. package/dist/modules/src/avi/avi-demuxer.d.ts +44 -0
  12. package/dist/modules/src/avi/avi-demuxer.d.ts.map +1 -0
  13. package/dist/modules/src/avi/avi-misc.d.ts +88 -0
  14. package/dist/modules/src/avi/avi-misc.d.ts.map +1 -0
  15. package/dist/modules/src/avi/avi-muxer.d.ts +45 -0
  16. package/dist/modules/src/avi/avi-muxer.d.ts.map +1 -0
  17. package/dist/modules/src/avi/riff-writer.d.ts +26 -0
  18. package/dist/modules/src/avi/riff-writer.d.ts.map +1 -0
  19. package/dist/modules/src/codec-data.d.ts +8 -3
  20. package/dist/modules/src/codec-data.d.ts.map +1 -1
  21. package/dist/modules/src/codec.d.ts +10 -10
  22. package/dist/modules/src/codec.d.ts.map +1 -1
  23. package/dist/modules/src/conversion.d.ts +33 -16
  24. package/dist/modules/src/conversion.d.ts.map +1 -1
  25. package/dist/modules/src/custom-coder.d.ts +8 -8
  26. package/dist/modules/src/custom-coder.d.ts.map +1 -1
  27. package/dist/modules/src/demuxer.d.ts +3 -3
  28. package/dist/modules/src/demuxer.d.ts.map +1 -1
  29. package/dist/modules/src/encode.d.ts +8 -8
  30. package/dist/modules/src/encode.d.ts.map +1 -1
  31. package/dist/modules/src/flac/flac-demuxer.d.ts +7 -7
  32. package/dist/modules/src/flac/flac-demuxer.d.ts.map +1 -1
  33. package/dist/modules/src/flac/flac-misc.d.ts +3 -3
  34. package/dist/modules/src/flac/flac-misc.d.ts.map +1 -1
  35. package/dist/modules/src/flac/flac-muxer.d.ts +5 -5
  36. package/dist/modules/src/flac/flac-muxer.d.ts.map +1 -1
  37. package/dist/modules/src/id3.d.ts +3 -3
  38. package/dist/modules/src/id3.d.ts.map +1 -1
  39. package/dist/modules/src/index.d.ts +20 -20
  40. package/dist/modules/src/index.d.ts.map +1 -1
  41. package/dist/modules/src/input-format.d.ts +22 -0
  42. package/dist/modules/src/input-format.d.ts.map +1 -1
  43. package/dist/modules/src/input-track.d.ts +8 -8
  44. package/dist/modules/src/input-track.d.ts.map +1 -1
  45. package/dist/modules/src/input.d.ts +12 -12
  46. package/dist/modules/src/isobmff/isobmff-boxes.d.ts +2 -2
  47. package/dist/modules/src/isobmff/isobmff-boxes.d.ts.map +1 -1
  48. package/dist/modules/src/isobmff/isobmff-demuxer.d.ts +12 -12
  49. package/dist/modules/src/isobmff/isobmff-demuxer.d.ts.map +1 -1
  50. package/dist/modules/src/isobmff/isobmff-misc.d.ts.map +1 -1
  51. package/dist/modules/src/isobmff/isobmff-muxer.d.ts +11 -11
  52. package/dist/modules/src/isobmff/isobmff-muxer.d.ts.map +1 -1
  53. package/dist/modules/src/isobmff/isobmff-reader.d.ts +2 -2
  54. package/dist/modules/src/isobmff/isobmff-reader.d.ts.map +1 -1
  55. package/dist/modules/src/matroska/ebml.d.ts +3 -3
  56. package/dist/modules/src/matroska/ebml.d.ts.map +1 -1
  57. package/dist/modules/src/matroska/matroska-demuxer.d.ts +13 -13
  58. package/dist/modules/src/matroska/matroska-demuxer.d.ts.map +1 -1
  59. package/dist/modules/src/matroska/matroska-input.d.ts +33 -0
  60. package/dist/modules/src/matroska/matroska-input.d.ts.map +1 -0
  61. package/dist/modules/src/matroska/matroska-misc.d.ts.map +1 -1
  62. package/dist/modules/src/matroska/matroska-muxer.d.ts +5 -5
  63. package/dist/modules/src/matroska/matroska-muxer.d.ts.map +1 -1
  64. package/dist/modules/src/media-sink.d.ts +5 -5
  65. package/dist/modules/src/media-sink.d.ts.map +1 -1
  66. package/dist/modules/src/media-source.d.ts +22 -4
  67. package/dist/modules/src/media-source.d.ts.map +1 -1
  68. package/dist/modules/src/metadata.d.ts +2 -2
  69. package/dist/modules/src/metadata.d.ts.map +1 -1
  70. package/dist/modules/src/misc.d.ts +5 -4
  71. package/dist/modules/src/misc.d.ts.map +1 -1
  72. package/dist/modules/src/mp3/mp3-demuxer.d.ts +7 -7
  73. package/dist/modules/src/mp3/mp3-demuxer.d.ts.map +1 -1
  74. package/dist/modules/src/mp3/mp3-muxer.d.ts +4 -4
  75. package/dist/modules/src/mp3/mp3-muxer.d.ts.map +1 -1
  76. package/dist/modules/src/mp3/mp3-reader.d.ts +2 -2
  77. package/dist/modules/src/mp3/mp3-reader.d.ts.map +1 -1
  78. package/dist/modules/src/mp3/mp3-writer.d.ts +1 -1
  79. package/dist/modules/src/mp3/mp3-writer.d.ts.map +1 -1
  80. package/dist/modules/src/muxer.d.ts +4 -4
  81. package/dist/modules/src/muxer.d.ts.map +1 -1
  82. package/dist/modules/src/node.d.ts +1 -1
  83. package/dist/modules/src/ogg/ogg-demuxer.d.ts +7 -7
  84. package/dist/modules/src/ogg/ogg-demuxer.d.ts.map +1 -1
  85. package/dist/modules/src/ogg/ogg-misc.d.ts +1 -1
  86. package/dist/modules/src/ogg/ogg-misc.d.ts.map +1 -1
  87. package/dist/modules/src/ogg/ogg-muxer.d.ts +5 -5
  88. package/dist/modules/src/ogg/ogg-muxer.d.ts.map +1 -1
  89. package/dist/modules/src/ogg/ogg-reader.d.ts +1 -1
  90. package/dist/modules/src/ogg/ogg-reader.d.ts.map +1 -1
  91. package/dist/modules/src/output-format.d.ts +51 -6
  92. package/dist/modules/src/output-format.d.ts.map +1 -1
  93. package/dist/modules/src/output.d.ts +13 -13
  94. package/dist/modules/src/output.d.ts.map +1 -1
  95. package/dist/modules/src/packet.d.ts +1 -1
  96. package/dist/modules/src/packet.d.ts.map +1 -1
  97. package/dist/modules/src/pcm.d.ts.map +1 -1
  98. package/dist/modules/src/reader.d.ts +2 -2
  99. package/dist/modules/src/reader.d.ts.map +1 -1
  100. package/dist/modules/src/sample.d.ts +57 -15
  101. package/dist/modules/src/sample.d.ts.map +1 -1
  102. package/dist/modules/src/source.d.ts +3 -3
  103. package/dist/modules/src/source.d.ts.map +1 -1
  104. package/dist/modules/src/subtitles.d.ts +1 -1
  105. package/dist/modules/src/subtitles.d.ts.map +1 -1
  106. package/dist/modules/src/target.d.ts +2 -2
  107. package/dist/modules/src/target.d.ts.map +1 -1
  108. package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
  109. package/dist/modules/src/wave/riff-writer.d.ts +1 -1
  110. package/dist/modules/src/wave/riff-writer.d.ts.map +1 -1
  111. package/dist/modules/src/wave/wave-demuxer.d.ts +6 -6
  112. package/dist/modules/src/wave/wave-demuxer.d.ts.map +1 -1
  113. package/dist/modules/src/wave/wave-muxer.d.ts +4 -4
  114. package/dist/modules/src/wave/wave-muxer.d.ts.map +1 -1
  115. package/dist/modules/src/writer.d.ts +1 -1
  116. package/dist/modules/src/writer.d.ts.map +1 -1
  117. package/dist/packages/eac3/eac3.wasm +0 -0
  118. package/dist/packages/eac3/mediabunny-eac3.js +1058 -0
  119. package/dist/packages/eac3/mediabunny-eac3.min.js +44 -0
  120. package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.js +694 -0
  121. package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.min.js +58 -0
  122. package/dist/packages/mpeg4/mediabunny-mpeg4.js +1198 -0
  123. package/dist/packages/mpeg4/mediabunny-mpeg4.min.js +44 -0
  124. package/dist/packages/mpeg4/xvid.wasm +0 -0
  125. package/package.json +18 -57
  126. package/dist/bundles/mediabunny.cjs +0 -26140
  127. package/dist/bundles/mediabunny.min.cjs +0 -147
  128. package/dist/bundles/mediabunny.min.mjs +0 -146
  129. package/dist/mediabunny.d.ts +0 -3319
  130. package/dist/modules/shared/mp3-misc.js +0 -147
  131. package/dist/modules/src/adts/adts-demuxer.js +0 -239
  132. package/dist/modules/src/adts/adts-muxer.js +0 -80
  133. package/dist/modules/src/adts/adts-reader.js +0 -63
  134. package/dist/modules/src/codec-data.js +0 -1730
  135. package/dist/modules/src/codec.js +0 -869
  136. package/dist/modules/src/conversion.js +0 -1459
  137. package/dist/modules/src/custom-coder.js +0 -117
  138. package/dist/modules/src/demuxer.js +0 -12
  139. package/dist/modules/src/encode.js +0 -442
  140. package/dist/modules/src/flac/flac-demuxer.js +0 -504
  141. package/dist/modules/src/flac/flac-misc.js +0 -135
  142. package/dist/modules/src/flac/flac-muxer.js +0 -222
  143. package/dist/modules/src/id3.js +0 -848
  144. package/dist/modules/src/index.js +0 -28
  145. package/dist/modules/src/input-format.js +0 -480
  146. package/dist/modules/src/input-track.js +0 -372
  147. package/dist/modules/src/input.js +0 -188
  148. package/dist/modules/src/isobmff/isobmff-boxes.js +0 -1480
  149. package/dist/modules/src/isobmff/isobmff-demuxer.js +0 -2618
  150. package/dist/modules/src/isobmff/isobmff-misc.js +0 -20
  151. package/dist/modules/src/isobmff/isobmff-muxer.js +0 -966
  152. package/dist/modules/src/isobmff/isobmff-reader.js +0 -72
  153. package/dist/modules/src/matroska/ebml.js +0 -653
  154. package/dist/modules/src/matroska/matroska-demuxer.js +0 -2133
  155. package/dist/modules/src/matroska/matroska-misc.js +0 -20
  156. package/dist/modules/src/matroska/matroska-muxer.js +0 -1017
  157. package/dist/modules/src/media-sink.js +0 -1736
  158. package/dist/modules/src/media-source.js +0 -1825
  159. package/dist/modules/src/metadata.js +0 -193
  160. package/dist/modules/src/misc.js +0 -623
  161. package/dist/modules/src/mp3/mp3-demuxer.js +0 -285
  162. package/dist/modules/src/mp3/mp3-muxer.js +0 -123
  163. package/dist/modules/src/mp3/mp3-reader.js +0 -26
  164. package/dist/modules/src/mp3/mp3-writer.js +0 -78
  165. package/dist/modules/src/muxer.js +0 -50
  166. package/dist/modules/src/node.js +0 -9
  167. package/dist/modules/src/ogg/ogg-demuxer.js +0 -763
  168. package/dist/modules/src/ogg/ogg-misc.js +0 -78
  169. package/dist/modules/src/ogg/ogg-muxer.js +0 -353
  170. package/dist/modules/src/ogg/ogg-reader.js +0 -65
  171. package/dist/modules/src/output-format.js +0 -527
  172. package/dist/modules/src/output.js +0 -300
  173. package/dist/modules/src/packet.js +0 -182
  174. package/dist/modules/src/pcm.js +0 -85
  175. package/dist/modules/src/reader.js +0 -236
  176. package/dist/modules/src/sample.js +0 -1056
  177. package/dist/modules/src/source.js +0 -1182
  178. package/dist/modules/src/subtitles.js +0 -575
  179. package/dist/modules/src/target.js +0 -140
  180. package/dist/modules/src/wave/riff-writer.js +0 -30
  181. package/dist/modules/src/wave/wave-demuxer.js +0 -447
  182. package/dist/modules/src/wave/wave-muxer.js +0 -318
  183. package/dist/modules/src/writer.js +0 -370
  184. package/src/adts/adts-demuxer.ts +0 -331
  185. package/src/adts/adts-muxer.ts +0 -111
  186. package/src/adts/adts-reader.ts +0 -85
  187. package/src/codec-data.ts +0 -2078
  188. package/src/codec.ts +0 -1092
  189. package/src/conversion.ts +0 -2112
  190. package/src/custom-coder.ts +0 -197
  191. package/src/demuxer.ts +0 -24
  192. package/src/encode.ts +0 -739
  193. package/src/flac/flac-demuxer.ts +0 -730
  194. package/src/flac/flac-misc.ts +0 -164
  195. package/src/flac/flac-muxer.ts +0 -320
  196. package/src/id3.ts +0 -925
  197. package/src/index.ts +0 -221
  198. package/src/input-format.ts +0 -541
  199. package/src/input-track.ts +0 -529
  200. package/src/input.ts +0 -235
  201. package/src/isobmff/isobmff-boxes.ts +0 -1719
  202. package/src/isobmff/isobmff-demuxer.ts +0 -3190
  203. package/src/isobmff/isobmff-misc.ts +0 -29
  204. package/src/isobmff/isobmff-muxer.ts +0 -1348
  205. package/src/isobmff/isobmff-reader.ts +0 -91
  206. package/src/matroska/ebml.ts +0 -730
  207. package/src/matroska/matroska-demuxer.ts +0 -2481
  208. package/src/matroska/matroska-misc.ts +0 -29
  209. package/src/matroska/matroska-muxer.ts +0 -1276
  210. package/src/media-sink.ts +0 -2179
  211. package/src/media-source.ts +0 -2243
  212. package/src/metadata.ts +0 -320
  213. package/src/misc.ts +0 -798
  214. package/src/mp3/mp3-demuxer.ts +0 -383
  215. package/src/mp3/mp3-muxer.ts +0 -166
  216. package/src/mp3/mp3-reader.ts +0 -34
  217. package/src/mp3/mp3-writer.ts +0 -120
  218. package/src/muxer.ts +0 -88
  219. package/src/node.ts +0 -11
  220. package/src/ogg/ogg-demuxer.ts +0 -1053
  221. package/src/ogg/ogg-misc.ts +0 -116
  222. package/src/ogg/ogg-muxer.ts +0 -497
  223. package/src/ogg/ogg-reader.ts +0 -93
  224. package/src/output-format.ts +0 -945
  225. package/src/output.ts +0 -488
  226. package/src/packet.ts +0 -263
  227. package/src/pcm.ts +0 -112
  228. package/src/reader.ts +0 -323
  229. package/src/sample.ts +0 -1461
  230. package/src/source.ts +0 -1688
  231. package/src/subtitles.ts +0 -711
  232. package/src/target.ts +0 -204
  233. package/src/tsconfig.json +0 -16
  234. package/src/wave/riff-writer.ts +0 -36
  235. package/src/wave/wave-demuxer.ts +0 -529
  236. package/src/wave/wave-muxer.ts +0 -371
  237. package/src/writer.ts +0 -490
@@ -1,541 +0,0 @@
1
- /*!
2
- * Copyright (c) 2025-present, Vanilagy and contributors
3
- *
4
- * This Source Code Form is subject to the terms of the Mozilla Public
5
- * License, v. 2.0. If a copy of the MPL was not distributed with this
6
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
- */
8
-
9
- import { Demuxer } from './demuxer';
10
- import { Input } from './input';
11
- import { IsobmffDemuxer } from './isobmff/isobmff-demuxer';
12
- import {
13
- EBMLId,
14
- MAX_HEADER_SIZE,
15
- MIN_HEADER_SIZE,
16
- readAsciiString,
17
- readElementHeader,
18
- readElementSize,
19
- readUnsignedInt,
20
- readVarIntSize,
21
- } from './matroska/ebml';
22
- import { MatroskaDemuxer } from './matroska/matroska-demuxer';
23
- import { Mp3Demuxer } from './mp3/mp3-demuxer';
24
- import { FRAME_HEADER_SIZE } from '../shared/mp3-misc';
25
- import { ID3_V2_HEADER_SIZE, readId3V2Header } from './id3';
26
- import { readNextFrameHeader } from './mp3/mp3-reader';
27
- import { OggDemuxer } from './ogg/ogg-demuxer';
28
- import { WaveDemuxer } from './wave/wave-demuxer';
29
- import { MAX_FRAME_HEADER_SIZE, MIN_FRAME_HEADER_SIZE, readFrameHeader } from './adts/adts-reader';
30
- import { AdtsDemuxer } from './adts/adts-demuxer';
31
- import { readAscii } from './reader';
32
- import { FlacDemuxer } from './flac/flac-demuxer';
33
-
34
- /**
35
- * Base class representing an input media file format.
36
- * @group Input formats
37
- * @public
38
- */
39
- export abstract class InputFormat {
40
- /** @internal */
41
- abstract _canReadInput(input: Input): Promise<boolean>;
42
-
43
- /** @internal */
44
- abstract _createDemuxer(input: Input): Demuxer;
45
-
46
- /** Returns the name of the input format. */
47
- abstract get name(): string;
48
- /** Returns the typical base MIME type of the input format. */
49
- abstract get mimeType(): string;
50
- }
51
-
52
- /**
53
- * Format representing files compatible with the ISO base media file format (ISOBMFF), like MP4 or MOV files.
54
- * @group Input formats
55
- * @public
56
- */
57
- export abstract class IsobmffInputFormat extends InputFormat {
58
- /** @internal */
59
- protected async _getMajorBrand(input: Input) {
60
- let slice = input._reader.requestSlice(0, 12);
61
- if (slice instanceof Promise) slice = await slice;
62
- if (!slice) return null;
63
-
64
- slice.skip(4);
65
- const fourCc = readAscii(slice, 4);
66
-
67
- if (fourCc !== 'ftyp') {
68
- return null;
69
- }
70
-
71
- return readAscii(slice, 4);
72
- }
73
-
74
- /** @internal */
75
- _createDemuxer(input: Input) {
76
- return new IsobmffDemuxer(input);
77
- }
78
- }
79
-
80
- /**
81
- * MPEG-4 Part 14 (MP4) file format.
82
- *
83
- * Do not instantiate this class; use the {@link MP4} singleton instead.
84
- *
85
- * @group Input formats
86
- * @public
87
- */
88
- export class Mp4InputFormat extends IsobmffInputFormat {
89
- /** @internal */
90
- async _canReadInput(input: Input) {
91
- const majorBrand = await this._getMajorBrand(input);
92
- return !!majorBrand && majorBrand !== 'qt ';
93
- }
94
-
95
- get name() {
96
- return 'MP4';
97
- }
98
-
99
- get mimeType() {
100
- return 'video/mp4';
101
- }
102
- }
103
-
104
- /**
105
- * QuickTime File Format (QTFF), often called MOV.
106
- *
107
- * Do not instantiate this class; use the {@link QTFF} singleton instead.
108
- *
109
- * @group Input formats
110
- * @public
111
- */
112
- export class QuickTimeInputFormat extends IsobmffInputFormat {
113
- /** @internal */
114
- async _canReadInput(input: Input) {
115
- const majorBrand = await this._getMajorBrand(input);
116
- return majorBrand === 'qt ';
117
- }
118
-
119
- get name() {
120
- return 'QuickTime File Format';
121
- }
122
-
123
- get mimeType() {
124
- return 'video/quicktime';
125
- }
126
- }
127
-
128
- /**
129
- * Matroska file format.
130
- *
131
- * Do not instantiate this class; use the {@link MATROSKA} singleton instead.
132
- *
133
- * @group Input formats
134
- * @public
135
- */
136
- export class MatroskaInputFormat extends InputFormat {
137
- /** @internal */
138
- protected async isSupportedEBMLOfDocType(input: Input, desiredDocType: string) {
139
- let headerSlice = input._reader.requestSlice(0, MAX_HEADER_SIZE);
140
- if (headerSlice instanceof Promise) headerSlice = await headerSlice;
141
- if (!headerSlice) return false;
142
-
143
- const varIntSize = readVarIntSize(headerSlice);
144
- if (varIntSize === null) {
145
- return false;
146
- }
147
-
148
- if (varIntSize < 1 || varIntSize > 8) {
149
- return false;
150
- }
151
-
152
- const id = readUnsignedInt(headerSlice, varIntSize);
153
- if (id !== EBMLId.EBML) {
154
- return false;
155
- }
156
-
157
- const dataSize = readElementSize(headerSlice);
158
- if (dataSize === null) {
159
- return false; // Miss me with that shit
160
- }
161
-
162
- let dataSlice = input._reader.requestSlice(headerSlice.filePos, dataSize);
163
- if (dataSlice instanceof Promise) dataSlice = await dataSlice;
164
- if (!dataSlice) return false;
165
-
166
- const startPos = headerSlice.filePos;
167
-
168
- while (dataSlice.filePos <= startPos + dataSize - MIN_HEADER_SIZE) {
169
- const header = readElementHeader(dataSlice);
170
- if (!header) break;
171
-
172
- const { id, size } = header;
173
- const dataStartPos = dataSlice.filePos;
174
- if (size === null) return false;
175
-
176
- switch (id) {
177
- case EBMLId.EBMLVersion: {
178
- const ebmlVersion = readUnsignedInt(dataSlice, size);
179
- if (ebmlVersion !== 1) {
180
- return false;
181
- }
182
- }; break;
183
- case EBMLId.EBMLReadVersion: {
184
- const ebmlReadVersion = readUnsignedInt(dataSlice, size);
185
- if (ebmlReadVersion !== 1) {
186
- return false;
187
- }
188
- }; break;
189
- case EBMLId.DocType: {
190
- const docType = readAsciiString(dataSlice, size);
191
- if (docType !== desiredDocType) {
192
- return false;
193
- }
194
- }; break;
195
- case EBMLId.DocTypeVersion: {
196
- const docTypeVersion = readUnsignedInt(dataSlice, size);
197
- if (docTypeVersion > 4) { // Support up to Matroska v4
198
- return false;
199
- }
200
- }; break;
201
- }
202
-
203
- dataSlice.filePos = dataStartPos + size;
204
- }
205
-
206
- return true;
207
- }
208
-
209
- /** @internal */
210
- _canReadInput(input: Input) {
211
- return this.isSupportedEBMLOfDocType(input, 'matroska');
212
- }
213
-
214
- /** @internal */
215
- _createDemuxer(input: Input) {
216
- return new MatroskaDemuxer(input);
217
- }
218
-
219
- get name() {
220
- return 'Matroska';
221
- }
222
-
223
- get mimeType() {
224
- return 'video/x-matroska';
225
- }
226
- }
227
-
228
- /**
229
- * WebM file format, based on Matroska.
230
- *
231
- * Do not instantiate this class; use the {@link WEBM} singleton instead.
232
- *
233
- * @group Input formats
234
- * @public
235
- */
236
- export class WebMInputFormat extends MatroskaInputFormat {
237
- /** @internal */
238
- override _canReadInput(input: Input) {
239
- return this.isSupportedEBMLOfDocType(input, 'webm');
240
- }
241
-
242
- override get name() {
243
- return 'WebM';
244
- }
245
-
246
- override get mimeType() {
247
- return 'video/webm';
248
- }
249
- }
250
-
251
- /**
252
- * MP3 file format.
253
- *
254
- * Do not instantiate this class; use the {@link MP3} singleton instead.
255
- *
256
- * @group Input formats
257
- * @public
258
- */
259
- export class Mp3InputFormat extends InputFormat {
260
- /** @internal */
261
- async _canReadInput(input: Input) {
262
- let slice = input._reader.requestSlice(0, 10);
263
- if (slice instanceof Promise) slice = await slice;
264
- if (!slice) return false;
265
-
266
- let currentPos = 0;
267
- let id3V2HeaderFound = false;
268
-
269
- while (true) {
270
- let slice = input._reader.requestSlice(currentPos, ID3_V2_HEADER_SIZE);
271
- if (slice instanceof Promise) slice = await slice;
272
- if (!slice) break;
273
-
274
- const id3V2Header = readId3V2Header(slice);
275
- if (!id3V2Header) {
276
- break;
277
- }
278
-
279
- id3V2HeaderFound = true;
280
- currentPos = slice.filePos + id3V2Header.size;
281
- }
282
-
283
- const firstResult = await readNextFrameHeader(input._reader, currentPos, currentPos + 4096);
284
- if (!firstResult) {
285
- return false;
286
- }
287
-
288
- if (id3V2HeaderFound) {
289
- // If there was an ID3v2 tag at the start, we can be pretty sure this is MP3 by now
290
- return true;
291
- }
292
-
293
- currentPos = firstResult.startPos + firstResult.header.totalSize;
294
-
295
- // Fine, we found one frame header, but we're still not entirely sure this is MP3. Let's check if we can find
296
- // another header right after it:
297
- const secondResult = await readNextFrameHeader(input._reader, currentPos, currentPos + FRAME_HEADER_SIZE);
298
- if (!secondResult) {
299
- return false;
300
- }
301
-
302
- const firstHeader = firstResult.header;
303
- const secondHeader = secondResult.header;
304
-
305
- // In a well-formed MP3 file, we'd expect these two frames to share some similarities:
306
- if (firstHeader.channel !== secondHeader.channel || firstHeader.sampleRate !== secondHeader.sampleRate) {
307
- return false;
308
- }
309
-
310
- // We have found two matching consecutive MP3 frames, a strong indicator that this is an MP3 file
311
- return true;
312
- }
313
-
314
- /** @internal */
315
- _createDemuxer(input: Input) {
316
- return new Mp3Demuxer(input);
317
- }
318
-
319
- get name() {
320
- return 'MP3';
321
- }
322
-
323
- get mimeType() {
324
- return 'audio/mpeg';
325
- }
326
- }
327
-
328
- /**
329
- * WAVE file format, based on RIFF.
330
- *
331
- * Do not instantiate this class; use the {@link WAVE} singleton instead.
332
- *
333
- * @group Input formats
334
- * @public
335
- */
336
- export class WaveInputFormat extends InputFormat {
337
- /** @internal */
338
- async _canReadInput(input: Input) {
339
- let slice = input._reader.requestSlice(0, 12);
340
- if (slice instanceof Promise) slice = await slice;
341
- if (!slice) return false;
342
-
343
- const riffType = readAscii(slice, 4);
344
- if (riffType !== 'RIFF' && riffType !== 'RIFX' && riffType !== 'RF64') {
345
- return false;
346
- }
347
-
348
- slice.skip(4);
349
-
350
- const format = readAscii(slice, 4);
351
- return format === 'WAVE';
352
- }
353
-
354
- /** @internal */
355
- _createDemuxer(input: Input) {
356
- return new WaveDemuxer(input);
357
- }
358
-
359
- get name() {
360
- return 'WAVE';
361
- }
362
-
363
- get mimeType() {
364
- return 'audio/wav';
365
- }
366
- }
367
-
368
- /**
369
- * Ogg file format.
370
- *
371
- * Do not instantiate this class; use the {@link OGG} singleton instead.
372
- *
373
- * @group Input formats
374
- * @public
375
- */
376
- export class OggInputFormat extends InputFormat {
377
- /** @internal */
378
- async _canReadInput(input: Input) {
379
- let slice = input._reader.requestSlice(0, 4);
380
- if (slice instanceof Promise) slice = await slice;
381
- if (!slice) return false;
382
-
383
- return readAscii(slice, 4) === 'OggS';
384
- }
385
-
386
- /** @internal */
387
- _createDemuxer(input: Input) {
388
- return new OggDemuxer(input);
389
- }
390
-
391
- get name() {
392
- return 'Ogg';
393
- }
394
-
395
- get mimeType() {
396
- return 'application/ogg';
397
- }
398
- }
399
- /**
400
- * FLAC file format.
401
- *
402
- * Do not instantiate this class; use the {@link FLAC} singleton instead.
403
- *
404
- * @group Input formats
405
- * @public
406
- */
407
- export class FlacInputFormat extends InputFormat {
408
- /** @internal */
409
- async _canReadInput(input: Input) {
410
- let slice = input._reader.requestSlice(0, 4);
411
- if (slice instanceof Promise) slice = await slice;
412
- if (!slice) return false;
413
-
414
- return readAscii(slice, 4) === 'fLaC';
415
- }
416
-
417
- get name() {
418
- return 'FLAC';
419
- }
420
-
421
- get mimeType() {
422
- return 'audio/flac';
423
- }
424
-
425
- /** @internal */
426
- _createDemuxer(input: Input): Demuxer {
427
- return new FlacDemuxer(input);
428
- }
429
- }
430
-
431
- /**
432
- * ADTS file format.
433
- *
434
- * Do not instantiate this class; use the {@link ADTS} singleton instead.
435
- *
436
- * @group Input formats
437
- * @public
438
- */
439
- export class AdtsInputFormat extends InputFormat {
440
- /** @internal */
441
- async _canReadInput(input: Input) {
442
- let slice = input._reader.requestSliceRange(0, MIN_FRAME_HEADER_SIZE, MAX_FRAME_HEADER_SIZE);
443
- if (slice instanceof Promise) slice = await slice;
444
- if (!slice) return false;
445
-
446
- const firstHeader = readFrameHeader(slice);
447
- if (!firstHeader) {
448
- return false;
449
- }
450
-
451
- slice = input._reader.requestSliceRange(firstHeader.frameLength, MIN_FRAME_HEADER_SIZE, MAX_FRAME_HEADER_SIZE);
452
- if (slice instanceof Promise) slice = await slice;
453
- if (!slice) return false;
454
-
455
- const secondHeader = readFrameHeader(slice);
456
- if (!secondHeader) {
457
- return false;
458
- }
459
-
460
- return firstHeader.objectType === secondHeader.objectType
461
- && firstHeader.samplingFrequencyIndex === secondHeader.samplingFrequencyIndex
462
- && firstHeader.channelConfiguration === secondHeader.channelConfiguration;
463
- }
464
-
465
- /** @internal */
466
- _createDemuxer(input: Input) {
467
- return new AdtsDemuxer(input);
468
- }
469
-
470
- get name() {
471
- return 'ADTS';
472
- }
473
-
474
- get mimeType() {
475
- return 'audio/aac';
476
- }
477
- }
478
-
479
- /**
480
- * MP4 input format singleton.
481
- * @group Input formats
482
- * @public
483
- */
484
- export const MP4 = /* #__PURE__ */ new Mp4InputFormat();
485
- /**
486
- * QuickTime File Format input format singleton.
487
- * @group Input formats
488
- * @public
489
- */
490
- export const QTFF = /* #__PURE__ */ new QuickTimeInputFormat();
491
- /**
492
- * Matroska input format singleton.
493
- * @group Input formats
494
- * @public
495
- */
496
- export const MATROSKA = /* #__PURE__ */ new MatroskaInputFormat();
497
- /**
498
- * WebM input format singleton.
499
- * @group Input formats
500
- * @public
501
- */
502
- export const WEBM = /* #__PURE__ */ new WebMInputFormat();
503
- /**
504
- * MP3 input format singleton.
505
- * @group Input formats
506
- * @public
507
- */
508
- export const MP3 = /* #__PURE__ */ new Mp3InputFormat();
509
- /**
510
- * WAVE input format singleton.
511
- * @group Input formats
512
- * @public
513
- */
514
- export const WAVE = /* #__PURE__ */ new WaveInputFormat();
515
- /**
516
- * Ogg input format singleton.
517
- * @group Input formats
518
- * @public
519
- */
520
- export const OGG = /* #__PURE__ */ new OggInputFormat();
521
- /**
522
- * ADTS input format singleton.
523
- * @group Input formats
524
- * @public
525
- */
526
- export const ADTS = /* #__PURE__ */ new AdtsInputFormat();
527
-
528
- /**
529
- * FLAC input format singleton.
530
- * @group Input formats
531
- * @public
532
- */
533
- export const FLAC = /* #__PURE__ */ new FlacInputFormat();
534
-
535
- /**
536
- * List of all input format singletons. If you don't need to support all input formats, you should specify the
537
- * formats individually for better tree shaking.
538
- * @group Input formats
539
- * @public
540
- */
541
- export const ALL_FORMATS: InputFormat[] = [MP4, QTFF, MATROSKA, WEBM, WAVE, OGG, FLAC, MP3, ADTS];