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