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