node-av 3.1.2 → 4.0.0

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 (157) hide show
  1. package/README.md +65 -52
  2. package/binding.gyp +4 -0
  3. package/dist/api/audio-frame-buffer.d.ts +201 -0
  4. package/dist/api/audio-frame-buffer.js +275 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +319 -78
  7. package/dist/api/bitstream-filter.js +680 -151
  8. package/dist/api/bitstream-filter.js.map +1 -1
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  14. package/dist/api/data/test_vp8.ivf +0 -0
  15. package/dist/api/data/test_vp9.ivf +0 -0
  16. package/dist/api/decoder.d.ts +279 -17
  17. package/dist/api/decoder.js +998 -209
  18. package/dist/api/decoder.js.map +1 -1
  19. package/dist/api/{media-input.d.ts → demuxer.d.ts} +294 -44
  20. package/dist/api/demuxer.js +1968 -0
  21. package/dist/api/demuxer.js.map +1 -0
  22. package/dist/api/encoder.d.ts +308 -50
  23. package/dist/api/encoder.js +1133 -111
  24. package/dist/api/encoder.js.map +1 -1
  25. package/dist/api/filter-presets.d.ts +12 -5
  26. package/dist/api/filter-presets.js +21 -7
  27. package/dist/api/filter-presets.js.map +1 -1
  28. package/dist/api/filter.d.ts +406 -40
  29. package/dist/api/filter.js +966 -139
  30. package/dist/api/filter.js.map +1 -1
  31. package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
  32. package/dist/api/fmp4-stream.js +539 -0
  33. package/dist/api/fmp4-stream.js.map +1 -0
  34. package/dist/api/hardware.d.ts +58 -6
  35. package/dist/api/hardware.js +127 -11
  36. package/dist/api/hardware.js.map +1 -1
  37. package/dist/api/index.d.ts +6 -4
  38. package/dist/api/index.js +14 -8
  39. package/dist/api/index.js.map +1 -1
  40. package/dist/api/io-stream.d.ts +3 -3
  41. package/dist/api/io-stream.js +5 -4
  42. package/dist/api/io-stream.js.map +1 -1
  43. package/dist/api/{media-output.d.ts → muxer.d.ts} +274 -60
  44. package/dist/api/muxer.js +1934 -0
  45. package/dist/api/muxer.js.map +1 -0
  46. package/dist/api/pipeline.d.ts +77 -29
  47. package/dist/api/pipeline.js +435 -425
  48. package/dist/api/pipeline.js.map +1 -1
  49. package/dist/api/rtp-stream.d.ts +312 -0
  50. package/dist/api/rtp-stream.js +630 -0
  51. package/dist/api/rtp-stream.js.map +1 -0
  52. package/dist/api/types.d.ts +476 -55
  53. package/dist/api/utilities/async-queue.d.ts +91 -0
  54. package/dist/api/utilities/async-queue.js +162 -0
  55. package/dist/api/utilities/async-queue.js.map +1 -0
  56. package/dist/api/utilities/audio-sample.d.ts +1 -1
  57. package/dist/api/utilities/image.d.ts +1 -1
  58. package/dist/api/utilities/index.d.ts +2 -0
  59. package/dist/api/utilities/index.js +4 -0
  60. package/dist/api/utilities/index.js.map +1 -1
  61. package/dist/api/utilities/media-type.d.ts +1 -1
  62. package/dist/api/utilities/pixel-format.d.ts +1 -1
  63. package/dist/api/utilities/sample-format.d.ts +1 -1
  64. package/dist/api/utilities/scheduler.d.ts +169 -0
  65. package/dist/api/utilities/scheduler.js +136 -0
  66. package/dist/api/utilities/scheduler.js.map +1 -0
  67. package/dist/api/utilities/streaming.d.ts +74 -15
  68. package/dist/api/utilities/streaming.js +170 -12
  69. package/dist/api/utilities/streaming.js.map +1 -1
  70. package/dist/api/utilities/timestamp.d.ts +1 -1
  71. package/dist/api/webrtc-stream.d.ts +288 -0
  72. package/dist/api/webrtc-stream.js +440 -0
  73. package/dist/api/webrtc-stream.js.map +1 -0
  74. package/dist/constants/constants.d.ts +51 -1
  75. package/dist/constants/constants.js +47 -1
  76. package/dist/constants/constants.js.map +1 -1
  77. package/dist/constants/encoders.d.ts +2 -1
  78. package/dist/constants/encoders.js +4 -3
  79. package/dist/constants/encoders.js.map +1 -1
  80. package/dist/constants/hardware.d.ts +26 -0
  81. package/dist/constants/hardware.js +27 -0
  82. package/dist/constants/hardware.js.map +1 -0
  83. package/dist/constants/index.d.ts +1 -0
  84. package/dist/constants/index.js +1 -0
  85. package/dist/constants/index.js.map +1 -1
  86. package/dist/lib/binding.d.ts +19 -8
  87. package/dist/lib/binding.js.map +1 -1
  88. package/dist/lib/codec-context.d.ts +87 -0
  89. package/dist/lib/codec-context.js +125 -4
  90. package/dist/lib/codec-context.js.map +1 -1
  91. package/dist/lib/codec-parameters.d.ts +183 -1
  92. package/dist/lib/codec-parameters.js +209 -0
  93. package/dist/lib/codec-parameters.js.map +1 -1
  94. package/dist/lib/codec-parser.d.ts +23 -0
  95. package/dist/lib/codec-parser.js +25 -0
  96. package/dist/lib/codec-parser.js.map +1 -1
  97. package/dist/lib/codec.d.ts +26 -4
  98. package/dist/lib/codec.js +35 -0
  99. package/dist/lib/codec.js.map +1 -1
  100. package/dist/lib/dictionary.js +1 -0
  101. package/dist/lib/dictionary.js.map +1 -1
  102. package/dist/lib/error.js +1 -1
  103. package/dist/lib/error.js.map +1 -1
  104. package/dist/lib/filter-context.d.ts +52 -11
  105. package/dist/lib/filter-context.js +56 -12
  106. package/dist/lib/filter-context.js.map +1 -1
  107. package/dist/lib/filter-graph.d.ts +9 -0
  108. package/dist/lib/filter-graph.js +13 -0
  109. package/dist/lib/filter-graph.js.map +1 -1
  110. package/dist/lib/filter.d.ts +21 -0
  111. package/dist/lib/filter.js +28 -0
  112. package/dist/lib/filter.js.map +1 -1
  113. package/dist/lib/format-context.d.ts +48 -14
  114. package/dist/lib/format-context.js +76 -7
  115. package/dist/lib/format-context.js.map +1 -1
  116. package/dist/lib/frame.d.ts +168 -0
  117. package/dist/lib/frame.js +212 -0
  118. package/dist/lib/frame.js.map +1 -1
  119. package/dist/lib/hardware-device-context.d.ts +3 -2
  120. package/dist/lib/hardware-device-context.js.map +1 -1
  121. package/dist/lib/index.d.ts +1 -0
  122. package/dist/lib/index.js +2 -0
  123. package/dist/lib/index.js.map +1 -1
  124. package/dist/lib/input-format.d.ts +21 -0
  125. package/dist/lib/input-format.js +42 -2
  126. package/dist/lib/input-format.js.map +1 -1
  127. package/dist/lib/native-types.d.ts +48 -26
  128. package/dist/lib/option.d.ts +25 -13
  129. package/dist/lib/option.js +28 -0
  130. package/dist/lib/option.js.map +1 -1
  131. package/dist/lib/output-format.d.ts +22 -1
  132. package/dist/lib/output-format.js +28 -0
  133. package/dist/lib/output-format.js.map +1 -1
  134. package/dist/lib/packet.d.ts +35 -0
  135. package/dist/lib/packet.js +52 -2
  136. package/dist/lib/packet.js.map +1 -1
  137. package/dist/lib/stream.d.ts +126 -0
  138. package/dist/lib/stream.js +188 -5
  139. package/dist/lib/stream.js.map +1 -1
  140. package/dist/lib/sync-queue.d.ts +179 -0
  141. package/dist/lib/sync-queue.js +197 -0
  142. package/dist/lib/sync-queue.js.map +1 -0
  143. package/dist/lib/types.d.ts +27 -1
  144. package/dist/lib/utilities.d.ts +281 -53
  145. package/dist/lib/utilities.js +298 -55
  146. package/dist/lib/utilities.js.map +1 -1
  147. package/install/check.js +18 -7
  148. package/package.json +20 -19
  149. package/dist/api/fmp4.js +0 -710
  150. package/dist/api/fmp4.js.map +0 -1
  151. package/dist/api/media-input.js +0 -1075
  152. package/dist/api/media-input.js.map +0 -1
  153. package/dist/api/media-output.js +0 -1040
  154. package/dist/api/media-output.js.map +0 -1
  155. package/dist/api/webrtc.d.ts +0 -664
  156. package/dist/api/webrtc.js +0 -1132
  157. package/dist/api/webrtc.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import type { AVCodecID, AVMediaType, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
1
+ import type { AVCodecID, AVHWDeviceType, AVMediaType, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
2
+ import type { FFHWDeviceType } from '../constants/hardware.js';
2
3
  import type { FormatContext } from './format-context.js';
3
4
  import type { NativeCodecParameters, NativeWrapper } from './native-types.js';
4
5
  import type { ChannelLayout, IRational } from './types.js';
@@ -197,78 +198,49 @@ export declare function avSampleFmtIsPlanar(sampleFmt: AVSampleFormat): boolean;
197
198
  */
198
199
  export declare function avGetCodecName(codecId: AVCodecID): string | null;
199
200
  /**
200
- * Get DASH/RFC 6381 codec string from codec parameters.
201
+ * Get RFC 6381 codec string from codec parameters.
201
202
  *
202
- * Generates codec strings for MPEG-DASH manifests following RFC 6381.
203
- * Uses FFmpeg's dashenc.c implementation for accurate codec strings.
204
- *
205
- * Supported codecs:
206
- * - **WebM codecs**: VP8, VP9 (detailed), Vorbis, Opus, FLAC
207
- * - **H.264** (avc1): `avc1.PPCCLL` (profile, constraints, level)
208
- * - **HEVC** (hvc1/hev1): Base tag only (`hvc1` or `hev1`) - no profile details
209
- * - **AV1** (av01): `av01.P.LLT.BB...` (profile, level, tier, bitdepth, etc.)
210
- * - **AAC** (mp4a): `mp4a.OT.AOT` (object type, audio object type)
211
- *
212
- * Note: For HLS with detailed HEVC codec strings, use {@link avGetCodecStringHls}.
213
- *
214
- * @param codecpar - Codec parameters
215
- *
216
- * @returns DASH codec string, or null if cannot be determined
217
- *
218
- * @example
219
- * ```typescript
220
- * import { avGetCodecStringDash } from 'node-av/lib';
221
- *
222
- * // Get codec string from DASH output stream
223
- * const stream = dashOutput.video();
224
- * const codecString = avGetCodecStringDash(stream.codecpar);
225
- * console.log(codecString); // "hev1" for HEVC, "avc1.42c01e" for H.264
226
- *
227
- * // Use for DASH manifest
228
- * const mimeType = `video/mp4; codecs="${codecString}"`;
229
- * ```
230
- *
231
- * @see [RFC 6381](https://tools.ietf.org/html/rfc6381) - RFC 6381: Codecs Parameter Specification
232
- * @see [dashenc](https://ffmpeg.org/doxygen/trunk/dashenc_8c_source.html#l00345) - FFmpeg dashenc.c implementation
233
- */
234
- export declare function avGetCodecStringDash(codecpar: NativeWrapper<NativeCodecParameters>): string | null;
235
- /**
236
- * Get HLS codec string from codec parameters.
237
- *
238
- * Generates codec strings for HLS playlists. Uses FFmpeg's hlsenc.c implementation.
239
- * Provides detailed HEVC codec strings with profile, tier, level, and constraints.
203
+ * Generates codec strings for MPEG-DASH and HLS manifests following RFC 6381.
204
+ * Uses FFmpeg's centralized ff_make_codec_str() implementation (libavformat/codecstring.c).
240
205
  *
241
206
  * Supported codecs:
207
+ * - **WebM codecs**: VP8, VP9 (with detailed profile/level), Vorbis, Opus, FLAC
242
208
  * - **H.264** (avc1): `avc1.PPCCLL` (profile, constraints, level)
243
209
  * - **HEVC** (hvc1): `hvc1.P.PC.TL.C` (profile, profile_compatibility, tier+level, constraints)
244
- * - **AAC**: `mp4a.40.AOT` (audio object type based on profile)
210
+ * - **AV1** (av01): `av01.P.LLT.BB...` (profile, level, tier, bitdepth, color info)
211
+ * - **AAC**: `mp4a.40.AOT` (audio object type)
245
212
  * - **MP2**: `mp4a.40.33`
246
213
  * - **MP3**: `mp4a.40.34`
247
214
  * - **AC-3**: `ac-3`
248
215
  * - **E-AC-3**: `ec-3`
249
- *
250
- * Note: For DASH manifests, use {@link avGetCodecStringDash} instead.
216
+ * - **MPEG-4 Visual**: `mp4v.20` (profile/level not implemented)
251
217
  *
252
218
  * @param codecpar - Codec parameters
253
219
  *
254
- * @returns HLS codec string, or null if cannot be determined
220
+ * @param frameRate - Optional frame rate for VP9 level calculation (only used for VP9)
221
+ *
222
+ * @returns RFC 6381 codec string, or null if codec not supported
255
223
  *
256
224
  * @example
257
225
  * ```typescript
258
- * import { avGetCodecStringHls } from 'node-av/lib';
226
+ * import { avGetCodecString } from 'node-av/lib';
227
+ *
228
+ * // Get codec string for DASH/HLS manifest
229
+ * const stream = output.video();
230
+ * const codecString = avGetCodecString(stream.codecpar);
231
+ * console.log(codecString); // "hvc1.1.6.L93.B0" for HEVC, "avc1.42c01e" for H.264
259
232
  *
260
- * // Get detailed HEVC codec string for HLS
261
- * const stream = hlsOutput.video();
262
- * const codecString = avGetCodecStringHls(stream.codecpar);
263
- * console.log(codecString); // "hvc1.1.6.L93.B0" - detailed HEVC profile info
233
+ * // VP9 with frame rate for accurate level
234
+ * const codecStringVP9 = avGetCodecString(stream.codecpar, { num: 30, den: 1 });
235
+ * console.log(codecStringVP9); // "vp09.00.30.08" - detailed VP9 string
264
236
  *
265
- * // Use for HLS playlist
266
- * const codecsAttr = `CODECS="${codecString}"`;
237
+ * // Use for DASH/HLS manifest
238
+ * const mimeType = `video/mp4; codecs="${codecString}"`;
267
239
  * ```
268
240
  *
269
- * @see [hlsenc](https://ffmpeg.org/doxygen/trunk/hlsenc_8c_source.html#l00351) - FFmpeg hlsenc.c implementation
241
+ * @see [codecstring.c](https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/codecstring.c) - FFmpeg implementation
270
242
  */
271
- export declare function avGetCodecStringHls(codecpar: NativeWrapper<NativeCodecParameters>): string | null;
243
+ export declare function avGetCodecString(codecpar: NativeWrapper<NativeCodecParameters>, frameRate?: IRational): string | null;
272
244
  /**
273
245
  * Get DASH MIME type for codec parameters.
274
246
  *
@@ -363,6 +335,52 @@ export declare function avGetPixFmtFromName(name: string): AVPixelFormat;
363
335
  * @see [av_pix_fmt_desc_get](https://ffmpeg.org/doxygen/7.1/pixdesc_8c.html#afe0c3e8aef5173de28bbdaea4298f5f0) - FFmpeg Doxygen
364
336
  */
365
337
  export declare function avIsHardwarePixelFormat(pixFmt: AVPixelFormat): boolean;
338
+ /**
339
+ * Get hardware device type name.
340
+ *
341
+ * Returns the string name for a hardware device type enum value.
342
+ *
343
+ * Direct mapping to av_hwdevice_get_type_name().
344
+ *
345
+ * @param type - Hardware device type enum
346
+ *
347
+ * @returns Device type name (e.g. "videotoolbox", "cuda"), or null if unknown
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * import { AV_HWDEVICE_TYPE_VIDEOTOOLBOX, AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
352
+ *
353
+ * const name1 = avGetHardwareDeviceTypeName(AV_HWDEVICE_TYPE_VIDEOTOOLBOX); // Returns "videotoolbox"
354
+ * const name2 = avGetHardwareDeviceTypeName(AV_HWDEVICE_TYPE_CUDA); // Returns "cuda"
355
+ * ```
356
+ *
357
+ * @see [av_hwdevice_get_type_name](https://ffmpeg.org/doxygen/7.1/hwcontext_8h.html#afb2b99a15f3fdde25a2fd19353ac5a67) - FFmpeg Doxygen
358
+ */
359
+ export declare function avGetHardwareDeviceTypeName(type: AVHWDeviceType): FFHWDeviceType;
360
+ /**
361
+ * Get hardware device type from name.
362
+ *
363
+ * Looks up the hardware device type enum from its string name.
364
+ * Returns AV_HWDEVICE_TYPE_NONE if the name is not recognized.
365
+ *
366
+ * Direct mapping to av_hwdevice_find_type_by_name().
367
+ *
368
+ * @param name - Hardware device type name (e.g. "videotoolbox", "cuda")
369
+ *
370
+ * @returns Hardware device type enum, or AV_HWDEVICE_TYPE_NONE if not found
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * import { avGetHardwareDeviceTypeFromName } from 'node-av/lib';
375
+ *
376
+ * const type1 = avGetHardwareDeviceTypeFromName("videotoolbox"); // Returns AV_HWDEVICE_TYPE_VIDEOTOOLBOX
377
+ * const type2 = avGetHardwareDeviceTypeFromName("cuda"); // Returns AV_HWDEVICE_TYPE_CUDA
378
+ * const none = avGetHardwareDeviceTypeFromName("invalid"); // Returns AV_HWDEVICE_TYPE_NONE
379
+ * ```
380
+ *
381
+ * @see [av_hwdevice_find_type_by_name](https://ffmpeg.org/doxygen/7.1/hwcontext_8h.html#a541943ddced791765349645a30adfa4d) - FFmpeg Doxygen
382
+ */
383
+ export declare function avGetHardwareDeviceTypeFromName(name: FFHWDeviceType): AVHWDeviceType;
366
384
  /**
367
385
  * Get media type string.
368
386
  *
@@ -698,6 +716,216 @@ export declare function avUsleep(usec: number): void;
698
716
  * @see [av_rescale_rnd](https://ffmpeg.org/doxygen/7.1/group__lavu__math.html#ga82d40664213508918093822461cc597e) - FFmpeg Doxygen
699
717
  */
700
718
  export declare function avRescaleRnd(a: bigint | number, b: bigint | number, c: bigint | number, rnd: number): bigint;
719
+ /**
720
+ * Rescale a timestamp while preserving accuracy with coarse input timebases.
721
+ *
722
+ * Used for audio streamcopy to maintain accuracy when input timebase is coarse.
723
+ * Direct mapping to av_rescale_delta().
724
+ *
725
+ * @param inTb - Input timebase
726
+ *
727
+ * @param inTs - Input timestamp
728
+ *
729
+ * @param fsTb - Duration timebase (e.g., {1, sampleRate})
730
+ *
731
+ * @param duration - Duration in fsTb units
732
+ *
733
+ * @param lastRef - Reference object with `value` property (modified by function)
734
+ *
735
+ * @param lastRef.value - Last output timestamp (bigint)
736
+ *
737
+ * @param outTb - Output timebase
738
+ *
739
+ * @returns Rescaled timestamp
740
+ *
741
+ * @example
742
+ * ```typescript
743
+ * const inTb = { num: 1, den: 48000 };
744
+ * const inTs = 1000000n;
745
+ * const fsTb = { num: 1, den: 44100 };
746
+ * const duration = 1024;
747
+ * const lastRef = { value: 0n };
748
+ * const outTb = { num: 1, den: 96000 };
749
+ *
750
+ * const rescaled = avRescaleDelta(inTb, inTs, fsTb, duration, lastRef, outTb);
751
+ * ```
752
+ *
753
+ * @see [av_rescale_delta](https://ffmpeg.org/doxygen/7.1/group__lavu__math.html) - FFmpeg Doxygen
754
+ */
755
+ export declare function avRescaleDelta(inTb: IRational, inTs: bigint | number, fsTb: IRational, duration: number, lastRef: {
756
+ value: bigint;
757
+ }, outTb: IRational): bigint;
758
+ /**
759
+ * Multiply two rational numbers.
760
+ *
761
+ * Multiplies two rational numbers using FFmpeg's av_mul_q() which normalizes the result.
762
+ * This is more accurate than manual multiplication as it reduces the fraction.
763
+ *
764
+ * Direct mapping to av_mul_q().
765
+ *
766
+ * @param a - First rational number
767
+ *
768
+ * @param b - Second rational number
769
+ *
770
+ * @returns Product of a and b as a normalized rational
771
+ *
772
+ * @example
773
+ * ```typescript
774
+ * // Multiply framerate by 2
775
+ * const framerate = { num: 25, den: 1 };
776
+ * const doubled = avMulQ(framerate, { num: 2, den: 1 });
777
+ * // Returns { num: 50, den: 1 }
778
+ *
779
+ * // Calculate field rate for interlaced video
780
+ * const fieldRate = avMulQ(framerate, { num: 2, den: 1 });
781
+ * ```
782
+ *
783
+ * @see [av_mul_q](https://ffmpeg.org/doxygen/trunk/group__lavu__math__rational.html#ga89c0e84e30e2f90196e11fc254e4fc3f) - FFmpeg Doxygen
784
+ */
785
+ export declare function avMulQ(a: IRational, b: IRational): IRational;
786
+ /**
787
+ * Invert a rational number.
788
+ *
789
+ * Returns the reciprocal of a rational number using FFmpeg's av_inv_q().
790
+ * Swaps numerator and denominator: (a/b) becomes (b/a).
791
+ *
792
+ * Direct mapping to av_inv_q().
793
+ *
794
+ * @param q - Rational number to invert
795
+ *
796
+ * @returns Inverted rational (reciprocal)
797
+ *
798
+ * @example
799
+ * ```typescript
800
+ * // Convert framerate to frame duration
801
+ * const framerate = { num: 25, den: 1 }; // 25 fps
802
+ * const frameDuration = avInvQ(framerate); // 1/25 seconds
803
+ * // Returns { num: 1, den: 25 }
804
+ *
805
+ * // Get timebase from framerate
806
+ * const timebase = avInvQ({ num: 30000, den: 1001 }); // NTSC
807
+ * // Returns { num: 1001, den: 30000 }
808
+ * ```
809
+ *
810
+ * @see [av_inv_q](https://ffmpeg.org/doxygen/trunk/group__lavu__math__rational.html#ga587a784cb48299feea51d7dbbc6cc38c) - FFmpeg Doxygen
811
+ */
812
+ export declare function avInvQ(q: IRational): IRational;
813
+ /**
814
+ * Add two rational numbers.
815
+ *
816
+ * Adds two rational numbers using FFmpeg's av_add_q() which normalizes the result.
817
+ * This is more accurate than manual addition as it reduces the fraction.
818
+ *
819
+ * Direct mapping to av_add_q().
820
+ *
821
+ * @param a - First rational number
822
+ *
823
+ * @param b - Second rational number
824
+ *
825
+ * @returns Sum of a and b as a normalized rational
826
+ *
827
+ * @example
828
+ * ```typescript
829
+ * // Add two fractions
830
+ * const a = { num: 1, den: 2 }; // 1/2
831
+ * const b = { num: 1, den: 4 }; // 1/4
832
+ * const sum = avAddQ(a, b); // 3/4
833
+ * // Returns { num: 3, den: 4 }
834
+ *
835
+ * // Add timestamps with different timebases
836
+ * const ts1 = { num: 1000, den: 30000 };
837
+ * const ts2 = { num: 500, den: 30000 };
838
+ * const total = avAddQ(ts1, ts2);
839
+ * // Returns { num: 1, den: 20 } (normalized from 1500/30000)
840
+ * ```
841
+ *
842
+ * @see [av_add_q](https://ffmpeg.org/doxygen/trunk/group__lavu__math__rational.html#gac4af1feb227bd1095fc2cab42d933f52) - FFmpeg Doxygen
843
+ */
844
+ export declare function avAddQ(a: IRational, b: IRational): IRational;
845
+ /**
846
+ * Calculate greatest common divisor.
847
+ *
848
+ * Computes the GCD of two integers using FFmpeg's av_gcd().
849
+ * Uses the Euclidean algorithm for efficient computation.
850
+ *
851
+ * Direct mapping to av_gcd().
852
+ *
853
+ * @param a - First integer
854
+ *
855
+ * @param b - Second integer
856
+ *
857
+ * @returns Greatest common divisor of a and b
858
+ *
859
+ * @example
860
+ * ```typescript
861
+ * const gcd = avGcd(48000, 44100);
862
+ * console.log(gcd); // 300
863
+ *
864
+ * // Used for calculating LCM
865
+ * const lcm = (a * b) / avGcd(a, b);
866
+ * ```
867
+ *
868
+ * @see [av_gcd](https://ffmpeg.org/doxygen/trunk/group__lavu__math.html#ga0e8419780352de538c1c15098cb1a587) - FFmpeg Doxygen
869
+ */
870
+ export declare function avGcd(a: bigint | number, b: bigint | number): bigint;
871
+ /**
872
+ * Rescale timestamp with specified rounding mode.
873
+ *
874
+ * Rescales a timestamp from one time base to another with specific rounding behavior.
875
+ * More control than avRescaleQ() which uses default rounding.
876
+ *
877
+ * Direct mapping to av_rescale_q_rnd().
878
+ *
879
+ * @param a - Timestamp to rescale
880
+ *
881
+ * @param bq - Source time base
882
+ *
883
+ * @param cq - Destination time base
884
+ *
885
+ * @param rnd - Rounding mode (AV_ROUND_ZERO, AV_ROUND_INF, AV_ROUND_DOWN, AV_ROUND_UP, AV_ROUND_NEAR_INF)
886
+ *
887
+ * @returns Rescaled timestamp
888
+ *
889
+ * @example
890
+ * ```typescript
891
+ * import { AV_ROUND_UP, AV_ROUND_DOWN } from 'node-av/constants';
892
+ *
893
+ * const pts = 1000n;
894
+ * const srcTb = { num: 1, den: 48000 };
895
+ * const dstTb = { num: 1, den: 90000 };
896
+ *
897
+ * // Round up for safer comparisons
898
+ * const ptsUp = avRescaleQRnd(pts, srcTb, dstTb, AV_ROUND_UP);
899
+ *
900
+ * // Round down for conservative timestamps
901
+ * const ptsDown = avRescaleQRnd(pts, srcTb, dstTb, AV_ROUND_DOWN);
902
+ * ```
903
+ *
904
+ * @see [av_rescale_q_rnd](https://ffmpeg.org/doxygen/trunk/group__lavu__math.html#ga60044a302e86b5c2d8b19a81c8179f30) - FFmpeg Doxygen
905
+ */
906
+ export declare function avRescaleQRnd(a: bigint | number | null, bq: IRational, cq: IRational, rnd: number): bigint;
907
+ /**
908
+ * Get the duration of a single audio frame in samples.
909
+ *
910
+ * Returns the number of samples per audio frame for codecs with constant frame size,
911
+ * or calculates it based on frame bytes for variable frame size codecs.
912
+ *
913
+ * Direct mapping to av_get_audio_frame_duration2().
914
+ *
915
+ * @param codecpar - Codec parameters
916
+ *
917
+ * @param frameBytes - Size of the frame in bytes
918
+ *
919
+ * @returns Number of samples in the frame, or 0 if unknown
920
+ *
921
+ * @example
922
+ * ```typescript
923
+ * const frameDuration = avGetAudioFrameDuration2(codecpar, frameBytes);
924
+ * ```
925
+ *
926
+ * @see [av_get_audio_frame_duration2](https://ffmpeg.org/doxygen/7.1/group__lavc__misc.html) - FFmpeg Doxygen
927
+ */
928
+ export declare function avGetAudioFrameDuration2(codecpar: NativeWrapper<NativeCodecParameters>, frameBytes: number): number;
701
929
  /**
702
930
  * Allocate audio samples buffer.
703
931
  *