@revizly/node-av 5.2.2-beta.1

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