node-av 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +377 -0
  4. package/binding.gyp +78 -0
  5. package/dist/api/bitstream-filter.d.ts +246 -0
  6. package/dist/api/bitstream-filter.js +369 -0
  7. package/dist/api/bitstream-filter.js.map +1 -0
  8. package/dist/api/decoder.d.ts +257 -0
  9. package/dist/api/decoder.js +424 -0
  10. package/dist/api/decoder.js.map +1 -0
  11. package/dist/api/encoder.d.ts +298 -0
  12. package/dist/api/encoder.js +574 -0
  13. package/dist/api/encoder.js.map +1 -0
  14. package/dist/api/filter.d.ts +457 -0
  15. package/dist/api/filter.js +876 -0
  16. package/dist/api/filter.js.map +1 -0
  17. package/dist/api/hardware.d.ts +318 -0
  18. package/dist/api/hardware.js +558 -0
  19. package/dist/api/hardware.js.map +1 -0
  20. package/dist/api/index.d.ts +12 -0
  21. package/dist/api/index.js +20 -0
  22. package/dist/api/index.js.map +1 -0
  23. package/dist/api/io-stream.d.ts +109 -0
  24. package/dist/api/io-stream.js +124 -0
  25. package/dist/api/io-stream.js.map +1 -0
  26. package/dist/api/media-input.d.ts +295 -0
  27. package/dist/api/media-input.js +456 -0
  28. package/dist/api/media-input.js.map +1 -0
  29. package/dist/api/media-output.d.ts +274 -0
  30. package/dist/api/media-output.js +486 -0
  31. package/dist/api/media-output.js.map +1 -0
  32. package/dist/api/pipeline.d.ts +117 -0
  33. package/dist/api/pipeline.js +836 -0
  34. package/dist/api/pipeline.js.map +1 -0
  35. package/dist/api/types.d.ts +440 -0
  36. package/dist/api/types.js +2 -0
  37. package/dist/api/types.js.map +1 -0
  38. package/dist/api/utilities/audio-sample.d.ts +115 -0
  39. package/dist/api/utilities/audio-sample.js +110 -0
  40. package/dist/api/utilities/audio-sample.js.map +1 -0
  41. package/dist/api/utilities/channel-layout.d.ts +83 -0
  42. package/dist/api/utilities/channel-layout.js +87 -0
  43. package/dist/api/utilities/channel-layout.js.map +1 -0
  44. package/dist/api/utilities/image.d.ts +177 -0
  45. package/dist/api/utilities/image.js +183 -0
  46. package/dist/api/utilities/image.js.map +1 -0
  47. package/dist/api/utilities/index.d.ts +8 -0
  48. package/dist/api/utilities/index.js +17 -0
  49. package/dist/api/utilities/index.js.map +1 -0
  50. package/dist/api/utilities/media-type.d.ts +56 -0
  51. package/dist/api/utilities/media-type.js +60 -0
  52. package/dist/api/utilities/media-type.js.map +1 -0
  53. package/dist/api/utilities/pixel-format.d.ts +94 -0
  54. package/dist/api/utilities/pixel-format.js +102 -0
  55. package/dist/api/utilities/pixel-format.js.map +1 -0
  56. package/dist/api/utilities/sample-format.d.ts +132 -0
  57. package/dist/api/utilities/sample-format.js +144 -0
  58. package/dist/api/utilities/sample-format.js.map +1 -0
  59. package/dist/api/utilities/streaming.d.ts +104 -0
  60. package/dist/api/utilities/streaming.js +137 -0
  61. package/dist/api/utilities/streaming.js.map +1 -0
  62. package/dist/api/utilities/timestamp.d.ts +187 -0
  63. package/dist/api/utilities/timestamp.js +200 -0
  64. package/dist/api/utilities/timestamp.js.map +1 -0
  65. package/dist/api/utils.d.ts +61 -0
  66. package/dist/api/utils.js +330 -0
  67. package/dist/api/utils.js.map +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +5 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lib/audio-fifo.d.ts +339 -0
  72. package/dist/lib/audio-fifo.js +365 -0
  73. package/dist/lib/audio-fifo.js.map +1 -0
  74. package/dist/lib/binding.d.ts +192 -0
  75. package/dist/lib/binding.js +70 -0
  76. package/dist/lib/binding.js.map +1 -0
  77. package/dist/lib/bitstream-filter-context.d.ts +345 -0
  78. package/dist/lib/bitstream-filter-context.js +407 -0
  79. package/dist/lib/bitstream-filter-context.js.map +1 -0
  80. package/dist/lib/bitstream-filter.d.ts +124 -0
  81. package/dist/lib/bitstream-filter.js +138 -0
  82. package/dist/lib/bitstream-filter.js.map +1 -0
  83. package/dist/lib/channel-layouts.d.ts +51 -0
  84. package/dist/lib/channel-layouts.js +55 -0
  85. package/dist/lib/channel-layouts.js.map +1 -0
  86. package/dist/lib/codec-context.d.ts +763 -0
  87. package/dist/lib/codec-context.js +974 -0
  88. package/dist/lib/codec-context.js.map +1 -0
  89. package/dist/lib/codec-parameters.d.ts +362 -0
  90. package/dist/lib/codec-parameters.js +460 -0
  91. package/dist/lib/codec-parameters.js.map +1 -0
  92. package/dist/lib/codec-parser.d.ts +185 -0
  93. package/dist/lib/codec-parser.js +193 -0
  94. package/dist/lib/codec-parser.js.map +1 -0
  95. package/dist/lib/codec.d.ts +432 -0
  96. package/dist/lib/codec.js +492 -0
  97. package/dist/lib/codec.js.map +1 -0
  98. package/dist/lib/constants.d.ts +2037 -0
  99. package/dist/lib/constants.js +1659 -0
  100. package/dist/lib/constants.js.map +1 -0
  101. package/dist/lib/dictionary.d.ts +371 -0
  102. package/dist/lib/dictionary.js +406 -0
  103. package/dist/lib/dictionary.js.map +1 -0
  104. package/dist/lib/error.d.ts +216 -0
  105. package/dist/lib/error.js +254 -0
  106. package/dist/lib/error.js.map +1 -0
  107. package/dist/lib/filter-context.d.ts +445 -0
  108. package/dist/lib/filter-context.js +505 -0
  109. package/dist/lib/filter-context.js.map +1 -0
  110. package/dist/lib/filter-graph.d.ts +556 -0
  111. package/dist/lib/filter-graph.js +608 -0
  112. package/dist/lib/filter-graph.js.map +1 -0
  113. package/dist/lib/filter-inout.d.ts +205 -0
  114. package/dist/lib/filter-inout.js +264 -0
  115. package/dist/lib/filter-inout.js.map +1 -0
  116. package/dist/lib/filter.d.ts +231 -0
  117. package/dist/lib/filter.js +260 -0
  118. package/dist/lib/filter.js.map +1 -0
  119. package/dist/lib/format-context.d.ts +798 -0
  120. package/dist/lib/format-context.js +845 -0
  121. package/dist/lib/format-context.js.map +1 -0
  122. package/dist/lib/frame.d.ts +784 -0
  123. package/dist/lib/frame.js +933 -0
  124. package/dist/lib/frame.js.map +1 -0
  125. package/dist/lib/hardware-device-context.d.ts +407 -0
  126. package/dist/lib/hardware-device-context.js +429 -0
  127. package/dist/lib/hardware-device-context.js.map +1 -0
  128. package/dist/lib/hardware-frames-context.d.ts +374 -0
  129. package/dist/lib/hardware-frames-context.js +430 -0
  130. package/dist/lib/hardware-frames-context.js.map +1 -0
  131. package/dist/lib/index.d.ts +31 -0
  132. package/dist/lib/index.js +54 -0
  133. package/dist/lib/index.js.map +1 -0
  134. package/dist/lib/input-format.d.ts +216 -0
  135. package/dist/lib/input-format.js +246 -0
  136. package/dist/lib/input-format.js.map +1 -0
  137. package/dist/lib/io-context.d.ts +495 -0
  138. package/dist/lib/io-context.js +550 -0
  139. package/dist/lib/io-context.js.map +1 -0
  140. package/dist/lib/log.d.ts +201 -0
  141. package/dist/lib/log.js +219 -0
  142. package/dist/lib/log.js.map +1 -0
  143. package/dist/lib/native-types.d.ts +719 -0
  144. package/dist/lib/native-types.js +2 -0
  145. package/dist/lib/native-types.js.map +1 -0
  146. package/dist/lib/option.d.ts +589 -0
  147. package/dist/lib/option.js +853 -0
  148. package/dist/lib/option.js.map +1 -0
  149. package/dist/lib/output-format.d.ts +179 -0
  150. package/dist/lib/output-format.js +205 -0
  151. package/dist/lib/output-format.js.map +1 -0
  152. package/dist/lib/packet.d.ts +487 -0
  153. package/dist/lib/packet.js +558 -0
  154. package/dist/lib/packet.js.map +1 -0
  155. package/dist/lib/rational.d.ts +210 -0
  156. package/dist/lib/rational.js +233 -0
  157. package/dist/lib/rational.js.map +1 -0
  158. package/dist/lib/software-resample-context.d.ts +572 -0
  159. package/dist/lib/software-resample-context.js +610 -0
  160. package/dist/lib/software-resample-context.js.map +1 -0
  161. package/dist/lib/software-scale-context.d.ts +290 -0
  162. package/dist/lib/software-scale-context.js +308 -0
  163. package/dist/lib/software-scale-context.js.map +1 -0
  164. package/dist/lib/stream.d.ts +322 -0
  165. package/dist/lib/stream.js +408 -0
  166. package/dist/lib/stream.js.map +1 -0
  167. package/dist/lib/types.d.ts +59 -0
  168. package/dist/lib/types.js +8 -0
  169. package/dist/lib/types.js.map +1 -0
  170. package/dist/lib/utilities.d.ts +346 -0
  171. package/dist/lib/utilities.js +424 -0
  172. package/dist/lib/utilities.js.map +1 -0
  173. package/install/check.js +113 -0
  174. package/install/ffmpeg.js +163 -0
  175. package/package.json +107 -0
@@ -0,0 +1,763 @@
1
+ import { HardwareDeviceContext } from './hardware-device-context.js';
2
+ import { HardwareFramesContext } from './hardware-frames-context.js';
3
+ import { OptionMember } from './option.js';
4
+ import { Rational } from './rational.js';
5
+ import type { CodecParameters } from './codec-parameters.js';
6
+ 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
+ import type { Dictionary } from './dictionary.js';
9
+ import type { Frame } from './frame.js';
10
+ import type { NativeCodecContext, NativeWrapper } from './native-types.js';
11
+ import type { Packet } from './packet.js';
12
+ import type { ChannelLayout } from './types.js';
13
+ /**
14
+ * Codec context for encoding and decoding media.
15
+ *
16
+ * Central structure for media encoding and decoding operations.
17
+ * Manages codec state, parameters, and threading.
18
+ * Supports both software and hardware acceleration.
19
+ *
20
+ * Direct mapping to FFmpeg's AVCodecContext.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { CodecContext, Codec, FFmpegError } from 'node-av';
25
+ * import { AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P } from 'node-av/constants';
26
+ *
27
+ * // Create and configure decoder context
28
+ * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
29
+ * const ctx = new CodecContext();
30
+ * ctx.allocContext3(codec);
31
+ *
32
+ * // Configure parameters
33
+ * ctx.width = 1920;
34
+ * ctx.height = 1080;
35
+ * ctx.pixelFormat = AV_PIX_FMT_YUV420P;
36
+ *
37
+ * // Open codec
38
+ * const ret = await ctx.open2(codec, null);
39
+ * FFmpegError.throwIfError(ret, 'open2');
40
+ *
41
+ * // 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
50
+ * }
51
+ *
52
+ * // Cleanup
53
+ * ctx.freeContext();
54
+ * ```
55
+ */
56
+ export declare class CodecContext extends OptionMember<NativeCodecContext> implements Disposable, NativeWrapper<NativeCodecContext> {
57
+ private _hwDeviceCtx?;
58
+ 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
+ constructor();
77
+ /**
78
+ * Codec type.
79
+ *
80
+ * Identifies whether this is a video, audio, subtitle, or data codec.
81
+ *
82
+ * Direct mapping to AVCodecContext->codec_type
83
+ */
84
+ get codecType(): AVMediaType;
85
+ set codecType(value: AVMediaType);
86
+ /**
87
+ * Codec ID.
88
+ *
89
+ * Identifies the specific codec (e.g., AV_CODEC_ID_H264, AV_CODEC_ID_AAC).
90
+ *
91
+ * Direct mapping to AVCodecContext->codec_id
92
+ */
93
+ get codecId(): AVCodecID;
94
+ set codecId(value: AVCodecID);
95
+ /**
96
+ * The average bitrate.
97
+ *
98
+ * Direct mapping to AVCodecContext->bit_rate
99
+ *
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.
102
+ */
103
+ get bitRate(): bigint;
104
+ set bitRate(value: bigint);
105
+ /**
106
+ * Time base for timestamps.
107
+ *
108
+ * The fundamental unit of time (in seconds) for frame timestamps.
109
+ *
110
+ * Direct mapping to AVCodecContext->time_base
111
+ *
112
+ * - encoding: MUST be set by user.
113
+ * - decoding: the use of this field for decoding is deprecated. Use framerate instead.
114
+ */
115
+ get timeBase(): Rational;
116
+ set timeBase(value: Rational);
117
+ /**
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.
121
+ */
122
+ get pktTimebase(): Rational;
123
+ set pktTimebase(value: Rational);
124
+ /**
125
+ * 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
131
+ */
132
+ get delay(): number;
133
+ /**
134
+ * AV_CODEC_FLAG_* flags.
135
+ * - encoding: Set by user.
136
+ * - decoding: Set by user.
137
+ */
138
+ get flags(): AVCodecFlag;
139
+ set flags(value: AVCodecFlag);
140
+ /**
141
+ * AV_CODEC_FLAG2_* flags.
142
+ * - encoding: Set by user.
143
+ * - decoding: Set by user.
144
+ */
145
+ get flags2(): AVCodecFlag2;
146
+ set flags2(value: AVCodecFlag2);
147
+ /**
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.
158
+ */
159
+ get extraData(): Buffer | null;
160
+ set extraData(value: Buffer | null);
161
+ /**
162
+ * Profile (FF_PROFILE_H264_BASELINE, FF_PROFILE_H264_MAIN, etc.)
163
+ * - encoding: Set by user.
164
+ * - decoding: Set by libavcodec.
165
+ */
166
+ get profile(): AVProfile;
167
+ set profile(value: AVProfile);
168
+ /**
169
+ * Level (FF_LEVEL_UNKNOWN, or codec-specific values)
170
+ * - encoding: Set by user.
171
+ * - decoding: Set by libavcodec.
172
+ */
173
+ get level(): number;
174
+ set level(value: number);
175
+ /**
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.
180
+ */
181
+ get threadCount(): number;
182
+ set threadCount(value: number);
183
+ /**
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.
190
+ */
191
+ get width(): number;
192
+ set width(value: number);
193
+ /**
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.
200
+ */
201
+ get height(): number;
202
+ set height(value: number);
203
+ /**
204
+ * The number of pictures in a group of pictures, or 0 for intra_only.
205
+ * - encoding: Set by user.
206
+ * - decoding: unused
207
+ */
208
+ get gopSize(): number;
209
+ set gopSize(value: number);
210
+ /**
211
+ * Pixel format.
212
+ * - encoding: Set by user.
213
+ * - decoding: Set by user if known, overridden by libavcodec while
214
+ * parsing the data.
215
+ */
216
+ get pixelFormat(): AVPixelFormat;
217
+ set pixelFormat(value: AVPixelFormat);
218
+ /**
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
223
+ */
224
+ get maxBFrames(): number;
225
+ set maxBFrames(value: number);
226
+ /**
227
+ * Macroblock decision mode.
228
+ *
229
+ * Direct mapping to AVCodecContext->mb_decision
230
+ *
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
238
+ */
239
+ get mbDecision(): number;
240
+ set mbDecision(value: number);
241
+ /**
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
247
+ */
248
+ get hasBFrames(): number;
249
+ /**
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.
255
+ */
256
+ get sampleAspectRatio(): Rational;
257
+ set sampleAspectRatio(value: Rational);
258
+ /**
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.
264
+ */
265
+ get framerate(): Rational;
266
+ set framerate(value: Rational);
267
+ /**
268
+ * Color range (AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, etc.)
269
+ * - encoding: Set by user
270
+ * - decoding: Set by libavcodec
271
+ */
272
+ get colorRange(): AVColorRange;
273
+ set colorRange(value: AVColorRange);
274
+ /**
275
+ * Chromaticity coordinates of the source primaries.
276
+ * - encoding: Set by user
277
+ * - decoding: Set by libavcodec
278
+ */
279
+ get colorPrimaries(): AVColorPrimaries;
280
+ set colorPrimaries(value: AVColorPrimaries);
281
+ /**
282
+ * Color Transfer Characteristic.
283
+ * - encoding: Set by user
284
+ * - decoding: Set by libavcodec
285
+ */
286
+ get colorTrc(): AVColorTransferCharacteristic;
287
+ set colorTrc(value: AVColorTransferCharacteristic);
288
+ /**
289
+ * YUV colorspace type.
290
+ * - encoding: Set by user
291
+ * - decoding: Set by libavcodec
292
+ */
293
+ get colorSpace(): AVColorSpace;
294
+ set colorSpace(value: AVColorSpace);
295
+ /**
296
+ * Location of chroma samples.
297
+ * - encoding: Set by user
298
+ * - decoding: Set by libavcodec
299
+ */
300
+ get chromaLocation(): AVChromaLocation;
301
+ set chromaLocation(value: AVChromaLocation);
302
+ /**
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.
307
+ */
308
+ get sampleRate(): number;
309
+ set sampleRate(value: number);
310
+ /**
311
+ * Number of audio channels.
312
+ * @deprecated use ch_layout.nb_channels
313
+ */
314
+ get channels(): number;
315
+ set channels(value: number);
316
+ /**
317
+ * Audio sample format.
318
+ * - encoding: Set by user.
319
+ * - decoding: Set by libavcodec.
320
+ */
321
+ get sampleFormat(): AVSampleFormat;
322
+ set sampleFormat(value: AVSampleFormat);
323
+ /**
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.
330
+ */
331
+ get frameSize(): number;
332
+ set frameSize(value: number);
333
+ /**
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
338
+ */
339
+ get frameNumber(): number;
340
+ /**
341
+ * Audio channel layout.
342
+ * - encoding: Set by user.
343
+ * - decoding: Set by user, may be overwritten by libavcodec.
344
+ * @deprecated use ch_layout
345
+ */
346
+ get channelLayout(): ChannelLayout;
347
+ set channelLayout(value: ChannelLayout);
348
+ /**
349
+ * Minimum quantizer.
350
+ * - encoding: Set by user.
351
+ * - decoding: unused
352
+ */
353
+ get qMin(): number;
354
+ set qMin(value: number);
355
+ /**
356
+ * Maximum quantizer.
357
+ * - encoding: Set by user.
358
+ * - decoding: unused
359
+ */
360
+ get qMax(): number;
361
+ set qMax(value: number);
362
+ /**
363
+ * Decoder bitstream buffer size.
364
+ * - encoding: Set by user.
365
+ * - decoding: unused
366
+ */
367
+ get rcBufferSize(): number;
368
+ set rcBufferSize(value: number);
369
+ /**
370
+ * Maximum bitrate.
371
+ * - encoding: Set by user.
372
+ * - decoding: Set by user, may be overwritten by libavcodec.
373
+ */
374
+ get rcMaxRate(): bigint;
375
+ set rcMaxRate(value: bigint);
376
+ /**
377
+ * Minimum bitrate.
378
+ * - encoding: Set by user.
379
+ * - decoding: unused
380
+ */
381
+ get rcMinRate(): bigint;
382
+ set rcMinRate(value: bigint);
383
+ /**
384
+ * Hardware device context for hardware acceleration.
385
+ *
386
+ * Direct mapping to AVCodecContext->hw_device_ctx
387
+ *
388
+ * If the codec supports hardware acceleration, this should be set
389
+ * to the hardware device context before opening the codec.
390
+ */
391
+ get hwDeviceCtx(): HardwareDeviceContext | null;
392
+ set hwDeviceCtx(value: HardwareDeviceContext | null);
393
+ /**
394
+ * Hardware frames context for hardware acceleration.
395
+ *
396
+ * Direct mapping to AVCodecContext->hw_frames_ctx
397
+ *
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.
401
+ */
402
+ get hwFramesCtx(): HardwareFramesContext | null;
403
+ set hwFramesCtx(value: HardwareFramesContext | null);
404
+ /**
405
+ * Check if the codec context is open.
406
+ *
407
+ * Direct mapping to avcodec_is_open()
408
+ *
409
+ * @returns true if the codec is open and ready for encoding/decoding
410
+ */
411
+ get isOpen(): boolean;
412
+ /**
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.
417
+ *
418
+ * Direct mapping to avcodec_alloc_context3()
419
+ *
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.
423
+ *
424
+ * @throws {Error} Memory allocation failure (ENOMEM)
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * import { CodecContext, Codec } from 'node-av';
429
+ * import { AV_CODEC_ID_H264 } from 'node-av/constants';
430
+ *
431
+ * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
432
+ * const ctx = new CodecContext();
433
+ * ctx.allocContext3(codec);
434
+ * // Context is now allocated with H264 defaults
435
+ * ```
436
+ *
437
+ * @see {@link open2} To open the codec
438
+ * @see {@link freeContext} To free the context
439
+ */
440
+ allocContext3(codec?: Codec | null): void;
441
+ /**
442
+ * Free the codec context and everything associated with it.
443
+ *
444
+ * Releases all resources associated with the codec context.
445
+ * The context becomes invalid after this call.
446
+ *
447
+ * Direct mapping to avcodec_free_context()
448
+ *
449
+ * @example
450
+ * ```typescript
451
+ * ctx.freeContext();
452
+ * // ctx is now invalid and should not be used
453
+ * ```
454
+ */
455
+ freeContext(): void;
456
+ /**
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().
461
+ *
462
+ * Direct mapping to avcodec_open2()
463
+ *
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.
468
+ *
469
+ * @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
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * import { FFmpegError } from 'node-av';
478
+ *
479
+ * const ret = await ctx.open2(codec, null);
480
+ * FFmpegError.throwIfError(ret, 'open2');
481
+ * ```
482
+ *
483
+ * @see {@link close} To close the codec context
484
+ * @see {@link allocContext3} Must be called before open2()
485
+ */
486
+ open2(codec?: Codec | null, options?: Dictionary | null): Promise<number>;
487
+ /**
488
+ * Fill the codec context based on the values from the supplied codec parameters.
489
+ *
490
+ * Direct mapping to avcodec_parameters_to_context()
491
+ *
492
+ * @param params - Codec parameters to copy from
493
+ *
494
+ * @returns 0 on success, negative AVERROR on error:
495
+ * - 0: Success
496
+ * - AVERROR(EINVAL): Invalid parameters
497
+ * - <0: Other errors
498
+ *
499
+ * @example
500
+ * ```typescript
501
+ * // Copy parameters from stream to codec context
502
+ * const ret = ctx.parametersToContext(stream.codecpar);
503
+ * if (ret < 0) {
504
+ * throw new FFmpegError(ret);
505
+ * }
506
+ * ```
507
+ *
508
+ * @see parametersFromContext() - To copy in the opposite direction
509
+ */
510
+ parametersToContext(params: CodecParameters): number;
511
+ /**
512
+ * Fill the parameters struct based on the values from the supplied codec context.
513
+ *
514
+ * Direct mapping to avcodec_parameters_from_context()
515
+ *
516
+ * @param params - Codec parameters to fill
517
+ *
518
+ * @returns 0 on success, negative AVERROR on error:
519
+ * - 0: Success
520
+ * - AVERROR(EINVAL): Invalid parameters
521
+ * - <0: Other errors
522
+ *
523
+ * @example
524
+ * ```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
+ * }
530
+ * ```
531
+ *
532
+ * @see parametersToContext() - To copy in the opposite direction
533
+ */
534
+ parametersFromContext(params: CodecParameters): number;
535
+ /**
536
+ * Reset the internal codec state / flush internal buffers.
537
+ * Should be called when seeking or switching to a different stream.
538
+ *
539
+ * Direct mapping to avcodec_flush_buffers()
540
+ *
541
+ * @example
542
+ * ```typescript
543
+ * // Flush buffers when seeking
544
+ * formatContext.seekFrame(streamIndex, timestamp, flags);
545
+ * codecContext.flushBuffers();
546
+ * ```
547
+ */
548
+ flushBuffers(): void;
549
+ /**
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.
554
+ *
555
+ * Direct mapping to avcodec_send_packet()
556
+ *
557
+ * @param packet - The input packet. May be NULL to signal end of stream (flush).
558
+ *
559
+ * @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
566
+ *
567
+ * @example
568
+ * ```typescript
569
+ * import { FFmpegError, Frame } from 'node-av';
570
+ * import { AVERROR_EAGAIN } from 'node-av/constants';
571
+ *
572
+ * // Decode packet
573
+ * const ret = await decoder.sendPacket(packet);
574
+ * 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');
580
+ * } else {
581
+ * FFmpegError.throwIfError(ret, 'sendPacket');
582
+ * }
583
+ * ```
584
+ *
585
+ * @see {@link receiveFrame} To retrieve decoded frames
586
+ */
587
+ sendPacket(packet: Packet | null): Promise<number>;
588
+ /**
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.
593
+ *
594
+ * Direct mapping to avcodec_receive_frame()
595
+ *
596
+ * @param frame - Frame to receive decoded data. Must be allocated.
597
+ *
598
+ * @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
604
+ *
605
+ * @example
606
+ * ```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');
620
+ *
621
+ * // Process frame
622
+ * processFrame(frame);
623
+ * frame.unref();
624
+ * }
625
+ * ```
626
+ *
627
+ * @see {@link sendPacket} To send input packets
628
+ */
629
+ receiveFrame(frame: Frame): Promise<number>;
630
+ /**
631
+ * Supply a raw video or audio frame to the encoder.
632
+ *
633
+ * Sends uncompressed frame data to the encoder.
634
+ * Use receivePacket() to retrieve buffered output packets.
635
+ *
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).
640
+ *
641
+ * @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
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * import { Packet, FFmpegError } from 'node-av';
652
+ * import { AVERROR_EAGAIN } from 'node-av/constants';
653
+ *
654
+ * // Send frame to encoder
655
+ * const ret = await encoder.sendFrame(frame);
656
+ * 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');
662
+ * } else {
663
+ * FFmpegError.throwIfError(ret, 'sendFrame');
664
+ * }
665
+ * ```
666
+ *
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.
672
+ */
673
+ sendFrame(frame: Frame | null): Promise<number>;
674
+ /**
675
+ * Read encoded data from the encoder.
676
+ *
677
+ * Retrieves compressed packets from the encoder.
678
+ * The packet must be allocated before calling.
679
+ *
680
+ * Direct mapping to avcodec_receive_packet()
681
+ *
682
+ * @param packet - Packet to receive encoded data. Must be allocated.
683
+ *
684
+ * @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
690
+ *
691
+ * @example
692
+ * ```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();
711
+ * }
712
+ * ```
713
+ *
714
+ * @see sendFrame() - To send input frames
715
+ */
716
+ receivePacket(packet: Packet): Promise<number>;
717
+ /**
718
+ * Set the hardware pixel format for hardware acceleration.
719
+ *
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.
723
+ *
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
726
+ *
727
+ * @example
728
+ * ```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
+ * );
737
+ * ```
738
+ */
739
+ setHardwarePixelFormat(hwFormat: AVPixelFormat, swFormat?: AVPixelFormat): void;
740
+ /**
741
+ * Get the native FFmpeg AVCodecContext pointer.
742
+ *
743
+ * @internal For use by other wrapper classes
744
+ * @returns The underlying native codec context object
745
+ */
746
+ getNative(): NativeCodecContext;
747
+ /**
748
+ * Dispose of the codec context.
749
+ *
750
+ * Implements the Disposable interface for automatic cleanup.
751
+ * Equivalent to calling freeContext().
752
+ *
753
+ * @example
754
+ * ```typescript
755
+ * {
756
+ * using ctx = new CodecContext();
757
+ * ctx.allocContext3(codec);
758
+ * // ... use context
759
+ * } // Automatically freed when leaving scope
760
+ * ```
761
+ */
762
+ [Symbol.dispose](): void;
763
+ }