node-av 1.1.0 → 1.3.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 (166) hide show
  1. package/README.md +51 -59
  2. package/dist/api/bitstream-filter.d.ts +183 -123
  3. package/dist/api/bitstream-filter.js +185 -127
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +282 -130
  6. package/dist/api/decoder.js +290 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +249 -160
  9. package/dist/api/encoder.js +276 -207
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +1944 -96
  12. package/dist/api/filter-presets.js +2059 -105
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +264 -200
  15. package/dist/api/filter.js +269 -231
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +246 -117
  18. package/dist/api/hardware.js +440 -217
  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 -55
  24. package/dist/api/io-stream.js +43 -40
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -139
  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 +208 -126
  30. package/dist/api/media-output.js +212 -126
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +361 -38
  33. package/dist/api/pipeline.js +255 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +26 -187
  36. package/dist/api/utilities/audio-sample.d.ts +0 -8
  37. package/dist/api/utilities/audio-sample.js +0 -8
  38. package/dist/api/utilities/audio-sample.js.map +1 -1
  39. package/dist/api/utilities/channel-layout.d.ts +0 -8
  40. package/dist/api/utilities/channel-layout.js +0 -8
  41. package/dist/api/utilities/channel-layout.js.map +1 -1
  42. package/dist/api/utilities/image.d.ts +0 -8
  43. package/dist/api/utilities/image.js +0 -8
  44. package/dist/api/utilities/image.js.map +1 -1
  45. package/dist/api/utilities/index.d.ts +3 -3
  46. package/dist/api/utilities/index.js +3 -3
  47. package/dist/api/utilities/index.js.map +1 -1
  48. package/dist/api/utilities/media-type.d.ts +1 -9
  49. package/dist/api/utilities/media-type.js +1 -9
  50. package/dist/api/utilities/media-type.js.map +1 -1
  51. package/dist/api/utilities/pixel-format.d.ts +1 -9
  52. package/dist/api/utilities/pixel-format.js +1 -9
  53. package/dist/api/utilities/pixel-format.js.map +1 -1
  54. package/dist/api/utilities/sample-format.d.ts +1 -9
  55. package/dist/api/utilities/sample-format.js +1 -9
  56. package/dist/api/utilities/sample-format.js.map +1 -1
  57. package/dist/api/utilities/streaming.d.ts +0 -8
  58. package/dist/api/utilities/streaming.js +0 -8
  59. package/dist/api/utilities/streaming.js.map +1 -1
  60. package/dist/api/utilities/timestamp.d.ts +0 -8
  61. package/dist/api/utilities/timestamp.js +0 -8
  62. package/dist/api/utilities/timestamp.js.map +1 -1
  63. package/dist/api/utils.d.ts +1 -2
  64. package/dist/api/utils.js +11 -0
  65. package/dist/api/utils.js.map +1 -1
  66. package/dist/constants/constants.d.ts +1 -1
  67. package/dist/constants/constants.js +2 -0
  68. package/dist/constants/constants.js.map +1 -1
  69. package/dist/lib/audio-fifo.d.ts +127 -170
  70. package/dist/lib/audio-fifo.js +130 -173
  71. package/dist/lib/audio-fifo.js.map +1 -1
  72. package/dist/lib/binding.d.ts +1 -0
  73. package/dist/lib/binding.js +7 -0
  74. package/dist/lib/binding.js.map +1 -1
  75. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  76. package/dist/lib/bitstream-filter-context.js +139 -188
  77. package/dist/lib/bitstream-filter-context.js.map +1 -1
  78. package/dist/lib/bitstream-filter.d.ts +68 -54
  79. package/dist/lib/bitstream-filter.js +68 -54
  80. package/dist/lib/bitstream-filter.js.map +1 -1
  81. package/dist/lib/codec-context.d.ts +316 -380
  82. package/dist/lib/codec-context.js +316 -381
  83. package/dist/lib/codec-context.js.map +1 -1
  84. package/dist/lib/codec-parameters.d.ts +160 -170
  85. package/dist/lib/codec-parameters.js +162 -172
  86. package/dist/lib/codec-parameters.js.map +1 -1
  87. package/dist/lib/codec-parser.d.ts +91 -104
  88. package/dist/lib/codec-parser.js +92 -103
  89. package/dist/lib/codec-parser.js.map +1 -1
  90. package/dist/lib/codec.d.ts +266 -283
  91. package/dist/lib/codec.js +270 -287
  92. package/dist/lib/codec.js.map +1 -1
  93. package/dist/lib/dictionary.d.ts +149 -203
  94. package/dist/lib/dictionary.js +158 -212
  95. package/dist/lib/dictionary.js.map +1 -1
  96. package/dist/lib/error.d.ts +96 -130
  97. package/dist/lib/error.js +98 -128
  98. package/dist/lib/error.js.map +1 -1
  99. package/dist/lib/filter-context.d.ts +284 -218
  100. package/dist/lib/filter-context.js +290 -227
  101. package/dist/lib/filter-context.js.map +1 -1
  102. package/dist/lib/filter-graph.d.ts +251 -292
  103. package/dist/lib/filter-graph.js +253 -294
  104. package/dist/lib/filter-graph.js.map +1 -1
  105. package/dist/lib/filter-inout.d.ts +87 -95
  106. package/dist/lib/filter-inout.js +87 -95
  107. package/dist/lib/filter-inout.js.map +1 -1
  108. package/dist/lib/filter.d.ts +93 -111
  109. package/dist/lib/filter.js +93 -111
  110. package/dist/lib/filter.js.map +1 -1
  111. package/dist/lib/format-context.d.ts +320 -428
  112. package/dist/lib/format-context.js +313 -385
  113. package/dist/lib/format-context.js.map +1 -1
  114. package/dist/lib/frame.d.ts +262 -405
  115. package/dist/lib/frame.js +263 -408
  116. package/dist/lib/frame.js.map +1 -1
  117. package/dist/lib/hardware-device-context.d.ts +149 -203
  118. package/dist/lib/hardware-device-context.js +149 -203
  119. package/dist/lib/hardware-device-context.js.map +1 -1
  120. package/dist/lib/hardware-frames-context.d.ts +170 -180
  121. package/dist/lib/hardware-frames-context.js +171 -181
  122. package/dist/lib/hardware-frames-context.js.map +1 -1
  123. package/dist/lib/index.d.ts +3 -2
  124. package/dist/lib/index.js +3 -3
  125. package/dist/lib/index.js.map +1 -1
  126. package/dist/lib/input-format.d.ts +89 -117
  127. package/dist/lib/input-format.js +89 -117
  128. package/dist/lib/input-format.js.map +1 -1
  129. package/dist/lib/io-context.d.ts +209 -241
  130. package/dist/lib/io-context.js +220 -252
  131. package/dist/lib/io-context.js.map +1 -1
  132. package/dist/lib/log.d.ts +85 -119
  133. package/dist/lib/log.js +85 -122
  134. package/dist/lib/log.js.map +1 -1
  135. package/dist/lib/native-types.d.ts +118 -106
  136. package/dist/lib/native-types.js +0 -7
  137. package/dist/lib/native-types.js.map +1 -1
  138. package/dist/lib/option.d.ts +437 -218
  139. package/dist/lib/option.js +462 -226
  140. package/dist/lib/option.js.map +1 -1
  141. package/dist/lib/output-format.d.ts +77 -101
  142. package/dist/lib/output-format.js +77 -101
  143. package/dist/lib/output-format.js.map +1 -1
  144. package/dist/lib/packet.d.ts +172 -240
  145. package/dist/lib/packet.js +172 -241
  146. package/dist/lib/packet.js.map +1 -1
  147. package/dist/lib/rational.d.ts +0 -2
  148. package/dist/lib/rational.js +0 -2
  149. package/dist/lib/rational.js.map +1 -1
  150. package/dist/lib/software-resample-context.d.ts +241 -325
  151. package/dist/lib/software-resample-context.js +242 -326
  152. package/dist/lib/software-resample-context.js.map +1 -1
  153. package/dist/lib/software-scale-context.d.ts +129 -173
  154. package/dist/lib/software-scale-context.js +131 -175
  155. package/dist/lib/software-scale-context.js.map +1 -1
  156. package/dist/lib/stream.d.ts +87 -197
  157. package/dist/lib/stream.js +87 -197
  158. package/dist/lib/stream.js.map +1 -1
  159. package/dist/lib/utilities.d.ts +435 -181
  160. package/dist/lib/utilities.js +438 -182
  161. package/dist/lib/utilities.js.map +1 -1
  162. package/install/check.js +0 -1
  163. package/install/ffmpeg.js +0 -11
  164. package/package.json +25 -18
  165. package/release_notes.md +24 -59
  166. package/CHANGELOG.md +0 -8
@@ -1,310 +1,399 @@
1
- /**
2
- * Encoder - High-level wrapper for media encoding
3
- *
4
- * Simplifies FFmpeg's encoding API with automatic codec selection,
5
- * parameter configuration, and packet management.
6
- *
7
- * Handles codec initialization, frame encoding, and packet output.
8
- * Supports hardware acceleration and zero-copy transcoding.
9
- *
10
- * @module api/encoder
11
- */
12
1
  import { Codec, CodecContext, Packet } from '../lib/index.js';
13
- import type { AVCodecID, AVPixelFormat } from '../constants/constants.js';
2
+ import type { AVCodecID } from '../constants/constants.js';
14
3
  import type { FFEncoderCodec } from '../constants/encoders.js';
15
4
  import type { Frame } from '../lib/index.js';
16
5
  import type { EncoderOptions, StreamInfo } from './types.js';
17
6
  /**
18
- * High-level encoder for media streams.
19
- *
20
- * Handles codec initialization, frame encoding, and packet output.
21
- * Supports various codecs with flexible configuration options.
7
+ * High-level encoder for audio and video streams.
22
8
  *
23
- * Manages codec context lifecycle and provides automatic cleanup.
24
- * Supports hardware acceleration with shared frames context for zero-copy.
9
+ * Provides a simplified interface for encoding media frames to packets.
10
+ * Handles codec initialization, hardware acceleration setup, and packet management.
11
+ * Supports both synchronous frame-by-frame encoding and async iteration over packets.
12
+ * Essential component in media processing pipelines for converting raw frames to compressed data.
25
13
  *
26
14
  * @example
27
15
  * ```typescript
16
+ * import { Encoder } from 'node-av/api';
17
+ * import { AV_CODEC_ID_H264, FF_ENCODER_LIBX264 } from 'node-av/constants';
18
+ *
28
19
  * // Create H.264 encoder
29
- * const encoder = await Encoder.create('libx264', {
20
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, {
21
+ * type: 'video',
30
22
  * width: 1920,
31
23
  * height: 1080,
32
- * pixelFormat: 'yuv420p',
24
+ * pixelFormat: AV_PIX_FMT_YUV420P,
25
+ * timeBase: { num: 1, den: 30 },
26
+ * frameRate: { num: 30, den: 1 }
27
+ * }, {
33
28
  * bitrate: '5M',
34
- * gopSize: 60,
35
- * options: {
36
- * preset: 'fast',
37
- * crf: 23
38
- * }
29
+ * gopSize: 60
39
30
  * });
40
31
  *
41
32
  * // Encode frames
42
33
  * const packet = await encoder.encode(frame);
43
34
  * if (packet) {
44
- * // Write packet to output
45
- * }
46
- *
47
- * // Flush encoder
48
- * let packet;
49
- * while ((packet = await encoder.flush()) !== null) {
50
- * // Process final packets
35
+ * await output.writePacket(packet);
36
+ * packet.free();
51
37
  * }
52
- * encoder.close();
53
38
  * ```
54
39
  *
55
40
  * @example
56
41
  * ```typescript
57
- * // With hardware acceleration
58
- * const hw = await HardwareContext.auto();
59
- * const encoder = await Encoder.create('h264_videotoolbox', {
60
- * width: 1920,
61
- * height: 1080,
62
- * pixelFormat: 'nv12',
63
- * bitrate: '5M',
64
- * hardware: hw
42
+ * // Hardware-accelerated encoding
43
+ * import { HardwareContext } from 'node-av/api';
44
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
45
+ *
46
+ * const hw = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
47
+ * const encoder = await Encoder.create('h264_nvenc', streamInfo, {
48
+ * hardware: hw,
49
+ * bitrate: '10M'
65
50
  * });
66
- * // ... use encoder
67
- * encoder.close(); // Also disposes hardware
68
- * hw?.dispose(); // Safe to call again (no-op)
51
+ *
52
+ * // Frames with hw_frames_ctx will be encoded on GPU
53
+ * for await (const packet of encoder.packets(frames)) {
54
+ * await output.writePacket(packet);
55
+ * packet.free();
56
+ * }
69
57
  * ```
58
+ *
59
+ * @see {@link Decoder} For decoding packets to frames
60
+ * @see {@link MediaOutput} For writing encoded packets
61
+ * @see {@link HardwareContext} For GPU acceleration
70
62
  */
71
63
  export declare class Encoder implements Disposable {
72
64
  private codecContext;
73
65
  private packet;
74
- private codecName;
66
+ private codec;
75
67
  private isOpen;
76
- private supportedFormats;
77
- private preferredFormat?;
78
68
  private hardware?;
79
69
  /**
80
- * Private constructor - use Encoder.create() instead.
81
- *
82
- * Initializes the encoder with a codec context and allocates a packet buffer.
83
- *
84
- * @param codecContext - Initialized codec context
85
- * @param codecName - Name of the codec
86
- * @param hardware - Optional hardware context for hardware pixel format
70
+ * @param codecContext - Configured codec context
71
+ * @param codec - Encoder codec
72
+ * @param hardware - Optional hardware context
73
+ * @internal
87
74
  */
88
75
  private constructor();
89
76
  /**
90
77
  * Create an encoder with specified codec and options.
91
78
  *
92
- * Factory method that handles codec discovery, context setup,
93
- * and initialization.
79
+ * Initializes an encoder with the appropriate codec and configuration.
80
+ * Automatically configures parameters based on input stream info.
81
+ * Handles hardware acceleration setup if provided.
94
82
  *
95
- * Uses avcodec_find_encoder_by_name() to locate the codec,
96
- * configures the context with provided options, and opens it.
97
- * Handles hardware setup including shared frames context for zero-copy.
83
+ * Direct mapping to avcodec_find_encoder_by_name() or avcodec_find_encoder().
98
84
  *
99
- * @param encoderCodec - Codec to use for encoding
100
- * @param input - Stream or StreamInfo to copy parameters from
85
+ * @param encoderCodec - Codec name, ID, or instance to use for encoding
86
+ * @param input - Stream information to configure encoder
101
87
  * @param options - Encoder configuration options
88
+ * @returns Configured encoder instance
102
89
  *
103
- * @returns Promise resolving to configured Encoder
90
+ * @throws {Error} If encoder not found or unsupported format
104
91
  *
105
- * @throws {Error} If codec not found or configuration fails
92
+ * @throws {FFmpegError} If codec initialization fails
106
93
  *
107
94
  * @example
108
95
  * ```typescript
109
- * // Video encoder from stream
110
- * const videoStream = media.video();
111
- * const videoEncoder = await Encoder.create('libx264', videoStream, {
96
+ * // From decoder stream info
97
+ * const streamInfo = decoder.getOutputStreamInfo();
98
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, streamInfo, {
112
99
  * bitrate: '5M',
113
- * gopSize: 60
100
+ * gopSize: 60,
101
+ * options: {
102
+ * preset: 'fast',
103
+ * crf: '23'
104
+ * }
114
105
  * });
106
+ * ```
115
107
  *
116
- * // Audio encoder from stream
117
- * const audioStream = media.audio();
118
- * const audioEncoder = await Encoder.create('aac', audioStream, {
108
+ * @example
109
+ * ```typescript
110
+ * // With custom stream info
111
+ * const encoder = await Encoder.create(FF_ENCODER_AAC, {
112
+ * type: 'audio',
113
+ * sampleRate: 48000,
114
+ * sampleFormat: AV_SAMPLE_FMT_FLTP,
115
+ * channelLayout: AV_CH_LAYOUT_STEREO,
116
+ * timeBase: { num: 1, den: 48000 }
117
+ * }, {
119
118
  * bitrate: '192k'
120
119
  * });
120
+ * ```
121
121
  *
122
+ * @example
123
+ * ```typescript
124
+ * // Hardware encoder
125
+ * const hw = HardwareContext.auto();
126
+ * const encoder = await Encoder.create('hevc_videotoolbox', streamInfo, {
127
+ * hardware: hw,
128
+ * bitrate: '8M'
129
+ * });
122
130
  * ```
131
+ *
132
+ * @see {@link Decoder.getOutputStreamInfo} For stream info source
133
+ * @see {@link EncoderOptions} For configuration options
123
134
  */
124
135
  static create(encoderCodec: FFEncoderCodec | AVCodecID | Codec, input: StreamInfo, options?: EncoderOptions): Promise<Encoder>;
125
136
  /**
126
137
  * Check if encoder is open.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * if (encoder.isEncoderOpen) {
142
+ * const packet = await encoder.encode(frame);
143
+ * }
144
+ * ```
127
145
  */
128
146
  get isEncoderOpen(): boolean;
129
147
  /**
130
- * Get output stream information.
148
+ * Check if encoder uses hardware acceleration.
131
149
  *
132
- * Returns the encoder output format configuration.
133
- * Useful for setting up subsequent processing stages.
150
+ * @returns true if hardware-accelerated
134
151
  *
135
- * For hardware encoders, returns the hardware pixel format even before
136
- * the first frame is encoded.
152
+ * @example
153
+ * ```typescript
154
+ * if (encoder.isHardware()) {
155
+ * console.log('Using GPU acceleration');
156
+ * }
157
+ * ```
137
158
  *
138
- * @returns StreamInfo with encoder output properties
159
+ * @see {@link HardwareContext} For hardware setup
139
160
  */
140
- getOutputStreamInfo(): StreamInfo;
161
+ isHardware(): boolean;
141
162
  /**
142
- * Encode a frame and return a packet if available.
163
+ * Encode a frame to a packet.
143
164
  *
144
- * Sends frame to encoder and attempts to receive a packet.
145
- * May return null if encoder needs more data.
165
+ * Sends a frame to the encoder and attempts to receive an encoded packet.
166
+ * Handles internal buffering - may return null if more frames needed.
167
+ * Automatically manages encoder state and hardware context binding.
146
168
  *
147
- * Uses avcodec_send_frame() and avcodec_receive_packet() internally.
148
- * The encoder may buffer frames before producing packets.
169
+ * Direct mapping to avcodec_send_frame() and avcodec_receive_packet().
149
170
  *
150
- * @param frame - Frame to encode (or null to flush)
171
+ * @param frame - Raw frame to encode (or null to flush)
172
+ * @returns Encoded packet or null if more data needed
151
173
  *
152
- * @returns Promise resolving to Packet or null
174
+ * @throws {Error} If encoder is closed
153
175
  *
154
- * @throws {Error} If encoder is closed or encode fails
176
+ * @throws {FFmpegError} If encoding fails
155
177
  *
156
178
  * @example
157
179
  * ```typescript
158
180
  * const packet = await encoder.encode(frame);
159
181
  * if (packet) {
160
- * // Write packet to output
182
+ * console.log(`Encoded packet with PTS: ${packet.pts}`);
161
183
  * await output.writePacket(packet);
184
+ * packet.free();
162
185
  * }
163
186
  * ```
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // Encode loop
191
+ * for await (const frame of decoder.frames(input.packets())) {
192
+ * const packet = await encoder.encode(frame);
193
+ * if (packet) {
194
+ * await output.writePacket(packet);
195
+ * packet.free();
196
+ * }
197
+ * frame.free();
198
+ * }
199
+ * ```
200
+ *
201
+ * @see {@link packets} For automatic frame iteration
202
+ * @see {@link flush} For end-of-stream handling
164
203
  */
165
204
  encode(frame: Frame | null): Promise<Packet | null>;
166
205
  /**
167
- * Async iterator that encodes frames and yields packets.
168
- *
169
- * Encodes all provided frames and yields resulting packets.
170
- * Automatically handles encoder flushing at the end.
171
- * Input frames are automatically freed after encoding.
206
+ * Encode frame stream to packet stream.
172
207
  *
173
- * Processes frames in sequence, encoding each and yielding packets.
174
- * After all frames are processed, flushes the encoder for remaining packets.
208
+ * High-level async generator for complete encoding pipeline.
209
+ * Automatically manages frame memory, encoder state,
210
+ * and flushes buffered packets at end.
211
+ * Primary interface for stream-based encoding.
175
212
  *
176
- * IMPORTANT: The yielded packets MUST be freed by the caller!
177
- * Input frames are automatically freed after processing.
213
+ * @param frames - Async iterable of frames (freed automatically)
214
+ * @yields Encoded packets (caller must free)
215
+ * @throws {Error} If encoder is closed
178
216
  *
179
- * @param frames - Async iterable of frames to encode (will be freed automatically)
217
+ * @throws {FFmpegError} If encoding fails
180
218
  *
181
- * @yields Encoded packets (ownership transferred to caller)
219
+ * @example
220
+ * ```typescript
221
+ * // Basic encoding pipeline
222
+ * for await (const packet of encoder.packets(decoder.frames(input.packets()))) {
223
+ * await output.writePacket(packet);
224
+ * packet.free(); // Must free output packets
225
+ * }
226
+ * ```
182
227
  *
183
228
  * @example
184
229
  * ```typescript
185
- * // Transcode video
186
- * for await (const packet of encoder.packets(decoder.frames(media.packets()))) {
230
+ * // With frame filtering
231
+ * async function* filteredFrames() {
232
+ * for await (const frame of decoder.frames(input.packets())) {
233
+ * await filter.filterFrame(frame);
234
+ * const filtered = await filter.getFrame();
235
+ * if (filtered) {
236
+ * yield filtered;
237
+ * }
238
+ * }
239
+ * }
240
+ *
241
+ * for await (const packet of encoder.packets(filteredFrames())) {
187
242
  * await output.writePacket(packet);
188
- * packet.free(); // Must free output packet
243
+ * packet.free();
189
244
  * }
190
245
  * ```
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * // Pipeline integration
250
+ * import { pipeline } from 'node-av/api';
251
+ *
252
+ * const control = pipeline(
253
+ * input,
254
+ * decoder,
255
+ * encoder,
256
+ * output
257
+ * );
258
+ * await control.completion;
259
+ * ```
260
+ *
261
+ * @see {@link encode} For single frame encoding
262
+ * @see {@link Decoder.frames} For frame source
191
263
  */
192
264
  packets(frames: AsyncIterable<Frame>): AsyncGenerator<Packet>;
193
265
  /**
194
- * Flush encoder and get remaining packets.
266
+ * Flush encoder and get buffered packet.
195
267
  *
196
- * Sends null frame to trigger flush mode.
197
- * Call repeatedly until it returns null.
268
+ * Signals end-of-stream and retrieves remaining packets.
269
+ * Call repeatedly until null to get all buffered packets.
270
+ * Essential for ensuring all frames are encoded.
198
271
  *
199
- * Uses avcodec_send_frame(NULL) to signal end of stream.
200
- * Retrieves buffered packets from the encoder.
272
+ * Direct mapping to avcodec_send_frame(NULL).
201
273
  *
202
- * @returns Promise resolving to Packet or null
274
+ * @returns Buffered packet or null if none remaining
203
275
  *
204
276
  * @throws {Error} If encoder is closed
205
277
  *
206
278
  * @example
207
279
  * ```typescript
208
- * // Flush all remaining packets
280
+ * // Flush remaining packets
209
281
  * let packet;
210
282
  * while ((packet = await encoder.flush()) !== null) {
211
- * // Write final packets
283
+ * console.log('Got buffered packet');
212
284
  * await output.writePacket(packet);
285
+ * packet.free();
213
286
  * }
214
287
  * ```
288
+ *
289
+ * @see {@link flushPackets} For async iteration
290
+ * @see {@link packets} For complete encoding pipeline
215
291
  */
216
292
  flush(): Promise<Packet | null>;
217
293
  /**
218
- * Flush encoder and yield all remaining packets as a generator.
294
+ * Flush all buffered packets as async generator.
219
295
  *
220
- * More convenient than calling flush() in a loop.
221
- * Automatically sends flush signal and yields all buffered packets.
222
- *
223
- * @returns Async generator of remaining packets
296
+ * Convenient async iteration over remaining packets.
297
+ * Automatically handles repeated flush calls.
298
+ * Useful for end-of-stream processing.
224
299
  *
300
+ * @yields Buffered packets
225
301
  * @throws {Error} If encoder is closed
226
302
  *
227
303
  * @example
228
304
  * ```typescript
229
- * // Process all remaining packets with generator
305
+ * // Flush at end of encoding
230
306
  * for await (const packet of encoder.flushPackets()) {
231
- * await output.writePacket(packet, streamIdx);
232
- * using _ = packet; // Auto cleanup
307
+ * console.log('Processing buffered packet');
308
+ * await output.writePacket(packet);
309
+ * packet.free();
233
310
  * }
234
311
  * ```
312
+ *
313
+ * @see {@link flush} For single packet flush
314
+ * @see {@link packets} For complete pipeline
235
315
  */
236
316
  flushPackets(): AsyncGenerator<Packet>;
237
317
  /**
238
318
  * Close encoder and free resources.
239
319
  *
240
- * After closing, the encoder cannot be used again.
241
- *
242
- * Frees the packet buffer and codec context.
243
- * Note: Does NOT dispose the HardwareContext - caller is responsible for that.
244
- */
245
- close(): void;
246
- /**
247
- * Get the codec name.
248
- */
249
- getCodecName(): string;
250
- /**
251
- * Get codec context for advanced configuration.
252
- *
253
- * Use with caution - direct manipulation may cause issues.
254
- *
255
- * Provides access to the underlying AVCodecContext for advanced operations.
320
+ * Releases codec context and internal packet buffer.
321
+ * Safe to call multiple times.
322
+ * Does NOT dispose hardware context - caller is responsible.
323
+ * Automatically called by Symbol.dispose.
256
324
  *
257
- * @returns CodecContext or null if closed
325
+ * @example
326
+ * ```typescript
327
+ * const encoder = await Encoder.create(FF_ENCODER_LIBX264, streamInfo);
328
+ * try {
329
+ * // Use encoder
330
+ * } finally {
331
+ * encoder.close();
332
+ * }
333
+ * ```
258
334
  *
259
- * @internal
335
+ * @see {@link Symbol.dispose} For automatic cleanup
260
336
  */
261
- getCodecContext(): CodecContext | null;
337
+ close(): void;
262
338
  /**
263
- * Get the preferred pixel format for this encoder.
339
+ * Get encoder codec.
264
340
  *
265
- * Returns the first supported format, which is usually the most efficient.
341
+ * Returns the codec used by this encoder.
342
+ * Useful for checking codec capabilities and properties.
266
343
  *
267
- * @returns Preferred pixel format or null if not available
344
+ * @returns Codec instance
268
345
  *
269
346
  * @example
270
347
  * ```typescript
271
- * const format = encoder.getPreferredPixelFormat();
272
- * if (format) {
273
- * console.log(`Encoder prefers format: ${format}`);
274
- * }
348
+ * const codec = encoder.getCodec();
349
+ * console.log(`Using codec: ${codec.name}`);
350
+ * console.log(`Capabilities: ${codec.capabilities}`);
275
351
  * ```
352
+ *
353
+ * @see {@link Codec} For codec properties
276
354
  */
277
- getPreferredPixelFormat(): AVPixelFormat | null;
355
+ getCodec(): Codec;
278
356
  /**
279
- * Get all supported pixel formats for this encoder.
357
+ * Get underlying codec context.
280
358
  *
281
- * Returns a list of pixel formats that this encoder can accept.
359
+ * Returns the internal codec context for advanced operations.
360
+ * Returns null if encoder is closed.
282
361
  *
283
- * @returns Array of supported pixel formats
362
+ * @returns Codec context or null
284
363
  *
285
- * @example
286
- * ```typescript
287
- * const formats = encoder.getSupportedPixelFormats();
288
- * console.log(`Encoder supports: ${formats.join(', ')}`);
289
- * ```
364
+ * @internal
290
365
  */
291
- getSupportedPixelFormats(): AVPixelFormat[];
366
+ getCodecContext(): CodecContext | null;
292
367
  /**
293
- * Receive a packet from the encoder.
368
+ * Receive packet from encoder.
294
369
  *
295
- * Internal method to receive encoded packets.
370
+ * Internal method to get encoded packets from codec.
371
+ * Handles packet cloning and error checking.
296
372
  *
297
- * Uses avcodec_receive_packet() to get encoded packets from the codec.
298
- * Clones the packet for the user to prevent internal buffer corruption.
373
+ * Direct mapping to avcodec_receive_packet().
299
374
  *
300
- * @returns Packet or null if no packet available
375
+ * @returns Cloned packet or null
376
+ *
377
+ * @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
378
+ *
379
+ * @internal
301
380
  */
302
381
  private receivePacket;
303
382
  /**
304
- * Symbol.dispose for automatic cleanup.
383
+ * Dispose of encoder.
384
+ *
385
+ * Implements Disposable interface for automatic cleanup.
386
+ * Equivalent to calling close().
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * {
391
+ * using encoder = await Encoder.create(FF_ENCODER_LIBX264, streamInfo);
392
+ * // Encode frames...
393
+ * } // Automatically closed
394
+ * ```
305
395
  *
306
- * Implements the Disposable interface for automatic resource management.
307
- * Calls close() to free all resources.
396
+ * @see {@link close} For manual cleanup
308
397
  */
309
398
  [Symbol.dispose](): void;
310
399
  }