@kenzuya/mediabunny 1.26.0 → 1.28.6

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 (238) hide show
  1. package/README.md +1 -1
  2. package/dist/bundles/{mediabunny.mjs → mediabunny.js} +21963 -21390
  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/ogg/ogg-demuxer.d.ts +7 -7
  83. package/dist/modules/src/ogg/ogg-demuxer.d.ts.map +1 -1
  84. package/dist/modules/src/ogg/ogg-misc.d.ts +1 -1
  85. package/dist/modules/src/ogg/ogg-misc.d.ts.map +1 -1
  86. package/dist/modules/src/ogg/ogg-muxer.d.ts +5 -5
  87. package/dist/modules/src/ogg/ogg-muxer.d.ts.map +1 -1
  88. package/dist/modules/src/ogg/ogg-reader.d.ts +1 -1
  89. package/dist/modules/src/ogg/ogg-reader.d.ts.map +1 -1
  90. package/dist/modules/src/output-format.d.ts +51 -6
  91. package/dist/modules/src/output-format.d.ts.map +1 -1
  92. package/dist/modules/src/output.d.ts +13 -13
  93. package/dist/modules/src/output.d.ts.map +1 -1
  94. package/dist/modules/src/packet.d.ts +1 -1
  95. package/dist/modules/src/packet.d.ts.map +1 -1
  96. package/dist/modules/src/pcm.d.ts.map +1 -1
  97. package/dist/modules/src/reader.d.ts +2 -2
  98. package/dist/modules/src/reader.d.ts.map +1 -1
  99. package/dist/modules/src/sample.d.ts +57 -15
  100. package/dist/modules/src/sample.d.ts.map +1 -1
  101. package/dist/modules/src/source.d.ts +3 -3
  102. package/dist/modules/src/source.d.ts.map +1 -1
  103. package/dist/modules/src/subtitles.d.ts +1 -1
  104. package/dist/modules/src/subtitles.d.ts.map +1 -1
  105. package/dist/modules/src/target.d.ts +2 -2
  106. package/dist/modules/src/target.d.ts.map +1 -1
  107. package/dist/modules/src/tsconfig.tsbuildinfo +1 -1
  108. package/dist/modules/src/wave/riff-writer.d.ts +1 -1
  109. package/dist/modules/src/wave/riff-writer.d.ts.map +1 -1
  110. package/dist/modules/src/wave/wave-demuxer.d.ts +6 -6
  111. package/dist/modules/src/wave/wave-demuxer.d.ts.map +1 -1
  112. package/dist/modules/src/wave/wave-muxer.d.ts +4 -4
  113. package/dist/modules/src/wave/wave-muxer.d.ts.map +1 -1
  114. package/dist/modules/src/writer.d.ts +1 -1
  115. package/dist/modules/src/writer.d.ts.map +1 -1
  116. package/dist/packages/eac3/eac3.wasm +0 -0
  117. package/dist/packages/eac3/mediabunny-eac3.js +1058 -0
  118. package/dist/packages/eac3/mediabunny-eac3.min.js +44 -0
  119. package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.js +694 -0
  120. package/dist/packages/mp3-encoder/mediabunny-mp3-encoder.min.js +58 -0
  121. package/dist/packages/mpeg4/mediabunny-mpeg4.js +1198 -0
  122. package/dist/packages/mpeg4/mediabunny-mpeg4.min.js +44 -0
  123. package/dist/packages/mpeg4/xvid.wasm +0 -0
  124. package/package.json +18 -57
  125. package/dist/bundles/mediabunny.cjs +0 -26140
  126. package/dist/bundles/mediabunny.min.cjs +0 -147
  127. package/dist/bundles/mediabunny.min.mjs +0 -146
  128. package/dist/mediabunny.d.ts +0 -3319
  129. package/dist/modules/shared/mp3-misc.js +0 -147
  130. package/dist/modules/src/adts/adts-demuxer.js +0 -239
  131. package/dist/modules/src/adts/adts-muxer.js +0 -80
  132. package/dist/modules/src/adts/adts-reader.js +0 -63
  133. package/dist/modules/src/codec-data.js +0 -1730
  134. package/dist/modules/src/codec.js +0 -869
  135. package/dist/modules/src/conversion.js +0 -1459
  136. package/dist/modules/src/custom-coder.js +0 -117
  137. package/dist/modules/src/demuxer.js +0 -12
  138. package/dist/modules/src/encode.js +0 -442
  139. package/dist/modules/src/flac/flac-demuxer.js +0 -504
  140. package/dist/modules/src/flac/flac-misc.js +0 -135
  141. package/dist/modules/src/flac/flac-muxer.js +0 -222
  142. package/dist/modules/src/id3.js +0 -848
  143. package/dist/modules/src/index.js +0 -28
  144. package/dist/modules/src/input-format.js +0 -480
  145. package/dist/modules/src/input-track.js +0 -372
  146. package/dist/modules/src/input.js +0 -188
  147. package/dist/modules/src/isobmff/isobmff-boxes.js +0 -1480
  148. package/dist/modules/src/isobmff/isobmff-demuxer.js +0 -2618
  149. package/dist/modules/src/isobmff/isobmff-misc.js +0 -20
  150. package/dist/modules/src/isobmff/isobmff-muxer.js +0 -966
  151. package/dist/modules/src/isobmff/isobmff-reader.js +0 -72
  152. package/dist/modules/src/matroska/ebml.js +0 -653
  153. package/dist/modules/src/matroska/matroska-demuxer.js +0 -2133
  154. package/dist/modules/src/matroska/matroska-misc.js +0 -20
  155. package/dist/modules/src/matroska/matroska-muxer.js +0 -1017
  156. package/dist/modules/src/media-sink.js +0 -1736
  157. package/dist/modules/src/media-source.js +0 -1825
  158. package/dist/modules/src/metadata.js +0 -193
  159. package/dist/modules/src/misc.js +0 -623
  160. package/dist/modules/src/mp3/mp3-demuxer.js +0 -285
  161. package/dist/modules/src/mp3/mp3-muxer.js +0 -123
  162. package/dist/modules/src/mp3/mp3-reader.js +0 -26
  163. package/dist/modules/src/mp3/mp3-writer.js +0 -78
  164. package/dist/modules/src/muxer.js +0 -50
  165. package/dist/modules/src/node.d.ts +0 -9
  166. package/dist/modules/src/node.d.ts.map +0 -1
  167. package/dist/modules/src/node.js +0 -9
  168. package/dist/modules/src/ogg/ogg-demuxer.js +0 -763
  169. package/dist/modules/src/ogg/ogg-misc.js +0 -78
  170. package/dist/modules/src/ogg/ogg-muxer.js +0 -353
  171. package/dist/modules/src/ogg/ogg-reader.js +0 -65
  172. package/dist/modules/src/output-format.js +0 -527
  173. package/dist/modules/src/output.js +0 -300
  174. package/dist/modules/src/packet.js +0 -182
  175. package/dist/modules/src/pcm.js +0 -85
  176. package/dist/modules/src/reader.js +0 -236
  177. package/dist/modules/src/sample.js +0 -1056
  178. package/dist/modules/src/source.js +0 -1182
  179. package/dist/modules/src/subtitles.js +0 -575
  180. package/dist/modules/src/target.js +0 -140
  181. package/dist/modules/src/wave/riff-writer.js +0 -30
  182. package/dist/modules/src/wave/wave-demuxer.js +0 -447
  183. package/dist/modules/src/wave/wave-muxer.js +0 -318
  184. package/dist/modules/src/writer.js +0 -370
  185. package/src/adts/adts-demuxer.ts +0 -331
  186. package/src/adts/adts-muxer.ts +0 -111
  187. package/src/adts/adts-reader.ts +0 -85
  188. package/src/codec-data.ts +0 -2078
  189. package/src/codec.ts +0 -1092
  190. package/src/conversion.ts +0 -2112
  191. package/src/custom-coder.ts +0 -197
  192. package/src/demuxer.ts +0 -24
  193. package/src/encode.ts +0 -739
  194. package/src/flac/flac-demuxer.ts +0 -730
  195. package/src/flac/flac-misc.ts +0 -164
  196. package/src/flac/flac-muxer.ts +0 -320
  197. package/src/id3.ts +0 -925
  198. package/src/index.ts +0 -221
  199. package/src/input-format.ts +0 -541
  200. package/src/input-track.ts +0 -529
  201. package/src/input.ts +0 -235
  202. package/src/isobmff/isobmff-boxes.ts +0 -1719
  203. package/src/isobmff/isobmff-demuxer.ts +0 -3190
  204. package/src/isobmff/isobmff-misc.ts +0 -29
  205. package/src/isobmff/isobmff-muxer.ts +0 -1348
  206. package/src/isobmff/isobmff-reader.ts +0 -91
  207. package/src/matroska/ebml.ts +0 -730
  208. package/src/matroska/matroska-demuxer.ts +0 -2481
  209. package/src/matroska/matroska-misc.ts +0 -29
  210. package/src/matroska/matroska-muxer.ts +0 -1276
  211. package/src/media-sink.ts +0 -2179
  212. package/src/media-source.ts +0 -2243
  213. package/src/metadata.ts +0 -320
  214. package/src/misc.ts +0 -798
  215. package/src/mp3/mp3-demuxer.ts +0 -383
  216. package/src/mp3/mp3-muxer.ts +0 -166
  217. package/src/mp3/mp3-reader.ts +0 -34
  218. package/src/mp3/mp3-writer.ts +0 -120
  219. package/src/muxer.ts +0 -88
  220. package/src/node.ts +0 -11
  221. package/src/ogg/ogg-demuxer.ts +0 -1053
  222. package/src/ogg/ogg-misc.ts +0 -116
  223. package/src/ogg/ogg-muxer.ts +0 -497
  224. package/src/ogg/ogg-reader.ts +0 -93
  225. package/src/output-format.ts +0 -945
  226. package/src/output.ts +0 -488
  227. package/src/packet.ts +0 -263
  228. package/src/pcm.ts +0 -112
  229. package/src/reader.ts +0 -323
  230. package/src/sample.ts +0 -1461
  231. package/src/source.ts +0 -1688
  232. package/src/subtitles.ts +0 -711
  233. package/src/target.ts +0 -204
  234. package/src/tsconfig.json +0 -16
  235. package/src/wave/riff-writer.ts +0 -36
  236. package/src/wave/wave-demuxer.ts +0 -529
  237. package/src/wave/wave-muxer.ts +0 -371
  238. package/src/writer.ts +0 -490
@@ -1,529 +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 { AudioCodec, MediaCodec, SubtitleCodec, VideoCodec } from './codec';
10
- import { determineVideoPacketType } from './codec-data';
11
- import { customAudioDecoders, customVideoDecoders } from './custom-coder';
12
- import { Input } from './input';
13
- import { EncodedPacketSink, PacketRetrievalOptions } from './media-sink';
14
- import { assert, Rotation } from './misc';
15
- import { TrackType } from './output';
16
- import { EncodedPacket, PacketType } from './packet';
17
- import { TrackDisposition } from './metadata';
18
- import { SubtitleCue } from './subtitles';
19
-
20
- /**
21
- * Contains aggregate statistics about the encoded packets of a track.
22
- * @group Input files & tracks
23
- * @public
24
- */
25
- export type PacketStats = {
26
- /** The total number of packets. */
27
- packetCount: number;
28
- /** The average number of packets per second. For video tracks, this will equal the average frame rate (FPS). */
29
- averagePacketRate: number;
30
- /** The average number of bits per second. */
31
- averageBitrate: number;
32
- };
33
-
34
- export interface InputTrackBacking {
35
- getId(): number;
36
- getCodec(): MediaCodec | null;
37
- getInternalCodecId(): string | number | Uint8Array | null;
38
- getName(): string | null;
39
- getLanguageCode(): string;
40
- getTimeResolution(): number;
41
- getDisposition(): TrackDisposition;
42
- getFirstTimestamp(): Promise<number>;
43
- computeDuration(): Promise<number>;
44
-
45
- getFirstPacket(options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
46
- getPacket(timestamp: number, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
47
- getNextPacket(packet: EncodedPacket, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
48
- getKeyPacket(timestamp: number, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
49
- getNextKeyPacket(packet: EncodedPacket, options: PacketRetrievalOptions): Promise<EncodedPacket | null>;
50
- }
51
-
52
- /**
53
- * Represents a media track in an input file.
54
- * @group Input files & tracks
55
- * @public
56
- */
57
- export abstract class InputTrack {
58
- /** The input file this track belongs to. */
59
- readonly input: Input;
60
- /** @internal */
61
- _backing: InputTrackBacking;
62
-
63
- /** @internal */
64
- constructor(input: Input, backing: InputTrackBacking) {
65
- this.input = input;
66
- this._backing = backing;
67
- }
68
-
69
- /** The type of the track. */
70
- abstract get type(): TrackType;
71
- /** The codec of the track's packets. */
72
- abstract get codec(): MediaCodec | null;
73
- /** Returns the full codec parameter string for this track. */
74
- abstract getCodecParameterString(): Promise<string | null>;
75
- /** Checks if this track's packets can be decoded by the browser. */
76
- abstract canDecode(): Promise<boolean>;
77
- /**
78
- * For a given packet of this track, this method determines the actual type of this packet (key/delta) by looking
79
- * into its bitstream. Returns null if the type couldn't be determined.
80
- */
81
- abstract determinePacketType(packet: EncodedPacket): Promise<PacketType | null>;
82
-
83
- /** Returns true if and only if this track is a video track. */
84
- isVideoTrack(): this is InputVideoTrack {
85
- return this instanceof InputVideoTrack;
86
- }
87
-
88
- /** Returns true if and only if this track is an audio track. */
89
- isAudioTrack(): this is InputAudioTrack {
90
- return this instanceof InputAudioTrack;
91
- }
92
-
93
- /** Returns true if and only if this track is a subtitle track. */
94
- isSubtitleTrack(): this is InputSubtitleTrack {
95
- return this instanceof InputSubtitleTrack;
96
- }
97
-
98
- /** The unique ID of this track in the input file. */
99
- get id() {
100
- return this._backing.getId();
101
- }
102
-
103
- /**
104
- * The identifier of the codec used internally by the container. It is not homogenized by Mediabunny
105
- * and depends entirely on the container format.
106
- *
107
- * This field can be used to determine the codec of a track in case Mediabunny doesn't know that codec.
108
- *
109
- * - For ISOBMFF files, this field returns the name of the Sample Description Box (e.g. `'avc1'`).
110
- * - For Matroska files, this field returns the value of the `CodecID` element.
111
- * - For WAVE files, this field returns the value of the format tag in the `'fmt '` chunk.
112
- * - For ADTS files, this field contains the `MPEG-4 Audio Object Type`.
113
- * - In all other cases, this field is `null`.
114
- */
115
- get internalCodecId() {
116
- return this._backing.getInternalCodecId();
117
- }
118
-
119
- /**
120
- * The ISO 639-2/T language code for this track. If the language is unknown, this field is `'und'` (undetermined).
121
- */
122
- get languageCode() {
123
- return this._backing.getLanguageCode();
124
- }
125
-
126
- /** A user-defined name for this track. */
127
- get name() {
128
- return this._backing.getName();
129
- }
130
-
131
- /**
132
- * A positive number x such that all timestamps and durations of all packets of this track are
133
- * integer multiples of 1/x.
134
- */
135
- get timeResolution() {
136
- return this._backing.getTimeResolution();
137
- }
138
-
139
- /** The track's disposition, i.e. information about its intended usage. */
140
- get disposition() {
141
- return this._backing.getDisposition();
142
- }
143
-
144
- /**
145
- * Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value
146
- * may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples
147
- * with a negative timestamp should not be presented.
148
- */
149
- getFirstTimestamp() {
150
- return this._backing.getFirstTimestamp();
151
- }
152
-
153
- /** Returns the end timestamp of the last packet of this track, in seconds. */
154
- computeDuration() {
155
- return this._backing.computeDuration();
156
- }
157
-
158
- /**
159
- * Computes aggregate packet statistics for this track, such as average packet rate or bitrate.
160
- *
161
- * @param targetPacketCount - This optional parameter sets a target for how many packets this method must have
162
- * looked at before it can return early; this means, you can use it to aggregate only a subset (prefix) of all
163
- * packets. This is very useful for getting a great estimate of video frame rate without having to scan through the
164
- * entire file.
165
- */
166
- async computePacketStats(targetPacketCount = Infinity): Promise<PacketStats> {
167
- const sink = new EncodedPacketSink(this);
168
-
169
- let startTimestamp = Infinity;
170
- let endTimestamp = -Infinity;
171
- let packetCount = 0;
172
- let totalPacketBytes = 0;
173
-
174
- for await (const packet of sink.packets(undefined, undefined, { metadataOnly: true })) {
175
- if (
176
- packetCount >= targetPacketCount
177
- // This additional condition is needed to produce correct results with out-of-presentation-order packets
178
- && packet.timestamp >= endTimestamp
179
- ) {
180
- break;
181
- }
182
-
183
- startTimestamp = Math.min(startTimestamp, packet.timestamp);
184
- endTimestamp = Math.max(endTimestamp, packet.timestamp + packet.duration);
185
-
186
- packetCount++;
187
- totalPacketBytes += packet.byteLength;
188
- }
189
-
190
- return {
191
- packetCount,
192
- averagePacketRate: packetCount
193
- ? Number((packetCount / (endTimestamp - startTimestamp)).toPrecision(16))
194
- : 0,
195
- averageBitrate: packetCount
196
- ? Number((8 * totalPacketBytes / (endTimestamp - startTimestamp)).toPrecision(16))
197
- : 0,
198
- };
199
- }
200
- }
201
-
202
- export interface InputVideoTrackBacking extends InputTrackBacking {
203
- getCodec(): VideoCodec | null;
204
- getCodedWidth(): number;
205
- getCodedHeight(): number;
206
- getRotation(): Rotation;
207
- getColorSpace(): Promise<VideoColorSpaceInit>;
208
- canBeTransparent(): Promise<boolean>;
209
- getDecoderConfig(): Promise<VideoDecoderConfig | null>;
210
- }
211
-
212
- /**
213
- * Represents a video track in an input file.
214
- * @group Input files & tracks
215
- * @public
216
- */
217
- export class InputVideoTrack extends InputTrack {
218
- /** @internal */
219
- override _backing: InputVideoTrackBacking;
220
-
221
- /** @internal */
222
- constructor(input: Input, backing: InputVideoTrackBacking) {
223
- super(input, backing);
224
-
225
- this._backing = backing;
226
- }
227
-
228
- get type(): TrackType {
229
- return 'video';
230
- }
231
-
232
- get codec(): VideoCodec | null {
233
- return this._backing.getCodec();
234
- }
235
-
236
- /** The width in pixels of the track's coded samples, before any transformations or rotations. */
237
- get codedWidth() {
238
- return this._backing.getCodedWidth();
239
- }
240
-
241
- /** The height in pixels of the track's coded samples, before any transformations or rotations. */
242
- get codedHeight() {
243
- return this._backing.getCodedHeight();
244
- }
245
-
246
- /** The angle in degrees by which the track's frames should be rotated (clockwise). */
247
- get rotation() {
248
- return this._backing.getRotation();
249
- }
250
-
251
- /** The width in pixels of the track's frames after rotation. */
252
- get displayWidth() {
253
- const rotation = this._backing.getRotation();
254
- return rotation % 180 === 0 ? this._backing.getCodedWidth() : this._backing.getCodedHeight();
255
- }
256
-
257
- /** The height in pixels of the track's frames after rotation. */
258
- get displayHeight() {
259
- const rotation = this._backing.getRotation();
260
- return rotation % 180 === 0 ? this._backing.getCodedHeight() : this._backing.getCodedWidth();
261
- }
262
-
263
- /** Returns the color space of the track's samples. */
264
- getColorSpace() {
265
- return this._backing.getColorSpace();
266
- }
267
-
268
- /** If this method returns true, the track's samples use a high dynamic range (HDR). */
269
- async hasHighDynamicRange() {
270
- const colorSpace = await this._backing.getColorSpace();
271
-
272
- return (colorSpace.primaries as string) === 'bt2020' || (colorSpace.primaries as string) === 'smpte432'
273
- || (colorSpace.transfer as string) === 'pg' || (colorSpace.transfer as string) === 'hlg'
274
- || (colorSpace.matrix as string) === 'bt2020-ncl';
275
- }
276
-
277
- /** Checks if this track may contain transparent samples with alpha data. */
278
- canBeTransparent() {
279
- return this._backing.canBeTransparent();
280
- }
281
-
282
- /**
283
- * Returns the [decoder configuration](https://www.w3.org/TR/webcodecs/#video-decoder-config) for decoding the
284
- * track's packets using a [`VideoDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/VideoDecoder). Returns
285
- * null if the track's codec is unknown.
286
- */
287
- getDecoderConfig() {
288
- return this._backing.getDecoderConfig();
289
- }
290
-
291
- async getCodecParameterString() {
292
- const decoderConfig = await this._backing.getDecoderConfig();
293
- return decoderConfig?.codec ?? null;
294
- }
295
-
296
- async canDecode() {
297
- try {
298
- const decoderConfig = await this._backing.getDecoderConfig();
299
- if (!decoderConfig) {
300
- return false;
301
- }
302
-
303
- const codec = this._backing.getCodec();
304
- assert(codec !== null);
305
-
306
- if (customVideoDecoders.some(x => x.supports(codec, decoderConfig))) {
307
- return true;
308
- }
309
-
310
- if (typeof VideoDecoder === 'undefined') {
311
- return false;
312
- }
313
-
314
- const support = await VideoDecoder.isConfigSupported(decoderConfig);
315
- return support.supported === true;
316
- } catch (error) {
317
- console.error('Error during decodability check:', error);
318
- return false;
319
- }
320
- }
321
-
322
- async determinePacketType(packet: EncodedPacket): Promise<PacketType | null> {
323
- if (!(packet instanceof EncodedPacket)) {
324
- throw new TypeError('packet must be an EncodedPacket.');
325
- }
326
- if (packet.isMetadataOnly) {
327
- throw new TypeError('packet must not be metadata-only to determine its type.');
328
- }
329
-
330
- if (this.codec === null) {
331
- return null;
332
- }
333
-
334
- const decoderConfig = await this.getDecoderConfig();
335
- assert(decoderConfig);
336
-
337
- return determineVideoPacketType(this.codec, decoderConfig, packet.data);
338
- }
339
- }
340
-
341
- export interface InputAudioTrackBacking extends InputTrackBacking {
342
- getCodec(): AudioCodec | null;
343
- getNumberOfChannels(): number;
344
- getSampleRate(): number;
345
- getDecoderConfig(): Promise<AudioDecoderConfig | null>;
346
- }
347
-
348
- /**
349
- * Represents an audio track in an input file.
350
- * @group Input files & tracks
351
- * @public
352
- */
353
- export class InputAudioTrack extends InputTrack {
354
- /** @internal */
355
- override _backing: InputAudioTrackBacking;
356
-
357
- /** @internal */
358
- constructor(input: Input, backing: InputAudioTrackBacking) {
359
- super(input, backing);
360
-
361
- this._backing = backing;
362
- }
363
-
364
- get type(): TrackType {
365
- return 'audio';
366
- }
367
-
368
- get codec(): AudioCodec | null {
369
- return this._backing.getCodec();
370
- }
371
-
372
- /** The number of audio channels in the track. */
373
- get numberOfChannels() {
374
- return this._backing.getNumberOfChannels();
375
- }
376
-
377
- /** The track's audio sample rate in hertz. */
378
- get sampleRate() {
379
- return this._backing.getSampleRate();
380
- }
381
-
382
- /**
383
- * Returns the [decoder configuration](https://www.w3.org/TR/webcodecs/#audio-decoder-config) for decoding the
384
- * track's packets using an [`AudioDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/AudioDecoder). Returns
385
- * null if the track's codec is unknown.
386
- */
387
- getDecoderConfig() {
388
- return this._backing.getDecoderConfig();
389
- }
390
-
391
- async getCodecParameterString() {
392
- const decoderConfig = await this._backing.getDecoderConfig();
393
- return decoderConfig?.codec ?? null;
394
- }
395
-
396
- async canDecode() {
397
- try {
398
- const decoderConfig = await this._backing.getDecoderConfig();
399
- if (!decoderConfig) {
400
- return false;
401
- }
402
-
403
- const codec = this._backing.getCodec();
404
- assert(codec !== null);
405
-
406
- if (customAudioDecoders.some(x => x.supports(codec, decoderConfig))) {
407
- return true;
408
- }
409
-
410
- if (decoderConfig.codec.startsWith('pcm-')) {
411
- return true; // Since we decode it ourselves
412
- } else {
413
- if (typeof AudioDecoder === 'undefined') {
414
- return false;
415
- }
416
-
417
- const support = await AudioDecoder.isConfigSupported(decoderConfig);
418
- return support.supported === true;
419
- }
420
- } catch (error) {
421
- console.error('Error during decodability check:', error);
422
- return false;
423
- }
424
- }
425
-
426
- async determinePacketType(packet: EncodedPacket): Promise<PacketType | null> {
427
- if (!(packet instanceof EncodedPacket)) {
428
- throw new TypeError('packet must be an EncodedPacket.');
429
- }
430
-
431
- if (this.codec === null) {
432
- return null;
433
- }
434
-
435
- return 'key'; // No audio codec with delta packets
436
- }
437
- }
438
-
439
- export interface InputSubtitleTrackBacking extends InputTrackBacking {
440
- getCodec(): SubtitleCodec | null;
441
- getCodecPrivate(): string | null;
442
- getCues(): AsyncGenerator<SubtitleCue>;
443
- }
444
-
445
- /**
446
- * Represents a subtitle track in an input file.
447
- * @group Input files & tracks
448
- * @public
449
- */
450
- export class InputSubtitleTrack extends InputTrack {
451
- /** @internal */
452
- override _backing: InputSubtitleTrackBacking;
453
-
454
- /** @internal */
455
- constructor(input: Input, backing: InputSubtitleTrackBacking) {
456
- super(input, backing);
457
-
458
- this._backing = backing;
459
- }
460
-
461
- get type(): TrackType {
462
- return 'subtitle';
463
- }
464
-
465
- get codec(): SubtitleCodec | null {
466
- return this._backing.getCodec();
467
- }
468
-
469
- /**
470
- * Returns an async iterator that yields all subtitle cues in this track.
471
- */
472
- getCues(): AsyncGenerator<SubtitleCue> {
473
- return this._backing.getCues();
474
- }
475
-
476
- /**
477
- * Exports all subtitle cues to text format. If targetFormat is specified,
478
- * attempts to convert to that format (limited conversion support).
479
- */
480
- async exportToText(targetFormat?: SubtitleCodec): Promise<string> {
481
- const cues: SubtitleCue[] = [];
482
- for await (const cue of this.getCues()) {
483
- cues.push(cue);
484
- }
485
-
486
- const codec = targetFormat || this.codec;
487
- const codecPrivate = this._backing.getCodecPrivate();
488
-
489
- if (codec === 'srt') {
490
- const { formatCuesToSrt } = await import('./subtitles');
491
- return formatCuesToSrt(cues);
492
- } else if (codec === 'ass' || codec === 'ssa') {
493
- const { formatCuesToAss, splitAssIntoCues } = await import('./subtitles');
494
-
495
- // For ASS, we need to merge Comment lines from CodecPrivate with Dialogue lines from blocks
496
- // CodecPrivate contains: header + Comment lines
497
- // Blocks contain: Dialogue lines (without timestamps)
498
- // We need to reconstruct full ASS file
499
-
500
- // Parse CodecPrivate to extract the header with Comments preserved
501
- const parsed = codecPrivate ? splitAssIntoCues(codecPrivate) : { header: '', cues: [] };
502
-
503
- // Use the header (includes Comment lines) and add our cues (from blocks)
504
- return formatCuesToAss(cues, parsed.header);
505
- } else if (codec === 'webvtt') {
506
- const { formatCuesToWebVTT } = await import('./subtitles');
507
- // Use codecPrivate as preamble if available
508
- return formatCuesToWebVTT(cues, codecPrivate || undefined);
509
- } else {
510
- // Fallback to SRT for unknown formats
511
- const { formatCuesToSrt } = await import('./subtitles');
512
- return formatCuesToSrt(cues);
513
- }
514
- }
515
-
516
- async getCodecParameterString(): Promise<string | null> {
517
- return this.codec;
518
- }
519
-
520
- async canDecode(): Promise<boolean> {
521
- // Subtitles are always text-based and can be decoded
522
- return this.codec !== null;
523
- }
524
-
525
- async determinePacketType(packet: EncodedPacket): Promise<PacketType | null> {
526
- // Subtitle packets are always key packets
527
- return 'key';
528
- }
529
- }