node-av 1.1.0 → 1.2.0

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 (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -3
  21. package/dist/api/index.js +1 -1
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  27. package/dist/api/media-input.js +205 -103
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +210 -128
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. package/CHANGELOG.md +0 -8
@@ -4,11 +4,12 @@ import { HardwareFramesContext } from './hardware-frames-context.js';
4
4
  import { OptionMember } from './option.js';
5
5
  import { Rational } from './rational.js';
6
6
  /**
7
- * Codec context for encoding and decoding media.
7
+ * Codec context for encoding and decoding.
8
8
  *
9
- * Central structure for media encoding and decoding operations.
10
- * Manages codec state, parameters, and threading.
11
- * Supports both software and hardware acceleration.
9
+ * Main structure for codec operations, containing all codec parameters and state.
10
+ * Handles encoding raw frames to packets and decoding packets to frames.
11
+ * Supports both software and hardware-accelerated codecs.
12
+ * Must be configured and opened before use.
12
13
  *
13
14
  * Direct mapping to FFmpeg's AVCodecContext.
14
15
  *
@@ -17,64 +18,45 @@ import { Rational } from './rational.js';
17
18
  * import { CodecContext, Codec, FFmpegError } from 'node-av';
18
19
  * import { AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P } from 'node-av/constants';
19
20
  *
20
- * // Create and configure decoder context
21
+ * // Create decoder
22
+ * const decoder = new CodecContext();
21
23
  * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
22
- * const ctx = new CodecContext();
23
- * ctx.allocContext3(codec);
24
+ * decoder.allocContext3(codec);
24
25
  *
25
- * // Configure parameters
26
- * ctx.width = 1920;
27
- * ctx.height = 1080;
28
- * ctx.pixelFormat = AV_PIX_FMT_YUV420P;
26
+ * // Configure from stream parameters
27
+ * decoder.parametersToContext(stream.codecpar);
29
28
  *
30
- * // Open codec
31
- * const ret = await ctx.open2(codec, null);
29
+ * // Open decoder
30
+ * let ret = await decoder.open2(codec);
32
31
  * FFmpegError.throwIfError(ret, 'open2');
33
32
  *
34
33
  * // Decode packets
35
- * const sendRet = await ctx.sendPacket(packet);
36
- * FFmpegError.throwIfError(sendRet, 'sendPacket');
37
- *
38
- * while (true) {
39
- * const ret = await ctx.receiveFrame(frame);
40
- * if (ret === AVERROR_EOF || ret === AVERROR(EAGAIN)) break;
41
- * FFmpegError.throwIfError(ret, 'receiveFrame');
42
- * // Process frame
34
+ * ret = await decoder.sendPacket(packet);
35
+ * if (ret >= 0) {
36
+ * ret = await decoder.receiveFrame(frame);
37
+ * if (ret >= 0) {
38
+ * // Process decoded frame
39
+ * }
43
40
  * }
44
41
  *
45
42
  * // Cleanup
46
- * ctx.freeContext();
43
+ * decoder.freeContext();
47
44
  * ```
45
+ *
46
+ * @see [AVCodecContext](https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html) - FFmpeg Doxygen
47
+ * @see {@link Codec} For finding codecs
48
+ * @see {@link CodecParameters} For stream parameters
48
49
  */
49
50
  export class CodecContext extends OptionMember {
50
51
  _hwDeviceCtx; // Cache for hardware device context wrapper
51
52
  _hwFramesCtx; // Cache for hardware frames context wrapper
52
- /**
53
- * Create a new codec context.
54
- *
55
- * The context is uninitialized - you must call allocContext3() before use.
56
- * No FFmpeg resources are allocated until initialization.
57
- *
58
- * Direct wrapper around AVCodecContext.
59
- *
60
- * @example
61
- * ```typescript
62
- * import { CodecContext, Codec } from 'node-av';
63
- *
64
- * const ctx = new CodecContext();
65
- * ctx.allocContext3(codec);
66
- * // Context is now ready for configuration
67
- * ```
68
- */
69
53
  constructor() {
70
54
  super(new bindings.CodecContext());
71
55
  }
72
56
  /**
73
- * Codec type.
74
- *
75
- * Identifies whether this is a video, audio, subtitle, or data codec.
57
+ * Type of codec (video/audio/subtitle).
76
58
  *
77
- * Direct mapping to AVCodecContext->codec_type
59
+ * Direct mapping to AVCodecContext->codec_type.
78
60
  */
79
61
  get codecType() {
80
62
  return this.native.codecType;
@@ -83,11 +65,9 @@ export class CodecContext extends OptionMember {
83
65
  this.native.codecType = value;
84
66
  }
85
67
  /**
86
- * Codec ID.
68
+ * Codec identifier.
87
69
  *
88
- * Identifies the specific codec (e.g., AV_CODEC_ID_H264, AV_CODEC_ID_AAC).
89
- *
90
- * Direct mapping to AVCodecContext->codec_id
70
+ * Direct mapping to AVCodecContext->codec_id.
91
71
  */
92
72
  get codecId() {
93
73
  return this.native.codecId;
@@ -96,12 +76,12 @@ export class CodecContext extends OptionMember {
96
76
  this.native.codecId = value;
97
77
  }
98
78
  /**
99
- * The average bitrate.
79
+ * Average bitrate.
100
80
  *
101
- * Direct mapping to AVCodecContext->bit_rate
81
+ * Target bitrate for encoding, detected bitrate for decoding.
82
+ * In bits per second.
102
83
  *
103
- * - encoding: Set by user, unused for constant quantizer encoding.
104
- * - decoding: Set by user, may be overwritten by libavcodec if this info is available in the stream.
84
+ * Direct mapping to AVCodecContext->bit_rate.
105
85
  */
106
86
  get bitRate() {
107
87
  return this.native.bitRate;
@@ -112,12 +92,9 @@ export class CodecContext extends OptionMember {
112
92
  /**
113
93
  * Time base for timestamps.
114
94
  *
115
- * The fundamental unit of time (in seconds) for frame timestamps.
116
- *
117
- * Direct mapping to AVCodecContext->time_base
95
+ * Fundamental unit of time in seconds for this context.
118
96
  *
119
- * - encoding: MUST be set by user.
120
- * - decoding: the use of this field for decoding is deprecated. Use framerate instead.
97
+ * Direct mapping to AVCodecContext->time_base.
121
98
  */
122
99
  get timeBase() {
123
100
  const tb = this.native.timeBase;
@@ -127,9 +104,11 @@ export class CodecContext extends OptionMember {
127
104
  this.native.timeBase = { num: value.num, den: value.den };
128
105
  }
129
106
  /**
130
- * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
131
- * This is the fundamental unit of time (in seconds) in terms
132
- * of which frame timestamps are represented.
107
+ * Packet time base.
108
+ *
109
+ * Time base of the packets from/to the demuxer/muxer.
110
+ *
111
+ * Direct mapping to AVCodecContext->pkt_timebase.
133
112
  */
134
113
  get pktTimebase() {
135
114
  const tb = this.native.pktTimebase;
@@ -140,19 +119,20 @@ export class CodecContext extends OptionMember {
140
119
  }
141
120
  /**
142
121
  * Codec delay.
143
- * - encoding: Number of frames delay there will be from the encoder input to
144
- * the decoder output. (we assume the decoder matches the spec)
145
- * - decoding: Number of frames delay in addition to what a standard decoder
146
- * as specified in the spec would produce.
147
- * @readonly
122
+ *
123
+ * Number of frames the decoder needs to output before first frame.
124
+ *
125
+ * Direct mapping to AVCodecContext->delay.
148
126
  */
149
127
  get delay() {
150
128
  return this.native.delay;
151
129
  }
152
130
  /**
153
- * AV_CODEC_FLAG_* flags.
154
- * - encoding: Set by user.
155
- * - decoding: Set by user.
131
+ * Codec flags.
132
+ *
133
+ * Combination of AV_CODEC_FLAG_* values.
134
+ *
135
+ * Direct mapping to AVCodecContext->flags.
156
136
  */
157
137
  get flags() {
158
138
  return this.native.flags;
@@ -161,9 +141,11 @@ export class CodecContext extends OptionMember {
161
141
  this.native.flags = value;
162
142
  }
163
143
  /**
164
- * AV_CODEC_FLAG2_* flags.
165
- * - encoding: Set by user.
166
- * - decoding: Set by user.
144
+ * Additional codec flags.
145
+ *
146
+ * Combination of AV_CODEC_FLAG2_* values.
147
+ *
148
+ * Direct mapping to AVCodecContext->flags2.
167
149
  */
168
150
  get flags2() {
169
151
  return this.native.flags2;
@@ -172,16 +154,11 @@ export class CodecContext extends OptionMember {
172
154
  this.native.flags2 = value;
173
155
  }
174
156
  /**
175
- * Some codecs need / can use extradata like Huffman tables.
176
- * MJPEG: Huffman tables
177
- * rv10: additional flags
178
- * MPEG-4: global headers (they can be in the bitstream or here)
179
- * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
180
- * than extradata_size to avoid problems if it is read with the bitstream reader.
181
- * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
182
- * Must be allocated with the av_malloc() family of functions.
183
- * - encoding: Set/allocated/freed by libavcodec.
184
- * - decoding: Set/allocated/freed by user.
157
+ * Extra binary data for codec.
158
+ *
159
+ * Contains codec-specific initialization data.
160
+ *
161
+ * Direct mapping to AVCodecContext->extradata.
185
162
  */
186
163
  get extraData() {
187
164
  return this.native.extraData;
@@ -190,9 +167,11 @@ export class CodecContext extends OptionMember {
190
167
  this.native.extraData = value;
191
168
  }
192
169
  /**
193
- * Profile (FF_PROFILE_H264_BASELINE, FF_PROFILE_H264_MAIN, etc.)
194
- * - encoding: Set by user.
195
- * - decoding: Set by libavcodec.
170
+ * Codec profile.
171
+ *
172
+ * FF_PROFILE_* value indicating codec profile.
173
+ *
174
+ * Direct mapping to AVCodecContext->profile.
196
175
  */
197
176
  get profile() {
198
177
  return this.native.profile;
@@ -201,9 +180,11 @@ export class CodecContext extends OptionMember {
201
180
  this.native.profile = value;
202
181
  }
203
182
  /**
204
- * Level (FF_LEVEL_UNKNOWN, or codec-specific values)
205
- * - encoding: Set by user.
206
- * - decoding: Set by libavcodec.
183
+ * Codec level.
184
+ *
185
+ * Level within the specified profile.
186
+ *
187
+ * Direct mapping to AVCodecContext->level.
207
188
  */
208
189
  get level() {
209
190
  return this.native.level;
@@ -212,10 +193,12 @@ export class CodecContext extends OptionMember {
212
193
  this.native.level = value;
213
194
  }
214
195
  /**
215
- * Thread count.
216
- * Is used to decide how many independent tasks should be passed to execute().
217
- * - encoding: Set by user.
218
- * - decoding: Set by user.
196
+ * Thread count for codec.
197
+ *
198
+ * Number of threads to use for decoding/encoding.
199
+ * 0 for automatic selection.
200
+ *
201
+ * Direct mapping to AVCodecContext->thread_count.
219
202
  */
220
203
  get threadCount() {
221
204
  return this.native.threadCount;
@@ -224,12 +207,9 @@ export class CodecContext extends OptionMember {
224
207
  this.native.threadCount = value;
225
208
  }
226
209
  /**
227
- * Picture width.
228
- * - encoding: MUST be set by user.
229
- * - decoding: May be set by the user before opening the decoder if known e.g.
230
- * from the container. Some decoders will require the dimensions
231
- * to be set by the caller. During decoding, the decoder may
232
- * overwrite those values as required while parsing the data.
210
+ * Picture width in pixels.
211
+ *
212
+ * Direct mapping to AVCodecContext->width.
233
213
  */
234
214
  get width() {
235
215
  return this.native.width;
@@ -238,12 +218,9 @@ export class CodecContext extends OptionMember {
238
218
  this.native.width = value;
239
219
  }
240
220
  /**
241
- * Picture height.
242
- * - encoding: MUST be set by user.
243
- * - decoding: May be set by the user before opening the decoder if known e.g.
244
- * from the container. Some decoders will require the dimensions
245
- * to be set by the caller. During decoding, the decoder may
246
- * overwrite those values as required while parsing the data.
221
+ * Picture height in pixels.
222
+ *
223
+ * Direct mapping to AVCodecContext->height.
247
224
  */
248
225
  get height() {
249
226
  return this.native.height;
@@ -252,9 +229,11 @@ export class CodecContext extends OptionMember {
252
229
  this.native.height = value;
253
230
  }
254
231
  /**
255
- * The number of pictures in a group of pictures, or 0 for intra_only.
256
- * - encoding: Set by user.
257
- * - decoding: unused
232
+ * Group of pictures size.
233
+ *
234
+ * Maximum number of frames between keyframes.
235
+ *
236
+ * Direct mapping to AVCodecContext->gop_size.
258
237
  */
259
238
  get gopSize() {
260
239
  return this.native.gopSize;
@@ -264,9 +243,10 @@ export class CodecContext extends OptionMember {
264
243
  }
265
244
  /**
266
245
  * Pixel format.
267
- * - encoding: Set by user.
268
- * - decoding: Set by user if known, overridden by libavcodec while
269
- * parsing the data.
246
+ *
247
+ * Format of the video frames.
248
+ *
249
+ * Direct mapping to AVCodecContext->pix_fmt.
270
250
  */
271
251
  get pixelFormat() {
272
252
  return this.native.pixelFormat;
@@ -275,10 +255,11 @@ export class CodecContext extends OptionMember {
275
255
  this.native.pixelFormat = value;
276
256
  }
277
257
  /**
278
- * Maximum number of B-frames between non-B-frames.
279
- * Note: The output will be delayed by max_b_frames+1 relative to the input.
280
- * - encoding: Set by user.
281
- * - decoding: unused
258
+ * Maximum number of B-frames.
259
+ *
260
+ * B-frames between non-B-frames.
261
+ *
262
+ * Direct mapping to AVCodecContext->max_b_frames.
282
263
  */
283
264
  get maxBFrames() {
284
265
  return this.native.maxBFrames;
@@ -289,15 +270,9 @@ export class CodecContext extends OptionMember {
289
270
  /**
290
271
  * Macroblock decision mode.
291
272
  *
292
- * Direct mapping to AVCodecContext->mb_decision
273
+ * Algorithm for macroblock decision.
293
274
  *
294
- * - encoding: Set by user.
295
- * - decoding: unused
296
- *
297
- * Values:
298
- * - 0 (FF_MB_DECISION_SIMPLE): uses mb_cmp
299
- * - 1 (FF_MB_DECISION_BITS): chooses the one which needs the fewest bits
300
- * - 2 (FF_MB_DECISION_RD): rate distortion
275
+ * Direct mapping to AVCodecContext->mb_decision.
301
276
  */
302
277
  get mbDecision() {
303
278
  return this.native.mbDecision;
@@ -306,21 +281,21 @@ export class CodecContext extends OptionMember {
306
281
  this.native.mbDecision = value;
307
282
  }
308
283
  /**
309
- * Size of the frame reordering buffer in the decoder.
310
- * For MPEG-2 it is 1 IPB or 0 low delay IP.
311
- * - encoding: Set by libavcodec.
312
- * - decoding: Set by libavcodec.
313
- * @readonly
284
+ * Number of frames delay in decoder.
285
+ *
286
+ * For codecs with B-frames.
287
+ *
288
+ * Direct mapping to AVCodecContext->has_b_frames.
314
289
  */
315
290
  get hasBFrames() {
316
291
  return this.native.hasBFrames;
317
292
  }
318
293
  /**
319
- * Sample aspect ratio (0 if unknown).
320
- * That is the width of a pixel divided by the height of the pixel.
321
- * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
322
- * - encoding: Set by user.
323
- * - decoding: Set by libavcodec.
294
+ * Sample aspect ratio.
295
+ *
296
+ * Pixel width/height ratio.
297
+ *
298
+ * Direct mapping to AVCodecContext->sample_aspect_ratio.
324
299
  */
325
300
  get sampleAspectRatio() {
326
301
  const sar = this.native.sampleAspectRatio;
@@ -330,11 +305,11 @@ export class CodecContext extends OptionMember {
330
305
  this.native.sampleAspectRatio = { num: value.num, den: value.den };
331
306
  }
332
307
  /**
333
- * Framerate.
334
- * - encoding: May be used to signal the framerate of CFR content to an encoder.
335
- * - decoding: For codecs that store a framerate value in the compressed
336
- * bitstream, the decoder may export it here. { 0, 1} when
337
- * unknown.
308
+ * Frame rate.
309
+ *
310
+ * Frames per second for encoding.
311
+ *
312
+ * Direct mapping to AVCodecContext->framerate.
338
313
  */
339
314
  get framerate() {
340
315
  const fr = this.native.framerate;
@@ -344,9 +319,11 @@ export class CodecContext extends OptionMember {
344
319
  this.native.framerate = { num: value.num, den: value.den };
345
320
  }
346
321
  /**
347
- * Color range (AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, etc.)
348
- * - encoding: Set by user
349
- * - decoding: Set by libavcodec
322
+ * Color range.
323
+ *
324
+ * MPEG (limited) or JPEG (full) range.
325
+ *
326
+ * Direct mapping to AVCodecContext->color_range.
350
327
  */
351
328
  get colorRange() {
352
329
  return this.native.colorRange;
@@ -355,9 +332,11 @@ export class CodecContext extends OptionMember {
355
332
  this.native.colorRange = value;
356
333
  }
357
334
  /**
358
- * Chromaticity coordinates of the source primaries.
359
- * - encoding: Set by user
360
- * - decoding: Set by libavcodec
335
+ * Color primaries.
336
+ *
337
+ * Chromaticity coordinates of source primaries.
338
+ *
339
+ * Direct mapping to AVCodecContext->color_primaries.
361
340
  */
362
341
  get colorPrimaries() {
363
342
  return this.native.colorPrimaries;
@@ -366,9 +345,11 @@ export class CodecContext extends OptionMember {
366
345
  this.native.colorPrimaries = value;
367
346
  }
368
347
  /**
369
- * Color Transfer Characteristic.
370
- * - encoding: Set by user
371
- * - decoding: Set by libavcodec
348
+ * Color transfer characteristic.
349
+ *
350
+ * Transfer function (gamma).
351
+ *
352
+ * Direct mapping to AVCodecContext->color_trc.
372
353
  */
373
354
  get colorTrc() {
374
355
  return this.native.colorTrc;
@@ -377,9 +358,11 @@ export class CodecContext extends OptionMember {
377
358
  this.native.colorTrc = value;
378
359
  }
379
360
  /**
380
- * YUV colorspace type.
381
- * - encoding: Set by user
382
- * - decoding: Set by libavcodec
361
+ * YUV color space.
362
+ *
363
+ * Color space for YUV content.
364
+ *
365
+ * Direct mapping to AVCodecContext->colorspace.
383
366
  */
384
367
  get colorSpace() {
385
368
  return this.native.colorSpace;
@@ -388,9 +371,11 @@ export class CodecContext extends OptionMember {
388
371
  this.native.colorSpace = value;
389
372
  }
390
373
  /**
391
- * Location of chroma samples.
392
- * - encoding: Set by user
393
- * - decoding: Set by libavcodec
374
+ * Chroma sample location.
375
+ *
376
+ * Position of chroma samples.
377
+ *
378
+ * Direct mapping to AVCodecContext->chroma_sample_location.
394
379
  */
395
380
  get chromaLocation() {
396
381
  return this.native.chromaLocation;
@@ -399,10 +384,11 @@ export class CodecContext extends OptionMember {
399
384
  this.native.chromaLocation = value;
400
385
  }
401
386
  /**
402
- * Sample rate of the audio data.
403
- * - encoding: MUST be set by user.
404
- * - decoding: May be set by the user before opening the decoder if known e.g.
405
- * from the container. The decoder can change this value.
387
+ * Audio sample rate.
388
+ *
389
+ * Samples per second.
390
+ *
391
+ * Direct mapping to AVCodecContext->sample_rate.
406
392
  */
407
393
  get sampleRate() {
408
394
  return this.native.sampleRate;
@@ -412,7 +398,8 @@ export class CodecContext extends OptionMember {
412
398
  }
413
399
  /**
414
400
  * Number of audio channels.
415
- * @deprecated use ch_layout.nb_channels
401
+ *
402
+ * Direct mapping to AVCodecContext->channels.
416
403
  */
417
404
  get channels() {
418
405
  return this.native.channels;
@@ -422,8 +409,10 @@ export class CodecContext extends OptionMember {
422
409
  }
423
410
  /**
424
411
  * Audio sample format.
425
- * - encoding: Set by user.
426
- * - decoding: Set by libavcodec.
412
+ *
413
+ * Format of audio samples.
414
+ *
415
+ * Direct mapping to AVCodecContext->sample_fmt.
427
416
  */
428
417
  get sampleFormat() {
429
418
  return this.native.sampleFormat;
@@ -432,12 +421,9 @@ export class CodecContext extends OptionMember {
432
421
  this.native.sampleFormat = value;
433
422
  }
434
423
  /**
435
- * Number of samples per channel in an audio frame.
436
- * - encoding: Set by libavcodec in avcodec_open2(). Each submitted frame
437
- * except the last must contain exactly frame_size samples per channel.
438
- * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
439
- * frame size is not restricted.
440
- * - decoding: May be set by some decoders to indicate constant frame size.
424
+ * Number of samples per audio frame.
425
+ *
426
+ * Direct mapping to AVCodecContext->frame_size.
441
427
  */
442
428
  get frameSize() {
443
429
  return this.native.frameSize;
@@ -446,19 +432,21 @@ export class CodecContext extends OptionMember {
446
432
  this.native.frameSize = value;
447
433
  }
448
434
  /**
449
- * Frame counter, set by libavcodec.
450
- * - decoding: Total number of frames returned from the decoder so far.
451
- * - encoding: Total number of frames passed to the encoder so far.
452
- * @readonly
435
+ * Current frame number.
436
+ *
437
+ * Frame counter for debugging.
438
+ *
439
+ * Direct mapping to AVCodecContext->frame_number.
453
440
  */
454
441
  get frameNumber() {
455
442
  return this.native.frameNumber;
456
443
  }
457
444
  /**
458
445
  * Audio channel layout.
459
- * - encoding: Set by user.
460
- * - decoding: Set by user, may be overwritten by libavcodec.
461
- * @deprecated use ch_layout
446
+ *
447
+ * Describes channel configuration.
448
+ *
449
+ * Direct mapping to AVCodecContext->ch_layout.
462
450
  */
463
451
  get channelLayout() {
464
452
  return this.native.channelLayout;
@@ -468,8 +456,10 @@ export class CodecContext extends OptionMember {
468
456
  }
469
457
  /**
470
458
  * Minimum quantizer.
471
- * - encoding: Set by user.
472
- * - decoding: unused
459
+ *
460
+ * Minimum quantization parameter.
461
+ *
462
+ * Direct mapping to AVCodecContext->qmin.
473
463
  */
474
464
  get qMin() {
475
465
  return this.native.qMin;
@@ -479,8 +469,10 @@ export class CodecContext extends OptionMember {
479
469
  }
480
470
  /**
481
471
  * Maximum quantizer.
482
- * - encoding: Set by user.
483
- * - decoding: unused
472
+ *
473
+ * Maximum quantization parameter.
474
+ *
475
+ * Direct mapping to AVCodecContext->qmax.
484
476
  */
485
477
  get qMax() {
486
478
  return this.native.qMax;
@@ -489,9 +481,11 @@ export class CodecContext extends OptionMember {
489
481
  this.native.qMax = value;
490
482
  }
491
483
  /**
484
+ * Rate control buffer size.
485
+ *
492
486
  * Decoder bitstream buffer size.
493
- * - encoding: Set by user.
494
- * - decoding: unused
487
+ *
488
+ * Direct mapping to AVCodecContext->rc_buffer_size.
495
489
  */
496
490
  get rcBufferSize() {
497
491
  return this.native.rcBufferSize;
@@ -501,8 +495,10 @@ export class CodecContext extends OptionMember {
501
495
  }
502
496
  /**
503
497
  * Maximum bitrate.
504
- * - encoding: Set by user.
505
- * - decoding: Set by user, may be overwritten by libavcodec.
498
+ *
499
+ * Maximum bitrate in bits per second.
500
+ *
501
+ * Direct mapping to AVCodecContext->rc_max_rate.
506
502
  */
507
503
  get rcMaxRate() {
508
504
  return this.native.rcMaxRate;
@@ -512,8 +508,10 @@ export class CodecContext extends OptionMember {
512
508
  }
513
509
  /**
514
510
  * Minimum bitrate.
515
- * - encoding: Set by user.
516
- * - decoding: unused
511
+ *
512
+ * Minimum bitrate in bits per second.
513
+ *
514
+ * Direct mapping to AVCodecContext->rc_min_rate.
517
515
  */
518
516
  get rcMinRate() {
519
517
  return this.native.rcMinRate;
@@ -521,14 +519,12 @@ export class CodecContext extends OptionMember {
521
519
  set rcMinRate(value) {
522
520
  this.native.rcMinRate = value;
523
521
  }
524
- // Hardware Acceleration
525
522
  /**
526
- * Hardware device context for hardware acceleration.
523
+ * Hardware device context.
527
524
  *
528
- * Direct mapping to AVCodecContext->hw_device_ctx
525
+ * Reference to hardware device for acceleration.
529
526
  *
530
- * If the codec supports hardware acceleration, this should be set
531
- * to the hardware device context before opening the codec.
527
+ * Direct mapping to AVCodecContext->hw_device_ctx.
532
528
  */
533
529
  get hwDeviceCtx() {
534
530
  const native = this.native.hwDeviceCtx;
@@ -553,13 +549,11 @@ export class CodecContext extends OptionMember {
553
549
  this._hwDeviceCtx = undefined;
554
550
  }
555
551
  /**
556
- * Hardware frames context for hardware acceleration.
552
+ * Hardware frames context.
557
553
  *
558
- * Direct mapping to AVCodecContext->hw_frames_ctx
554
+ * Reference to hardware frames for GPU memory.
559
555
  *
560
- * For decoders, this is an optional field that the decoder can set
561
- * to provide the caller with hardware frames. For encoders, this
562
- * must be set by the caller before opening the encoder.
556
+ * Direct mapping to AVCodecContext->hw_frames_ctx.
563
557
  */
564
558
  get hwFramesCtx() {
565
559
  const native = this.native.hwFramesCtx;
@@ -584,38 +578,29 @@ export class CodecContext extends OptionMember {
584
578
  this._hwFramesCtx = undefined;
585
579
  }
586
580
  /**
587
- * Check if the codec context is open.
588
- *
589
- * Direct mapping to avcodec_is_open()
581
+ * Check if codec is open.
590
582
  *
591
- * @returns true if the codec is open and ready for encoding/decoding
583
+ * True if the codec has been opened.
592
584
  */
593
585
  get isOpen() {
594
586
  return this.native.isOpen;
595
587
  }
596
588
  /**
597
- * Allocate an AVCodecContext and set its fields to default values.
598
- *
599
- * Allocates the codec context and initializes with codec-specific defaults.
600
- * Must be called before using the context.
589
+ * Allocate codec context.
601
590
  *
602
- * Direct mapping to avcodec_alloc_context3()
591
+ * Allocates and initializes the context for the given codec.
603
592
  *
604
- * @param codec - If non-NULL, allocate private data and initialize defaults
605
- * for the given codec. It is illegal to then call open2()
606
- * with a different codec.
593
+ * Direct mapping to avcodec_alloc_context3().
607
594
  *
608
- * @throws {Error} Memory allocation failure (ENOMEM)
595
+ * @param codec - Codec to use (null for default)
609
596
  *
610
597
  * @example
611
598
  * ```typescript
612
- * import { CodecContext, Codec } from 'node-av';
599
+ * import { Codec } from 'node-av';
613
600
  * import { AV_CODEC_ID_H264 } from 'node-av/constants';
614
601
  *
615
602
  * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
616
- * const ctx = new CodecContext();
617
603
  * ctx.allocContext3(codec);
618
- * // Context is now allocated with H264 defaults
619
604
  * ```
620
605
  *
621
606
  * @see {@link open2} To open the codec
@@ -625,329 +610,278 @@ export class CodecContext extends OptionMember {
625
610
  this.native.allocContext3(codec?.getNative() ?? null);
626
611
  }
627
612
  /**
628
- * Free the codec context and everything associated with it.
613
+ * Free the codec context.
629
614
  *
630
- * Releases all resources associated with the codec context.
631
- * The context becomes invalid after this call.
615
+ * Releases all resources. The context becomes invalid.
632
616
  *
633
- * Direct mapping to avcodec_free_context()
617
+ * Direct mapping to avcodec_free_context().
634
618
  *
635
619
  * @example
636
620
  * ```typescript
637
621
  * ctx.freeContext();
638
- * // ctx is now invalid and should not be used
622
+ * // Context is now invalid
639
623
  * ```
624
+ *
625
+ * @see {@link Symbol.dispose} For automatic cleanup
626
+ * @see {@link allocContext3} To allocate a new context
640
627
  */
641
628
  freeContext() {
642
629
  this.native.freeContext();
643
630
  }
644
631
  /**
645
- * Initialize the AVCodecContext to use the given AVCodec.
646
- *
647
- * Opens the codec and prepares it for encoding or decoding.
648
- * Prior to using this function the context has to be allocated with allocContext3().
632
+ * Open the codec.
649
633
  *
650
- * Direct mapping to avcodec_open2()
634
+ * Initializes the codec for encoding/decoding.
635
+ * Must be called before processing frames/packets.
651
636
  *
652
- * @param codec - The codec to open this context for. If a non-NULL codec has been
653
- * previously passed to allocContext3() for this context, then this
654
- * parameter MUST be either NULL or equal to the previously passed codec.
655
- * @param options - A dictionary filled with AVCodecContext and codec-private options.
637
+ * Direct mapping to avcodec_open2().
656
638
  *
639
+ * @param codec - Codec to open with (null to use already set)
640
+ * @param options - Codec-specific options
657
641
  * @returns 0 on success, negative AVERROR on error:
658
- * - 0: Success
659
- * - AVERROR(EINVAL): Invalid parameters or codec not found
660
- * - AVERROR(ENOMEM): Memory allocation failure
661
- * - <0: Other codec-specific errors
642
+ * - AVERROR_EINVAL: Invalid parameters
643
+ * - AVERROR_ENOMEM: Memory allocation failure
662
644
  *
663
645
  * @example
664
646
  * ```typescript
665
647
  * import { FFmpegError } from 'node-av';
666
648
  *
667
- * const ret = await ctx.open2(codec, null);
649
+ * const ret = await ctx.open2(codec);
668
650
  * FFmpegError.throwIfError(ret, 'open2');
651
+ * // Codec is now open and ready
669
652
  * ```
670
653
  *
671
- * @see {@link close} To close the codec context
672
- * @see {@link allocContext3} Must be called before open2()
654
+ * @see {@link allocContext3} Must be called first
655
+ * @see {@link isOpen} To check if open
673
656
  */
674
657
  async open2(codec = null, options = null) {
675
658
  return await this.native.open2(codec?.getNative() ?? null, options?.getNative() ?? null);
676
659
  }
677
660
  /**
678
- * Fill the codec context based on the values from the supplied codec parameters.
661
+ * Fill codec context from parameters.
679
662
  *
680
- * Direct mapping to avcodec_parameters_to_context()
663
+ * Copies codec parameters from stream to context.
664
+ * Used when setting up decoders.
681
665
  *
682
- * @param params - Codec parameters to copy from
666
+ * Direct mapping to avcodec_parameters_to_context().
683
667
  *
668
+ * @param params - Source codec parameters
684
669
  * @returns 0 on success, negative AVERROR on error:
685
- * - 0: Success
686
- * - AVERROR(EINVAL): Invalid parameters
687
- * - <0: Other errors
670
+ * - AVERROR_EINVAL: Invalid parameters
688
671
  *
689
672
  * @example
690
673
  * ```typescript
691
- * // Copy parameters from stream to codec context
674
+ * import { FFmpegError } from 'node-av';
675
+ *
692
676
  * const ret = ctx.parametersToContext(stream.codecpar);
693
- * if (ret < 0) {
694
- * throw new FFmpegError(ret);
695
- * }
677
+ * FFmpegError.throwIfError(ret, 'parametersToContext');
696
678
  * ```
697
679
  *
698
- * @see parametersFromContext() - To copy in the opposite direction
680
+ * @see {@link parametersFromContext} For the reverse
699
681
  */
700
682
  parametersToContext(params) {
701
683
  return this.native.parametersToContext(params.getNative());
702
684
  }
703
685
  /**
704
- * Fill the parameters struct based on the values from the supplied codec context.
686
+ * Fill parameters from codec context.
705
687
  *
706
- * Direct mapping to avcodec_parameters_from_context()
688
+ * Copies codec parameters from context to stream.
689
+ * Used when setting up encoders.
707
690
  *
708
- * @param params - Codec parameters to fill
691
+ * Direct mapping to avcodec_parameters_from_context().
709
692
  *
693
+ * @param params - Destination codec parameters
710
694
  * @returns 0 on success, negative AVERROR on error:
711
- * - 0: Success
712
- * - AVERROR(EINVAL): Invalid parameters
713
- * - <0: Other errors
695
+ * - AVERROR_EINVAL: Invalid parameters
714
696
  *
715
697
  * @example
716
698
  * ```typescript
717
- * // Copy parameters from codec context to stream
718
- * const ret = ctx.parametersFromContext(outputStream.codecpar);
719
- * if (ret < 0) {
720
- * throw new FFmpegError(ret);
721
- * }
699
+ * import { FFmpegError } from 'node-av';
700
+ *
701
+ * const ret = ctx.parametersFromContext(stream.codecpar);
702
+ * FFmpegError.throwIfError(ret, 'parametersFromContext');
722
703
  * ```
723
704
  *
724
- * @see parametersToContext() - To copy in the opposite direction
705
+ * @see {@link parametersToContext} For the reverse
725
706
  */
726
707
  parametersFromContext(params) {
727
708
  return this.native.parametersFromContext(params.getNative());
728
709
  }
729
710
  /**
730
- * Reset the internal codec state / flush internal buffers.
731
- * Should be called when seeking or switching to a different stream.
711
+ * Flush codec buffers.
712
+ *
713
+ * Resets the internal codec state.
714
+ * Used when seeking or switching streams.
732
715
  *
733
- * Direct mapping to avcodec_flush_buffers()
716
+ * Direct mapping to avcodec_flush_buffers().
734
717
  *
735
718
  * @example
736
719
  * ```typescript
737
- * // Flush buffers when seeking
738
- * formatContext.seekFrame(streamIndex, timestamp, flags);
739
- * codecContext.flushBuffers();
720
+ * // Flush when seeking
721
+ * ctx.flushBuffers();
722
+ * // Codec is now ready for new data
740
723
  * ```
741
724
  */
742
725
  flushBuffers() {
743
726
  this.native.flushBuffers();
744
727
  }
745
728
  /**
746
- * Supply raw packet data as input to a decoder.
747
- *
748
- * Sends compressed data to the decoder for processing.
749
- * The decoder may buffer the packet internally.
729
+ * Send packet to decoder.
750
730
  *
751
- * Direct mapping to avcodec_send_packet()
731
+ * Submits encoded data for decoding.
732
+ * Call receiveFrame() to get decoded frames.
752
733
  *
753
- * @param packet - The input packet. May be NULL to signal end of stream (flush).
734
+ * Direct mapping to avcodec_send_packet().
754
735
  *
736
+ * @param packet - Packet to decode (null to flush)
755
737
  * @returns 0 on success, negative AVERROR on error:
756
- * - 0: Success
757
- * - AVERROR(EAGAIN): Input not accepted - must read output with receiveFrame() first
758
- * - AVERROR_EOF: Decoder has been flushed, no new packets can be sent
759
- * - AVERROR(EINVAL): Codec not opened, is an encoder, or requires flush
760
- * - AVERROR(ENOMEM): Failed to add packet to internal queue
761
- * - <0: Other legitimate decoding errors
738
+ * - AVERROR_EAGAIN: Must receive frames first
739
+ * - AVERROR_EOF: Decoder has been flushed
740
+ * - AVERROR_EINVAL: Invalid decoder state
741
+ * - AVERROR_ENOMEM: Memory allocation failure
762
742
  *
763
743
  * @example
764
744
  * ```typescript
765
- * import { FFmpegError, Frame } from 'node-av';
766
- * import { AVERROR_EAGAIN } from 'node-av/constants';
745
+ * import { FFmpegError } from 'node-av';
746
+ * import { AVERROR_EAGAIN } from 'node-av';
767
747
  *
768
- * // Decode packet
769
- * const ret = await decoder.sendPacket(packet);
748
+ * const ret = await ctx.sendPacket(packet);
770
749
  * if (ret === AVERROR_EAGAIN) {
771
- * // Need to read output first
772
- * const frame = new Frame();
773
- * frame.alloc();
774
- * const recvRet = await decoder.receiveFrame(frame);
775
- * FFmpegError.throwIfError(recvRet, 'receiveFrame');
750
+ * // Need to receive frames first
776
751
  * } else {
777
752
  * FFmpegError.throwIfError(ret, 'sendPacket');
778
753
  * }
779
754
  * ```
780
755
  *
781
- * @see {@link receiveFrame} To retrieve decoded frames
756
+ * @see {@link receiveFrame} To get decoded frames
782
757
  */
783
758
  async sendPacket(packet) {
784
759
  return await this.native.sendPacket(packet?.getNative() ?? null);
785
760
  }
786
761
  /**
787
- * Return decoded output data from a decoder.
788
- *
789
- * Retrieves decoded frames from the decoder.
790
- * The frame must be allocated before calling this function.
762
+ * Receive decoded frame.
791
763
  *
792
- * Direct mapping to avcodec_receive_frame()
764
+ * Gets a decoded frame from the decoder.
765
+ * Call after sendPacket().
793
766
  *
794
- * @param frame - Frame to receive decoded data. Must be allocated.
767
+ * Direct mapping to avcodec_receive_frame().
795
768
  *
769
+ * @param frame - Frame to receive into
796
770
  * @returns 0 on success, negative AVERROR on error:
797
- * - 0: Success, a frame was returned
798
- * - AVERROR(EAGAIN): Output not available, must send new input
799
- * - AVERROR_EOF: Decoder fully flushed, no more frames
800
- * - AVERROR(EINVAL): Codec not opened or is an encoder
801
- * - <0: Other legitimate decoding errors
771
+ * - AVERROR_EAGAIN: Need more input
772
+ * - AVERROR_EOF: All frames have been output
773
+ * - AVERROR_EINVAL: Invalid decoder state
802
774
  *
803
775
  * @example
804
776
  * ```typescript
805
- * import { Frame, FFmpegError } from 'node-av';
806
- * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
807
- *
808
- * // Receive all frames from decoder
809
- * const frame = new Frame();
810
- * frame.alloc();
811
- *
812
- * while (true) {
813
- * const ret = await decoder.receiveFrame(frame);
814
- * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
815
- * break;
816
- * }
817
- * FFmpegError.throwIfError(ret, 'receiveFrame');
777
+ * import { FFmpegError } from 'node-av';
778
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
818
779
  *
819
- * // Process frame
820
- * processFrame(frame);
821
- * frame.unref();
780
+ * const ret = await ctx.receiveFrame(frame);
781
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
782
+ * // No frame available
783
+ * } else {
784
+ * FFmpegError.throwIfError(ret, 'receiveFrame');
785
+ * // Process decoded frame
822
786
  * }
823
787
  * ```
824
788
  *
825
- * @see {@link sendPacket} To send input packets
789
+ * @see {@link sendPacket} To send packets for decoding
826
790
  */
827
791
  async receiveFrame(frame) {
828
792
  return await this.native.receiveFrame(frame.getNative());
829
793
  }
830
794
  /**
831
- * Supply a raw video or audio frame to the encoder.
795
+ * Send frame to encoder.
832
796
  *
833
- * Sends uncompressed frame data to the encoder.
834
- * Use receivePacket() to retrieve buffered output packets.
797
+ * Submits raw frame for encoding.
798
+ * Call receivePacket() to get encoded packets.
835
799
  *
836
- * Direct mapping to avcodec_send_frame()
837
- *
838
- * @param frame - AVFrame containing the raw audio or video frame to be encoded.
839
- * Can be NULL for flush packet (signals end of stream).
800
+ * Direct mapping to avcodec_send_frame().
840
801
  *
802
+ * @param frame - Frame to encode (null to flush)
841
803
  * @returns 0 on success, negative AVERROR on error:
842
- * - 0: Success
843
- * - AVERROR(EAGAIN): Input not accepted - must read output with receivePacket()
844
- * - AVERROR_EOF: Encoder has been flushed, no new frames can be sent
845
- * - AVERROR(EINVAL): Codec not opened, is a decoder, or requires flush
846
- * - AVERROR(ENOMEM): Failed to add packet to internal queue
847
- * - <0: Other legitimate encoding errors
804
+ * - AVERROR_EAGAIN: Must receive packets first
805
+ * - AVERROR_EOF: Encoder has been flushed
806
+ * - AVERROR_EINVAL: Invalid encoder state
807
+ * - AVERROR_ENOMEM: Memory allocation failure
848
808
  *
849
809
  * @example
850
810
  * ```typescript
851
- * import { Packet, FFmpegError } from 'node-av';
852
- * import { AVERROR_EAGAIN } from 'node-av/constants';
811
+ * import { FFmpegError } from 'node-av';
812
+ * import { AVERROR_EAGAIN } from 'node-av';
853
813
  *
854
- * // Send frame to encoder
855
- * const ret = await encoder.sendFrame(frame);
814
+ * const ret = await ctx.sendFrame(frame);
856
815
  * if (ret === AVERROR_EAGAIN) {
857
- * // Need to read output first
858
- * const packet = new Packet();
859
- * packet.alloc();
860
- * const recvRet = await encoder.receivePacket(packet);
861
- * FFmpegError.throwIfError(recvRet, 'receivePacket');
816
+ * // Need to receive packets first
862
817
  * } else {
863
818
  * FFmpegError.throwIfError(ret, 'sendFrame');
864
819
  * }
865
820
  * ```
866
821
  *
867
- * @see {@link receivePacket} To retrieve encoded packets
868
- *
869
- * @note For audio: If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
870
- * can have any number of samples. If not set, frame.nbSamples must equal
871
- * avctx.frameSize for all frames except the last.
822
+ * @see {@link receivePacket} To get encoded packets
872
823
  */
873
824
  async sendFrame(frame) {
874
825
  return await this.native.sendFrame(frame?.getNative() ?? null);
875
826
  }
876
827
  /**
877
- * Read encoded data from the encoder.
828
+ * Receive encoded packet.
878
829
  *
879
- * Retrieves compressed packets from the encoder.
880
- * The packet must be allocated before calling.
830
+ * Gets an encoded packet from the encoder.
831
+ * Call after sendFrame().
881
832
  *
882
- * Direct mapping to avcodec_receive_packet()
883
- *
884
- * @param packet - Packet to receive encoded data. Must be allocated.
833
+ * Direct mapping to avcodec_receive_packet().
885
834
  *
835
+ * @param packet - Packet to receive into
886
836
  * @returns 0 on success, negative AVERROR on error:
887
- * - 0: Success, a packet was returned
888
- * - AVERROR(EAGAIN): Output not available, must send new input
889
- * - AVERROR_EOF: Encoder fully flushed, no more packets
890
- * - AVERROR(EINVAL): Codec not opened or is a decoder
891
- * - <0: Other legitimate encoding errors
837
+ * - AVERROR_EAGAIN: Need more input
838
+ * - AVERROR_EOF: All packets have been output
839
+ * - AVERROR_EINVAL: Invalid encoder state
892
840
  *
893
841
  * @example
894
842
  * ```typescript
895
- * import { Packet, FFmpegError } from 'node-av';
896
- * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
897
- *
898
- * // Receive all packets from encoder
899
- * const packet = new Packet();
900
- * packet.alloc();
901
- *
902
- * while (true) {
903
- * const ret = await encoder.receivePacket(packet);
904
- * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
905
- * break;
906
- * }
907
- * if (ret < 0) {
908
- * throw new FFmpegError(ret);
909
- * }
910
- * // Write packet to output
911
- * await formatContext.writeFrame(packet);
912
- * packet.unref();
843
+ * import { FFmpegError } from 'node-av';
844
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
845
+ *
846
+ * const ret = await ctx.receivePacket(packet);
847
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
848
+ * // No packet available
849
+ * } else {
850
+ * FFmpegError.throwIfError(ret, 'receivePacket');
851
+ * // Process encoded packet
913
852
  * }
914
853
  * ```
915
854
  *
916
- * @see sendFrame() - To send input frames
855
+ * @see {@link sendFrame} To send frames for encoding
917
856
  */
918
857
  async receivePacket(packet) {
919
858
  return await this.native.receivePacket(packet.getNative());
920
859
  }
921
860
  /**
922
- * Set the hardware pixel format for hardware acceleration.
861
+ * Set hardware pixel format.
923
862
  *
924
- * This configures the codec context to prefer a specific hardware pixel format
925
- * when negotiating formats with FFmpeg. Optionally, a software fallback format
926
- * can be specified.
863
+ * Configures hardware acceleration pixel formats.
864
+ * Used in get_format callback for hardware decoding.
927
865
  *
928
- * @param hwFormat - The preferred hardware pixel format (e.g., AV_PIX_FMT_VIDEOTOOLBOX)
929
- * @param swFormat - Optional software fallback format if hardware format is not available
866
+ * @param hwFormat - Hardware pixel format
867
+ * @param swFormat - Software pixel format (optional)
930
868
  *
931
869
  * @example
932
870
  * ```typescript
933
- * // For VideoToolbox hardware decoding on macOS
934
- * codecContext.setHardwarePixelFormat(AV_PIX_FMT_VIDEOTOOLBOX);
935
- *
936
- * // With software fallback
937
- * codecContext.setHardwarePixelFormat(
938
- * AV_PIX_FMT_VIDEOTOOLBOX,
939
- * AV_PIX_FMT_YUV420P // Fallback to YUV420P if hardware not available
940
- * );
871
+ * import { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12 } from 'node-av/constants';
872
+ *
873
+ * ctx.setHardwarePixelFormat(AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12);
941
874
  * ```
942
875
  */
943
876
  setHardwarePixelFormat(hwFormat, swFormat) {
944
877
  this.native.setHardwarePixelFormat(hwFormat, swFormat);
945
878
  }
946
879
  /**
947
- * Get the native FFmpeg AVCodecContext pointer.
880
+ * Get the underlying native CodecContext object.
881
+ *
882
+ * @returns The native CodecContext binding object
948
883
  *
949
- * @internal For use by other wrapper classes
950
- * @returns The underlying native codec context object
884
+ * @internal
951
885
  */
952
886
  getNative() {
953
887
  return this.native;
@@ -963,7 +897,8 @@ export class CodecContext extends OptionMember {
963
897
  * {
964
898
  * using ctx = new CodecContext();
965
899
  * ctx.allocContext3(codec);
966
- * // ... use context
900
+ * await ctx.open2();
901
+ * // Use context...
967
902
  * } // Automatically freed when leaving scope
968
903
  * ```
969
904
  */