node-av-lgpl 0.0.0 → 7.1.0-beta.2

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 +384 -0
  283. package/dist/lib/stream.js +525 -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,1509 @@
1
+ import { CodecContext } from '../lib/codec-context.js';
2
+ import { Codec } from '../lib/codec.js';
3
+ import { Frame } from '../lib/frame.js';
4
+ import { Packet } from '../lib/packet.js';
5
+ import { SchedulerControl } from './utilities/scheduler.js';
6
+ import type { AVCodecFlag, AVCodecID, AVThreadType, EncoderOptionsFor, EOFSignal, FFEncoderCodec } from '../constants/index.js';
7
+ import type { AudioFrameBufferOptions } from './audio-frame-buffer.js';
8
+ import type { Decoder } from './decoder.js';
9
+ import type { FilterComplexAPI } from './filter-complex.js';
10
+ import type { FilterAPI } from './filter.js';
11
+ import type { Muxer } from './muxer.js';
12
+ import type { ContextOptions } from './utilities/context-options.js';
13
+ /**
14
+ * A bitrate-style value: a number/bigint of bits per second, or a string with a
15
+ * unit suffix such as `'5M'` or `'128k'`.
16
+ */
17
+ type BitrateValue = number | bigint | string;
18
+ /**
19
+ * Fields to set on the encoder's {@link CodecContext}.
20
+ *
21
+ * The writable codec-context fields (derived from the class), with the
22
+ * rate-control fields widened to also accept a unit-suffixed string like `'5M'`.
23
+ */
24
+ export type EncoderContextOptions = Omit<ContextOptions<CodecContext>, 'bitRate' | 'rcMinRate' | 'rcMaxRate' | 'rcBufferSize'> & {
25
+ bitRate?: BitrateValue;
26
+ rcMinRate?: BitrateValue;
27
+ rcMaxRate?: BitrateValue;
28
+ rcBufferSize?: BitrateValue;
29
+ };
30
+ /**
31
+ * Options for encoder creation.
32
+ */
33
+ export interface EncoderOptions<C = unknown> {
34
+ /**
35
+ * Target bitrate.
36
+ *
37
+ * Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
38
+ * Used for rate control in video and audio encoding.
39
+ *
40
+ * @default The codec's default for audio, 1M for video
41
+ *
42
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { bitRate: '5M' }`.
43
+ */
44
+ bitrate?: number | bigint | string;
45
+ /**
46
+ * Minimum bitrate for rate control.
47
+ *
48
+ * Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
49
+ * Used with variable bitrate encoding to enforce quality floor.
50
+ *
51
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { rcMinRate: '1M' }`.
52
+ */
53
+ minRate?: number | bigint | string;
54
+ /**
55
+ * Maximum bitrate for rate control.
56
+ *
57
+ * Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
58
+ * Used with variable bitrate encoding to enforce bitrate ceiling.
59
+ *
60
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { rcMaxRate: '8M' }`.
61
+ */
62
+ maxRate?: number | bigint | string;
63
+ /**
64
+ * Rate control buffer size.
65
+ *
66
+ * Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
67
+ * Determines the decoder buffer model size for rate control.
68
+ *
69
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { rcBufferSize: '2M' }`.
70
+ */
71
+ bufSize?: number | bigint | string;
72
+ /**
73
+ * Group of Pictures (GOP) size.
74
+ *
75
+ * Number of frames between keyframes.
76
+ * Larger GOP improves compression but reduces seekability.
77
+ *
78
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { gopSize: 60 }`.
79
+ */
80
+ gopSize?: number;
81
+ /**
82
+ * Maximum number of consecutive B-frames.
83
+ *
84
+ * B-frames improve compression but increase encoding complexity.
85
+ * Maximum B-frames allowed between I or P frames.
86
+ *
87
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { maxBFrames: 0 }`.
88
+ */
89
+ maxBFrames?: number;
90
+ /**
91
+ * Fields to set on the underlying codec context.
92
+ *
93
+ * The home for all raw {@link CodecContext} settings: rate control
94
+ * (`bitRate`, `rcMinRate`, `rcMaxRate`, `rcBufferSize` — each accepting a
95
+ * unit-suffixed string like `'5M'`), `gopSize`, `maxBFrames`, threading, color
96
+ * /HDR metadata, profile, level, aspect ratio, etc. The allowed keys are
97
+ * derived from the class, so every writable field is available and correctly
98
+ * typed. Applied after node-av's derived settings (resolution, pixel/sample
99
+ * format, color, timebase) and immediately before `avcodec_open2`, so values
100
+ * here override the derived defaults.
101
+ *
102
+ * For the codec tag use a numeric FourCC here, or the string form (e.g.
103
+ * `'hvc1'`) via {@link EncoderOptions.configure}.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * await Encoder.create(FF_ENCODER_LIBX265, {
108
+ * decoder,
109
+ * context: {
110
+ * bitRate: '5M',
111
+ * gopSize: 60,
112
+ * colorPrimaries: AVCOL_PRI_BT2020,
113
+ * },
114
+ * });
115
+ * ```
116
+ */
117
+ context?: EncoderContextOptions;
118
+ /**
119
+ * Configure the underlying codec context just before it is opened.
120
+ *
121
+ * The imperative escape hatch for cases the {@link EncoderOptions.context} bag
122
+ * cannot express: additive flags via `setFlags`, other methods, conditional
123
+ * logic, or setter-only input forms (e.g. a `'hvc1'` FourCC string). Called
124
+ * with the encoder's {@link CodecContext} after `context` is applied and
125
+ * immediately before `avcodec_open2`.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * await Encoder.create(FF_ENCODER_LIBX265, {
130
+ * decoder,
131
+ * configure: (ctx) => {
132
+ * ctx.codecTag = 'hvc1';
133
+ * },
134
+ * });
135
+ * ```
136
+ */
137
+ configure?: (context: CodecContext) => void;
138
+ /**
139
+ * Optional decoder reference for metadata extraction.
140
+ *
141
+ * Used to extract bits_per_raw_sample and other decoder-specific properties.
142
+ * Helps maintain quality during transcoding.
143
+ */
144
+ decoder?: Decoder;
145
+ /**
146
+ * Optional filter reference for metadata extraction.
147
+ *
148
+ * Used to extract filter output parameters.
149
+ * Ensures encoder matches filter output characteristics.
150
+ */
151
+ filter?: FilterAPI | FilterComplexAPI;
152
+ /**
153
+ * Number of threads to use for encoding.
154
+ *
155
+ * Set to 0 to auto-detect based on CPU cores.
156
+ *
157
+ * @default 1
158
+ *
159
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { threadCount: 0 }`.
160
+ */
161
+ threadCount?: number;
162
+ /**
163
+ * Type of threading to use for encoding.
164
+ *
165
+ * - `FF_THREAD_FRAME` (1): Encode multiple frames in parallel.
166
+ * Higher throughput but adds latency (1 frame delay per thread).
167
+ *
168
+ * - `FF_THREAD_SLICE` (2): Encode parts of a single frame in parallel.
169
+ * Lower latency, suitable for real-time encoding.
170
+ *
171
+ * @default FFmpeg default (both methods, codec chooses best)
172
+ *
173
+ * @deprecated Use the {@link EncoderOptions.context} option instead, e.g. `context: { threadType: FF_THREAD_SLICE }`.
174
+ */
175
+ threadType?: AVThreadType;
176
+ /**
177
+ * Automatically resample incoming audio to a format the codec supports.
178
+ *
179
+ * Audio encoders only accept specific sample rates, sample formats, and channel
180
+ * layouts (e.g. libmp3lame rejects 96 kHz; AAC needs planar `fltp`). When `true`,
181
+ * the encoder transparently converts each frame to the nearest supported
182
+ * sample rate / sample format / channel layout (like `ffmpeg`'s automatic
183
+ * `aresample`). When `false` (default), an unsupported input raises a descriptive
184
+ * error instead — keeping behaviour explicit and 1:1 with the codec.
185
+ *
186
+ * Has no effect on video.
187
+ *
188
+ * @default false
189
+ */
190
+ autoResample?: boolean;
191
+ /**
192
+ * Timing of audio for codecs with a fixed frame size (AAC, Opus, MP3, …).
193
+ *
194
+ * Such codecs take their input through an {@link AudioFrameBuffer}, which keeps the
195
+ * timestamps of the input frames, fills small gaps with silence and drops small
196
+ * overlaps. Set `maxGapFill: 0` for real-time outputs such as RTP, so that input gaps
197
+ * become timestamp jumps instead of a burst of late silence, or `timestamps: 'samples'`
198
+ * to count the output from 0 by its samples regardless of the input timestamps. Has
199
+ * no effect on video or on codecs that take any frame size; `autoResample` keeps the
200
+ * input timing for those either way.
201
+ *
202
+ * @default {}
203
+ */
204
+ audioFrameBuffer?: AudioFrameBufferOptions;
205
+ /**
206
+ * Automatically convert incoming video to a pixel format the codec supports.
207
+ *
208
+ * Video encoders only accept specific pixel formats (e.g. libx264 wants planar
209
+ * YUV like `yuv420p` and rejects `rgb24`). When `true`, the encoder transparently
210
+ * converts each frame to the least-loss supported pixel format via swscale (like
211
+ * `ffmpeg`'s automatic `format` filter), keeping the same resolution. When `false`
212
+ * (default), an unsupported input raises a descriptive error instead — keeping
213
+ * behaviour explicit and 1:1 with the codec.
214
+ *
215
+ * Resolution is never changed (the encoder already adopts the frame's dimensions),
216
+ * and hardware frames are left untouched (their format is negotiated via the
217
+ * hardware frames context). Has no effect on audio.
218
+ *
219
+ * @default false
220
+ */
221
+ autoFormat?: boolean;
222
+ /**
223
+ * Keep each frame's `pictType` instead of clearing it before encoding.
224
+ *
225
+ * By default the encoder resets `frame.pictType` to `AV_PICTURE_TYPE_NONE`,
226
+ * since decoded input frames carry frame-type hints that should not drive the
227
+ * output GOP structure when re-encoding. That clearing also discards a
228
+ * deliberately requested keyframe: setting `frame.pictType = AV_PICTURE_TYPE_I`
229
+ * (with `forced-idr` on encoders that support it) is the standard FFmpeg way
230
+ * to force an IDR for a specific frame.
231
+ *
232
+ * Set to `true` to pass `pictType` through — needed for on-demand keyframes in
233
+ * live streaming (packet-loss recovery, a late-joining viewer). Leave `false`
234
+ * for transcoding, where the input's frame types should be ignored.
235
+ *
236
+ * @default false
237
+ */
238
+ preserveFramePictType?: boolean;
239
+ /**
240
+ * Additional codec-specific options.
241
+ *
242
+ * Key-value pairs of FFmpeg private codec options, passed directly to the encoder.
243
+ * When the codec is created from a branded constant (e.g. `FF_ENCODER_LIBX264`),
244
+ * these are strongly typed to that codec's known options (autocomplete + validation);
245
+ * otherwise any string/number/boolean values are accepted.
246
+ */
247
+ options?: EncoderOptionsFor<C>;
248
+ /**
249
+ * AbortSignal for cancellation.
250
+ *
251
+ * When aborted, async generators stop yielding and async methods throw AbortError.
252
+ */
253
+ signal?: AbortSignal;
254
+ }
255
+ /**
256
+ * High-level encoder for audio and video streams.
257
+ *
258
+ * Provides a simplified interface for encoding media frames to packets.
259
+ * Handles codec initialization, hardware acceleration setup, and packet management.
260
+ * Supports both synchronous frame-by-frame encoding and async iteration over packets.
261
+ * Essential component in media processing pipelines for converting raw frames to compressed data.
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * import { Encoder } from 'node-av/api';
266
+ * import { AV_CODEC_ID_H264, FF_ENCODER_LIBX264 } from 'node-av/constants';
267
+ *
268
+ * // Create H.264 encoder
269
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, {
270
+ * type: 'video',
271
+ * width: 1920,
272
+ * height: 1080,
273
+ * pixelFormat: AV_PIX_FMT_YUV420P,
274
+ * timeBase: { num: 1, den: 30 },
275
+ * frameRate: { num: 30, den: 1 }
276
+ * }, {
277
+ * bitrate: '5M',
278
+ * gopSize: 60
279
+ * });
280
+ *
281
+ * // Encode frames
282
+ * const packet = await encoder.encode(frame);
283
+ * if (packet) {
284
+ * await output.writePacket(packet);
285
+ * packet.free();
286
+ * }
287
+ * ```
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * // Hardware-accelerated encoding with lazy initialization
292
+ * import { HardwareContext } from 'node-av/api';
293
+ * import { FF_ENCODER_H264_VIDEOTOOLBOX } from 'node-av/constants';
294
+ *
295
+ * const hw = HardwareContext.auto();
296
+ * const encoderCodec = hw?.getEncoderCodec('h264') ?? FF_ENCODER_H264_VIDEOTOOLBOX;
297
+ * const encoder = await Encoder.create(encoderCodec, {
298
+ * timeBase: video.timeBase,
299
+ * bitrate: '10M'
300
+ * });
301
+ *
302
+ * // Hardware context will be detected from first frame's hw_frames_ctx
303
+ * for await (const packet of encoder.packets(frames)) {
304
+ * await output.writePacket(packet);
305
+ * packet.free();
306
+ * }
307
+ * ```
308
+ *
309
+ * @see {@link Decoder} For decoding packets to frames
310
+ * @see {@link Muxer} For writing encoded packets
311
+ * @see {@link HardwareContext} For GPU acceleration
312
+ */
313
+ export declare class Encoder implements Disposable {
314
+ private codecContext;
315
+ private packet;
316
+ private codec;
317
+ private initializePromise;
318
+ private initialized;
319
+ private isClosed;
320
+ private opts?;
321
+ private options;
322
+ private audioFrameBuffer?;
323
+ private autoResample;
324
+ private audioResampler?;
325
+ private resampledFrame?;
326
+ private resampleChangesRate;
327
+ private resampleInputRate;
328
+ private audioInputLayout?;
329
+ private autoFormat;
330
+ private videoScaler?;
331
+ private scaledFrame?;
332
+ private videoTargetFormat?;
333
+ private supportsParamChange?;
334
+ private encoderChannels?;
335
+ private nextVideoPts?;
336
+ private droppedKeyframe;
337
+ private keyframeRequested;
338
+ private inputQueue;
339
+ private outputQueue;
340
+ private workerPromise;
341
+ private pipeToPromise;
342
+ private signal?;
343
+ /**
344
+ * @param codecContext - Configured codec context
345
+ *
346
+ * @param codec - Encoder codec
347
+ *
348
+ * @param options - Encoder options
349
+ *
350
+ * @param opts - Encoder options as Dictionary
351
+ *
352
+ * @internal
353
+ */
354
+ private constructor();
355
+ /**
356
+ * Create an encoder with specified codec and options.
357
+ *
358
+ * Initializes an encoder with the appropriate codec and configuration.
359
+ * Uses lazy initialization - encoder is opened when first frame is received.
360
+ * Hardware context will be automatically detected from first frame if not provided.
361
+ *
362
+ * Direct mapping to avcodec_find_encoder_by_name() or avcodec_find_encoder().
363
+ *
364
+ * @param encoderCodec - Codec name, ID, or instance to use for encoding
365
+ *
366
+ * @param options - Optional encoder configuration options including required timeBase
367
+ *
368
+ * @returns Configured encoder instance
369
+ *
370
+ * @throws {Error} If encoder not found
371
+ *
372
+ * @throws {RangeError} If an audioFrameBuffer option is out of range
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * // From decoder stream info
377
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, {
378
+ * timeBase: video.timeBase,
379
+ * bitrate: '5M',
380
+ * gopSize: 60,
381
+ * options: {
382
+ * preset: 'fast',
383
+ * crf: '23'
384
+ * }
385
+ * });
386
+ * ```
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * // With custom stream info
391
+ * const encoder = await Encoder.create(FF_ENCODER_AAC, {
392
+ * timeBase: audio.timeBase,
393
+ * bitrate: '192k'
394
+ * });
395
+ * ```
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * // Hardware encoder
400
+ * const hw = HardwareContext.auto();
401
+ * const encoderCodec = hw?.getEncoderCodec('h264') ?? FF_ENCODER_H264_VIDEOTOOLBOX;
402
+ * const encoder = await Encoder.create(encoderCodec, {
403
+ * timeBase: video.timeBase,
404
+ * bitrate: '8M'
405
+ * });
406
+ * ```
407
+ *
408
+ * @see {@link EncoderOptions} For configuration options
409
+ * @see {@link createSync} For synchronous version
410
+ */
411
+ static create<const C extends FFEncoderCodec | AVCodecID | Codec>(encoderCodec: C, options?: EncoderOptions<C>): Promise<Encoder>;
412
+ /**
413
+ * Create an encoder with specified codec and options synchronously.
414
+ * Synchronous version of create.
415
+ *
416
+ * Initializes an encoder with the appropriate codec and configuration.
417
+ * Uses lazy initialization - encoder is opened when first frame is received.
418
+ * Hardware context will be automatically detected from first frame if not provided.
419
+ *
420
+ * Direct mapping to avcodec_find_encoder_by_name() or avcodec_find_encoder().
421
+ *
422
+ * @param encoderCodec - Codec name, ID, or instance to use for encoding
423
+ *
424
+ * @param options - Optional encoder configuration options including required timeBase
425
+ *
426
+ * @returns Configured encoder instance
427
+ *
428
+ * @throws {Error} If encoder not found or timeBase not provided
429
+ *
430
+ * @throws {FFmpegError} If codec allocation fails
431
+ *
432
+ * @throws {RangeError} If an audioFrameBuffer option is out of range
433
+ *
434
+ * @example
435
+ * ```typescript
436
+ * // From decoder stream info
437
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, {
438
+ * timeBase: video.timeBase,
439
+ * bitrate: '5M',
440
+ * gopSize: 60,
441
+ * options: {
442
+ * preset: 'fast',
443
+ * crf: '23'
444
+ * }
445
+ * });
446
+ * ```
447
+ *
448
+ * @example
449
+ * ```typescript
450
+ * // With custom stream info
451
+ * const encoder = await Encoder.create(FF_ENCODER_AAC, {
452
+ * timeBase: audio.timeBase,
453
+ * bitrate: '192k'
454
+ * });
455
+ * ```
456
+ *
457
+ * @example
458
+ * ```typescript
459
+ * // Hardware encoder
460
+ * const hw = HardwareContext.auto();
461
+ * const encoderCodec = hw?.getEncoderCodec('h264') ?? FF_ENCODER_H264_VIDEOTOOLBOX;
462
+ * const encoder = await Encoder.create(encoderCodec, {
463
+ * timeBase: video.timeBase,
464
+ * bitrate: '8M'
465
+ * });
466
+ * ```
467
+ *
468
+ * @see {@link EncoderOptions} For configuration options
469
+ * @see {@link create} For async version
470
+ */
471
+ static createSync<const C extends FFEncoderCodec | AVCodecID | Codec>(encoderCodec: C, options?: EncoderOptions<C>): Encoder;
472
+ /**
473
+ * Encode a single frame into a self-contained image buffer.
474
+ *
475
+ * One-shot, stateless helper for intra-only image codecs (MJPEG, PNG, WebP, ...).
476
+ * Creates a fresh encoder, encodes the frame, flushes and frees everything in one call.
477
+ * The encoder adopts dimensions, pixel format and hardware context from the frame,
478
+ * so any frame size works without reconfiguration.
479
+ *
480
+ * @param encoderCodec - Encoder codec (name, ID, branded constant, or Codec)
481
+ *
482
+ * @param frame - Frame to encode
483
+ *
484
+ * @param options - Optional encoder configuration (e.g. `{ options: { q: 3 } }` for MJPEG quality)
485
+ *
486
+ * @returns Encoded image bytes
487
+ *
488
+ * @throws {FFmpegError} If the encoder is not found or encoding fails
489
+ *
490
+ * @throws {Error} If the encoder produced no output
491
+ *
492
+ * @example
493
+ * ```typescript
494
+ * const jpeg = await Encoder.encodeOne(FF_ENCODER_MJPEG, frame, { options: { q: 3 } });
495
+ * ```
496
+ *
497
+ * @see {@link EncoderPool} For reusing encoders across recurring resolutions
498
+ */
499
+ static encodeOne<const C extends FFEncoderCodec | AVCodecID | Codec>(encoderCodec: C, frame: Frame, options?: EncoderOptions<C>): Promise<Buffer>;
500
+ /**
501
+ * Encode a single frame into a self-contained image buffer synchronously.
502
+ * Synchronous version of encodeOne.
503
+ *
504
+ * One-shot, stateless helper for intra-only image codecs (MJPEG, PNG, WebP, ...).
505
+ * Creates a fresh encoder, encodes the frame, flushes and frees everything in one call.
506
+ * The encoder adopts dimensions, pixel format and hardware context from the frame,
507
+ * so any frame size works without reconfiguration.
508
+ *
509
+ * @param encoderCodec - Encoder codec (name, ID, branded constant, or Codec)
510
+ *
511
+ * @param frame - Frame to encode
512
+ *
513
+ * @param options - Optional encoder configuration (e.g. `{ options: { q: 3 } }` for MJPEG quality)
514
+ *
515
+ * @returns Encoded image bytes
516
+ *
517
+ * @throws {FFmpegError} If the encoder is not found or encoding fails
518
+ *
519
+ * @throws {Error} If the encoder produced no output
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * const jpeg = Encoder.encodeOneSync(FF_ENCODER_MJPEG, frame, { options: { q: 3 } });
524
+ * ```
525
+ *
526
+ * @see {@link encodeOne} For async version
527
+ * @see {@link EncoderPool} For reusing encoders across recurring resolutions
528
+ */
529
+ static encodeOneSync<const C extends FFEncoderCodec | AVCodecID | Codec>(encoderCodec: C, frame: Frame, options?: EncoderOptions<C>): Buffer;
530
+ /**
531
+ * Check if encoder is open.
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * if (encoder.isEncoderOpen) {
536
+ * const packet = await encoder.encode(frame);
537
+ * }
538
+ * ```
539
+ */
540
+ get isEncoderOpen(): boolean;
541
+ /**
542
+ * Check if encoder has been initialized.
543
+ *
544
+ * Returns true after first frame has been processed and encoder opened.
545
+ * Useful for checking if encoder has received frame properties.
546
+ *
547
+ * @returns true if encoder has been initialized with frame data
548
+ *
549
+ * @example
550
+ * ```typescript
551
+ * if (!encoder.isEncoderInitialized) {
552
+ * console.log('Encoder will initialize on first frame');
553
+ * }
554
+ * ```
555
+ */
556
+ get isEncoderInitialized(): boolean;
557
+ /**
558
+ * Codec flags.
559
+ *
560
+ * @returns Current codec flags
561
+ *
562
+ * @throws {Error} If encoder is closed
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * const flags = encoder.codecFlags;
567
+ * console.log('Current flags:', flags);
568
+ * ```
569
+ *
570
+ * @see {@link setCodecFlags} To set flags
571
+ * @see {@link clearCodecFlags} To clear flags
572
+ * @see {@link hasCodecFlags} To check flags
573
+ */
574
+ get codecFlags(): AVCodecFlag;
575
+ /**
576
+ * Set codec flags.
577
+ *
578
+ * @param flags - One or more flag values to set
579
+ *
580
+ * @throws {Error} If encoder is already initialized or closed
581
+ *
582
+ * @example
583
+ * ```typescript
584
+ * import { AV_CODEC_FLAG_GLOBAL_HEADER, AV_CODEC_FLAG_QSCALE } from 'node-av/constants';
585
+ *
586
+ * // Set multiple flags before initialization
587
+ * encoder.setCodecFlags(AV_CODEC_FLAG_GLOBAL_HEADER, AV_CODEC_FLAG_QSCALE);
588
+ * ```
589
+ *
590
+ * @see {@link clearCodecFlags} To clear flags
591
+ * @see {@link hasCodecFlags} To check flags
592
+ * @see {@link codecFlags} For direct flag access
593
+ */
594
+ setCodecFlags(...flags: AVCodecFlag[]): void;
595
+ /**
596
+ * Clear codec flags.
597
+ *
598
+ * @param flags - One or more flag values to clear
599
+ *
600
+ * @throws {Error} If encoder is already initialized or closed
601
+ *
602
+ * @example
603
+ * ```typescript
604
+ * import { AV_CODEC_FLAG_QSCALE } from 'node-av/constants';
605
+ *
606
+ * // Clear specific flag before initialization
607
+ * encoder.clearCodecFlags(AV_CODEC_FLAG_QSCALE);
608
+ * ```
609
+ *
610
+ * @see {@link setCodecFlags} To set flags
611
+ * @see {@link hasCodecFlags} To check flags
612
+ * @see {@link codecFlags} For direct flag access
613
+ */
614
+ clearCodecFlags(...flags: AVCodecFlag[]): void;
615
+ /**
616
+ * Check if codec has specific flags.
617
+ *
618
+ * Tests whether all specified codec flags are set using bitwise AND.
619
+ *
620
+ * @param flags - One or more flag values to check
621
+ *
622
+ * @returns true if all specified flags are set, false otherwise
623
+ *
624
+ * @throws {Error} If encoder is closed
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * import { AV_CODEC_FLAG_GLOBAL_HEADER } from 'node-av/constants';
629
+ *
630
+ * if (encoder.hasCodecFlags(AV_CODEC_FLAG_GLOBAL_HEADER)) {
631
+ * console.log('Global header flag is set');
632
+ * }
633
+ * ```
634
+ *
635
+ * @see {@link setCodecFlags} To set flags
636
+ * @see {@link clearCodecFlags} To clear flags
637
+ * @see {@link codecFlags} For direct flag access
638
+ */
639
+ hasCodecFlags(...flags: AVCodecFlag[]): boolean;
640
+ /**
641
+ * Check if encoder uses hardware acceleration.
642
+ *
643
+ * @returns true if hardware-accelerated
644
+ *
645
+ * @example
646
+ * ```typescript
647
+ * if (encoder.isHardware()) {
648
+ * console.log('Using GPU acceleration');
649
+ * }
650
+ * ```
651
+ *
652
+ * @see {@link HardwareContext} For hardware setup
653
+ */
654
+ isHardware(): boolean;
655
+ /**
656
+ * Check if encoder is ready for processing.
657
+ *
658
+ * @returns true if initialized and ready
659
+ *
660
+ * @example
661
+ * ```typescript
662
+ * if (encoder.isReady()) {
663
+ * const packet = await encoder.encode(frame);
664
+ * }
665
+ * ```
666
+ */
667
+ isReady(): boolean;
668
+ /**
669
+ * Encode the next frame as a keyframe.
670
+ *
671
+ * Answers receiver feedback such as an RTCP PLI, so a receiver that lost
672
+ * packets resyncs on the next frame instead of waiting for the next GOP.
673
+ * Set the encoder's `forced-idr` option where it has one, otherwise some
674
+ * encoders (libx264, NVENC, QSV, AMF) emit an I frame that is not an IDR.
675
+ *
676
+ * @example
677
+ * ```typescript
678
+ * sender.onPictureLossIndication.subscribe(() => {
679
+ * encoder.requestKeyframe();
680
+ * });
681
+ * ```
682
+ */
683
+ requestKeyframe(): void;
684
+ /**
685
+ * Send a frame to the encoder.
686
+ *
687
+ * Sends a raw frame to the encoder for encoding.
688
+ * Does not return encoded packets - use {@link receive} to retrieve packets.
689
+ * On first frame, automatically initializes encoder with frame properties.
690
+ * A single frame can produce zero, one, or multiple packets depending on codec buffering.
691
+ *
692
+ * **Important**: This method only SENDS the frame to the encoder.
693
+ * You must call {@link receive} separately (potentially multiple times) to get encoded packets.
694
+ *
695
+ * Like FFmpeg CLI, a video frame whose timestamp lands on the previous frame's
696
+ * in the encoder time base moves to the next tick, and one that lies entirely
697
+ * before it is dropped, since encoders need strictly increasing timestamps.
698
+ *
699
+ * Direct mapping to avcodec_send_frame().
700
+ *
701
+ * @param frame - Raw frame to send to encoder, or null to flush
702
+ *
703
+ * @throws {FFmpegError} If sending frame fails
704
+ *
705
+ * @example
706
+ * ```typescript
707
+ * // Send frame and receive packets
708
+ * await encoder.encode(frame);
709
+ *
710
+ * // Receive all available packets
711
+ * while (true) {
712
+ * const packet = await encoder.receive();
713
+ * if (!packet) break;
714
+ * console.log(`Encoded packet with PTS: ${packet.pts}`);
715
+ * await output.writePacket(packet);
716
+ * packet.free();
717
+ * }
718
+ * ```
719
+ *
720
+ * @example
721
+ * ```typescript
722
+ * for await (const frame of decoder.frames(input.packets())) {
723
+ * // Send frame
724
+ * await encoder.encode(frame);
725
+ *
726
+ * // Receive available packets
727
+ * let packet;
728
+ * while ((packet = await encoder.receive())) {
729
+ * await output.writePacket(packet);
730
+ * packet.free();
731
+ * }
732
+ * frame.free();
733
+ * }
734
+ * ```
735
+ *
736
+ * @see {@link receive} For receiving encoded packets
737
+ * @see {@link encodeAll} For combined send+receive operation
738
+ * @see {@link packets} For automatic frame iteration
739
+ * @see {@link flush} For end-of-stream handling
740
+ * @see {@link encodeSync} For synchronous version
741
+ */
742
+ encode(frame: Frame | null): Promise<void>;
743
+ /**
744
+ * Send a frame to the encoder synchronously.
745
+ * Synchronous version of encode.
746
+ *
747
+ * Sends a raw frame to the encoder for encoding.
748
+ * Does not return encoded packets - use {@link receiveSync} to retrieve packets.
749
+ * On first frame, automatically initializes encoder with frame properties.
750
+ * A single frame can produce zero, one, or multiple packets depending on codec buffering.
751
+ *
752
+ * **Important**: This method only SENDS the frame to the encoder.
753
+ * You must call {@link receiveSync} separately (potentially multiple times) to get encoded packets.
754
+ *
755
+ * Like FFmpeg CLI, a video frame whose timestamp lands on the previous frame's
756
+ * in the encoder time base moves to the next tick, and one that lies entirely
757
+ * before it is dropped, since encoders need strictly increasing timestamps.
758
+ *
759
+ * Direct mapping to avcodec_send_frame().
760
+ *
761
+ * @param frame - Raw frame to send to encoder, or null to flush
762
+ *
763
+ * @throws {FFmpegError} If sending frame fails
764
+ *
765
+ * @example
766
+ * ```typescript
767
+ * // Send frame and receive packets
768
+ * encoder.encodeSync(frame);
769
+ *
770
+ * // Receive all available packets
771
+ * let packet;
772
+ * while ((packet = encoder.receiveSync())) {
773
+ * console.log(`Encoded packet with PTS: ${packet.pts}`);
774
+ * output.writePacketSync(packet);
775
+ * packet.free();
776
+ * }
777
+ * ```
778
+ *
779
+ * @see {@link receiveSync} For receiving encoded packets
780
+ * @see {@link encodeAllSync} For combined send+receive operation
781
+ * @see {@link packetsSync} For automatic frame iteration
782
+ * @see {@link flushSync} For end-of-stream handling
783
+ * @see {@link encode} For async version
784
+ */
785
+ encodeSync(frame: Frame | null): void;
786
+ /**
787
+ * Encode a frame to packets.
788
+ *
789
+ * Sends a frame to the encoder and receives all available encoded packets.
790
+ * Returns array of packets - may be empty if encoder needs more data.
791
+ * On first frame, automatically initializes encoder with frame properties.
792
+ * One frame can produce zero, one, or multiple packets depending on codec.
793
+ *
794
+ * Direct mapping to avcodec_send_frame() and avcodec_receive_packet().
795
+ *
796
+ * @param frame - Raw frame to encode (or null to flush)
797
+ *
798
+ * @returns Array of encoded packets (empty if more data needed or encoder is closed)
799
+ *
800
+ * @throws {FFmpegError} If encoding fails
801
+ *
802
+ * @example
803
+ * ```typescript
804
+ * const packets = await encoder.encodeAll(frame);
805
+ * for (const packet of packets) {
806
+ * console.log(`Encoded packet with PTS: ${packet.pts}`);
807
+ * await output.writePacket(packet);
808
+ * packet.free();
809
+ * }
810
+ * ```
811
+ *
812
+ * @example
813
+ * ```typescript
814
+ * // Encode loop
815
+ * for await (const frame of decoder.frames(input.packets())) {
816
+ * const packets = await encoder.encodeAll(frame);
817
+ * for (const packet of packets) {
818
+ * await output.writePacket(packet);
819
+ * packet.free();
820
+ * }
821
+ * frame.free();
822
+ * }
823
+ * ```
824
+ *
825
+ * @see {@link encode} For single packet encoding
826
+ * @see {@link packets} For automatic frame iteration
827
+ * @see {@link flush} For end-of-stream handling
828
+ * @see {@link encodeAllSync} For synchronous version
829
+ */
830
+ encodeAll(frame: Frame | null): Promise<Packet[]>;
831
+ /**
832
+ * Encode a frame to packets synchronously.
833
+ * Synchronous version of encodeAll.
834
+ *
835
+ * Sends a frame to the encoder and receives all available encoded packets.
836
+ * Returns array of packets - may be empty if encoder needs more data.
837
+ * On first frame, automatically initializes encoder with frame properties.
838
+ * One frame can produce zero, one, or multiple packets depending on codec.
839
+ *
840
+ * Direct mapping to avcodec_send_frame() and avcodec_receive_packet().
841
+ *
842
+ * @param frame - Raw frame to encode (or null to flush)
843
+ *
844
+ * @returns Array of encoded packets (empty if more data needed or encoder is closed)
845
+ *
846
+ * @throws {FFmpegError} If encoding fails
847
+ *
848
+ * @example
849
+ * ```typescript
850
+ * const packets = encoder.encodeAllSync(frame);
851
+ * for (const packet of packets) {
852
+ * console.log(`Encoded packet with PTS: ${packet.pts}`);
853
+ * output.writePacketSync(packet);
854
+ * packet.free();
855
+ * }
856
+ * ```
857
+ *
858
+ * @example
859
+ * ```typescript
860
+ * // Encode loop
861
+ * for (const frame of decoder.framesSync(packets)) {
862
+ * const packets = encoder.encodeAllSync(frame);
863
+ * for (const packet of packets) {
864
+ * output.writePacketSync(packet);
865
+ * packet.free();
866
+ * }
867
+ * frame.free();
868
+ * }
869
+ * ```
870
+ *
871
+ * @see {@link encodeSync} For single packet encoding
872
+ * @see {@link packetsSync} For automatic frame iteration
873
+ * @see {@link flushSync} For end-of-stream handling
874
+ * @see {@link encodeAll} For async version
875
+ */
876
+ encodeAllSync(frame: Frame | null): Packet[];
877
+ /**
878
+ * Encode frame stream to packet stream.
879
+ *
880
+ * High-level async generator for complete encoding pipeline.
881
+ * Encoder is only flushed when EOF (null) signal is explicitly received.
882
+ * Primary interface for stream-based encoding.
883
+ *
884
+ * **EOF Handling:**
885
+ * - Send null to flush encoder and get remaining buffered packets
886
+ * - Generator yields null after flushing when null is received
887
+ * - No automatic flushing - encoder stays open until EOF or close()
888
+ *
889
+ * @param frames - Async iterable of frames, single frame, or null to flush
890
+ *
891
+ * @yields {Packet | null} Encoded packets, followed by null when explicitly flushed
892
+ *
893
+ * @throws {FFmpegError} If encoding fails
894
+ *
895
+ * @example
896
+ * ```typescript
897
+ * // Stream of frames with automatic EOF propagation
898
+ * for await (const packet of encoder.packets(decoder.frames(input.packets()))) {
899
+ * if (packet === null) {
900
+ * console.log('Encoder flushed');
901
+ * break;
902
+ * }
903
+ * await output.writePacket(packet);
904
+ * packet.free(); // Must free output packets
905
+ * }
906
+ * ```
907
+ *
908
+ * @example
909
+ * ```typescript
910
+ * // Single frame - no automatic flush
911
+ * for await (const packet of encoder.packets(singleFrame)) {
912
+ * await output.writePacket(packet);
913
+ * packet.free();
914
+ * }
915
+ * // Encoder remains open, buffered packets not flushed
916
+ * ```
917
+ *
918
+ * @example
919
+ * ```typescript
920
+ * // Explicit flush with EOF
921
+ * for await (const packet of encoder.packets(null)) {
922
+ * if (packet === null) {
923
+ * console.log('All buffered packets flushed');
924
+ * break;
925
+ * }
926
+ * console.log('Buffered packet:', packet.pts);
927
+ * await output.writePacket(packet);
928
+ * packet.free();
929
+ * }
930
+ * ```
931
+ *
932
+ * @see {@link encode} For single frame encoding
933
+ * @see {@link Decoder.frames} For frame source
934
+ * @see {@link packetsSync} For sync version
935
+ */
936
+ packets(frames: AsyncIterable<Frame | null> | Frame | null): AsyncGenerator<Packet | null>;
937
+ /**
938
+ * Encode frame stream to packet stream synchronously.
939
+ * Synchronous version of packets.
940
+ *
941
+ * High-level sync generator for complete encoding pipeline.
942
+ * Encoder is only flushed when EOF (null) signal is explicitly received.
943
+ * Primary interface for stream-based encoding.
944
+ *
945
+ * **EOF Handling:**
946
+ * - Send null to flush encoder and get remaining buffered packets
947
+ * - Generator yields null after flushing when null is received
948
+ * - No automatic flushing - encoder stays open until EOF or close()
949
+ *
950
+ * @param frames - Iterable of frames, single frame, or null to flush
951
+ *
952
+ * @yields {Packet | null} Encoded packets, followed by null when explicitly flushed
953
+ *
954
+ * @throws {FFmpegError} If encoding fails
955
+ *
956
+ * @example
957
+ * ```typescript
958
+ * // Stream of frames with automatic EOF propagation
959
+ * for (const packet of encoder.packetsSync(decoder.framesSync(packets))) {
960
+ * if (packet === null) {
961
+ * console.log('Encoder flushed');
962
+ * break;
963
+ * }
964
+ * output.writePacketSync(packet);
965
+ * packet.free(); // Must free output packets
966
+ * }
967
+ * ```
968
+ *
969
+ * @example
970
+ * ```typescript
971
+ * // Single frame - no automatic flush
972
+ * for (const packet of encoder.packetsSync(singleFrame)) {
973
+ * output.writePacketSync(packet);
974
+ * packet.free();
975
+ * }
976
+ * // Encoder remains open, buffered packets not flushed
977
+ * ```
978
+ *
979
+ * @example
980
+ * ```typescript
981
+ * // Explicit flush with EOF
982
+ * for (const packet of encoder.packetsSync(null)) {
983
+ * if (packet === null) {
984
+ * console.log('All buffered packets flushed');
985
+ * break;
986
+ * }
987
+ * console.log('Buffered packet:', packet.pts);
988
+ * output.writePacketSync(packet);
989
+ * packet.free();
990
+ * }
991
+ * ```
992
+ *
993
+ * @see {@link encodeSync} For single frame encoding
994
+ * @see {@link Decoder.framesSync} For frame source
995
+ * @see {@link packets} For async version
996
+ */
997
+ packetsSync(frames: Iterable<Frame | null> | Frame | null): Generator<Packet | null>;
998
+ /**
999
+ * Flush encoder and signal end-of-stream.
1000
+ *
1001
+ * Sends null frame to encoder to signal end-of-stream.
1002
+ * Does nothing if encoder was never initialized or is closed.
1003
+ * Must call receive() to get remaining buffered packets.
1004
+ *
1005
+ * Direct mapping to avcodec_send_frame(NULL).
1006
+ *
1007
+ * @example
1008
+ * ```typescript
1009
+ * // Signal end of stream
1010
+ * await encoder.flush();
1011
+ *
1012
+ * // Then get remaining packets
1013
+ * let packet;
1014
+ * while ((packet = await encoder.receive()) !== null) {
1015
+ * console.log('Got buffered packet');
1016
+ * await output.writePacket(packet);
1017
+ * packet.free();
1018
+ * }
1019
+ * ```
1020
+ *
1021
+ * @see {@link flushPackets} For async iteration
1022
+ * @see {@link receive} For getting buffered packets
1023
+ * @see {@link flushSync} For synchronous version
1024
+ */
1025
+ flush(): Promise<void>;
1026
+ /**
1027
+ * Flush encoder and signal end-of-stream synchronously.
1028
+ * Synchronous version of flush.
1029
+ *
1030
+ * Sends null frame to encoder to signal end-of-stream.
1031
+ * Does nothing if encoder was never initialized or is closed.
1032
+ * Must call receiveSync() to get remaining buffered packets.
1033
+ *
1034
+ * Direct mapping to avcodec_send_frame(NULL).
1035
+ *
1036
+ * @example
1037
+ * ```typescript
1038
+ * // Signal end of stream
1039
+ * encoder.flushSync();
1040
+ *
1041
+ * // Then get remaining packets
1042
+ * let packet;
1043
+ * while ((packet = encoder.receiveSync()) !== null) {
1044
+ * console.log('Got buffered packet');
1045
+ * output.writePacketSync(packet);
1046
+ * packet.free();
1047
+ * }
1048
+ * ```
1049
+ *
1050
+ * @see {@link flushPacketsSync} For sync iteration
1051
+ * @see {@link receiveSync} For getting buffered packets
1052
+ * @see {@link flush} For async version
1053
+ */
1054
+ flushSync(): void;
1055
+ /**
1056
+ * Flush all buffered packets as async generator.
1057
+ *
1058
+ * Convenient async iteration over remaining packets.
1059
+ * Automatically handles flush and repeated receive calls.
1060
+ * Returns immediately if encoder was never initialized or is closed.
1061
+ *
1062
+ * @yields {Packet} Buffered packets
1063
+ *
1064
+ * @example
1065
+ * ```typescript
1066
+ * // Flush at end of encoding
1067
+ * for await (const packet of encoder.flushPackets()) {
1068
+ * console.log('Processing buffered packet');
1069
+ * await output.writePacket(packet);
1070
+ * packet.free();
1071
+ * }
1072
+ * ```
1073
+ *
1074
+ * @see {@link encode} For sending frames and receiving packets
1075
+ * @see {@link flush} For signaling end-of-stream
1076
+ * @see {@link flushPacketsSync} For synchronous version
1077
+ */
1078
+ flushPackets(): AsyncGenerator<Packet>;
1079
+ /**
1080
+ * Flush all buffered packets as generator synchronously.
1081
+ * Synchronous version of flushPackets.
1082
+ *
1083
+ * Convenient sync iteration over remaining packets.
1084
+ * Automatically handles flush and repeated receive calls.
1085
+ * Returns immediately if encoder was never initialized or is closed.
1086
+ *
1087
+ * @yields {Packet} Buffered packets
1088
+ *
1089
+ * @example
1090
+ * ```typescript
1091
+ * // Flush at end of encoding
1092
+ * for (const packet of encoder.flushPacketsSync()) {
1093
+ * console.log('Processing buffered packet');
1094
+ * output.writePacketSync(packet);
1095
+ * packet.free();
1096
+ * }
1097
+ * ```
1098
+ *
1099
+ * @see {@link encodeSync} For sending frames and receiving packets
1100
+ * @see {@link flushSync} For signaling end-of-stream
1101
+ * @see {@link flushPackets} For async version
1102
+ */
1103
+ flushPacketsSync(): Generator<Packet>;
1104
+ /**
1105
+ * Receive packet from encoder.
1106
+ *
1107
+ * Gets encoded packets from the codec's internal buffer.
1108
+ * Handles packet cloning and error checking.
1109
+ * Implements FFmpeg's send/receive pattern.
1110
+ *
1111
+ * **Return Values:**
1112
+ * - `Packet` - Successfully encoded packet (AVERROR >= 0)
1113
+ * - `null` - Need more input frames (AVERROR_EAGAIN), or encoder not initialized
1114
+ * - `undefined` - End of stream reached (AVERROR_EOF), or encoder is closed
1115
+ *
1116
+ * Direct mapping to avcodec_receive_packet().
1117
+ *
1118
+ * @returns Cloned packet, null if need more data, or undefined if stream ended
1119
+ *
1120
+ * @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
1121
+ *
1122
+ * @throws {Error} If packet cloning fails (out of memory)
1123
+ *
1124
+ * @example
1125
+ * ```typescript
1126
+ * // Process all buffered packets
1127
+ * while (true) {
1128
+ * const packet = await encoder.receive();
1129
+ * if (!packet) break; // Stop on EAGAIN or EOF
1130
+ * console.log(`Got packet with PTS: ${packet.pts}`);
1131
+ * await output.writePacket(packet);
1132
+ * packet.free();
1133
+ * }
1134
+ * ```
1135
+ *
1136
+ * @example
1137
+ * ```typescript
1138
+ * // Handle each return value explicitly
1139
+ * const packet = await encoder.receive();
1140
+ * if (packet === EOF) {
1141
+ * console.log('Encoder stream ended');
1142
+ * } else if (packet === null) {
1143
+ * console.log('Need more input frames');
1144
+ * } else {
1145
+ * console.log(`Got packet: pts=${packet.pts}`);
1146
+ * await output.writePacket(packet);
1147
+ * packet.free();
1148
+ * }
1149
+ * ```
1150
+ *
1151
+ * @see {@link encode} For sending frames and receiving packets
1152
+ * @see {@link flush} For signaling end-of-stream
1153
+ * @see {@link receiveSync} For synchronous version
1154
+ * @see {@link EOF} For end-of-stream signal
1155
+ */
1156
+ receive(): Promise<Packet | EOFSignal | null>;
1157
+ /**
1158
+ * Receive packet from encoder synchronously.
1159
+ * Synchronous version of receive.
1160
+ *
1161
+ * Gets encoded packets from the codec's internal buffer.
1162
+ * Handles packet cloning and error checking.
1163
+ * Implements FFmpeg's send/receive pattern.
1164
+ *
1165
+ * **Return Values:**
1166
+ * - `Packet` - Successfully encoded packet (AVERROR >= 0)
1167
+ * - `null` - Need more input frames (AVERROR_EAGAIN), or encoder not initialized
1168
+ * - `undefined` - End of stream reached (AVERROR_EOF), or encoder is closed
1169
+ *
1170
+ * Direct mapping to avcodec_receive_packet().
1171
+ *
1172
+ * @returns Cloned packet, null if need more data, or undefined if stream ended
1173
+ *
1174
+ * @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
1175
+ *
1176
+ * @throws {Error} If packet cloning fails (out of memory)
1177
+ *
1178
+ * @example
1179
+ * ```typescript
1180
+ * // Process all buffered packets
1181
+ * while (true) {
1182
+ * const packet = encoder.receiveSync();
1183
+ * if (!packet) break; // Stop on EAGAIN or EOF
1184
+ * console.log(`Got packet with PTS: ${packet.pts}`);
1185
+ * output.writePacketSync(packet);
1186
+ * packet.free();
1187
+ * }
1188
+ * ```
1189
+ *
1190
+ * @example
1191
+ * ```typescript
1192
+ * // Handle each return value explicitly
1193
+ * const packet = encoder.receiveSync();
1194
+ * if (packet === EOF) {
1195
+ * console.log('Encoder stream ended');
1196
+ * } else if (packet === null) {
1197
+ * console.log('Need more input frames');
1198
+ * } else {
1199
+ * console.log(`Got packet: pts=${packet.pts}`);
1200
+ * output.writePacketSync(packet);
1201
+ * packet.free();
1202
+ * }
1203
+ * ```
1204
+ *
1205
+ * @see {@link encodeSync} For sending frames and receiving packets
1206
+ * @see {@link flushSync} For signaling end-of-stream
1207
+ * @see {@link receive} For async version
1208
+ * @see {@link EOF} For end-of-stream signal
1209
+ */
1210
+ receiveSync(): Packet | EOFSignal | null;
1211
+ /**
1212
+ * Pipe encoded packets to muxer.
1213
+ *
1214
+ * @param target - Media output component to write packets to
1215
+ *
1216
+ * @param streamIndex - Stream index to write packets to
1217
+ *
1218
+ * @returns Scheduler for continued chaining
1219
+ *
1220
+ * @example
1221
+ * ```typescript
1222
+ * decoder.pipeTo(filter).pipeTo(encoder)
1223
+ * ```
1224
+ */
1225
+ pipeTo(target: Muxer, streamIndex: number): SchedulerControl<Frame>;
1226
+ /**
1227
+ * Close encoder and free resources.
1228
+ *
1229
+ * Releases codec context and internal packet buffer.
1230
+ * Safe to call multiple times.
1231
+ * Automatically called by Symbol.dispose.
1232
+ *
1233
+ * @example
1234
+ * ```typescript
1235
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, { ... });
1236
+ * try {
1237
+ * // Use encoder
1238
+ * } finally {
1239
+ * encoder.close();
1240
+ * }
1241
+ * ```
1242
+ *
1243
+ * @see {@link Symbol.dispose} For automatic cleanup
1244
+ */
1245
+ close(): void;
1246
+ /**
1247
+ * Get encoder codec.
1248
+ *
1249
+ * Returns the codec used by this encoder.
1250
+ * Useful for checking codec capabilities and properties.
1251
+ *
1252
+ * @returns Codec instance
1253
+ *
1254
+ * @internal
1255
+ *
1256
+ * @see {@link Codec} For codec details
1257
+ */
1258
+ getCodec(): Codec;
1259
+ /**
1260
+ * Get underlying codec context.
1261
+ *
1262
+ * Returns the codec context for advanced operations.
1263
+ * Useful for accessing low-level codec properties and settings.
1264
+ * Returns null if encoder is closed or not initialized.
1265
+ *
1266
+ * @returns Codec context or null if closed/not initialized
1267
+ *
1268
+ * @internal
1269
+ *
1270
+ * @see {@link CodecContext} For context details
1271
+ */
1272
+ getCodecContext(): CodecContext | null;
1273
+ /**
1274
+ * Worker loop for push-based processing.
1275
+ *
1276
+ * @internal
1277
+ */
1278
+ private runWorker;
1279
+ /**
1280
+ * Send frame to input queue or flush the pipeline.
1281
+ *
1282
+ * When frame is provided, queues it for encoding.
1283
+ * When null is provided, triggers flush sequence:
1284
+ * - Closes input queue
1285
+ * - Waits for worker completion
1286
+ * - Flushes encoder and sends remaining packets to output queue
1287
+ * - Closes output queue
1288
+ * - Waits for pipeTo task completion (writes to muxer)
1289
+ *
1290
+ * Used by scheduler system for pipeline control.
1291
+ *
1292
+ * @param frame - Frame to send, or null to flush
1293
+ *
1294
+ * @internal
1295
+ */
1296
+ private sendToQueue;
1297
+ /**
1298
+ * Receive packet from output queue.
1299
+ *
1300
+ * @returns Packet from output queue
1301
+ *
1302
+ * @internal
1303
+ */
1304
+ private receiveFromQueue;
1305
+ /**
1306
+ * Apply the user-supplied {@link EncoderOptions.context} bag to the codec context.
1307
+ *
1308
+ * Normalizes the rate-control fields (which accept `'5M'`-style strings) before
1309
+ * assigning every provided field via its setter.
1310
+ *
1311
+ * @internal
1312
+ */
1313
+ private applyContextBag;
1314
+ /**
1315
+ * Set the frame rate and time base of a video encoder from its first frame.
1316
+ *
1317
+ * Shared by both initialize variants.
1318
+ *
1319
+ * @param frame - First frame to encode
1320
+ *
1321
+ * @internal
1322
+ */
1323
+ private setupVideoTiming;
1324
+ /**
1325
+ * Initialize encoder from first frame.
1326
+ *
1327
+ * Sets codec context parameters from frame properties.
1328
+ * Configures hardware context if present in frame.
1329
+ * Opens encoder with accumulated options.
1330
+ *
1331
+ * @param frame - First frame to encode
1332
+ *
1333
+ * @throws {FFmpegError} If encoder open fails
1334
+ *
1335
+ * @internal
1336
+ */
1337
+ private initialize;
1338
+ /**
1339
+ * Initialize encoder from first frame synchronously.
1340
+ * Synchronous version of initialize.
1341
+ *
1342
+ * Sets codec context parameters from frame properties.
1343
+ * Configures hardware context if present in frame.
1344
+ * Opens encoder with accumulated options.
1345
+ *
1346
+ * @param frame - First frame to encode
1347
+ *
1348
+ * @throws {FFmpegError} If encoder open fails
1349
+ *
1350
+ * @internal
1351
+ *
1352
+ * @see {@link initialize} For async version
1353
+ */
1354
+ private initializeSync;
1355
+ /**
1356
+ * Setup hardware acceleration for encoder.
1357
+ *
1358
+ * Implements FFmpeg's hw_device_setup_for_encode logic.
1359
+ * Validates hardware frames context format and codec support.
1360
+ * Falls back to device context if frames context is incompatible.
1361
+ *
1362
+ * @param frame - Frame to get hardware context from
1363
+ *
1364
+ * @internal
1365
+ */
1366
+ private setupHardwareAcceleration;
1367
+ /**
1368
+ * Configure the codec context's audio parameters from the first frame.
1369
+ *
1370
+ * Audio encoders only accept specific sample rates / sample formats / channel
1371
+ * layouts. This picks codec-supported targets; if they differ from the input it
1372
+ * either sets up a resampler (when `autoResample`) or throws a descriptive error.
1373
+ *
1374
+ * @param frame - First audio frame
1375
+ *
1376
+ * @throws {Error} If the input is unsupported and `autoResample` is disabled
1377
+ *
1378
+ * @throws {FFmpegError} If the resampler fails to configure
1379
+ *
1380
+ * @internal
1381
+ */
1382
+ private setupAudioParams;
1383
+ /**
1384
+ * Lazily allocate the reused resampler output frame.
1385
+ *
1386
+ * @returns The allocated output frame
1387
+ *
1388
+ * @internal
1389
+ */
1390
+ private getResampleFrame;
1391
+ /**
1392
+ * Resample an incoming audio frame to the codec's target format.
1393
+ *
1394
+ * Reuses a single output frame; `swr_convert_frame` allocates/sizes its buffer.
1395
+ * The output keeps the input timing: with rate conversion it is stamped with the
1396
+ * time of its first output sample in 1/target_rate, otherwise it carries the input
1397
+ * frame's PTS and timebase.
1398
+ *
1399
+ * @param frame - Source audio frame
1400
+ *
1401
+ * @returns The resampled frame (owned by the encoder, reused across calls)
1402
+ *
1403
+ * @throws {FFmpegError} If resampling fails
1404
+ *
1405
+ * @internal
1406
+ */
1407
+ private resampleAudio;
1408
+ /**
1409
+ * Drain samples buffered inside the resampler (rate-conversion delay) into the
1410
+ * encoder path. Returns the drained frame if any, else null.
1411
+ *
1412
+ * @returns The drained frame (reused), or null when the resampler is empty
1413
+ *
1414
+ * @internal
1415
+ */
1416
+ private drainResampler;
1417
+ /**
1418
+ * Timestamp of the resampler's next output sample in 1/target_rate.
1419
+ *
1420
+ * Mirrors the aresample filter: the input PTS goes to swr_next_pts() in
1421
+ * 1/(in_rate * out_rate), which subtracts the samples still buffered in the
1422
+ * resampler. Without an input PTS (or when draining) swr continues from the
1423
+ * samples it has output so far.
1424
+ *
1425
+ * @param frame - Input frame about to be converted, or null when draining
1426
+ *
1427
+ * @returns Output timestamp in 1/target_rate
1428
+ *
1429
+ * @internal
1430
+ */
1431
+ private nextResampledPts;
1432
+ /**
1433
+ * Configure the codec context's pixel format from the first video frame.
1434
+ *
1435
+ * Video encoders only accept specific pixel formats. This keeps the input format
1436
+ * when the codec accepts it; otherwise it either sets up a swscale converter to
1437
+ * the least-loss supported format (when `autoFormat`) or throws a descriptive
1438
+ * error. Hardware frames are left untouched - their format is negotiated through
1439
+ * the hardware frames context, not swscale.
1440
+ *
1441
+ * @param frame - First video frame
1442
+ *
1443
+ * @throws {Error} If the input is unsupported and `autoFormat` is disabled
1444
+ *
1445
+ * @throws {FFmpegError} If the converter fails to configure
1446
+ *
1447
+ * @internal
1448
+ */
1449
+ private setupVideoFormat;
1450
+ /**
1451
+ * Lazily allocate the reused scaler output frame.
1452
+ *
1453
+ * @returns The allocated output frame
1454
+ *
1455
+ * @internal
1456
+ */
1457
+ private getScaledFrame;
1458
+ /**
1459
+ * Convert an incoming video frame to the codec's target pixel format.
1460
+ *
1461
+ * Reuses a single output frame; `sws_scale_frame` allocates/sizes its buffer.
1462
+ * Resolution is unchanged - only the pixel format differs. Timing is carried over
1463
+ * explicitly so the encoder's PTS rescale stays correct.
1464
+ *
1465
+ * @param frame - Source video frame
1466
+ *
1467
+ * @returns The converted frame (owned by the encoder, reused across calls)
1468
+ *
1469
+ * @internal
1470
+ */
1471
+ private scaleVideo;
1472
+ /**
1473
+ * Prepare frame for encoding.
1474
+ *
1475
+ * Implements FFmpeg's frame_encode() pre-encoding logic:
1476
+ * 1. Video: Keeps timestamps strictly increasing like the CLI's VFR sync
1477
+ * 2. Video: Sets frame.quality from encoder's globalQuality (like -qscale)
1478
+ * 3. Audio: Validates channel count consistency for encoders without PARAM_CHANGE capability
1479
+ *
1480
+ * This matches FFmpeg CLI behavior where these properties are automatically managed.
1481
+ *
1482
+ * @param frame - Frame to prepare for encoding
1483
+ *
1484
+ * @returns False if the frame must be dropped
1485
+ *
1486
+ * @throws {Error} If audio channel count changed and encoder doesn't support parameter changes
1487
+ *
1488
+ * @internal
1489
+ */
1490
+ private prepareFrameForEncoding;
1491
+ /**
1492
+ * Dispose of encoder.
1493
+ *
1494
+ * Implements Disposable interface for automatic cleanup.
1495
+ * Equivalent to calling close().
1496
+ *
1497
+ * @example
1498
+ * ```typescript
1499
+ * {
1500
+ * using encoder = await Encoder.create(FF_ENCODER_LIBX264, { ... });
1501
+ * // Encode frames...
1502
+ * } // Automatically closed
1503
+ * ```
1504
+ *
1505
+ * @see {@link close} For manual cleanup
1506
+ */
1507
+ [Symbol.dispose](): void;
1508
+ }
1509
+ export {};