@revizly/node-av 5.2.2-beta.1

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 (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,251 @@
1
+ import type { IRational } from './types.js';
2
+ /**
3
+ * Rational number type for precise fractional representations.
4
+ *
5
+ * Represents a rational number as a fraction (numerator/denominator).
6
+ * Used throughout FFmpeg for time bases, aspect ratios, frame rates,
7
+ * and other fractional values that require exact precision.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Rational } from 'node-av';
12
+ *
13
+ * // Common time bases
14
+ * const timebase = new Rational(1, 90000); // 90kHz for MPEG-TS
15
+ * const videoTimebase = new Rational(1, 25); // 25 fps
16
+ * const audioTimebase = new Rational(1, 48000); // 48kHz audio
17
+ *
18
+ * // Frame rates
19
+ * const framerate = new Rational(30, 1); // 30 fps
20
+ * const ntscFramerate = new Rational(30000, 1001); // 29.97 fps NTSC
21
+ * const palFramerate = new Rational(25, 1); // 25 fps PAL
22
+ *
23
+ * // Aspect ratios
24
+ * const aspectRatio = new Rational(16, 9); // 16:9
25
+ * const pixelAspect = new Rational(1, 1); // Square pixels
26
+ *
27
+ * // Arithmetic operations
28
+ * const doubled = timebase.mul(new Rational(2, 1));
29
+ * const inverted = framerate.inv(); // Get frame duration
30
+ * const sum = framerate.add(new Rational(5, 1)); // Add 5 fps
31
+ * ```
32
+ */
33
+ export declare class Rational {
34
+ readonly num: number;
35
+ readonly den: number;
36
+ /**
37
+ * Create a new rational number.
38
+ *
39
+ * Represents the fraction num/den.
40
+ *
41
+ * @param num - Numerator of the fraction
42
+ *
43
+ * @param den - Denominator of the fraction (must not be 0)
44
+ *
45
+ * @throws {Error} If denominator is 0
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { Rational } from 'node-av';
50
+ *
51
+ * // Create time base for 25 fps video
52
+ * const timebase = new Rational(1, 25);
53
+ *
54
+ * // Create NTSC frame rate (29.97 fps)
55
+ * const ntsc = new Rational(30000, 1001);
56
+ *
57
+ * // Will throw error
58
+ * try {
59
+ * const invalid = new Rational(1, 0);
60
+ * } catch (error) {
61
+ * console.error('Cannot have zero denominator');
62
+ * }
63
+ * ```
64
+ */
65
+ constructor(num: number, den: number);
66
+ /**
67
+ * Create a Rational from an IRational object.
68
+ *
69
+ * @param rational - The IRational object with num and den properties
70
+ *
71
+ * @returns A new Rational instance
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { Rational } from 'node-av';
76
+ *
77
+ * const obj = { num: 3, den: 4 };
78
+ * const rational = Rational.fromObject(obj);
79
+ * console.log(rational.toString()); // "3/4"
80
+ * ```
81
+ */
82
+ static fromObject(rational: IRational): Rational;
83
+ /**
84
+ * Add two rational numbers.
85
+ *
86
+ * Performs addition: (a/b) + (c/d) = (ad + bc) / bd
87
+ *
88
+ * @param other - The rational number to add
89
+ *
90
+ * @returns A new Rational representing the sum
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const a = new Rational(1, 2); // 1/2
95
+ * const b = new Rational(1, 3); // 1/3
96
+ * const sum = a.add(b); // 5/6
97
+ * console.log(sum.toString()); // "5/6"
98
+ * ```
99
+ */
100
+ add(other: Rational): Rational;
101
+ /**
102
+ * Subtract two rational numbers.
103
+ *
104
+ * Performs subtraction: (a/b) - (c/d) = (ad - bc) / bd
105
+ *
106
+ * @param other - The rational number to subtract
107
+ *
108
+ * @returns A new Rational representing the difference
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const a = new Rational(3, 4); // 3/4
113
+ * const b = new Rational(1, 4); // 1/4
114
+ * const diff = a.sub(b); // 2/4 = 1/2
115
+ * console.log(diff.toString()); // "2/4"
116
+ * ```
117
+ */
118
+ sub(other: Rational): Rational;
119
+ /**
120
+ * Multiply two rational numbers.
121
+ *
122
+ * Performs multiplication: (a/b) × (c/d) = (ac) / (bd)
123
+ *
124
+ * @param other - The rational number to multiply by
125
+ *
126
+ * @returns A new Rational representing the product
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const framerate = new Rational(30, 1); // 30 fps
131
+ * const duration = new Rational(5, 1); // 5 seconds
132
+ * const frames = framerate.mul(duration); // 150/1 = 150 frames
133
+ * console.log(frames.toDouble()); // 150
134
+ * ```
135
+ */
136
+ mul(other: Rational): Rational;
137
+ /**
138
+ * Divide two rational numbers.
139
+ *
140
+ * Performs division: (a/b) ÷ (c/d) = (ad) / (bc)
141
+ *
142
+ * @param other - The rational number to divide by
143
+ *
144
+ * @returns A new Rational representing the quotient
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const pixels = new Rational(1920, 1); // 1920 pixels width
149
+ * const aspect = new Rational(16, 9); // 16:9 aspect ratio
150
+ * const height = pixels.div(aspect); // Calculate height
151
+ * console.log(height.toDouble()); // 1080
152
+ * ```
153
+ */
154
+ div(other: Rational): Rational;
155
+ /**
156
+ * Check if this rational is valid (both num and den are positive).
157
+ *
158
+ * FFmpeg uses { 0, 0 } as "undefined" and { num, 0 } as infinity.
159
+ * This method returns true only if both values are positive.
160
+ *
161
+ * @returns true if num > 0 and den > 0
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const valid = new Rational(25, 1);
166
+ * console.log(valid.isValid()); // true
167
+ *
168
+ * const undefined = new Rational(0, 0);
169
+ * console.log(undefined.isValid()); // false
170
+ *
171
+ * const infinity = new Rational(1, 0);
172
+ * console.log(infinity.isValid()); // false
173
+ * ```
174
+ */
175
+ isValid(): boolean;
176
+ /**
177
+ * Invert the rational number (reciprocal).
178
+ *
179
+ * Returns the reciprocal: 1/(a/b) = b/a
180
+ *
181
+ * @returns A new Rational representing the reciprocal
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const framerate = new Rational(25, 1); // 25 fps
186
+ * const frameDuration = framerate.inv(); // 1/25 seconds per frame
187
+ * console.log(frameDuration.toString()); // "1/25"
188
+ * console.log(frameDuration.toDouble()); // 0.04 seconds
189
+ * ```
190
+ */
191
+ inv(): Rational;
192
+ /**
193
+ * Convert rational to floating point number.
194
+ *
195
+ * Calculates the decimal value: num / den
196
+ * Note: This may lose precision for some rational values.
197
+ *
198
+ * @returns The floating point representation (Infinity if den = 0, NaN if both = 0)
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const ntsc = new Rational(30000, 1001); // NTSC frame rate
203
+ * console.log(ntsc.toDouble()); // 29.97002997...
204
+ *
205
+ * const half = new Rational(1, 2);
206
+ * console.log(half.toDouble()); // 0.5
207
+ *
208
+ * const infinity = new Rational(1, 0);
209
+ * console.log(infinity.toDouble()); // Infinity
210
+ * ```
211
+ */
212
+ toDouble(): number;
213
+ /**
214
+ * Check if this rational equals another.
215
+ *
216
+ * Compares using cross-multiplication to avoid floating point errors.
217
+ * Two rationals a/b and c/d are equal if ad = bc.
218
+ *
219
+ * @param other - The rational to compare with
220
+ *
221
+ * @returns true if the rationals are equal, false otherwise
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const a = new Rational(2, 4);
226
+ * const b = new Rational(1, 2);
227
+ * const c = new Rational(3, 4);
228
+ *
229
+ * console.log(a.equals(b)); // true (both are 1/2)
230
+ * console.log(a.equals(c)); // false
231
+ * ```
232
+ */
233
+ equals(other: Rational): boolean;
234
+ /**
235
+ * Get string representation of the rational.
236
+ *
237
+ * Returns the rational in "num/den" format.
238
+ *
239
+ * @returns String representation as "numerator/denominator"
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const framerate = new Rational(30000, 1001);
244
+ * console.log(framerate.toString()); // "30000/1001"
245
+ *
246
+ * const timebase = new Rational(1, 90000);
247
+ * console.log(`Timebase: ${timebase}`); // "Timebase: 1/90000"
248
+ * ```
249
+ */
250
+ toString(): string;
251
+ }
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Rational number type for precise fractional representations.
3
+ *
4
+ * Represents a rational number as a fraction (numerator/denominator).
5
+ * Used throughout FFmpeg for time bases, aspect ratios, frame rates,
6
+ * and other fractional values that require exact precision.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Rational } from 'node-av';
11
+ *
12
+ * // Common time bases
13
+ * const timebase = new Rational(1, 90000); // 90kHz for MPEG-TS
14
+ * const videoTimebase = new Rational(1, 25); // 25 fps
15
+ * const audioTimebase = new Rational(1, 48000); // 48kHz audio
16
+ *
17
+ * // Frame rates
18
+ * const framerate = new Rational(30, 1); // 30 fps
19
+ * const ntscFramerate = new Rational(30000, 1001); // 29.97 fps NTSC
20
+ * const palFramerate = new Rational(25, 1); // 25 fps PAL
21
+ *
22
+ * // Aspect ratios
23
+ * const aspectRatio = new Rational(16, 9); // 16:9
24
+ * const pixelAspect = new Rational(1, 1); // Square pixels
25
+ *
26
+ * // Arithmetic operations
27
+ * const doubled = timebase.mul(new Rational(2, 1));
28
+ * const inverted = framerate.inv(); // Get frame duration
29
+ * const sum = framerate.add(new Rational(5, 1)); // Add 5 fps
30
+ * ```
31
+ */
32
+ export class Rational {
33
+ num;
34
+ den;
35
+ /**
36
+ * Create a new rational number.
37
+ *
38
+ * Represents the fraction num/den.
39
+ *
40
+ * @param num - Numerator of the fraction
41
+ *
42
+ * @param den - Denominator of the fraction (must not be 0)
43
+ *
44
+ * @throws {Error} If denominator is 0
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * import { Rational } from 'node-av';
49
+ *
50
+ * // Create time base for 25 fps video
51
+ * const timebase = new Rational(1, 25);
52
+ *
53
+ * // Create NTSC frame rate (29.97 fps)
54
+ * const ntsc = new Rational(30000, 1001);
55
+ *
56
+ * // Will throw error
57
+ * try {
58
+ * const invalid = new Rational(1, 0);
59
+ * } catch (error) {
60
+ * console.error('Cannot have zero denominator');
61
+ * }
62
+ * ```
63
+ */
64
+ constructor(num, den) {
65
+ this.num = num;
66
+ this.den = den;
67
+ // Note: FFmpeg allows den = 0 as a special value:
68
+ // - { 0, 0 } = undefined/not set
69
+ // - { num, 0 } = infinity
70
+ // We allow it for FFmpeg compatibility, but operations may fail.
71
+ }
72
+ /**
73
+ * Create a Rational from an IRational object.
74
+ *
75
+ * @param rational - The IRational object with num and den properties
76
+ *
77
+ * @returns A new Rational instance
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { Rational } from 'node-av';
82
+ *
83
+ * const obj = { num: 3, den: 4 };
84
+ * const rational = Rational.fromObject(obj);
85
+ * console.log(rational.toString()); // "3/4"
86
+ * ```
87
+ */
88
+ static fromObject(rational) {
89
+ return new Rational(rational.num, rational.den);
90
+ }
91
+ /**
92
+ * Add two rational numbers.
93
+ *
94
+ * Performs addition: (a/b) + (c/d) = (ad + bc) / bd
95
+ *
96
+ * @param other - The rational number to add
97
+ *
98
+ * @returns A new Rational representing the sum
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const a = new Rational(1, 2); // 1/2
103
+ * const b = new Rational(1, 3); // 1/3
104
+ * const sum = a.add(b); // 5/6
105
+ * console.log(sum.toString()); // "5/6"
106
+ * ```
107
+ */
108
+ add(other) {
109
+ return new Rational(this.num * other.den + other.num * this.den, this.den * other.den);
110
+ }
111
+ /**
112
+ * Subtract two rational numbers.
113
+ *
114
+ * Performs subtraction: (a/b) - (c/d) = (ad - bc) / bd
115
+ *
116
+ * @param other - The rational number to subtract
117
+ *
118
+ * @returns A new Rational representing the difference
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const a = new Rational(3, 4); // 3/4
123
+ * const b = new Rational(1, 4); // 1/4
124
+ * const diff = a.sub(b); // 2/4 = 1/2
125
+ * console.log(diff.toString()); // "2/4"
126
+ * ```
127
+ */
128
+ sub(other) {
129
+ return new Rational(this.num * other.den - other.num * this.den, this.den * other.den);
130
+ }
131
+ /**
132
+ * Multiply two rational numbers.
133
+ *
134
+ * Performs multiplication: (a/b) × (c/d) = (ac) / (bd)
135
+ *
136
+ * @param other - The rational number to multiply by
137
+ *
138
+ * @returns A new Rational representing the product
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const framerate = new Rational(30, 1); // 30 fps
143
+ * const duration = new Rational(5, 1); // 5 seconds
144
+ * const frames = framerate.mul(duration); // 150/1 = 150 frames
145
+ * console.log(frames.toDouble()); // 150
146
+ * ```
147
+ */
148
+ mul(other) {
149
+ return new Rational(this.num * other.num, this.den * other.den);
150
+ }
151
+ /**
152
+ * Divide two rational numbers.
153
+ *
154
+ * Performs division: (a/b) ÷ (c/d) = (ad) / (bc)
155
+ *
156
+ * @param other - The rational number to divide by
157
+ *
158
+ * @returns A new Rational representing the quotient
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const pixels = new Rational(1920, 1); // 1920 pixels width
163
+ * const aspect = new Rational(16, 9); // 16:9 aspect ratio
164
+ * const height = pixels.div(aspect); // Calculate height
165
+ * console.log(height.toDouble()); // 1080
166
+ * ```
167
+ */
168
+ div(other) {
169
+ return new Rational(this.num * other.den, this.den * other.num);
170
+ }
171
+ /**
172
+ * Check if this rational is valid (both num and den are positive).
173
+ *
174
+ * FFmpeg uses { 0, 0 } as "undefined" and { num, 0 } as infinity.
175
+ * This method returns true only if both values are positive.
176
+ *
177
+ * @returns true if num > 0 and den > 0
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const valid = new Rational(25, 1);
182
+ * console.log(valid.isValid()); // true
183
+ *
184
+ * const undefined = new Rational(0, 0);
185
+ * console.log(undefined.isValid()); // false
186
+ *
187
+ * const infinity = new Rational(1, 0);
188
+ * console.log(infinity.isValid()); // false
189
+ * ```
190
+ */
191
+ isValid() {
192
+ return this.num > 0 && this.den > 0;
193
+ }
194
+ /**
195
+ * Invert the rational number (reciprocal).
196
+ *
197
+ * Returns the reciprocal: 1/(a/b) = b/a
198
+ *
199
+ * @returns A new Rational representing the reciprocal
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const framerate = new Rational(25, 1); // 25 fps
204
+ * const frameDuration = framerate.inv(); // 1/25 seconds per frame
205
+ * console.log(frameDuration.toString()); // "1/25"
206
+ * console.log(frameDuration.toDouble()); // 0.04 seconds
207
+ * ```
208
+ */
209
+ inv() {
210
+ return new Rational(this.den, this.num);
211
+ }
212
+ /**
213
+ * Convert rational to floating point number.
214
+ *
215
+ * Calculates the decimal value: num / den
216
+ * Note: This may lose precision for some rational values.
217
+ *
218
+ * @returns The floating point representation (Infinity if den = 0, NaN if both = 0)
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const ntsc = new Rational(30000, 1001); // NTSC frame rate
223
+ * console.log(ntsc.toDouble()); // 29.97002997...
224
+ *
225
+ * const half = new Rational(1, 2);
226
+ * console.log(half.toDouble()); // 0.5
227
+ *
228
+ * const infinity = new Rational(1, 0);
229
+ * console.log(infinity.toDouble()); // Infinity
230
+ * ```
231
+ */
232
+ toDouble() {
233
+ return this.num / this.den; // JavaScript handles division by zero correctly (Infinity/NaN)
234
+ }
235
+ /**
236
+ * Check if this rational equals another.
237
+ *
238
+ * Compares using cross-multiplication to avoid floating point errors.
239
+ * Two rationals a/b and c/d are equal if ad = bc.
240
+ *
241
+ * @param other - The rational to compare with
242
+ *
243
+ * @returns true if the rationals are equal, false otherwise
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const a = new Rational(2, 4);
248
+ * const b = new Rational(1, 2);
249
+ * const c = new Rational(3, 4);
250
+ *
251
+ * console.log(a.equals(b)); // true (both are 1/2)
252
+ * console.log(a.equals(c)); // false
253
+ * ```
254
+ */
255
+ equals(other) {
256
+ return this.num * other.den === other.num * this.den;
257
+ }
258
+ /**
259
+ * Get string representation of the rational.
260
+ *
261
+ * Returns the rational in "num/den" format.
262
+ *
263
+ * @returns String representation as "numerator/denominator"
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const framerate = new Rational(30000, 1001);
268
+ * console.log(framerate.toString()); // "30000/1001"
269
+ *
270
+ * const timebase = new Rational(1, 90000);
271
+ * console.log(`Timebase: ${timebase}`); // "Timebase: 1/90000"
272
+ * ```
273
+ */
274
+ toString() {
275
+ return `${this.num}/${this.den}`;
276
+ }
277
+ }
278
+ //# sourceMappingURL=rational.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rational.js","sourceRoot":"","sources":["../../src/lib/rational.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,QAAQ;IA+BD;IACA;IA/BlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,YACkB,GAAW,EACX,GAAW;QADX,QAAG,GAAH,GAAG,CAAQ;QACX,QAAG,GAAH,GAAG,CAAQ;QAE3B,kDAAkD;QAClD,iCAAiC;QACjC,0BAA0B;QAC1B,iEAAiE;IACnE,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,UAAU,CAAC,QAAmB;QACnC,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,KAAe;QACjB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACzF,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,KAAe;QACjB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACzF,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,KAAe;QACjB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,KAAe;QACjB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,GAAG;QACD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,+DAA+D;IAC7F,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,KAAe;QACpB,OAAO,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;CACF"}