node-av-light 0.0.0-stage → 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 +710 -2
  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 +167 -4
@@ -0,0 +1,1336 @@
1
+ import { bindings } from './binding.js';
2
+ import { HardwareDeviceContext } from './hardware-device-context.js';
3
+ import { HardwareFramesContext } from './hardware-frames-context.js';
4
+ import { OptionMember } from './option.js';
5
+ import { Rational } from './rational.js';
6
+ import { stringToFourCC } from './utilities.js';
7
+ /**
8
+ * Codec context for encoding and decoding.
9
+ *
10
+ * Main structure for codec operations, containing all codec parameters and state.
11
+ * Handles encoding raw frames to packets and decoding packets to frames.
12
+ * Supports both software and hardware-accelerated codecs.
13
+ * Must be configured and opened before use.
14
+ *
15
+ * Direct mapping to FFmpeg's AVCodecContext.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { CodecContext, Codec, FFmpegError } from 'node-av';
20
+ * import { AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P } from 'node-av/constants';
21
+ *
22
+ * // Create decoder
23
+ * const decoder = new CodecContext();
24
+ * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
25
+ * decoder.allocContext3(codec);
26
+ *
27
+ * // Configure from stream parameters
28
+ * decoder.parametersToContext(stream.codecpar);
29
+ *
30
+ * // Open decoder
31
+ * let ret = await decoder.open2(codec);
32
+ * FFmpegError.throwIfError(ret, 'open2');
33
+ *
34
+ * // Decode packets
35
+ * ret = await decoder.sendPacket(packet);
36
+ * if (ret >= 0) {
37
+ * ret = await decoder.receiveFrame(frame);
38
+ * if (ret >= 0) {
39
+ * // Process decoded frame
40
+ * }
41
+ * }
42
+ *
43
+ * // Cleanup
44
+ * decoder.freeContext();
45
+ * ```
46
+ *
47
+ * @see [AVCodecContext](https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html) - FFmpeg Doxygen
48
+ * @see {@link Codec} For finding codecs
49
+ * @see {@link CodecParameters} For stream parameters
50
+ */
51
+ export class CodecContext extends OptionMember {
52
+ constructor() {
53
+ super(new bindings.CodecContext());
54
+ }
55
+ /**
56
+ * Type of codec (video/audio/subtitle).
57
+ *
58
+ * Direct mapping to AVCodecContext->codec_type.
59
+ */
60
+ get codecType() {
61
+ return this.native.codecType;
62
+ }
63
+ set codecType(value) {
64
+ this.native.codecType = value;
65
+ }
66
+ /**
67
+ * Codec identifier.
68
+ *
69
+ * Direct mapping to AVCodecContext->codec_id.
70
+ */
71
+ get codecId() {
72
+ return this.native.codecId;
73
+ }
74
+ set codecId(value) {
75
+ this.native.codecId = value;
76
+ }
77
+ /**
78
+ * Codec tag.
79
+ *
80
+ * Additional codec tag used by some formats.
81
+ *
82
+ * Direct mapping to AVCodecContext->codec_tag.
83
+ */
84
+ get codecTag() {
85
+ return this.native.codecTag;
86
+ }
87
+ set codecTag(value) {
88
+ if (typeof value === 'string') {
89
+ if (value.length !== 4) {
90
+ throw new Error('FourCC string must be exactly 4 characters');
91
+ }
92
+ value = stringToFourCC(value);
93
+ }
94
+ this.native.codecTag = value;
95
+ }
96
+ /**
97
+ * Codec tag as string (FourCC).
98
+ *
99
+ * Human-readable string representation of the codec tag.
100
+ * Returns the FourCC (Four Character Code) format.
101
+ */
102
+ get codecTagString() {
103
+ return this.native.codecTagString;
104
+ }
105
+ /**
106
+ * Average bitrate.
107
+ *
108
+ * Target bitrate for encoding, detected bitrate for decoding.
109
+ * In bits per second.
110
+ *
111
+ * Direct mapping to AVCodecContext->bit_rate.
112
+ */
113
+ get bitRate() {
114
+ return this.native.bitRate;
115
+ }
116
+ set bitRate(value) {
117
+ this.native.bitRate = value;
118
+ }
119
+ /**
120
+ * Time base for timestamps.
121
+ *
122
+ * Fundamental unit of time in seconds for this context.
123
+ *
124
+ * Direct mapping to AVCodecContext->time_base.
125
+ */
126
+ get timeBase() {
127
+ const tb = this.native.timeBase;
128
+ return new Rational(tb.num, tb.den);
129
+ }
130
+ set timeBase(value) {
131
+ this.native.timeBase = { num: value.num, den: value.den };
132
+ }
133
+ /**
134
+ * Packet time base.
135
+ *
136
+ * Time base of the packets from/to the demuxer/muxer.
137
+ *
138
+ * Direct mapping to AVCodecContext->pkt_timebase.
139
+ */
140
+ get pktTimebase() {
141
+ const tb = this.native.pktTimebase;
142
+ return new Rational(tb.num, tb.den);
143
+ }
144
+ set pktTimebase(value) {
145
+ this.native.pktTimebase = { num: value.num, den: value.den };
146
+ }
147
+ /**
148
+ * Codec delay.
149
+ *
150
+ * Number of frames the decoder needs to output before first frame.
151
+ *
152
+ * Direct mapping to AVCodecContext->delay.
153
+ */
154
+ get delay() {
155
+ return this.native.delay;
156
+ }
157
+ /**
158
+ * Codec flags.
159
+ *
160
+ * Combination of AV_CODEC_FLAG_* values.
161
+ *
162
+ * Direct mapping to AVCodecContext->flags.
163
+ */
164
+ get flags() {
165
+ return this.native.flags;
166
+ }
167
+ set flags(value) {
168
+ this.native.flags = value;
169
+ }
170
+ /**
171
+ * Additional codec flags.
172
+ *
173
+ * Combination of AV_CODEC_FLAG2_* values.
174
+ *
175
+ * Direct mapping to AVCodecContext->flags2.
176
+ */
177
+ get flags2() {
178
+ return this.native.flags2;
179
+ }
180
+ set flags2(value) {
181
+ this.native.flags2 = value;
182
+ }
183
+ /**
184
+ * Extra binary data for codec.
185
+ *
186
+ * Contains codec-specific initialization data.
187
+ *
188
+ * Direct mapping to AVCodecContext->extradata.
189
+ */
190
+ get extraData() {
191
+ return this.native.extraData;
192
+ }
193
+ set extraData(value) {
194
+ this.native.extraData = value;
195
+ }
196
+ /**
197
+ * Codec profile.
198
+ *
199
+ * FF_PROFILE_* value indicating codec profile.
200
+ *
201
+ * Direct mapping to AVCodecContext->profile.
202
+ */
203
+ get profile() {
204
+ return this.native.profile;
205
+ }
206
+ set profile(value) {
207
+ this.native.profile = value;
208
+ }
209
+ /**
210
+ * Codec level.
211
+ *
212
+ * Level within the specified profile.
213
+ *
214
+ * Direct mapping to AVCodecContext->level.
215
+ */
216
+ get level() {
217
+ return this.native.level;
218
+ }
219
+ set level(value) {
220
+ this.native.level = value;
221
+ }
222
+ /**
223
+ * Thread count for codec.
224
+ *
225
+ * Number of threads to use for decoding/encoding.
226
+ * 0 for automatic selection.
227
+ *
228
+ * Direct mapping to AVCodecContext->thread_count.
229
+ */
230
+ get threadCount() {
231
+ return this.native.threadCount;
232
+ }
233
+ set threadCount(value) {
234
+ this.native.threadCount = value;
235
+ }
236
+ /**
237
+ * Thread type for codec.
238
+ *
239
+ * Which multithreading methods to use.
240
+ * - FF_THREAD_FRAME (1): Decode more than one frame at once
241
+ * - FF_THREAD_SLICE (2): Decode more than one part of a single frame at once
242
+ *
243
+ * Direct mapping to AVCodecContext->thread_type.
244
+ */
245
+ get threadType() {
246
+ return this.native.threadType;
247
+ }
248
+ set threadType(value) {
249
+ this.native.threadType = value;
250
+ }
251
+ /**
252
+ * Picture width in pixels.
253
+ *
254
+ * Direct mapping to AVCodecContext->width.
255
+ */
256
+ get width() {
257
+ return this.native.width;
258
+ }
259
+ set width(value) {
260
+ this.native.width = value;
261
+ }
262
+ /**
263
+ * Picture height in pixels.
264
+ *
265
+ * Direct mapping to AVCodecContext->height.
266
+ */
267
+ get height() {
268
+ return this.native.height;
269
+ }
270
+ set height(value) {
271
+ this.native.height = value;
272
+ }
273
+ /**
274
+ * Group of pictures size.
275
+ *
276
+ * Maximum number of frames between keyframes.
277
+ *
278
+ * Direct mapping to AVCodecContext->gop_size.
279
+ */
280
+ get gopSize() {
281
+ return this.native.gopSize;
282
+ }
283
+ set gopSize(value) {
284
+ this.native.gopSize = value;
285
+ }
286
+ /**
287
+ * Pixel format.
288
+ *
289
+ * Format of the video frames.
290
+ *
291
+ * Direct mapping to AVCodecContext->pix_fmt.
292
+ */
293
+ get pixelFormat() {
294
+ return this.native.pixelFormat;
295
+ }
296
+ set pixelFormat(value) {
297
+ this.native.pixelFormat = value;
298
+ }
299
+ /**
300
+ * Maximum number of B-frames.
301
+ *
302
+ * B-frames between non-B-frames.
303
+ *
304
+ * Direct mapping to AVCodecContext->max_b_frames.
305
+ */
306
+ get maxBFrames() {
307
+ return this.native.maxBFrames;
308
+ }
309
+ set maxBFrames(value) {
310
+ this.native.maxBFrames = value;
311
+ }
312
+ /**
313
+ * Macroblock decision mode.
314
+ *
315
+ * Algorithm for macroblock decision.
316
+ *
317
+ * Direct mapping to AVCodecContext->mb_decision.
318
+ */
319
+ get mbDecision() {
320
+ return this.native.mbDecision;
321
+ }
322
+ set mbDecision(value) {
323
+ this.native.mbDecision = value;
324
+ }
325
+ /**
326
+ * Number of frames delay in decoder.
327
+ *
328
+ * For codecs with B-frames.
329
+ *
330
+ * Direct mapping to AVCodecContext->has_b_frames.
331
+ */
332
+ get hasBFrames() {
333
+ return this.native.hasBFrames;
334
+ }
335
+ /**
336
+ * Sample aspect ratio.
337
+ *
338
+ * Pixel width/height ratio.
339
+ *
340
+ * Direct mapping to AVCodecContext->sample_aspect_ratio.
341
+ */
342
+ get sampleAspectRatio() {
343
+ const sar = this.native.sampleAspectRatio;
344
+ return new Rational(sar.num || 0, sar.den || 1);
345
+ }
346
+ set sampleAspectRatio(value) {
347
+ this.native.sampleAspectRatio = { num: value.num, den: value.den };
348
+ }
349
+ /**
350
+ * Frame rate.
351
+ *
352
+ * Frames per second for encoding.
353
+ *
354
+ * Direct mapping to AVCodecContext->framerate.
355
+ */
356
+ get framerate() {
357
+ const fr = this.native.framerate;
358
+ return new Rational(fr.num, fr.den);
359
+ }
360
+ set framerate(value) {
361
+ this.native.framerate = { num: value.num, den: value.den };
362
+ }
363
+ /**
364
+ * Color range.
365
+ *
366
+ * MPEG (limited) or JPEG (full) range.
367
+ *
368
+ * Direct mapping to AVCodecContext->color_range.
369
+ */
370
+ get colorRange() {
371
+ return this.native.colorRange;
372
+ }
373
+ set colorRange(value) {
374
+ this.native.colorRange = value;
375
+ }
376
+ /**
377
+ * Color primaries.
378
+ *
379
+ * Chromaticity coordinates of source primaries.
380
+ *
381
+ * Direct mapping to AVCodecContext->color_primaries.
382
+ */
383
+ get colorPrimaries() {
384
+ return this.native.colorPrimaries;
385
+ }
386
+ set colorPrimaries(value) {
387
+ this.native.colorPrimaries = value;
388
+ }
389
+ /**
390
+ * Color transfer characteristic.
391
+ *
392
+ * Transfer function (gamma).
393
+ *
394
+ * Direct mapping to AVCodecContext->color_trc.
395
+ */
396
+ get colorTrc() {
397
+ return this.native.colorTrc;
398
+ }
399
+ set colorTrc(value) {
400
+ this.native.colorTrc = value;
401
+ }
402
+ /**
403
+ * YUV color space.
404
+ *
405
+ * Color space for YUV content.
406
+ *
407
+ * Direct mapping to AVCodecContext->colorspace.
408
+ */
409
+ get colorSpace() {
410
+ return this.native.colorSpace;
411
+ }
412
+ set colorSpace(value) {
413
+ this.native.colorSpace = value;
414
+ }
415
+ /**
416
+ * Chroma sample location.
417
+ *
418
+ * Position of chroma samples.
419
+ *
420
+ * Direct mapping to AVCodecContext->chroma_sample_location.
421
+ */
422
+ get chromaLocation() {
423
+ return this.native.chromaLocation;
424
+ }
425
+ set chromaLocation(value) {
426
+ this.native.chromaLocation = value;
427
+ }
428
+ /**
429
+ * Audio sample rate.
430
+ *
431
+ * Samples per second.
432
+ *
433
+ * Direct mapping to AVCodecContext->sample_rate.
434
+ */
435
+ get sampleRate() {
436
+ return this.native.sampleRate;
437
+ }
438
+ set sampleRate(value) {
439
+ this.native.sampleRate = value;
440
+ }
441
+ /**
442
+ * Number of audio channels.
443
+ *
444
+ * Direct mapping to AVCodecContext->channels.
445
+ */
446
+ get channels() {
447
+ return this.native.channels;
448
+ }
449
+ set channels(value) {
450
+ this.native.channels = value;
451
+ }
452
+ /**
453
+ * Audio sample format.
454
+ *
455
+ * Format of audio samples.
456
+ *
457
+ * Direct mapping to AVCodecContext->sample_fmt.
458
+ */
459
+ get sampleFormat() {
460
+ return this.native.sampleFormat;
461
+ }
462
+ set sampleFormat(value) {
463
+ this.native.sampleFormat = value;
464
+ }
465
+ /**
466
+ * Number of samples per audio frame.
467
+ *
468
+ * Direct mapping to AVCodecContext->frame_size.
469
+ */
470
+ get frameSize() {
471
+ return this.native.frameSize;
472
+ }
473
+ set frameSize(value) {
474
+ this.native.frameSize = value;
475
+ }
476
+ /**
477
+ * Number of bits per coded sample.
478
+ *
479
+ * Bits per sample/pixel from the demuxer (needed by some codecs).
480
+ * For uncompressed formats, this is the bits per sample.
481
+ *
482
+ * Direct mapping to AVCodecContext->bits_per_coded_sample.
483
+ */
484
+ get bitsPerCodedSample() {
485
+ return this.native.bitsPerCodedSample;
486
+ }
487
+ set bitsPerCodedSample(value) {
488
+ this.native.bitsPerCodedSample = value;
489
+ }
490
+ /**
491
+ * Number of bits per raw sample.
492
+ *
493
+ * Bits per sample before compression/encoding.
494
+ * Only set when different from bitsPerCodedSample.
495
+ *
496
+ * Direct mapping to AVCodecContext->bits_per_raw_sample.
497
+ */
498
+ get bitsPerRawSample() {
499
+ return this.native.bitsPerRawSample;
500
+ }
501
+ set bitsPerRawSample(value) {
502
+ this.native.bitsPerRawSample = value;
503
+ }
504
+ /**
505
+ * Current frame number.
506
+ *
507
+ * Frame counter for debugging.
508
+ *
509
+ * Direct mapping to AVCodecContext->frame_number.
510
+ */
511
+ get frameNumber() {
512
+ return this.native.frameNumber;
513
+ }
514
+ /**
515
+ * Audio channel layout.
516
+ *
517
+ * Describes channel configuration.
518
+ *
519
+ * Direct mapping to AVCodecContext->ch_layout.
520
+ */
521
+ get channelLayout() {
522
+ return this.native.channelLayout;
523
+ }
524
+ set channelLayout(value) {
525
+ this.native.channelLayout = value;
526
+ }
527
+ /**
528
+ * Minimum quantizer.
529
+ *
530
+ * Minimum quantization parameter.
531
+ *
532
+ * Direct mapping to AVCodecContext->qmin.
533
+ */
534
+ get qMin() {
535
+ return this.native.qMin;
536
+ }
537
+ set qMin(value) {
538
+ this.native.qMin = value;
539
+ }
540
+ /**
541
+ * Maximum quantizer.
542
+ *
543
+ * Maximum quantization parameter.
544
+ *
545
+ * Direct mapping to AVCodecContext->qmax.
546
+ */
547
+ get qMax() {
548
+ return this.native.qMax;
549
+ }
550
+ set qMax(value) {
551
+ this.native.qMax = value;
552
+ }
553
+ /**
554
+ * Global quality for constant quality mode.
555
+ *
556
+ * Used by encoders that support constant quality mode (e.g., -qscale in FFmpeg CLI).
557
+ * Set this value to enable constant quality encoding instead of constant bitrate.
558
+ * Valid range depends on the codec (e.g., 0-69 for MPEG-4, FF_LAMBDA_SCALE for others).
559
+ *
560
+ * Direct mapping to AVCodecContext->global_quality.
561
+ *
562
+ * @example
563
+ * ```typescript
564
+ * // MPEG-4 constant quality (lower = better quality)
565
+ * codecContext.globalQuality = 5 * FF_QP2LAMBDA;
566
+ * ```
567
+ */
568
+ get globalQuality() {
569
+ return this.native.globalQuality;
570
+ }
571
+ set globalQuality(value) {
572
+ this.native.globalQuality = value;
573
+ }
574
+ /**
575
+ * Rate control buffer size.
576
+ *
577
+ * Decoder bitstream buffer size.
578
+ *
579
+ * Direct mapping to AVCodecContext->rc_buffer_size.
580
+ */
581
+ get rcBufferSize() {
582
+ return this.native.rcBufferSize;
583
+ }
584
+ set rcBufferSize(value) {
585
+ this.native.rcBufferSize = value;
586
+ }
587
+ /**
588
+ * Maximum bitrate.
589
+ *
590
+ * Maximum bitrate in bits per second.
591
+ *
592
+ * Direct mapping to AVCodecContext->rc_max_rate.
593
+ */
594
+ get rcMaxRate() {
595
+ return this.native.rcMaxRate;
596
+ }
597
+ set rcMaxRate(value) {
598
+ this.native.rcMaxRate = value;
599
+ }
600
+ /**
601
+ * Minimum bitrate.
602
+ *
603
+ * Minimum bitrate in bits per second.
604
+ *
605
+ * Direct mapping to AVCodecContext->rc_min_rate.
606
+ */
607
+ get rcMinRate() {
608
+ return this.native.rcMinRate;
609
+ }
610
+ set rcMinRate(value) {
611
+ this.native.rcMinRate = value;
612
+ }
613
+ /**
614
+ * Hardware device context.
615
+ *
616
+ * Reference to hardware device for acceleration.
617
+ *
618
+ * Direct mapping to AVCodecContext->hw_device_ctx.
619
+ */
620
+ get hwDeviceCtx() {
621
+ // Not cached: the native getter returns a fresh object per access, so an
622
+ // identity-based cache can never hit
623
+ const native = this.native.hwDeviceCtx;
624
+ if (!native) {
625
+ return null;
626
+ }
627
+ const device = Object.create(HardwareDeviceContext.prototype);
628
+ device.native = native;
629
+ return device;
630
+ }
631
+ set hwDeviceCtx(value) {
632
+ this.native.hwDeviceCtx = value?.getNative() ?? null;
633
+ }
634
+ /**
635
+ * Number of extra hardware frames to allocate.
636
+ *
637
+ * Specifies additional hardware frame buffers for decoders that need them.
638
+ * Useful for hardware decoders requiring frame buffering or reordering.
639
+ *
640
+ * Direct mapping to AVCodecContext->extra_hw_frames.
641
+ */
642
+ get extraHWFrames() {
643
+ return this.native.extraHWFrames;
644
+ }
645
+ set extraHWFrames(value) {
646
+ this.native.extraHWFrames = value;
647
+ }
648
+ /**
649
+ * Hardware frames context.
650
+ *
651
+ * Reference to hardware frames for GPU memory.
652
+ *
653
+ * Direct mapping to AVCodecContext->hw_frames_ctx.
654
+ */
655
+ get hwFramesCtx() {
656
+ // Not cached: the native getter returns a fresh object per access, so an
657
+ // identity-based cache can never hit
658
+ const native = this.native.hwFramesCtx;
659
+ if (!native) {
660
+ return null;
661
+ }
662
+ const frames = Object.create(HardwareFramesContext.prototype);
663
+ frames.native = native;
664
+ return frames;
665
+ }
666
+ set hwFramesCtx(value) {
667
+ this.native.hwFramesCtx = value?.getNative() ?? null;
668
+ }
669
+ /**
670
+ * Check if codec is open.
671
+ *
672
+ * True if the codec has been opened.
673
+ */
674
+ get isOpen() {
675
+ return this.native.isOpen;
676
+ }
677
+ /**
678
+ * Allocate codec context.
679
+ *
680
+ * Allocates and initializes the context for the given codec.
681
+ *
682
+ * Direct mapping to avcodec_alloc_context3().
683
+ *
684
+ * @param codec - Codec to use (null for default)
685
+ *
686
+ * @example
687
+ * ```typescript
688
+ * import { Codec } from 'node-av';
689
+ * import { AV_CODEC_ID_H264 } from 'node-av/constants';
690
+ *
691
+ * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
692
+ * ctx.allocContext3(codec);
693
+ * ```
694
+ *
695
+ * @see {@link open2} To open the codec
696
+ * @see {@link freeContext} To free the context
697
+ */
698
+ allocContext3(codec = null) {
699
+ this.native.allocContext3(codec?.getNative() ?? null);
700
+ }
701
+ /**
702
+ * Free the codec context.
703
+ *
704
+ * Releases all resources. The context becomes invalid.
705
+ *
706
+ * Direct mapping to avcodec_free_context().
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * ctx.freeContext();
711
+ * // Context is now invalid
712
+ * ```
713
+ *
714
+ * @see {@link Symbol.dispose} For automatic cleanup
715
+ * @see {@link allocContext3} To allocate a new context
716
+ */
717
+ freeContext() {
718
+ this.native.freeContext();
719
+ }
720
+ /**
721
+ * Open the codec.
722
+ *
723
+ * Initializes the codec for encoding/decoding.
724
+ * Must be called before processing frames/packets.
725
+ *
726
+ * Direct mapping to avcodec_open2().
727
+ *
728
+ * @param codec - Codec to open with (null to use already set)
729
+ *
730
+ * @param options - Codec-specific options
731
+ *
732
+ * @returns 0 on success, negative AVERROR on error:
733
+ * - AVERROR_EINVAL: Invalid parameters
734
+ * - AVERROR_ENOMEM: Memory allocation failure
735
+ *
736
+ * @example
737
+ * ```typescript
738
+ * import { FFmpegError } from 'node-av';
739
+ *
740
+ * const ret = await ctx.open2(codec);
741
+ * FFmpegError.throwIfError(ret, 'open2');
742
+ * // Codec is now open and ready
743
+ * ```
744
+ *
745
+ * @see {@link allocContext3} Must be called first
746
+ * @see {@link isOpen} To check if open
747
+ */
748
+ async open2(codec = null, options = null) {
749
+ return await this.native.open2(codec?.getNative() ?? null, options?.getNative() ?? null);
750
+ }
751
+ /**
752
+ * Open the codec synchronously.
753
+ * Synchronous version of open2.
754
+ *
755
+ * Initializes the codec for encoding/decoding.
756
+ * Must be called before processing frames/packets.
757
+ *
758
+ * Direct mapping to avcodec_open2().
759
+ *
760
+ * @param codec - Codec to open with (null to use already set)
761
+ *
762
+ * @param options - Codec-specific options
763
+ *
764
+ * @returns 0 on success, negative AVERROR on error:
765
+ * - AVERROR_EINVAL: Invalid parameters
766
+ * - AVERROR_ENOMEM: Memory allocation failure
767
+ *
768
+ * @example
769
+ * ```typescript
770
+ * import { FFmpegError } from 'node-av';
771
+ *
772
+ * const ret = ctx.open2Sync(codec);
773
+ * FFmpegError.throwIfError(ret, 'open2Sync');
774
+ * // Codec is now open and ready
775
+ * ```
776
+ *
777
+ * @see {@link open2} For async version
778
+ */
779
+ open2Sync(codec = null, options = null) {
780
+ return this.native.open2Sync(codec?.getNative() ?? null, options?.getNative() ?? null);
781
+ }
782
+ /**
783
+ * Fill codec context from parameters.
784
+ *
785
+ * Copies codec parameters from stream to context.
786
+ * Used when setting up decoders.
787
+ *
788
+ * Direct mapping to avcodec_parameters_to_context().
789
+ *
790
+ * @param params - Source codec parameters
791
+ *
792
+ * @returns 0 on success, negative AVERROR on error:
793
+ * - AVERROR_EINVAL: Invalid parameters
794
+ *
795
+ * @example
796
+ * ```typescript
797
+ * import { FFmpegError } from 'node-av';
798
+ *
799
+ * const ret = ctx.parametersToContext(stream.codecpar);
800
+ * FFmpegError.throwIfError(ret, 'parametersToContext');
801
+ * ```
802
+ *
803
+ * @see {@link parametersFromContext} For the reverse
804
+ */
805
+ parametersToContext(params) {
806
+ return this.native.parametersToContext(params.getNative());
807
+ }
808
+ /**
809
+ * Fill parameters from codec context.
810
+ *
811
+ * Copies codec parameters from context to stream.
812
+ * Used when setting up encoders.
813
+ *
814
+ * Direct mapping to avcodec_parameters_from_context().
815
+ *
816
+ * @param params - Destination codec parameters
817
+ *
818
+ * @returns 0 on success, negative AVERROR on error:
819
+ * - AVERROR_EINVAL: Invalid parameters
820
+ *
821
+ * @example
822
+ * ```typescript
823
+ * import { FFmpegError } from 'node-av';
824
+ *
825
+ * const ret = ctx.parametersFromContext(stream.codecpar);
826
+ * FFmpegError.throwIfError(ret, 'parametersFromContext');
827
+ * ```
828
+ *
829
+ * @see {@link parametersToContext} For the reverse
830
+ */
831
+ parametersFromContext(params) {
832
+ return this.native.parametersFromContext(params.getNative());
833
+ }
834
+ /**
835
+ * Flush codec buffers.
836
+ *
837
+ * Resets the internal codec state.
838
+ * Used when seeking or switching streams.
839
+ *
840
+ * Direct mapping to avcodec_flush_buffers().
841
+ *
842
+ * @example
843
+ * ```typescript
844
+ * // Flush when seeking
845
+ * ctx.flushBuffers();
846
+ * // Codec is now ready for new data
847
+ * ```
848
+ */
849
+ flushBuffers() {
850
+ this.native.flushBuffers();
851
+ }
852
+ /**
853
+ * Send packet to decoder.
854
+ *
855
+ * Submits encoded data for decoding.
856
+ * Call receiveFrame() to get decoded frames.
857
+ *
858
+ * Direct mapping to avcodec_send_packet().
859
+ *
860
+ * @param packet - Packet to decode (null to flush)
861
+ *
862
+ * @returns 0 on success, negative AVERROR on error:
863
+ * - AVERROR_EAGAIN: Must receive frames first
864
+ * - AVERROR_EOF: Decoder has been flushed
865
+ * - AVERROR_EINVAL: Invalid decoder state
866
+ * - AVERROR_ENOMEM: Memory allocation failure
867
+ *
868
+ * @example
869
+ * ```typescript
870
+ * import { FFmpegError } from 'node-av';
871
+ * import { AVERROR_EAGAIN } from 'node-av';
872
+ *
873
+ * const ret = await ctx.sendPacket(packet);
874
+ * if (ret === AVERROR_EAGAIN) {
875
+ * // Need to receive frames first
876
+ * } else {
877
+ * FFmpegError.throwIfError(ret, 'sendPacket');
878
+ * }
879
+ * ```
880
+ *
881
+ * @see {@link receiveFrame} To get decoded frames
882
+ */
883
+ async sendPacket(packet) {
884
+ return await this.native.sendPacket(packet?.getNative() ?? null);
885
+ }
886
+ /**
887
+ * Send packet to decoder synchronously.
888
+ * Synchronous version of sendPacket.
889
+ *
890
+ * Submits compressed data for decoding.
891
+ * Call receiveFrameSync() to get decoded frames.
892
+ *
893
+ * Direct mapping to avcodec_send_packet().
894
+ *
895
+ * @param packet - Packet to decode (null to flush)
896
+ *
897
+ * @returns 0 on success, negative AVERROR on error:
898
+ * - AVERROR_EAGAIN: Must receive frames first
899
+ * - AVERROR_EOF: Decoder has been flushed
900
+ * - AVERROR_EINVAL: Invalid decoder state
901
+ * - AVERROR_ENOMEM: Memory allocation failure
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * import { FFmpegError } from 'node-av';
906
+ * import { AVERROR_EAGAIN } from 'node-av';
907
+ *
908
+ * const ret = ctx.sendPacketSync(packet);
909
+ * if (ret === AVERROR_EAGAIN) {
910
+ * // Need to receive frames first
911
+ * ctx.receiveFrameSync(frame);
912
+ * }
913
+ * ```
914
+ *
915
+ * @see {@link sendPacket} For async version
916
+ */
917
+ sendPacketSync(packet) {
918
+ return this.native.sendPacketSync(packet?.getNative() ?? null);
919
+ }
920
+ /**
921
+ * Receive decoded frame.
922
+ *
923
+ * Gets a decoded frame from the decoder.
924
+ * Call after sendPacket().
925
+ *
926
+ * Direct mapping to avcodec_receive_frame().
927
+ *
928
+ * @param frame - Frame to receive into
929
+ *
930
+ * @returns 0 on success, negative AVERROR on error:
931
+ * - AVERROR_EAGAIN: Need more input
932
+ * - AVERROR_EOF: All frames have been output
933
+ * - AVERROR_EINVAL: Invalid decoder state
934
+ *
935
+ * @example
936
+ * ```typescript
937
+ * import { FFmpegError } from 'node-av';
938
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
939
+ *
940
+ * const ret = await ctx.receiveFrame(frame);
941
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
942
+ * // No frame available
943
+ * } else {
944
+ * FFmpegError.throwIfError(ret, 'receiveFrame');
945
+ * // Process decoded frame
946
+ * }
947
+ * ```
948
+ *
949
+ * @see {@link sendPacket} To send packets for decoding
950
+ */
951
+ async receiveFrame(frame) {
952
+ return await this.native.receiveFrame(frame.getNative());
953
+ }
954
+ /**
955
+ * Receive decoded frame synchronously.
956
+ * Synchronous version of receiveFrame.
957
+ *
958
+ * Gets a decoded frame from the decoder.
959
+ * Call after sendPacketSync().
960
+ *
961
+ * Direct mapping to avcodec_receive_frame().
962
+ *
963
+ * @param frame - Frame to receive into
964
+ *
965
+ * @returns 0 on success, negative AVERROR on error:
966
+ * - AVERROR_EAGAIN: Need more input
967
+ * - AVERROR_EOF: All frames have been output
968
+ * - AVERROR_EINVAL: Invalid decoder state
969
+ *
970
+ * @example
971
+ * ```typescript
972
+ * import { FFmpegError } from 'node-av';
973
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
974
+ *
975
+ * const ret = ctx.receiveFrameSync(frame);
976
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
977
+ * // No frame available
978
+ * } else {
979
+ * FFmpegError.throwIfError(ret, 'receiveFrameSync');
980
+ * // Process frame
981
+ * }
982
+ * ```
983
+ *
984
+ * @see {@link receiveFrame} For async version
985
+ */
986
+ receiveFrameSync(frame) {
987
+ return this.native.receiveFrameSync(frame.getNative());
988
+ }
989
+ /**
990
+ * Send frame to encoder.
991
+ *
992
+ * Submits raw frame for encoding.
993
+ * Call receivePacket() to get encoded packets.
994
+ *
995
+ * Direct mapping to avcodec_send_frame().
996
+ *
997
+ * @param frame - Frame to encode (null to flush)
998
+ *
999
+ * @returns 0 on success, negative AVERROR on error:
1000
+ * - AVERROR_EAGAIN: Must receive packets first
1001
+ * - AVERROR_EOF: Encoder has been flushed
1002
+ * - AVERROR_EINVAL: Invalid encoder state
1003
+ * - AVERROR_ENOMEM: Memory allocation failure
1004
+ *
1005
+ * @example
1006
+ * ```typescript
1007
+ * import { FFmpegError } from 'node-av';
1008
+ * import { AVERROR_EAGAIN } from 'node-av';
1009
+ *
1010
+ * const ret = await ctx.sendFrame(frame);
1011
+ * if (ret === AVERROR_EAGAIN) {
1012
+ * // Need to receive packets first
1013
+ * } else {
1014
+ * FFmpegError.throwIfError(ret, 'sendFrame');
1015
+ * }
1016
+ * ```
1017
+ *
1018
+ * @see {@link receivePacket} To get encoded packets
1019
+ */
1020
+ async sendFrame(frame) {
1021
+ return await this.native.sendFrame(frame?.getNative() ?? null);
1022
+ }
1023
+ /**
1024
+ * Send frame to encoder synchronously.
1025
+ * Synchronous version of sendFrame.
1026
+ *
1027
+ * Submits raw frame for encoding.
1028
+ * Call receivePacketSync() to get encoded packets.
1029
+ *
1030
+ * Direct mapping to avcodec_send_frame().
1031
+ *
1032
+ * @param frame - Frame to encode (null to flush)
1033
+ *
1034
+ * @returns 0 on success, negative AVERROR on error:
1035
+ * - AVERROR_EAGAIN: Must receive packets first
1036
+ * - AVERROR_EOF: Encoder has been flushed
1037
+ * - AVERROR_EINVAL: Invalid encoder state
1038
+ * - AVERROR_ENOMEM: Memory allocation failure
1039
+ *
1040
+ * @example
1041
+ * ```typescript
1042
+ * import { FFmpegError } from 'node-av';
1043
+ * import { AVERROR_EAGAIN } from 'node-av';
1044
+ *
1045
+ * const ret = ctx.sendFrameSync(frame);
1046
+ * if (ret === AVERROR_EAGAIN) {
1047
+ * // Need to receive packets first
1048
+ * ctx.receivePacketSync(packet);
1049
+ * }
1050
+ * ```
1051
+ *
1052
+ * @see {@link sendFrame} For async version
1053
+ */
1054
+ sendFrameSync(frame) {
1055
+ return this.native.sendFrameSync(frame?.getNative() ?? null);
1056
+ }
1057
+ /**
1058
+ * Receive encoded packet.
1059
+ *
1060
+ * Gets an encoded packet from the encoder.
1061
+ * Call after sendFrame().
1062
+ *
1063
+ * Direct mapping to avcodec_receive_packet().
1064
+ *
1065
+ * @param packet - Packet to receive into
1066
+ *
1067
+ * @returns 0 on success, negative AVERROR on error:
1068
+ * - AVERROR_EAGAIN: Need more input
1069
+ * - AVERROR_EOF: All packets have been output
1070
+ * - AVERROR_EINVAL: Invalid encoder state
1071
+ *
1072
+ * @example
1073
+ * ```typescript
1074
+ * import { FFmpegError } from 'node-av';
1075
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
1076
+ *
1077
+ * const ret = await ctx.receivePacket(packet);
1078
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
1079
+ * // No packet available
1080
+ * } else {
1081
+ * FFmpegError.throwIfError(ret, 'receivePacket');
1082
+ * // Process encoded packet
1083
+ * }
1084
+ * ```
1085
+ *
1086
+ * @see {@link sendFrame} To send frames for encoding
1087
+ */
1088
+ async receivePacket(packet) {
1089
+ return await this.native.receivePacket(packet.getNative());
1090
+ }
1091
+ /**
1092
+ * Receive encoded packet synchronously.
1093
+ * Synchronous version of receivePacket.
1094
+ *
1095
+ * Gets an encoded packet from the encoder.
1096
+ * Call after sendFrameSync().
1097
+ *
1098
+ * Direct mapping to avcodec_receive_packet().
1099
+ *
1100
+ * @param packet - Packet to receive into
1101
+ *
1102
+ * @returns 0 on success, negative AVERROR on error:
1103
+ * - AVERROR_EAGAIN: Need more input
1104
+ * - AVERROR_EOF: All packets have been output
1105
+ * - AVERROR_EINVAL: Invalid encoder state
1106
+ *
1107
+ * @example
1108
+ * ```typescript
1109
+ * import { FFmpegError } from 'node-av';
1110
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
1111
+ *
1112
+ * const ret = ctx.receivePacketSync(packet);
1113
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
1114
+ * // No packet available
1115
+ * } else {
1116
+ * FFmpegError.throwIfError(ret, 'receivePacketSync');
1117
+ * // Process packet
1118
+ * }
1119
+ * ```
1120
+ *
1121
+ * @see {@link receivePacket} For async version
1122
+ */
1123
+ receivePacketSync(packet) {
1124
+ return this.native.receivePacketSync(packet.getNative());
1125
+ }
1126
+ /**
1127
+ * Set hardware pixel format.
1128
+ *
1129
+ * Configures hardware acceleration pixel formats.
1130
+ * Used in get_format callback for hardware decoding.
1131
+ *
1132
+ * @param hwFormat - Hardware pixel format
1133
+ *
1134
+ * @param swFormat - Software pixel format (optional)
1135
+ *
1136
+ * @example
1137
+ * ```typescript
1138
+ * import { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12 } from 'node-av/constants';
1139
+ *
1140
+ * ctx.setHardwarePixelFormat(AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12);
1141
+ * ```
1142
+ */
1143
+ setHardwarePixelFormat(hwFormat, swFormat) {
1144
+ this.native.setHardwarePixelFormat(hwFormat, swFormat);
1145
+ }
1146
+ /**
1147
+ * Set codec flags.
1148
+ *
1149
+ * Sets one or more flags using bitwise OR. Allows setting multiple flags
1150
+ * without manually performing bitwise operations.
1151
+ *
1152
+ * @param flags - One or more flag values to set
1153
+ *
1154
+ * @example
1155
+ * ```typescript
1156
+ * import { AV_CODEC_FLAG_QSCALE, AV_CODEC_FLAG_PSNR } from 'node-av/constants';
1157
+ *
1158
+ * // Set multiple flags at once
1159
+ * codecContext.setFlags(AV_CODEC_FLAG_QSCALE, AV_CODEC_FLAG_PSNR);
1160
+ * ```
1161
+ *
1162
+ * @see {@link clearFlags} To unset flags
1163
+ * @see {@link hasFlags} To check flags
1164
+ * @see {@link flags} For direct flag access
1165
+ */
1166
+ setFlags(...flags) {
1167
+ for (const flag of flags) {
1168
+ this.native.flags = (this.native.flags | flag);
1169
+ }
1170
+ }
1171
+ /**
1172
+ * Clear codec flags.
1173
+ *
1174
+ * Clears one or more flags using bitwise AND NOT. Allows clearing multiple
1175
+ * flags without manually performing bitwise operations.
1176
+ *
1177
+ * @param flags - One or more flag values to clear
1178
+ *
1179
+ * @example
1180
+ * ```typescript
1181
+ * import { AV_CODEC_FLAG_PSNR } from 'node-av/constants';
1182
+ *
1183
+ * // Clear specific flag
1184
+ * codecContext.clearFlags(AV_CODEC_FLAG_PSNR);
1185
+ * ```
1186
+ *
1187
+ * @see {@link setFlags} To set flags
1188
+ * @see {@link hasFlags} To check flags
1189
+ * @see {@link flags} For direct flag access
1190
+ */
1191
+ clearFlags(...flags) {
1192
+ for (const flag of flags) {
1193
+ this.native.flags = (this.native.flags & ~flag);
1194
+ }
1195
+ }
1196
+ /**
1197
+ * Check if codec has specific flags.
1198
+ *
1199
+ * Tests whether all specified flags are set using bitwise AND.
1200
+ *
1201
+ * @param flags - One or more flag values to check
1202
+ *
1203
+ * @returns true if all specified flags are set, false otherwise
1204
+ *
1205
+ * @example
1206
+ * ```typescript
1207
+ * import { AV_CODEC_FLAG_QSCALE } from 'node-av/constants';
1208
+ *
1209
+ * if (codecContext.hasFlags(AV_CODEC_FLAG_QSCALE)) {
1210
+ * console.log('QSCALE flag is set');
1211
+ * }
1212
+ * ```
1213
+ *
1214
+ * @see {@link setFlags} To set flags
1215
+ * @see {@link clearFlags} To unset flags
1216
+ * @see {@link flags} For direct flag access
1217
+ */
1218
+ hasFlags(...flags) {
1219
+ for (const flag of flags) {
1220
+ if ((this.native.flags & flag) !== flag) {
1221
+ return false;
1222
+ }
1223
+ }
1224
+ return true;
1225
+ }
1226
+ /**
1227
+ * Set codec flags2.
1228
+ *
1229
+ * Sets one or more flags2 values using bitwise OR. Allows setting multiple flags
1230
+ * without manually performing bitwise operations.
1231
+ *
1232
+ * @param flags - One or more flag2 values to set
1233
+ *
1234
+ * @example
1235
+ * ```typescript
1236
+ * import { AV_CODEC_FLAG2_FAST } from 'node-av/constants';
1237
+ *
1238
+ * // Set multiple flags2 at once
1239
+ * codecContext.setFlags2(AV_CODEC_FLAG2_FAST);
1240
+ * ```
1241
+ *
1242
+ * @see {@link clearFlags2} To unset flags2
1243
+ * @see {@link hasFlags2} To check flags2
1244
+ * @see {@link flags2} For direct flag2 access
1245
+ */
1246
+ setFlags2(...flags) {
1247
+ for (const flag of flags) {
1248
+ this.native.flags2 = (this.native.flags2 | flag);
1249
+ }
1250
+ }
1251
+ /**
1252
+ * Clear codec flags2.
1253
+ *
1254
+ * Clears one or more flags2 values using bitwise AND NOT. Allows clearing multiple
1255
+ * flags without manually performing bitwise operations.
1256
+ *
1257
+ * @param flags - One or more flag2 values to clear
1258
+ *
1259
+ * @example
1260
+ * ```typescript
1261
+ * import { AV_CODEC_FLAG2_FAST } from 'node-av/constants';
1262
+ *
1263
+ * // Clear specific flag2
1264
+ * codecContext.clearFlags2(AV_CODEC_FLAG2_FAST);
1265
+ * ```
1266
+ *
1267
+ * @see {@link setFlags2} To set flags2
1268
+ * @see {@link hasFlags2} To check flags2
1269
+ * @see {@link flags2} For direct flag2 access
1270
+ */
1271
+ clearFlags2(...flags) {
1272
+ for (const flag of flags) {
1273
+ this.native.flags2 = (this.native.flags2 & ~flag);
1274
+ }
1275
+ }
1276
+ /**
1277
+ * Check if codec has specific flags2.
1278
+ *
1279
+ * Tests whether all specified flags2 are set using bitwise AND.
1280
+ *
1281
+ * @param flags - One or more flag2 values to check
1282
+ *
1283
+ * @returns true if all specified flags2 are set, false otherwise
1284
+ *
1285
+ * @example
1286
+ * ```typescript
1287
+ * import { AV_CODEC_FLAG2_FAST } from 'node-av/constants';
1288
+ *
1289
+ * if (codecContext.hasFlags2(AV_CODEC_FLAG2_FAST)) {
1290
+ * console.log('FAST flag2 is set');
1291
+ * }
1292
+ * ```
1293
+ *
1294
+ * @see {@link setFlags2} To set flags2
1295
+ * @see {@link clearFlags2} To unset flags2
1296
+ * @see {@link flags2} For direct flag2 access
1297
+ */
1298
+ hasFlags2(...flags) {
1299
+ for (const flag of flags) {
1300
+ if ((this.native.flags2 & flag) !== flag) {
1301
+ return false;
1302
+ }
1303
+ }
1304
+ return true;
1305
+ }
1306
+ /**
1307
+ * Get the underlying native CodecContext object.
1308
+ *
1309
+ * @returns The native CodecContext binding object
1310
+ *
1311
+ * @internal
1312
+ */
1313
+ getNative() {
1314
+ return this.native;
1315
+ }
1316
+ /**
1317
+ * Dispose of the codec context.
1318
+ *
1319
+ * Implements the Disposable interface for automatic cleanup.
1320
+ * Equivalent to calling freeContext().
1321
+ *
1322
+ * @example
1323
+ * ```typescript
1324
+ * {
1325
+ * using ctx = new CodecContext();
1326
+ * ctx.allocContext3(codec);
1327
+ * await ctx.open2();
1328
+ * // Use context...
1329
+ * } // Automatically freed when leaving scope
1330
+ * ```
1331
+ */
1332
+ [Symbol.dispose]() {
1333
+ this.native[Symbol.dispose]();
1334
+ }
1335
+ }
1336
+ //# sourceMappingURL=codec-context.js.map