@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,1225 @@
1
+ import { FF_HWDEVICE_TYPE_NONE } from '../constants/hardware.js';
2
+ import { bindings } from './binding.js';
3
+ import { FFmpegError } from './error.js';
4
+ /**
5
+ * Get FFmpeg library information.
6
+ *
7
+ * Returns detailed information about the FFmpeg libraries including
8
+ * version numbers and build configuration.
9
+ *
10
+ * @returns FFmpeg information object with version, configuration, and library versions
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { getFFmpegInfo } from 'node-av/lib';
15
+ *
16
+ * const info = getFFmpegInfo();
17
+ * console.log('FFmpeg version:', info.version);
18
+ * console.log('Configuration:', info.configuration);
19
+ * console.log('libavcodec:', info.libraries.avcodec);
20
+ * ```
21
+ */
22
+ export function getFFmpegInfo() {
23
+ return bindings.getFFmpegInfo();
24
+ }
25
+ /**
26
+ * Get bytes per audio sample.
27
+ *
28
+ * Returns the number of bytes required to store a single audio sample
29
+ * in the specified format.
30
+ *
31
+ * Direct mapping to av_get_bytes_per_sample().
32
+ *
33
+ * @param sampleFmt - Audio sample format
34
+ *
35
+ * @returns Number of bytes per sample, or 0 if unknown format
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
40
+ *
41
+ * const bytesS16 = avGetBytesPerSample(AV_SAMPLE_FMT_S16); // Returns 2
42
+ * const bytesFloat = avGetBytesPerSample(AV_SAMPLE_FMT_FLTP); // Returns 4
43
+ * ```
44
+ *
45
+ * @see [av_get_bytes_per_sample](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#ga0c3c218e1dd570ad4917c69a35a6c77d) - FFmpeg Doxygen
46
+ */
47
+ export function avGetBytesPerSample(sampleFmt) {
48
+ return bindings.avGetBytesPerSample(sampleFmt);
49
+ }
50
+ /**
51
+ * Get sample format name.
52
+ *
53
+ * Returns the name of the audio sample format as a string.
54
+ *
55
+ * Direct mapping to av_get_sample_fmt_name().
56
+ *
57
+ * @param sampleFmt - Audio sample format
58
+ *
59
+ * @returns Format name, or null if unknown
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
64
+ *
65
+ * const name1 = avGetSampleFmtName(AV_SAMPLE_FMT_S16); // Returns "s16"
66
+ * const name2 = avGetSampleFmtName(AV_SAMPLE_FMT_FLTP); // Returns "fltp"
67
+ * ```
68
+ *
69
+ * @see [av_get_sample_fmt_name](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#ga31b9d149b2de9821a65f4f5612970838) - FFmpeg Doxygen
70
+ */
71
+ export function avGetSampleFmtName(sampleFmt) {
72
+ return bindings.avGetSampleFmtName(sampleFmt);
73
+ }
74
+ /**
75
+ * Get sample format from name string.
76
+ *
77
+ * Converts a sample format name (like "s16", "fltp", etc.) to the
78
+ * corresponding AVSampleFormat enum value.
79
+ *
80
+ * Direct mapping to av_get_sample_fmt().
81
+ *
82
+ * @param name - Sample format name (e.g., "s16", "fltp", "s32p")
83
+ *
84
+ * @returns Sample format enum, or AV_SAMPLE_FMT_NONE if unknown
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const fmt1 = avGetSampleFmtFromName("s16"); // Returns AV_SAMPLE_FMT_S16
89
+ * const fmt2 = avGetSampleFmtFromName("fltp"); // Returns AV_SAMPLE_FMT_FLTP
90
+ * const none = avGetSampleFmtFromName("invalid"); // Returns AV_SAMPLE_FMT_NONE
91
+ * ```
92
+ *
93
+ * @see [av_get_sample_fmt](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#ga5b95d0bf179912e8ff0d23ddfa99c9bc) - FFmpeg Doxygen
94
+ * @see {@link avGetSampleFmtName} For converting format to name string
95
+ */
96
+ export function avGetSampleFmtFromName(name) {
97
+ return bindings.avGetSampleFmtFromName(name);
98
+ }
99
+ /**
100
+ * Get packed sample format.
101
+ *
102
+ * Returns the packed (interleaved) version of a planar sample format,
103
+ * or the format itself if already packed.
104
+ *
105
+ * Direct mapping to av_get_packed_sample_fmt().
106
+ *
107
+ * @param sampleFmt - Audio sample format
108
+ *
109
+ * @returns Packed version of the format
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT } from 'node-av/constants';
114
+ *
115
+ * const packed = avGetPackedSampleFmt(AV_SAMPLE_FMT_FLTP); // Returns AV_SAMPLE_FMT_FLT
116
+ * const same = avGetPackedSampleFmt(AV_SAMPLE_FMT_FLT); // Returns AV_SAMPLE_FMT_FLT
117
+ * ```
118
+ *
119
+ * @see [av_get_packed_sample_fmt](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#ga7817ec0eff4dc6fc0962f31e6d138bca) - FFmpeg Doxygen
120
+ * @see {@link avGetPlanarSampleFmt} For getting planar version
121
+ */
122
+ export function avGetPackedSampleFmt(sampleFmt) {
123
+ return bindings.avGetPackedSampleFmt(sampleFmt);
124
+ }
125
+ /**
126
+ * Get planar sample format.
127
+ *
128
+ * Returns the planar (non-interleaved) version of a packed sample format,
129
+ * or the format itself if already planar.
130
+ *
131
+ * Direct mapping to av_get_planar_sample_fmt().
132
+ *
133
+ * @param sampleFmt - Audio sample format
134
+ *
135
+ * @returns Planar version of the format
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * import { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
140
+ *
141
+ * const planar = avGetPlanarSampleFmt(AV_SAMPLE_FMT_FLT); // Returns AV_SAMPLE_FMT_FLTP
142
+ * const same = avGetPlanarSampleFmt(AV_SAMPLE_FMT_FLTP); // Returns AV_SAMPLE_FMT_FLTP
143
+ * ```
144
+ *
145
+ * @see [av_get_planar_sample_fmt](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#ga82caf838259d95cc6c4fd87633bb0e19) - FFmpeg Doxygen
146
+ * @see {@link avGetPackedSampleFmt} For getting packed version
147
+ */
148
+ export function avGetPlanarSampleFmt(sampleFmt) {
149
+ return bindings.avGetPlanarSampleFmt(sampleFmt);
150
+ }
151
+ /**
152
+ * Check if sample format is planar.
153
+ *
154
+ * Returns whether the audio sample format stores channels in separate planes
155
+ * (planar) rather than interleaved.
156
+ *
157
+ * Direct mapping to av_sample_fmt_is_planar().
158
+ *
159
+ * @param sampleFmt - Audio sample format to check
160
+ *
161
+ * @returns True if planar, false if packed/interleaved
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P } from 'node-av/constants';
166
+ *
167
+ * const isPacked = avSampleFmtIsPlanar(AV_SAMPLE_FMT_S16); // Returns false
168
+ * const isPlanar = avSampleFmtIsPlanar(AV_SAMPLE_FMT_S16P); // Returns true
169
+ * ```
170
+ *
171
+ * @see [av_sample_fmt_is_planar](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#ga06ba8a64dc4382c422789a5d0b6bf592) - FFmpeg Doxygen
172
+ */
173
+ export function avSampleFmtIsPlanar(sampleFmt) {
174
+ return bindings.avSampleFmtIsPlanar(sampleFmt);
175
+ }
176
+ /**
177
+ * Get codec name from codec ID.
178
+ *
179
+ * Returns the canonical codec name corresponding to the codec ID.
180
+ *
181
+ * Direct mapping to avcodec_get_name().
182
+ *
183
+ * @param codecId - Codec ID from AVCodecID enum
184
+ *
185
+ * @returns Codec name string or null
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { AV_CODEC_ID_H264, AV_CODEC_ID_HEVC } from 'node-av/constants';
190
+ * import { avGetCodecName } from 'node-av/lib';
191
+ *
192
+ * const h264Name = avGetCodecName(AV_CODEC_ID_H264); // Returns "h264"
193
+ * const hevcName = avGetCodecName(AV_CODEC_ID_HEVC); // Returns "hevc"
194
+ * const unknownName = avGetCodecName(99999); // Returns null
195
+ * ```
196
+ *
197
+ * @see [avcodec_get_name](https://ffmpeg.org/doxygen/7.1/group__lavc__core.html#ga2016a52e94f867ebe5113bdf448e182d) - FFmpeg Doxygen
198
+ */
199
+ export function avGetCodecName(codecId) {
200
+ return bindings.avGetCodecName(codecId);
201
+ }
202
+ /**
203
+ * Get RFC 6381 codec string from codec parameters.
204
+ *
205
+ * Generates codec strings for MPEG-DASH and HLS manifests following RFC 6381.
206
+ * Uses FFmpeg's centralized ff_make_codec_str() implementation (libavformat/codecstring.c).
207
+ *
208
+ * Supported codecs:
209
+ * - **WebM codecs**: VP8, VP9 (with detailed profile/level), Vorbis, Opus, FLAC
210
+ * - **H.264** (avc1): `avc1.PPCCLL` (profile, constraints, level)
211
+ * - **HEVC** (hvc1): `hvc1.P.PC.TL.C` (profile, profile_compatibility, tier+level, constraints)
212
+ * - **AV1** (av01): `av01.P.LLT.BB...` (profile, level, tier, bitdepth, color info)
213
+ * - **AAC**: `mp4a.40.AOT` (audio object type)
214
+ * - **MP2**: `mp4a.40.33`
215
+ * - **MP3**: `mp4a.40.34`
216
+ * - **AC-3**: `ac-3`
217
+ * - **E-AC-3**: `ec-3`
218
+ * - **MPEG-4 Visual**: `mp4v.20` (profile/level not implemented)
219
+ *
220
+ * @param codecpar - Codec parameters
221
+ *
222
+ * @param frameRate - Optional frame rate for VP9 level calculation (only used for VP9)
223
+ *
224
+ * @returns RFC 6381 codec string, or null if codec not supported
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * import { avGetCodecString } from 'node-av/lib';
229
+ *
230
+ * // Get codec string for DASH/HLS manifest
231
+ * const stream = output.video();
232
+ * const codecString = avGetCodecString(stream.codecpar);
233
+ * console.log(codecString); // "hvc1.1.6.L93.B0" for HEVC, "avc1.42c01e" for H.264
234
+ *
235
+ * // VP9 with frame rate for accurate level
236
+ * const codecStringVP9 = avGetCodecString(stream.codecpar, { num: 30, den: 1 });
237
+ * console.log(codecStringVP9); // "vp09.00.30.08" - detailed VP9 string
238
+ *
239
+ * // Use for DASH/HLS manifest
240
+ * const mimeType = `video/mp4; codecs="${codecString}"`;
241
+ * ```
242
+ *
243
+ * @see [codecstring.c](https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/codecstring.c) - FFmpeg implementation
244
+ */
245
+ export function avGetCodecString(codecpar, frameRate) {
246
+ return bindings.avGetCodecString(codecpar.getNative(), frameRate);
247
+ }
248
+ /**
249
+ * Get DASH MIME type for codec parameters.
250
+ *
251
+ * Determines the MIME type for MPEG-DASH segments based on codec.
252
+ * Uses FFmpeg's segment type selection logic:
253
+ * - WebM codecs (VP8, VP9, Vorbis, Opus) → `video/webm` or `audio/webm`
254
+ * - All other codecs → `video/mp4` or `audio/mp4`
255
+ *
256
+ * @param codecpar - Codec parameters
257
+ *
258
+ * @returns MIME type string, or null if invalid media type
259
+ *
260
+ * @example
261
+ * ```typescript
262
+ * import { avGetMimeTypeDash } from 'node-av/lib';
263
+ *
264
+ * const stream = input.video();
265
+ * const mimeType = avGetMimeTypeDash(stream.codecpar);
266
+ * console.log(mimeType); // "video/mp4" for H.264
267
+ *
268
+ * // VP9 codec
269
+ * const mimeTypeVP9 = avGetMimeTypeDash(vp9Stream.codecpar);
270
+ * console.log(mimeTypeVP9); // "video/webm"
271
+ * ```
272
+ *
273
+ * @see https://ffmpeg.org/doxygen/trunk/dashenc_8c_source.html#l00285 - FFmpeg dashenc.c segment type selection
274
+ */
275
+ export function avGetMimeTypeDash(codecpar) {
276
+ return bindings.avGetMimeTypeDash(codecpar.getNative());
277
+ }
278
+ /**
279
+ * Get pixel format name.
280
+ *
281
+ * Returns the name of the pixel format as a string.
282
+ *
283
+ * Direct mapping to av_get_pix_fmt_name().
284
+ *
285
+ * @param pixFmt - Pixel format
286
+ *
287
+ * @returns Format name, or null if unknown
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
292
+ *
293
+ * const name1 = avGetPixFmtName(AV_PIX_FMT_YUV420P); // Returns "yuv420p"
294
+ * const name2 = avGetPixFmtName(AV_PIX_FMT_RGB24); // Returns "rgb24"
295
+ * ```
296
+ *
297
+ * @see [av_get_pix_fmt_name](https://ffmpeg.org/doxygen/7.1/pixdesc_8c.html#ab92e2a8a9b58c982560c49df9f01e47e) - FFmpeg Doxygen
298
+ */
299
+ export function avGetPixFmtName(pixFmt) {
300
+ return bindings.avGetPixFmtName(pixFmt);
301
+ }
302
+ /**
303
+ * Get pixel format from name.
304
+ *
305
+ * Returns the pixel format enum value from its string name.
306
+ *
307
+ * Direct mapping to av_get_pix_fmt().
308
+ *
309
+ * @param name - Pixel format name
310
+ *
311
+ * @returns Pixel format enum, or AV_PIX_FMT_NONE if unknown
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const fmt1 = avGetPixFmtFromName("yuv420p"); // Returns AV_PIX_FMT_YUV420P
316
+ * const fmt2 = avGetPixFmtFromName("rgb24"); // Returns AV_PIX_FMT_RGB24
317
+ * const none = avGetPixFmtFromName("invalid"); // Returns AV_PIX_FMT_NONE
318
+ * ```
319
+ *
320
+ * @see [av_get_pix_fmt](https://ffmpeg.org/doxygen/7.1/pixdesc_8h.html#a925ef18d69c24c3be8c53d5a7dc0660e) - FFmpeg Doxygen
321
+ */
322
+ export function avGetPixFmtFromName(name) {
323
+ return bindings.avGetPixFmtFromName(name);
324
+ }
325
+ /**
326
+ * Check if pixel format is hardware accelerated.
327
+ *
328
+ * Returns whether the pixel format represents hardware-accelerated frames
329
+ * (GPU memory) rather than software frames (system memory).
330
+ *
331
+ * Direct mapping to av_pix_fmt_desc_get() with hwaccel check.
332
+ *
333
+ * @param pixFmt - Pixel format to check
334
+ *
335
+ * @returns True if hardware format, false if software format
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_CUDA } from 'node-av/constants';
340
+ *
341
+ * const isSoftware = avIsHardwarePixelFormat(AV_PIX_FMT_YUV420P); // Returns false
342
+ * const isHardware = avIsHardwarePixelFormat(AV_PIX_FMT_CUDA); // Returns true
343
+ * ```
344
+ *
345
+ * @see [av_pix_fmt_desc_get](https://ffmpeg.org/doxygen/7.1/pixdesc_8c.html#afe0c3e8aef5173de28bbdaea4298f5f0) - FFmpeg Doxygen
346
+ */
347
+ export function avIsHardwarePixelFormat(pixFmt) {
348
+ return bindings.avIsHardwarePixelFormat(pixFmt);
349
+ }
350
+ /**
351
+ * Get hardware device type name.
352
+ *
353
+ * Returns the string name for a hardware device type enum value.
354
+ *
355
+ * Direct mapping to av_hwdevice_get_type_name().
356
+ *
357
+ * @param type - Hardware device type enum
358
+ *
359
+ * @returns Device type name (e.g. "videotoolbox", "cuda"), or null if unknown
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * import { AV_HWDEVICE_TYPE_VIDEOTOOLBOX, AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
364
+ *
365
+ * const name1 = avGetHardwareDeviceTypeName(AV_HWDEVICE_TYPE_VIDEOTOOLBOX); // Returns "videotoolbox"
366
+ * const name2 = avGetHardwareDeviceTypeName(AV_HWDEVICE_TYPE_CUDA); // Returns "cuda"
367
+ * ```
368
+ *
369
+ * @see [av_hwdevice_get_type_name](https://ffmpeg.org/doxygen/7.1/hwcontext_8h.html#afb2b99a15f3fdde25a2fd19353ac5a67) - FFmpeg Doxygen
370
+ */
371
+ export function avGetHardwareDeviceTypeName(type) {
372
+ const name = bindings.avGetHardwareDeviceTypeName(type);
373
+ return name ?? FF_HWDEVICE_TYPE_NONE;
374
+ }
375
+ /**
376
+ * Get hardware device type from name.
377
+ *
378
+ * Looks up the hardware device type enum from its string name.
379
+ * Returns AV_HWDEVICE_TYPE_NONE if the name is not recognized.
380
+ *
381
+ * Direct mapping to av_hwdevice_find_type_by_name().
382
+ *
383
+ * @param name - Hardware device type name (e.g. "videotoolbox", "cuda")
384
+ *
385
+ * @returns Hardware device type enum, or AV_HWDEVICE_TYPE_NONE if not found
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * import { avGetHardwareDeviceTypeFromName } from 'node-av/lib';
390
+ *
391
+ * const type1 = avGetHardwareDeviceTypeFromName("videotoolbox"); // Returns AV_HWDEVICE_TYPE_VIDEOTOOLBOX
392
+ * const type2 = avGetHardwareDeviceTypeFromName("cuda"); // Returns AV_HWDEVICE_TYPE_CUDA
393
+ * const none = avGetHardwareDeviceTypeFromName("invalid"); // Returns AV_HWDEVICE_TYPE_NONE
394
+ * ```
395
+ *
396
+ * @see [av_hwdevice_find_type_by_name](https://ffmpeg.org/doxygen/7.1/hwcontext_8h.html#a541943ddced791765349645a30adfa4d) - FFmpeg Doxygen
397
+ */
398
+ export function avGetHardwareDeviceTypeFromName(name) {
399
+ return bindings.avGetHardwareDeviceTypeFromName(name);
400
+ }
401
+ /**
402
+ * Get media type string.
403
+ *
404
+ * Returns a human-readable string for the media type.
405
+ *
406
+ * Direct mapping to av_get_media_type_string().
407
+ *
408
+ * @param mediaType - Media type enum
409
+ *
410
+ * @returns Media type name, or null if unknown
411
+ *
412
+ * @example
413
+ * ```typescript
414
+ * import { AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO } from 'node-av/constants';
415
+ *
416
+ * const video = avGetMediaTypeString(AVMEDIA_TYPE_VIDEO); // Returns "video"
417
+ * const audio = avGetMediaTypeString(AVMEDIA_TYPE_AUDIO); // Returns "audio"
418
+ * ```
419
+ *
420
+ * @see [av_get_media_type_string](https://ffmpeg.org/doxygen/7.1/group__lavu__misc.html#gaf21645cfa855b2caf9699d7dc7b2d08e) - FFmpeg Doxygen
421
+ */
422
+ export function avGetMediaTypeString(mediaType) {
423
+ return bindings.avGetMediaTypeString(mediaType);
424
+ }
425
+ /**
426
+ * Allocate image buffer.
427
+ *
428
+ * Allocates a buffer large enough to hold an image with the specified dimensions
429
+ * and pixel format. Returns buffer and layout information.
430
+ *
431
+ * Direct mapping to av_image_alloc().
432
+ *
433
+ * @param width - Image width in pixels
434
+ *
435
+ * @param height - Image height in pixels
436
+ *
437
+ * @param pixFmt - Pixel format
438
+ *
439
+ * @param align - Buffer alignment (typically 1 or 32)
440
+ *
441
+ * @returns Object with buffer, size, and line sizes
442
+ *
443
+ * @throws {FFmpegError} If allocation fails
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
448
+ *
449
+ * const { buffer, size, linesizes } = avImageAlloc(
450
+ * 1920, 1080, AV_PIX_FMT_YUV420P, 32
451
+ * );
452
+ * console.log(`Allocated ${size} bytes`);
453
+ * console.log(`Line sizes: ${linesizes}`);
454
+ * ```
455
+ *
456
+ * @see [av_image_alloc](https://ffmpeg.org/doxygen/7.1/group__lavu__picture.html#ga841e0a89a642e24141af1918a2c10448) - FFmpeg Doxygen
457
+ * @see {@link avImageGetBufferSize} To calculate size without allocating
458
+ */
459
+ export function avImageAlloc(width, height, pixFmt, align) {
460
+ const result = bindings.avImageAlloc(width, height, pixFmt, align);
461
+ if (typeof result === 'number') {
462
+ // Error code returned instead of object
463
+ throw new FFmpegError(result);
464
+ }
465
+ return result;
466
+ }
467
+ /**
468
+ * Copy image data.
469
+ *
470
+ * Copies image data from source to destination buffers.
471
+ *
472
+ * Direct mapping to av_image_copy2().
473
+ *
474
+ * @param dstData - Destination data planes
475
+ *
476
+ * @param dstLinesizes - Destination bytes per line
477
+ *
478
+ * @param srcData - Source data planes
479
+ *
480
+ * @param srcLinesizes - Source bytes per line
481
+ *
482
+ * @param pixFmt - Pixel format
483
+ *
484
+ * @param width - Image width
485
+ *
486
+ * @param height - Image height
487
+ *
488
+ * @example
489
+ * ```typescript
490
+ * avImageCopy2(
491
+ * dstPlanes, dstStrides,
492
+ * srcPlanes, srcStrides,
493
+ * AV_PIX_FMT_YUV420P, 1920, 1080
494
+ * );
495
+ * ```
496
+ *
497
+ * @see [av_image_copy2](https://ffmpeg.org/doxygen/7.1/group__lavu__picture.html#ga911cb7d723163b88bdbbdacbeeaacf2d) - FFmpeg Doxygen
498
+ */
499
+ export function avImageCopy2(dstData, dstLinesizes, srcData, srcLinesizes, pixFmt, width, height) {
500
+ bindings.avImageCopy2(dstData, dstLinesizes, srcData, srcLinesizes, pixFmt, width, height);
501
+ }
502
+ /**
503
+ * Get image buffer size.
504
+ *
505
+ * Calculates the required buffer size for an image without allocating.
506
+ *
507
+ * Direct mapping to av_image_get_buffer_size().
508
+ *
509
+ * @param pixFmt - Pixel format
510
+ *
511
+ * @param width - Image width
512
+ *
513
+ * @param height - Image height
514
+ *
515
+ * @param align - Buffer alignment
516
+ *
517
+ * @returns Required buffer size in bytes
518
+ *
519
+ * @example
520
+ * ```typescript
521
+ * import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
522
+ *
523
+ * const size = avImageGetBufferSize(AV_PIX_FMT_RGB24, 1920, 1080, 1);
524
+ * console.log(`Need ${size} bytes for Full HD RGB24`);
525
+ * ```
526
+ *
527
+ * @see [av_image_get_buffer_size](https://ffmpeg.org/doxygen/7.1/group__lavu__picture.html#ga24a67963c3ae0054a2a4bab35930e694) - FFmpeg Doxygen
528
+ * @see {@link avImageAlloc} To allocate the buffer
529
+ */
530
+ export function avImageGetBufferSize(pixFmt, width, height, align) {
531
+ return bindings.avImageGetBufferSize(pixFmt, width, height, align);
532
+ }
533
+ /**
534
+ * Copy image to buffer.
535
+ *
536
+ * Copies image data from separate planes to a single contiguous buffer.
537
+ *
538
+ * Direct mapping to av_image_copy_to_buffer().
539
+ *
540
+ * @param dst - Destination buffer
541
+ *
542
+ * @param dstSize - Destination buffer size
543
+ *
544
+ * @param srcData - Source data planes
545
+ *
546
+ * @param srcLinesize - Source bytes per line
547
+ *
548
+ * @param pixFmt - Pixel format
549
+ *
550
+ * @param width - Image width
551
+ *
552
+ * @param height - Image height
553
+ *
554
+ * @param align - Buffer alignment
555
+ *
556
+ * @returns Bytes written, or negative AVERROR
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * const buffer = Buffer.alloc(bufferSize);
561
+ * const written = avImageCopyToBuffer(
562
+ * buffer, bufferSize,
563
+ * srcPlanes, srcStrides,
564
+ * AV_PIX_FMT_YUV420P, 1920, 1080, 1
565
+ * );
566
+ * ```
567
+ *
568
+ * @see [av_image_copy_to_buffer](https://ffmpeg.org/doxygen/7.1/group__lavu__picture.html#ga6f8576f1ef0c2d9a9f7c5ac7f9a28c52) - FFmpeg Doxygen
569
+ */
570
+ export function avImageCopyToBuffer(dst, dstSize, srcData, srcLinesize, pixFmt, width, height, align) {
571
+ return bindings.avImageCopyToBuffer(dst, dstSize, srcData, srcLinesize, pixFmt, width, height, align);
572
+ }
573
+ /**
574
+ * Convert timestamp to string.
575
+ *
576
+ * Converts a timestamp to a string representation.
577
+ *
578
+ * Direct mapping to av_ts2str().
579
+ *
580
+ * @param ts - Timestamp value
581
+ *
582
+ * @returns String representation
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * const str1 = avTs2Str(1234567n); // Returns "1234567"
587
+ * const str2 = avTs2Str(null); // Returns "NOPTS"
588
+ * ```
589
+ *
590
+ * @see [av_ts2str](https://ffmpeg.org/doxygen/7.1/timestamp_8h.html#a86d797e907fa454ed5fd34bfb0bcd747) - FFmpeg Doxygen
591
+ */
592
+ export function avTs2Str(ts) {
593
+ return bindings.avTs2Str(ts);
594
+ }
595
+ /**
596
+ * Convert timestamp to time string.
597
+ *
598
+ * Converts a timestamp to a time string using the specified time base.
599
+ *
600
+ * Direct mapping to av_ts2timestr().
601
+ *
602
+ * @param ts - Timestamp value
603
+ *
604
+ * @param timeBase - Time base for conversion
605
+ *
606
+ * @returns Time string representation
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * const timeStr = avTs2TimeStr(90000n, { num: 1, den: 90000 }); // Returns "1.000000"
611
+ * const nopts = avTs2TimeStr(null, { num: 1, den: 1000 }); // Returns "NOPTS"
612
+ * ```
613
+ *
614
+ * @see [av_ts2timestr](https://ffmpeg.org/doxygen/7.1/timestamp_8h.html#ad344b91ede6b86fc0a530611293f42da) - FFmpeg Doxygen
615
+ */
616
+ export function avTs2TimeStr(ts, timeBase) {
617
+ if (!timeBase) {
618
+ return avTs2Str(ts);
619
+ }
620
+ return bindings.avTs2TimeStr(ts, timeBase);
621
+ }
622
+ /**
623
+ * Allocate image arrays.
624
+ *
625
+ * Allocates image data as separate plane arrays.
626
+ *
627
+ * @param width - Image width
628
+ *
629
+ * @param height - Image height
630
+ *
631
+ * @param pixFmt - Pixel format
632
+ *
633
+ * @param align - Buffer alignment
634
+ *
635
+ * @returns Object with data planes, line sizes, and total size
636
+ *
637
+ * @example
638
+ * ```typescript
639
+ * const { data, linesizes, size } = avImageAllocArrays(
640
+ * 1920, 1080, AV_PIX_FMT_YUV420P, 32
641
+ * );
642
+ * console.log(`Allocated ${data.length} planes, total ${size} bytes`);
643
+ * ```
644
+ */
645
+ export function avImageAllocArrays(width, height, pixFmt, align) {
646
+ const result = avImageAlloc(width, height, pixFmt, align);
647
+ // Split the buffer into planes based on pixel format
648
+ const data = [];
649
+ const linesizes = result.linesizes;
650
+ // For now, we'll treat it as a single buffer
651
+ // In a real implementation, we'd need to know the plane layout for each pixel format
652
+ data[0] = result.buffer;
653
+ return {
654
+ data,
655
+ linesizes,
656
+ size: result.size,
657
+ };
658
+ }
659
+ /**
660
+ * Compare timestamps.
661
+ *
662
+ * Compares two timestamps with different time bases.
663
+ *
664
+ * Direct mapping to av_compare_ts().
665
+ *
666
+ * @param tsA - First timestamp
667
+ *
668
+ * @param tbA - First time base
669
+ *
670
+ * @param tsB - Second timestamp
671
+ *
672
+ * @param tbB - Second time base
673
+ *
674
+ * @returns -1 if A < B, 0 if A == B, 1 if A > B
675
+ *
676
+ * @example
677
+ * ```typescript
678
+ * const cmp = avCompareTs(
679
+ * 1000n, { num: 1, den: 1000 }, // 1 second
680
+ * 900n, { num: 1, den: 900 } // 1 second
681
+ * );
682
+ * // Returns 0 (equal)
683
+ * ```
684
+ *
685
+ * @see [av_compare_ts](https://ffmpeg.org/doxygen/7.1/group__lavu__math.html#ga151744358fff630942b926e67e67c415) - FFmpeg Doxygen
686
+ */
687
+ export function avCompareTs(tsA, tbA, tsB, tbB) {
688
+ return bindings.avCompareTs(tsA, tbA, tsB, tbB);
689
+ }
690
+ /**
691
+ * Rescale timestamp.
692
+ *
693
+ * Rescales a timestamp from one time base to another.
694
+ *
695
+ * Direct mapping to av_rescale_q().
696
+ *
697
+ * @param a - Timestamp to rescale
698
+ *
699
+ * @param bq - Source time base
700
+ *
701
+ * @param cq - Destination time base
702
+ *
703
+ * @returns Rescaled timestamp
704
+ *
705
+ * @example
706
+ * ```typescript
707
+ * // Convert 1 second from 1000Hz to 90kHz
708
+ * const rescaled = avRescaleQ(
709
+ * 1000n,
710
+ * { num: 1, den: 1000 }, // 1000 Hz
711
+ * { num: 1, den: 90000 } // 90 kHz
712
+ * );
713
+ * // Returns 90000n
714
+ * ```
715
+ *
716
+ * @see [av_rescale_q](https://ffmpeg.org/doxygen/7.1/group__lavu__math.html#gaf02994a8bbeaa91d4757df179cbe567f) - FFmpeg Doxygen
717
+ */
718
+ export function avRescaleQ(a, bq, cq) {
719
+ return bindings.avRescaleQ(a, bq, cq);
720
+ }
721
+ /**
722
+ * Sleep for microseconds.
723
+ *
724
+ * Suspends execution for the specified number of microseconds.
725
+ *
726
+ * Direct mapping to av_usleep().
727
+ *
728
+ * @param usec - Microseconds to sleep
729
+ *
730
+ * @example
731
+ * ```typescript
732
+ * avUsleep(1000000); // Sleep for 1 second
733
+ * avUsleep(16667); // Sleep for ~16.67ms (60fps frame time)
734
+ * ```
735
+ *
736
+ * @see [av_usleep](https://ffmpeg.org/doxygen/7.1/time_8c.html#a4eee9c65835652a808973f4bc1641a51) - FFmpeg Doxygen
737
+ */
738
+ export function avUsleep(usec) {
739
+ bindings.avUsleep(usec);
740
+ }
741
+ /**
742
+ * Rescale with rounding.
743
+ *
744
+ * Rescales a value with specified rounding behavior.
745
+ *
746
+ * Direct mapping to av_rescale_rnd().
747
+ *
748
+ * @param a - Value to rescale
749
+ *
750
+ * @param b - Multiplier
751
+ *
752
+ * @param c - Divisor
753
+ *
754
+ * @param rnd - Rounding mode (AV_ROUND_*)
755
+ *
756
+ * @returns Rescaled value
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * import { AV_ROUND_NEAR_INF } from 'node-av/constants';
761
+ *
762
+ * const rescaled = avRescaleRnd(1000n, 90000n, 1000n, AV_ROUND_NEAR_INF);
763
+ * // Returns 90000n
764
+ * ```
765
+ *
766
+ * @see [av_rescale_rnd](https://ffmpeg.org/doxygen/7.1/group__lavu__math.html#ga82d40664213508918093822461cc597e) - FFmpeg Doxygen
767
+ */
768
+ export function avRescaleRnd(a, b, c, rnd) {
769
+ return bindings.avRescaleRnd(a, b, c, rnd);
770
+ }
771
+ /**
772
+ * Rescale a timestamp while preserving accuracy with coarse input timebases.
773
+ *
774
+ * Used for audio streamcopy to maintain accuracy when input timebase is coarse.
775
+ * Direct mapping to av_rescale_delta().
776
+ *
777
+ * @param inTb - Input timebase
778
+ *
779
+ * @param inTs - Input timestamp
780
+ *
781
+ * @param fsTb - Duration timebase (e.g., {1, sampleRate})
782
+ *
783
+ * @param duration - Duration in fsTb units
784
+ *
785
+ * @param lastRef - Reference object with `value` property (modified by function)
786
+ *
787
+ * @param lastRef.value - Last output timestamp (bigint)
788
+ *
789
+ * @param outTb - Output timebase
790
+ *
791
+ * @returns Rescaled timestamp
792
+ *
793
+ * @example
794
+ * ```typescript
795
+ * const inTb = { num: 1, den: 48000 };
796
+ * const inTs = 1000000n;
797
+ * const fsTb = { num: 1, den: 44100 };
798
+ * const duration = 1024;
799
+ * const lastRef = { value: 0n };
800
+ * const outTb = { num: 1, den: 96000 };
801
+ *
802
+ * const rescaled = avRescaleDelta(inTb, inTs, fsTb, duration, lastRef, outTb);
803
+ * ```
804
+ *
805
+ * @see [av_rescale_delta](https://ffmpeg.org/doxygen/7.1/group__lavu__math.html) - FFmpeg Doxygen
806
+ */
807
+ export function avRescaleDelta(inTb, inTs, fsTb, duration, lastRef, outTb) {
808
+ return bindings.avRescaleDelta(inTb, inTs, fsTb, duration, lastRef, outTb);
809
+ }
810
+ /**
811
+ * Multiply two rational numbers.
812
+ *
813
+ * Multiplies two rational numbers using FFmpeg's av_mul_q() which normalizes the result.
814
+ * This is more accurate than manual multiplication as it reduces the fraction.
815
+ *
816
+ * Direct mapping to av_mul_q().
817
+ *
818
+ * @param a - First rational number
819
+ *
820
+ * @param b - Second rational number
821
+ *
822
+ * @returns Product of a and b as a normalized rational
823
+ *
824
+ * @example
825
+ * ```typescript
826
+ * // Multiply framerate by 2
827
+ * const framerate = { num: 25, den: 1 };
828
+ * const doubled = avMulQ(framerate, { num: 2, den: 1 });
829
+ * // Returns { num: 50, den: 1 }
830
+ *
831
+ * // Calculate field rate for interlaced video
832
+ * const fieldRate = avMulQ(framerate, { num: 2, den: 1 });
833
+ * ```
834
+ *
835
+ * @see [av_mul_q](https://ffmpeg.org/doxygen/trunk/group__lavu__math__rational.html#ga89c0e84e30e2f90196e11fc254e4fc3f) - FFmpeg Doxygen
836
+ */
837
+ export function avMulQ(a, b) {
838
+ return bindings.avMulQ(a, b);
839
+ }
840
+ /**
841
+ * Invert a rational number.
842
+ *
843
+ * Returns the reciprocal of a rational number using FFmpeg's av_inv_q().
844
+ * Swaps numerator and denominator: (a/b) becomes (b/a).
845
+ *
846
+ * Direct mapping to av_inv_q().
847
+ *
848
+ * @param q - Rational number to invert
849
+ *
850
+ * @returns Inverted rational (reciprocal)
851
+ *
852
+ * @example
853
+ * ```typescript
854
+ * // Convert framerate to frame duration
855
+ * const framerate = { num: 25, den: 1 }; // 25 fps
856
+ * const frameDuration = avInvQ(framerate); // 1/25 seconds
857
+ * // Returns { num: 1, den: 25 }
858
+ *
859
+ * // Get timebase from framerate
860
+ * const timebase = avInvQ({ num: 30000, den: 1001 }); // NTSC
861
+ * // Returns { num: 1001, den: 30000 }
862
+ * ```
863
+ *
864
+ * @see [av_inv_q](https://ffmpeg.org/doxygen/trunk/group__lavu__math__rational.html#ga587a784cb48299feea51d7dbbc6cc38c) - FFmpeg Doxygen
865
+ */
866
+ export function avInvQ(q) {
867
+ return bindings.avInvQ(q);
868
+ }
869
+ /**
870
+ * Add two rational numbers.
871
+ *
872
+ * Adds two rational numbers using FFmpeg's av_add_q() which normalizes the result.
873
+ * This is more accurate than manual addition as it reduces the fraction.
874
+ *
875
+ * Direct mapping to av_add_q().
876
+ *
877
+ * @param a - First rational number
878
+ *
879
+ * @param b - Second rational number
880
+ *
881
+ * @returns Sum of a and b as a normalized rational
882
+ *
883
+ * @example
884
+ * ```typescript
885
+ * // Add two fractions
886
+ * const a = { num: 1, den: 2 }; // 1/2
887
+ * const b = { num: 1, den: 4 }; // 1/4
888
+ * const sum = avAddQ(a, b); // 3/4
889
+ * // Returns { num: 3, den: 4 }
890
+ *
891
+ * // Add timestamps with different timebases
892
+ * const ts1 = { num: 1000, den: 30000 };
893
+ * const ts2 = { num: 500, den: 30000 };
894
+ * const total = avAddQ(ts1, ts2);
895
+ * // Returns { num: 1, den: 20 } (normalized from 1500/30000)
896
+ * ```
897
+ *
898
+ * @see [av_add_q](https://ffmpeg.org/doxygen/trunk/group__lavu__math__rational.html#gac4af1feb227bd1095fc2cab42d933f52) - FFmpeg Doxygen
899
+ */
900
+ export function avAddQ(a, b) {
901
+ return bindings.avAddQ(a, b);
902
+ }
903
+ /**
904
+ * Calculate greatest common divisor.
905
+ *
906
+ * Computes the GCD of two integers using FFmpeg's av_gcd().
907
+ * Uses the Euclidean algorithm for efficient computation.
908
+ *
909
+ * Direct mapping to av_gcd().
910
+ *
911
+ * @param a - First integer
912
+ *
913
+ * @param b - Second integer
914
+ *
915
+ * @returns Greatest common divisor of a and b
916
+ *
917
+ * @example
918
+ * ```typescript
919
+ * const gcd = avGcd(48000, 44100);
920
+ * console.log(gcd); // 300
921
+ *
922
+ * // Used for calculating LCM
923
+ * const lcm = (a * b) / avGcd(a, b);
924
+ * ```
925
+ *
926
+ * @see [av_gcd](https://ffmpeg.org/doxygen/trunk/group__lavu__math.html#ga0e8419780352de538c1c15098cb1a587) - FFmpeg Doxygen
927
+ */
928
+ export function avGcd(a, b) {
929
+ return bindings.avGcd(a, b);
930
+ }
931
+ /**
932
+ * Rescale timestamp with specified rounding mode.
933
+ *
934
+ * Rescales a timestamp from one time base to another with specific rounding behavior.
935
+ * More control than avRescaleQ() which uses default rounding.
936
+ *
937
+ * Direct mapping to av_rescale_q_rnd().
938
+ *
939
+ * @param a - Timestamp to rescale
940
+ *
941
+ * @param bq - Source time base
942
+ *
943
+ * @param cq - Destination time base
944
+ *
945
+ * @param rnd - Rounding mode (AV_ROUND_ZERO, AV_ROUND_INF, AV_ROUND_DOWN, AV_ROUND_UP, AV_ROUND_NEAR_INF)
946
+ *
947
+ * @returns Rescaled timestamp
948
+ *
949
+ * @example
950
+ * ```typescript
951
+ * import { AV_ROUND_UP, AV_ROUND_DOWN } from 'node-av/constants';
952
+ *
953
+ * const pts = 1000n;
954
+ * const srcTb = { num: 1, den: 48000 };
955
+ * const dstTb = { num: 1, den: 90000 };
956
+ *
957
+ * // Round up for safer comparisons
958
+ * const ptsUp = avRescaleQRnd(pts, srcTb, dstTb, AV_ROUND_UP);
959
+ *
960
+ * // Round down for conservative timestamps
961
+ * const ptsDown = avRescaleQRnd(pts, srcTb, dstTb, AV_ROUND_DOWN);
962
+ * ```
963
+ *
964
+ * @see [av_rescale_q_rnd](https://ffmpeg.org/doxygen/trunk/group__lavu__math.html#ga60044a302e86b5c2d8b19a81c8179f30) - FFmpeg Doxygen
965
+ */
966
+ export function avRescaleQRnd(a, bq, cq, rnd) {
967
+ return bindings.avRescaleQRnd(a, bq, cq, rnd);
968
+ }
969
+ /**
970
+ * Get the duration of a single audio frame in samples.
971
+ *
972
+ * Returns the number of samples per audio frame for codecs with constant frame size,
973
+ * or calculates it based on frame bytes for variable frame size codecs.
974
+ *
975
+ * Direct mapping to av_get_audio_frame_duration2().
976
+ *
977
+ * @param codecpar - Codec parameters
978
+ *
979
+ * @param frameBytes - Size of the frame in bytes
980
+ *
981
+ * @returns Number of samples in the frame, or 0 if unknown
982
+ *
983
+ * @example
984
+ * ```typescript
985
+ * const frameDuration = avGetAudioFrameDuration2(codecpar, frameBytes);
986
+ * ```
987
+ *
988
+ * @see [av_get_audio_frame_duration2](https://ffmpeg.org/doxygen/7.1/group__lavc__misc.html) - FFmpeg Doxygen
989
+ */
990
+ export function avGetAudioFrameDuration2(codecpar, frameBytes) {
991
+ return bindings.avGetAudioFrameDuration2(codecpar.getNative(), frameBytes);
992
+ }
993
+ /**
994
+ * Allocate audio samples buffer.
995
+ *
996
+ * Allocates buffers for audio samples with the specified format.
997
+ *
998
+ * Direct mapping to av_samples_alloc().
999
+ *
1000
+ * @param nbChannels - Number of audio channels
1001
+ *
1002
+ * @param nbSamples - Number of samples per channel
1003
+ *
1004
+ * @param sampleFmt - Sample format
1005
+ *
1006
+ * @param align - Buffer alignment
1007
+ *
1008
+ * @returns Object with data buffers, line size, and total size
1009
+ *
1010
+ * @throws {FFmpegError} If allocation fails
1011
+ *
1012
+ * @example
1013
+ * ```typescript
1014
+ * import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
1015
+ *
1016
+ * const { data, linesize, size } = avSamplesAlloc(
1017
+ * 2, 1024, AV_SAMPLE_FMT_FLTP, 0
1018
+ * );
1019
+ * console.log(`Allocated ${data.length} buffers, ${size} bytes total`);
1020
+ * ```
1021
+ *
1022
+ * @see [av_samples_alloc](https://ffmpeg.org/doxygen/7.1/group__lavu__sampmanip.html#ga4db4c77f928d32c7d8854732f50b8c04) - FFmpeg Doxygen
1023
+ * @see {@link avSamplesGetBufferSize} To calculate size without allocating
1024
+ */
1025
+ export function avSamplesAlloc(nbChannels, nbSamples, sampleFmt, align) {
1026
+ const result = bindings.avSamplesAlloc(nbChannels, nbSamples, sampleFmt, align);
1027
+ if (typeof result === 'number') {
1028
+ throw new FFmpegError(result);
1029
+ }
1030
+ return result;
1031
+ }
1032
+ /**
1033
+ * Get audio samples buffer size.
1034
+ *
1035
+ * Calculates the required buffer size for audio samples.
1036
+ *
1037
+ * Direct mapping to av_samples_get_buffer_size().
1038
+ *
1039
+ * @param nbChannels - Number of channels
1040
+ *
1041
+ * @param nbSamples - Number of samples per channel
1042
+ *
1043
+ * @param sampleFmt - Sample format
1044
+ *
1045
+ * @param align - Buffer alignment
1046
+ *
1047
+ * @returns Object with size and line size
1048
+ *
1049
+ * @throws {FFmpegError} If parameters are invalid
1050
+ *
1051
+ * @example
1052
+ * ```typescript
1053
+ * import { AV_SAMPLE_FMT_S16 } from 'node-av/constants';
1054
+ *
1055
+ * const { size, linesize } = avSamplesGetBufferSize(
1056
+ * 2, 1024, AV_SAMPLE_FMT_S16, 0
1057
+ * );
1058
+ * console.log(`Need ${size} bytes, ${linesize} per channel`);
1059
+ * ```
1060
+ *
1061
+ * @see [av_samples_get_buffer_size](https://ffmpeg.org/doxygen/7.1/group__lavu__sampfmts.html#gaa7368bc4e3a366b688e81938ed55eb06) - FFmpeg Doxygen
1062
+ * @see {@link avSamplesAlloc} To allocate the buffer
1063
+ */
1064
+ export function avSamplesGetBufferSize(nbChannels, nbSamples, sampleFmt, align) {
1065
+ const result = bindings.avSamplesGetBufferSize(nbChannels, nbSamples, sampleFmt, align);
1066
+ if (typeof result === 'number') {
1067
+ throw new FFmpegError(result);
1068
+ }
1069
+ return result;
1070
+ }
1071
+ /**
1072
+ * Image crop function.
1073
+ *
1074
+ * Crops an image region from source buffer to destination buffer.
1075
+ *
1076
+ * @param dstBuffer - Destination buffer (must be pre-allocated)
1077
+ *
1078
+ * @param srcBuffer - Source buffer containing the image
1079
+ *
1080
+ * @param pixFmt - Pixel format
1081
+ *
1082
+ * @param srcWidth - Source image width
1083
+ *
1084
+ * @param srcHeight - Source image height
1085
+ *
1086
+ * @param cropX - X coordinate of crop region (left)
1087
+ *
1088
+ * @param cropY - Y coordinate of crop region (top)
1089
+ *
1090
+ * @param cropWidth - Width of crop region
1091
+ *
1092
+ * @param cropHeight - Height of crop region
1093
+ *
1094
+ * @returns Number of bytes copied
1095
+ *
1096
+ * @example
1097
+ * ```typescript
1098
+ * import { AV_PIX_FMT_NV12 } from 'node-av/constants';
1099
+ *
1100
+ * const dstSize = avImageGetBufferSize(AV_PIX_FMT_NV12, 100, 100, 1);
1101
+ * const dstBuffer = Buffer.alloc(dstSize);
1102
+ *
1103
+ * const bytesCopied = avImageCrop(
1104
+ * dstBuffer, srcBuffer,
1105
+ * AV_PIX_FMT_NV12,
1106
+ * 320, 180, // source dimensions
1107
+ * 10, 10, // crop position
1108
+ * 100, 100 // crop size
1109
+ * );
1110
+ * ```
1111
+ */
1112
+ export function avImageCrop(dstBuffer, srcBuffer, pixFmt, srcWidth, srcHeight, cropX, cropY, cropWidth, cropHeight) {
1113
+ return bindings.avImageCrop(dstBuffer, srcBuffer, pixFmt, srcWidth, srcHeight, cropX, cropY, cropWidth, cropHeight);
1114
+ }
1115
+ /**
1116
+ * Describe channel layout.
1117
+ *
1118
+ * Returns a human-readable description of a channel layout.
1119
+ *
1120
+ * Direct mapping to av_channel_layout_describe().
1121
+ *
1122
+ * @param channelLayout - Channel layout to describe
1123
+ *
1124
+ * @returns Layout description string, or null
1125
+ *
1126
+ * @example
1127
+ * ```typescript
1128
+ * const stereo = { nbChannels: 2, order: 1, u: { mask: 3n } };
1129
+ * const desc = avChannelLayoutDescribe(stereo); // Returns "stereo"
1130
+ * ```
1131
+ *
1132
+ * @see [av_channel_layout_describe](https://ffmpeg.org/doxygen/7.1/group__lavu__audio__channels.html#gacc7d7d1a280248aafb8f9196c9d4e24f) - FFmpeg Doxygen
1133
+ */
1134
+ export function avChannelLayoutDescribe(channelLayout) {
1135
+ return bindings.avChannelLayoutDescribe(channelLayout);
1136
+ }
1137
+ /**
1138
+ * Create SDP from format contexts.
1139
+ *
1140
+ * Creates an SDP (Session Description Protocol) string from format contexts.
1141
+ * Used for RTP/RTSP streaming.
1142
+ *
1143
+ * Direct mapping to av_sdp_create().
1144
+ *
1145
+ * @param contexts - Array of format contexts
1146
+ *
1147
+ * @returns SDP string, or null on error
1148
+ *
1149
+ * @example
1150
+ * ```typescript
1151
+ * const sdp = avSdpCreate([outputContext]);
1152
+ * if (sdp) {
1153
+ * console.log('SDP:\n' + sdp);
1154
+ * }
1155
+ * ```
1156
+ *
1157
+ * @see [av_sdp_create](https://ffmpeg.org/doxygen/7.1/group__lavf__misc.html#gaa2a7353a6bb0c8726797abd56b176af0) - FFmpeg Doxygen
1158
+ */
1159
+ export function avSdpCreate(contexts) {
1160
+ if (!Array.isArray(contexts) || contexts.length === 0) {
1161
+ return null;
1162
+ }
1163
+ // Pass the native objects to the binding
1164
+ const nativeContexts = contexts
1165
+ .map((ctx) => {
1166
+ if (ctx && typeof ctx.getNative === 'function') {
1167
+ const nativeCtx = ctx.getNative();
1168
+ if (nativeCtx) {
1169
+ return nativeCtx;
1170
+ }
1171
+ }
1172
+ })
1173
+ .filter((ctx) => ctx !== undefined);
1174
+ // If no valid contexts after filtering, return null
1175
+ if (nativeContexts.length === 0) {
1176
+ return null;
1177
+ }
1178
+ return bindings.avSdpCreate(nativeContexts);
1179
+ }
1180
+ /**
1181
+ * Predict and update DTS timestamps for demuxed packets.
1182
+ *
1183
+ * This is a native implementation of FFmpeg's `ist_dts_update()`.
1184
+ * It predicts the next DTS based on codec type and stream metadata,
1185
+ * handling both audio (sample-based) and video (frame-rate-based) timing.
1186
+ *
1187
+ * @param packet - Native Packet
1188
+ *
1189
+ * @param stream - Native Stream
1190
+ *
1191
+ * @param state - Current DTS prediction state
1192
+ *
1193
+ * @returns Updated state with new DTS values
1194
+ *
1195
+ * @example
1196
+ * ```typescript
1197
+ * const newState = dtsPredict(packet, stream, {
1198
+ * sawFirstTs: false,
1199
+ * dts: AV_NOPTS_VALUE,
1200
+ * nextDts: AV_NOPTS_VALUE,
1201
+ * firstDts: AV_NOPTS_VALUE,
1202
+ * });
1203
+ * ```
1204
+ */
1205
+ export function dtsPredict(packet, stream, state) {
1206
+ return bindings.dtsPredict(packet.getNative(), stream.getNative(), state);
1207
+ }
1208
+ /**
1209
+ * Convert string to FourCC.
1210
+ *
1211
+ * Converts a 4-character string to a packed FourCC integer.
1212
+ *
1213
+ * @param str - 4-character string
1214
+ *
1215
+ * @returns Packed FourCC as unsigned 32-bit integer
1216
+ *
1217
+ * @example
1218
+ * ```typescript
1219
+ * const fourcc = stringToFourCC("avc1"); // Returns 828601953 / 0x31637661
1220
+ * ```
1221
+ */
1222
+ export function stringToFourCC(str) {
1223
+ return ((str.charCodeAt(0) << 0) | (str.charCodeAt(1) << 8) | (str.charCodeAt(2) << 16) | (str.charCodeAt(3) << 24)) >>> 0; // Convert to unsigned 32-bit
1224
+ }
1225
+ //# sourceMappingURL=utilities.js.map