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
@@ -1,61 +1,47 @@
1
- /**
2
- * Decoder - High-level wrapper for media decoding
3
- *
4
- * Simplifies FFmpeg's decoding API with automatic codec selection,
5
- * parameter configuration, and frame management.
6
- *
7
- * Handles codec initialization, packet decoding, and frame output.
8
- * Supports hardware acceleration and zero-copy transcoding.
9
- *
10
- * @module api/decoder
11
- */
12
1
  import { CodecContext, Frame } from '../lib/index.js';
13
2
  import type { Packet, Stream } from '../lib/index.js';
14
- import type { DecoderOptions } from './types.js';
3
+ import type { DecoderOptions, StreamInfo } from './types.js';
15
4
  /**
16
- * High-level decoder for media streams.
17
- *
18
- * Handles codec initialization, packet decoding, and frame output.
19
- * Designed for simple, efficient decoding workflows.
5
+ * High-level decoder for audio and video streams.
20
6
  *
21
- * Manages codec context lifecycle and provides automatic cleanup.
22
- * Supports hardware acceleration with zero-copy frame sharing.
7
+ * Provides a simplified interface for decoding media streams from packets to frames.
8
+ * Handles codec initialization, hardware acceleration setup, and frame management.
9
+ * Supports both synchronous packet-by-packet decoding and async iteration over frames.
10
+ * Essential component in media processing pipelines for converting compressed data to raw frames.
23
11
  *
24
12
  * @example
25
13
  * ```typescript
26
- * // Create decoder for video stream
27
- * const media = await MediaInput.open('video.mp4');
28
- * const stream = media.video(); // Get video stream
29
- * const decoder = await Decoder.create(stream);
14
+ * import { MediaInput, Decoder } from 'node-av/api';
30
15
  *
31
- * // Decode packets
32
- * for await (const packet of media.packets()) {
33
- * if (packet.streamIndex === stream.index) {
34
- * const frame = await decoder.decode(packet);
35
- * if (frame) {
36
- * console.log(`Decoded frame: ${frame.width}x${frame.height}`);
37
- * // Process frame...
38
- * }
39
- * }
40
- * }
16
+ * // Open media and create decoder
17
+ * await using input = await MediaInput.open('video.mp4');
18
+ * using decoder = await Decoder.create(input.video());
41
19
  *
42
- * // Flush decoder
43
- * const lastFrame = await decoder.flush();
44
- * decoder.close();
20
+ * // Decode frames
21
+ * for await (const frame of decoder.frames(input.packets())) {
22
+ * console.log(`Decoded frame: ${frame.width}x${frame.height}`);
23
+ * frame.free();
24
+ * }
45
25
  * ```
46
26
  *
47
27
  * @example
48
28
  * ```typescript
49
- * // With hardware acceleration
50
- * const hw = await HardwareContext.auto();
51
- * const stream = media.video();
52
- * const decoder = await Decoder.create(stream, {
53
- * hardware: hw
54
- * });
55
- * // ... use decoder
56
- * decoder.close();
57
- * hw?.dispose(); // Safe to call again (no-op)
29
+ * import { HardwareContext } from 'node-av/api';
30
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
31
+ *
32
+ * // Setup hardware acceleration
33
+ * const hw = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
34
+ * using decoder = await Decoder.create(stream, { hardware: hw });
35
+ *
36
+ * // Frames will be decoded on GPU
37
+ * for await (const frame of decoder.frames(packets)) {
38
+ * // frame.hwFramesCtx contains GPU memory reference
39
+ * }
58
40
  * ```
41
+ *
42
+ * @see {@link Encoder} For encoding frames to packets
43
+ * @see {@link MediaInput} For reading media files
44
+ * @see {@link HardwareContext} For GPU acceleration
59
45
  */
60
46
  export declare class Decoder implements Disposable {
61
47
  private codecContext;
@@ -65,193 +51,363 @@ export declare class Decoder implements Disposable {
65
51
  private isOpen;
66
52
  private hardware?;
67
53
  /**
68
- * Private constructor - use Decoder.create() instead.
69
- *
70
- * Initializes the decoder with a codec context and allocates a frame buffer.
54
+ * @param codecContext - Configured codec context
55
+ * @param stream - Media stream being decoded
56
+ * @param hardware - Optional hardware context
57
+ * Use {@link create} factory method
71
58
  *
72
- * @param codecContext - Initialized codec context
73
- * @param stream - The stream this decoder is for
74
- * @param hardware - Optional hardware context for auto-sharing frames context
59
+ * @internal
75
60
  */
76
61
  private constructor();
77
62
  /**
78
- * Create a decoder for a specific stream.
63
+ * Create a decoder for a media stream.
79
64
  *
80
- * Factory method that handles codec discovery, context setup,
81
- * and initialization.
65
+ * Initializes a decoder with the appropriate codec and configuration.
66
+ * Automatically detects and configures hardware acceleration if provided.
67
+ * Applies custom codec options and threading configuration.
82
68
  *
83
- * Uses avcodec_find_decoder() to locate the appropriate codec,
84
- * then initializes and opens the codec context.
85
- *
86
- * @param stream - Stream to decode
69
+ * @param stream - Media stream to decode
87
70
  * @param options - Decoder configuration options
71
+ * @returns Configured decoder instance
88
72
  *
89
- * @returns Promise resolving to configured Decoder
73
+ * @throws {Error} If decoder not found for codec
74
+ * @throws {FFmpegError} If codec initialization fails
90
75
  *
91
- * @throws {Error} If codec unavailable
76
+ * @example
77
+ * ```typescript
78
+ * import { MediaInput, Decoder } from 'node-av/api';
79
+ *
80
+ * await using input = await MediaInput.open('video.mp4');
81
+ * using decoder = await Decoder.create(input.video());
82
+ * ```
92
83
  *
93
84
  * @example
94
85
  * ```typescript
95
- * const media = await MediaInput.open('video.mp4');
96
- * const stream = media.video();
97
- * const decoder = await Decoder.create(stream);
86
+ * using decoder = await Decoder.create(stream, {
87
+ * threads: 4,
88
+ * options: {
89
+ * 'refcounted_frames': '1',
90
+ * 'skip_frame': 'nonkey' // Only decode keyframes
91
+ * }
92
+ * });
93
+ * ```
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const hw = HardwareContext.auto();
98
+ * using decoder = await Decoder.create(stream, {
99
+ * hardware: hw,
100
+ * threads: 0 // Auto-detect thread count
101
+ * });
98
102
  * ```
103
+ *
104
+ * @see {@link HardwareContext} For GPU acceleration setup
105
+ * @see {@link DecoderOptions} For configuration options
99
106
  */
100
107
  static create(stream: Stream, options?: DecoderOptions): Promise<Decoder>;
101
108
  /**
102
109
  * Check if decoder is open.
110
+ *
111
+ * @returns true if decoder is open and ready
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * if (decoder.isDecoderOpen) {
116
+ * const frame = await decoder.decode(packet);
117
+ * }
118
+ * ```
103
119
  */
104
120
  get isDecoderOpen(): boolean;
105
121
  /**
106
- * Decode a packet and return a frame if available.
122
+ * Get output stream information.
123
+ *
124
+ * Returns format information about decoded frames.
125
+ * For hardware decoding, returns the hardware pixel format.
126
+ * Essential for configuring downstream components like encoders or filters.
127
+ *
128
+ * @returns Stream format information
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const info = decoder.getOutputStreamInfo();
133
+ * if (info.type === 'video') {
134
+ * console.log(`Video: ${info.width}x${info.height} @ ${info.pixelFormat}`);
135
+ * console.log(`Frame rate: ${info.frameRate.num}/${info.frameRate.den}`);
136
+ * }
137
+ * ```
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const info = decoder.getOutputStreamInfo();
142
+ * if (info.type === 'audio') {
143
+ * console.log(`Audio: ${info.sampleRate}Hz ${info.sampleFormat}`);
144
+ * console.log(`Channels: ${info.channelLayout}`);
145
+ * }
146
+ * ```
147
+ *
148
+ * @see {@link StreamInfo} For format details
149
+ * @see {@link Encoder.create} For matching encoder configuration
150
+ */
151
+ getOutputStreamInfo(): StreamInfo;
152
+ /**
153
+ * Check if decoder uses hardware acceleration.
154
+ *
155
+ * @returns true if hardware-accelerated
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * if (decoder.isHardware()) {
160
+ * console.log('Using GPU acceleration');
161
+ * }
162
+ * ```
107
163
  *
108
- * Sends packet to decoder and attempts to receive a frame.
109
- * May return null if decoder needs more data.
164
+ * @see {@link HardwareContext} For hardware setup
165
+ */
166
+ isHardware(): boolean;
167
+ /**
168
+ * Decode a packet to a frame.
110
169
  *
111
- * Uses avcodec_send_packet() and avcodec_receive_frame() internally.
112
- * The decoder may buffer packets before producing frames.
170
+ * Sends a packet to the decoder and attempts to receive a decoded frame.
171
+ * Handles internal buffering - may return null if more packets needed.
172
+ * Automatically manages decoder state and error recovery.
113
173
  *
114
- * @param packet - Packet to decode
174
+ * Direct mapping to avcodec_send_packet() and avcodec_receive_frame().
115
175
  *
116
- * @returns Promise resolving to Frame or null
176
+ * @param packet - Compressed packet to decode
177
+ * @returns Decoded frame or null if more data needed
117
178
  *
118
- * @throws {Error} If decoder is closed or decode fails
179
+ * @throws {Error} If decoder is closed
180
+ * @throws {FFmpegError} If decoding fails
119
181
  *
120
182
  * @example
121
183
  * ```typescript
122
184
  * const frame = await decoder.decode(packet);
123
185
  * if (frame) {
124
- * // Process frame
186
+ * console.log(`Decoded frame with PTS: ${frame.pts}`);
187
+ * frame.free();
125
188
  * }
126
189
  * ```
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * for await (const packet of input.packets()) {
194
+ * if (packet.streamIndex === decoder.getStreamIndex()) {
195
+ * const frame = await decoder.decode(packet);
196
+ * if (frame) {
197
+ * await processFrame(frame);
198
+ * frame.free();
199
+ * }
200
+ * }
201
+ * packet.free();
202
+ * }
203
+ * ```
204
+ *
205
+ * @see {@link frames} For automatic packet iteration
206
+ * @see {@link flush} For end-of-stream handling
127
207
  */
128
208
  decode(packet: Packet): Promise<Frame | null>;
129
209
  /**
130
- * Flush decoder and get remaining frames.
210
+ * Flush decoder and get buffered frame.
131
211
  *
132
- * Sends null packet to trigger flush mode.
133
- * Call repeatedly until it returns null.
212
+ * Signals end-of-stream and retrieves remaining frames.
213
+ * Call repeatedly until null to get all buffered frames.
214
+ * Essential for ensuring all frames are decoded.
134
215
  *
135
- * Uses avcodec_send_packet(NULL) to signal end of stream.
136
- * Retrieves buffered frames from the decoder.
216
+ * Direct mapping to avcodec_send_packet(NULL).
137
217
  *
138
- * @returns Promise resolving to Frame or null
218
+ * @returns Buffered frame or null if none remaining
139
219
  *
140
220
  * @throws {Error} If decoder is closed
141
221
  *
142
222
  * @example
143
223
  * ```typescript
144
- * // Flush all remaining frames
224
+ * // After all packets processed
145
225
  * let frame;
146
226
  * while ((frame = await decoder.flush()) !== null) {
147
- * // Process final frames
227
+ * console.log('Got buffered frame');
228
+ * await processFrame(frame);
229
+ * frame.free();
148
230
  * }
149
231
  * ```
232
+ *
233
+ * @see {@link flushFrames} For async iteration
234
+ * @see {@link frames} For complete decoding pipeline
150
235
  */
151
236
  flush(): Promise<Frame | null>;
152
237
  /**
153
- * Flush decoder and yield all remaining frames as a generator.
238
+ * Flush all buffered frames as async generator.
154
239
  *
155
- * More convenient than calling flush() in a loop.
156
- * Automatically sends flush signal and yields all buffered frames.
157
- *
158
- * IMPORTANT: The yielded frames MUST be freed by the caller!
159
- * Use 'using' statement or manually call frame.free() to avoid memory leaks.
160
- *
161
- * @returns Async generator of remaining frames
240
+ * Convenient async iteration over remaining frames.
241
+ * Automatically handles repeated flush calls.
242
+ * Useful for end-of-stream processing.
162
243
  *
244
+ * @yields Buffered frames
163
245
  * @throws {Error} If decoder is closed
164
246
  *
165
247
  * @example
166
248
  * ```typescript
167
- * // Process all remaining frames with generator
249
+ * // Flush at end of decoding
168
250
  * for await (const frame of decoder.flushFrames()) {
169
- * // Process final frame
170
- * using _ = frame; // Auto cleanup
251
+ * console.log('Processing buffered frame');
252
+ * await encoder.encode(frame);
253
+ * frame.free();
171
254
  * }
172
255
  * ```
256
+ *
257
+ * @see {@link flush} For single frame flush
258
+ * @see {@link frames} For complete pipeline
173
259
  */
174
260
  flushFrames(): AsyncGenerator<Frame>;
175
261
  /**
176
- * Async iterator that decodes packets and yields frames.
177
- *
178
- * Filters packets for this decoder's stream and yields decoded frames.
179
- * Automatically handles packet cleanup and decoder flushing.
262
+ * Decode packet stream to frame stream.
180
263
  *
181
- * Processes packets in sequence, decoding each and yielding frames.
182
- * After all packets are processed, flushes the decoder for remaining frames.
264
+ * High-level async generator for complete decoding pipeline.
265
+ * Automatically filters packets for this stream, manages memory,
266
+ * and flushes buffered frames at end.
267
+ * Primary interface for stream-based decoding.
183
268
  *
184
- * IMPORTANT: The yielded frames MUST be freed by the caller!
185
- * Use 'using' statement or manually call frame.free() to avoid memory leaks.
186
- *
187
- * @param packets - Async iterable of packets (e.g., from MediaInput.packets())
188
- *
189
- * @yields Decoded frames (ownership transferred to caller)
269
+ * @param packets - Async iterable of packets
270
+ * @yields Decoded frames
271
+ * @throws {Error} If decoder is closed
272
+ * @throws {FFmpegError} If decoding fails
190
273
  *
191
274
  * @example
192
275
  * ```typescript
193
- * // RECOMMENDED: Use 'using' for automatic cleanup
194
- * for await (using frame of decoder.frames(media.packets())) {
276
+ * await using input = await MediaInput.open('video.mp4');
277
+ * using decoder = await Decoder.create(input.video());
278
+ *
279
+ * for await (const frame of decoder.frames(input.packets())) {
195
280
  * console.log(`Frame: ${frame.width}x${frame.height}`);
196
- * // Frame is automatically freed at end of iteration
281
+ * frame.free();
197
282
  * }
283
+ * ```
198
284
  *
199
- * // OR: Manual cleanup
200
- * for await (const frame of decoder.frames(media.packets())) {
201
- * console.log(`Frame: ${frame.width}x${frame.height}`);
202
- * // Process frame...
203
- * frame.free(); // MUST call free()!
285
+ * @example
286
+ * ```typescript
287
+ * for await (const frame of decoder.frames(input.packets())) {
288
+ * // Process frame
289
+ * await filter.filterFrame(frame);
290
+ *
291
+ * // Frame automatically freed
292
+ * frame.free();
204
293
  * }
205
294
  * ```
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * import { pipeline } from 'node-av/api';
299
+ *
300
+ * const control = pipeline(
301
+ * input,
302
+ * decoder,
303
+ * encoder,
304
+ * output
305
+ * );
306
+ * await control.completion;
307
+ * ```
308
+ *
309
+ * @see {@link decode} For single packet decoding
310
+ * @see {@link MediaInput.packets} For packet source
206
311
  */
207
312
  frames(packets: AsyncIterable<Packet>): AsyncGenerator<Frame>;
208
313
  /**
209
314
  * Close decoder and free resources.
210
315
  *
211
- * After closing, the decoder cannot be used again.
316
+ * Releases codec context and internal frame buffer.
317
+ * Safe to call multiple times.
318
+ * Automatically called by Symbol.dispose.
319
+ *
320
+ * @example
321
+ * ```typescript
322
+ * const decoder = await Decoder.create(stream);
323
+ * try {
324
+ * // Use decoder
325
+ * } finally {
326
+ * decoder.close();
327
+ * }
328
+ * ```
212
329
  *
213
- * Frees the frame buffer and codec context.
214
- * Note: Does NOT dispose the HardwareContext - caller is responsible for that.
330
+ * @see {@link Symbol.dispose} For automatic cleanup
215
331
  */
216
332
  close(): void;
217
333
  /**
218
- * Get the stream index this decoder is for.
334
+ * Get stream index.
335
+ *
336
+ * Returns the index of the stream being decoded.
337
+ * Used for packet filtering in multi-stream files.
338
+ *
339
+ * @returns Stream index
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * if (packet.streamIndex === decoder.getStreamIndex()) {
344
+ * const frame = await decoder.decode(packet);
345
+ * }
346
+ * ```
347
+ *
348
+ * @see {@link getStream} For full stream object
219
349
  */
220
350
  getStreamIndex(): number;
221
351
  /**
222
- * Get the original stream this decoder was created from.
223
- * Used for stream-copy operations in pipeline.
352
+ * Get stream object.
353
+ *
354
+ * Returns the underlying stream being decoded.
355
+ * Provides access to stream metadata and parameters.
356
+ *
357
+ * @returns Stream object
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const stream = decoder.getStream();
362
+ * console.log(`Duration: ${stream.duration}`);
363
+ * console.log(`Time base: ${stream.timeBase.num}/${stream.timeBase.den}`);
364
+ * ```
365
+ *
366
+ * @see {@link Stream} For stream properties
367
+ * @see {@link getStreamIndex} For index only
224
368
  */
225
369
  getStream(): Stream;
226
370
  /**
227
- * Get codec context for advanced configuration.
228
- *
229
- * Use with caution - direct manipulation may cause issues.
371
+ * Get underlying codec context.
230
372
  *
231
- * Provides access to the underlying AVCodecContext for advanced operations.
373
+ * Returns the internal codec context for advanced operations.
374
+ * Returns null if decoder is closed.
232
375
  *
233
- * @returns CodecContext or null if closed
376
+ * @returns Codec context or null
234
377
  *
235
378
  * @internal
236
379
  */
237
380
  getCodecContext(): CodecContext | null;
238
381
  /**
239
- * Receive a frame from the decoder (internal).
382
+ * Receive frame from decoder.
240
383
  *
241
- * Internal method to receive decoded frames without conversion.
384
+ * Internal method to get decoded frames from codec.
385
+ * Handles frame cloning and error checking.
386
+ * Hardware frames include hw_frames_ctx reference.
242
387
  *
243
- * Uses avcodec_receive_frame() to get decoded frames from the codec.
244
- * Clones the frame for the user to prevent internal buffer corruption.
388
+ * Direct mapping to avcodec_receive_frame().
389
+ *
390
+ * @returns Cloned frame or null
391
+ *
392
+ * @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
245
393
  *
246
- * @returns Frame or null if no frame available
247
- * @internal
248
394
  */
249
395
  private receiveFrameInternal;
250
396
  /**
251
- * Symbol.dispose for automatic cleanup.
397
+ * Dispose of decoder.
398
+ *
399
+ * Implements Disposable interface for automatic cleanup.
400
+ * Equivalent to calling close().
401
+ *
402
+ * @example
403
+ * ```typescript
404
+ * {
405
+ * using decoder = await Decoder.create(stream);
406
+ * // Decode frames...
407
+ * } // Automatically closed
408
+ * ```
252
409
  *
253
- * Implements the Disposable interface for automatic resource management.
254
- * Calls close() to free all resources.
410
+ * @see {@link close} For manual cleanup
255
411
  */
256
412
  [Symbol.dispose](): void;
257
413
  }