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,82 +1,84 @@
1
- /**
2
- * MediaInput - Unified Input Handler for FFmpeg
3
- *
4
- * Provides a high-level interface for opening and reading media from various sources.
5
- * Supports files, URLs, and Buffers with automatic format detection.
6
- *
7
- * Central entry point for all media input operations.
8
- * Manages FormatContext lifecycle and provides stream information.
9
- *
10
- * @module api/media-input
11
- */
12
1
  import { FormatContext, Packet } from '../lib/index.js';
13
- import type { AVMediaType, AVSeekFlag, Stream } from '../lib/index.js';
2
+ import type { AVMediaType, AVSeekFlag } from '../constants/constants.js';
3
+ import type { Stream } from '../lib/index.js';
14
4
  import type { MediaInputOptions, RawData } from './types.js';
15
5
  /**
16
- * MediaInput - High-level media input handler.
17
- *
18
- * Opens and provides access to media streams from various sources.
19
- * Automatically detects format and finds stream information.
6
+ * High-level media input for reading and demuxing media files.
20
7
  *
21
- * Manages the FormatContext and provides convenient methods for
22
- * accessing streams, metadata, and packets.
8
+ * Provides simplified access to media streams, packets, and metadata.
9
+ * Handles file opening, format detection, and stream information extraction.
10
+ * Supports files, URLs, buffers, and raw data input with automatic cleanup.
11
+ * Essential component for media processing pipelines and transcoding.
23
12
  *
24
13
  * @example
25
14
  * ```typescript
26
15
  * import { MediaInput } from 'node-av/api';
27
16
  *
28
- * // Open from file
29
- * const media = await MediaInput.open('video.mp4');
30
- * console.log(`Found ${media.streams.length} streams`);
31
- * console.log(`Duration: ${media.duration} seconds`);
17
+ * // Open media file
18
+ * await using input = await MediaInput.open('video.mp4');
19
+ * console.log(`Format: ${input.formatName}`);
20
+ * console.log(`Duration: ${input.duration}s`);
32
21
  *
33
- * // Open from buffer
34
- * const buffer = await fs.readFile('video.mp4');
35
- * const media = await MediaInput.open(buffer);
36
- *
37
- * // Iterate packets
38
- * for await (const packet of media.packets()) {
22
+ * // Process packets
23
+ * for await (const packet of input.packets()) {
39
24
  * console.log(`Packet from stream ${packet.streamIndex}`);
25
+ * packet.free();
40
26
  * }
41
27
  * ```
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // From buffer
32
+ * const buffer = await fs.readFile('video.mp4');
33
+ * await using input = await MediaInput.open(buffer);
34
+ *
35
+ * // Access streams
36
+ * const videoStream = input.video();
37
+ * const audioStream = input.audio();
38
+ * ```
39
+ *
40
+ * @see {@link MediaOutput} For writing media files
41
+ * @see {@link Decoder} For decoding packets to frames
42
+ * @see {@link FormatContext} For low-level API
42
43
  */
43
44
  export declare class MediaInput implements AsyncDisposable {
44
45
  private formatContext;
45
46
  private _streams;
46
47
  private ioContext?;
47
48
  /**
48
- * Create a new MediaInput instance.
49
- *
50
- * Private constructor - use MediaInput.open() to create instances.
51
- *
52
- * Parses stream information immediately after construction.
53
- *
54
- * @param formatContext - Opened FormatContext
49
+ * @param formatContext - Opened format context
50
+ * @internal
55
51
  */
56
52
  private constructor();
57
53
  /**
58
- * Probe the format of media without fully opening it.
54
+ * Probe media format without fully opening the file.
59
55
  *
60
- * Detects the container format and basic information without
61
- * parsing all stream information. Useful for quick format validation.
56
+ * Detects format by analyzing file headers and content.
57
+ * Useful for format validation before processing.
62
58
  *
63
- * @param input - File path or Buffer to probe
59
+ * Direct mapping to av_probe_input_format().
64
60
  *
61
+ * @param input - File path or buffer to probe
65
62
  * @returns Format information or null if unrecognized
66
63
  *
67
64
  * @example
68
65
  * ```typescript
69
- * // Probe a file
70
66
  * const info = await MediaInput.probeFormat('video.mp4');
71
67
  * if (info) {
72
68
  * console.log(`Format: ${info.format}`);
73
69
  * console.log(`Confidence: ${info.confidence}%`);
74
70
  * }
71
+ * ```
75
72
  *
76
- * // Probe a buffer
77
- * const buffer = await fs.readFile('video.mp4');
73
+ * @example
74
+ * ```typescript
75
+ * // Probe from buffer
76
+ * const buffer = await fs.readFile('video.webm');
78
77
  * const info = await MediaInput.probeFormat(buffer);
78
+ * console.log(`MIME type: ${info?.mimeType}`);
79
79
  * ```
80
+ *
81
+ * @see {@link InputFormat.probe} For low-level probing
80
82
  */
81
83
  static probeFormat(input: string | Buffer): Promise<{
82
84
  format: string;
@@ -86,218 +88,319 @@ export declare class MediaInput implements AsyncDisposable {
86
88
  confidence: number;
87
89
  } | null>;
88
90
  /**
89
- * Open a media input from various sources.
91
+ * Open media from file, URL, buffer, or raw data.
90
92
  *
91
- * Creates a FormatContext and opens the input for reading.
92
- * Automatically detects format and finds stream information.
93
+ * Automatically detects format and extracts stream information.
94
+ * Supports various input sources with flexible configuration.
95
+ * Creates demuxer ready for packet extraction.
93
96
  *
94
- * Uses av_format_open_input() and av_find_stream_info() internally.
97
+ * Direct mapping to avformat_open_input() and avformat_find_stream_info().
95
98
  *
96
- * @param input - File path, URL, or Buffer
97
- * @param options - Optional configuration for timestamp handling
99
+ * @param input - File path, URL, buffer, or raw data descriptor
100
+ * @param options - Input configuration options
101
+ * @returns Opened media input instance
98
102
  *
99
- * @returns Promise resolving to MediaInput instance
100
- *
101
- * @throws {Error} If input cannot be opened or stream info not found
103
+ * @throws {Error} If format not found or open fails
104
+ * @throws {FFmpegError} If FFmpeg operations fail
102
105
  *
103
106
  * @example
104
107
  * ```typescript
105
- * // From file
106
- * const media = await MediaInput.open('video.mp4');
107
- *
108
- * // From URL
109
- * const media = await MediaInput.open('https://example.com/video.mp4');
110
- *
111
- * // From Buffer
112
- * const buffer = await fs.readFile('video.mp4');
113
- * const media = await MediaInput.open(buffer);
108
+ * // Open file
109
+ * await using input = await MediaInput.open('video.mp4');
114
110
  * ```
115
- */
116
- static open(input: string | Buffer, options?: MediaInputOptions): Promise<MediaInput>;
117
- /**
118
- * Open raw video or audio data.
119
- *
120
- * @param rawData - Raw video or audio configuration
121
111
  *
122
- * @returns Promise resolving to MediaInput instance
112
+ * @example
113
+ * ```typescript
114
+ * // Open URL
115
+ * await using input = await MediaInput.open('http://example.com/stream.m3u8');
116
+ * ```
123
117
  *
124
118
  * @example
125
119
  * ```typescript
126
- * // Raw video
127
- * const input = await MediaInput.open({
128
- * type: 'video',
129
- * data: 'input.yuv',
130
- * width: 1280,
131
- * height: 720,
132
- * pixelFormat: 'yuv420p',
133
- * frameRate: 30
120
+ * // Open with options
121
+ * await using input = await MediaInput.open('rtsp://camera.local', {
122
+ * format: 'rtsp',
123
+ * options: {
124
+ * rtsp_transport: 'tcp',
125
+ * analyzeduration: '5000000'
126
+ * }
134
127
  * });
128
+ * ```
135
129
  *
136
- * // Raw audio
137
- * const input = await MediaInput.open({
138
- * type: 'audio',
139
- * data: 'input.pcm',
140
- * sampleRate: 48000,
141
- * channels: 2,
142
- * sampleFormat: 's16le'
130
+ * @example
131
+ * ```typescript
132
+ * // Open raw video data
133
+ * await using input = await MediaInput.open({
134
+ * type: 'video',
135
+ * input: rawBuffer,
136
+ * width: 1920,
137
+ * height: 1080,
138
+ * pixelFormat: AV_PIX_FMT_YUV420P,
139
+ * frameRate: { num: 30, den: 1 }
143
140
  * });
144
141
  * ```
142
+ *
143
+ * @see {@link MediaInputOptions} For configuration options
144
+ * @see {@link RawData} For raw data input
145
145
  */
146
+ static open(input: string | Buffer, options?: MediaInputOptions): Promise<MediaInput>;
146
147
  static open(rawData: RawData, options?: MediaInputOptions): Promise<MediaInput>;
147
148
  /**
148
- * Get all streams in the container.
149
+ * Get all streams in the media.
149
150
  *
150
- * @returns Array of stream information
151
+ * @example
152
+ * ```typescript
153
+ * for (const stream of input.streams) {
154
+ * console.log(`Stream ${stream.index}: ${stream.codecpar.codecType}`);
155
+ * }
156
+ * ```
151
157
  */
152
158
  get streams(): Stream[];
153
159
  /**
154
160
  * Get media duration in seconds.
155
161
  *
156
- * Returns 0 if duration is not available.
162
+ * Returns 0 if duration is unknown or not available.
157
163
  *
158
- * @returns Duration in seconds
164
+ * @example
165
+ * ```typescript
166
+ * console.log(`Duration: ${input.duration} seconds`);
167
+ * ```
159
168
  */
160
169
  get duration(): number;
161
170
  /**
162
- * Get overall bitrate in kilobits per second.
171
+ * Get media bitrate in kilobits per second.
163
172
  *
164
- * Returns 0 if bitrate is not available.
173
+ * Returns 0 if bitrate is unknown.
165
174
  *
166
- * @returns Bitrate in kbps
175
+ * @example
176
+ * ```typescript
177
+ * console.log(`Bitrate: ${input.bitRate} kbps`);
178
+ * ```
167
179
  */
168
180
  get bitRate(): number;
169
181
  /**
170
- * Get container metadata.
182
+ * Get media metadata.
171
183
  *
172
- * @returns Metadata key-value pairs
184
+ * Returns all metadata tags as key-value pairs.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const metadata = input.metadata;
189
+ * console.log(`Title: ${metadata.title}`);
190
+ * console.log(`Artist: ${metadata.artist}`);
191
+ * ```
173
192
  */
174
193
  get metadata(): Record<string, string>;
175
194
  /**
176
- * Get container format name.
195
+ * Get format name.
177
196
  *
178
- * @returns Format name (e.g., 'mov,mp4,m4a,3gp,3g2,mj2')
197
+ * @example
198
+ * ```typescript
199
+ * console.log(`Format: ${input.formatName}`); // "mov,mp4,m4a,3gp,3g2,mj2"
200
+ * ```
179
201
  */
180
202
  get formatName(): string;
181
203
  /**
182
- * Get container format long name.
204
+ * Get format long name.
183
205
  *
184
- * @returns Format long name (e.g., 'QuickTime / MOV')
206
+ * @example
207
+ * ```typescript
208
+ * console.log(`Format: ${input.formatLongName}`); // "QuickTime / MOV"
209
+ * ```
185
210
  */
186
211
  get formatLongName(): string;
187
212
  /**
188
- * Get the first video stream.
213
+ * Get video stream by index.
189
214
  *
190
- * @param index - Video stream index (0 for first, 1 for second, etc.)
215
+ * Returns the nth video stream (0-based index).
216
+ * Returns undefined if stream doesn't exist.
191
217
  *
192
- * @returns Stream info or undefined if not found
218
+ * @param index - Video stream index (default: 0)
219
+ * @returns Video stream or undefined
193
220
  *
194
221
  * @example
195
222
  * ```typescript
196
- * const videoStream = media.video();
223
+ * const videoStream = input.video();
197
224
  * if (videoStream) {
198
- * console.log(`Video: ${videoStream.width}x${videoStream.height}`);
225
+ * console.log(`Video: ${videoStream.codecpar.width}x${videoStream.codecpar.height}`);
199
226
  * }
200
227
  * ```
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * // Get second video stream
232
+ * const secondVideo = input.video(1);
233
+ * ```
234
+ *
235
+ * @see {@link audio} For audio streams
236
+ * @see {@link findBestStream} For automatic selection
201
237
  */
202
238
  video(index?: number): Stream | undefined;
203
239
  /**
204
- * Get the first audio stream.
240
+ * Get audio stream by index.
205
241
  *
206
- * @param index - Audio stream index (0 for first, 1 for second, etc.)
242
+ * Returns the nth audio stream (0-based index).
243
+ * Returns undefined if stream doesn't exist.
207
244
  *
208
- * @returns Stream info or undefined if not found
245
+ * @param index - Audio stream index (default: 0)
246
+ * @returns Audio stream or undefined
209
247
  *
210
248
  * @example
211
249
  * ```typescript
212
- * const audioStream = media.audio();
250
+ * const audioStream = input.audio();
213
251
  * if (audioStream) {
214
- * console.log(`Audio: ${audioStream.sampleRate}Hz, ${audioStream.channels}ch`);
252
+ * console.log(`Audio: ${audioStream.codecpar.sampleRate}Hz`);
215
253
  * }
216
254
  * ```
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // Get second audio stream
259
+ * const secondAudio = input.audio(1);
260
+ * ```
261
+ *
262
+ * @see {@link video} For video streams
263
+ * @see {@link findBestStream} For automatic selection
217
264
  */
218
265
  audio(index?: number): Stream | undefined;
219
266
  /**
220
267
  * Find the best stream of a given type.
221
268
  *
222
- * Uses FFmpeg's stream selection logic to find the most suitable stream.
269
+ * Uses FFmpeg's stream selection algorithm.
270
+ * Considers codec support, default flags, and quality.
223
271
  *
224
- * Uses av_find_best_stream() internally for optimal stream selection.
272
+ * Direct mapping to av_find_best_stream().
225
273
  *
226
- * @param type - Media type to search for
274
+ * @param type - Media type to find
275
+ * @returns Best stream or undefined if not found
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
280
+ *
281
+ * const bestVideo = input.findBestStream(AVMEDIA_TYPE_VIDEO);
282
+ * if (bestVideo) {
283
+ * const decoder = await Decoder.create(bestVideo);
284
+ * }
285
+ * ```
227
286
  *
228
- * @returns Stream info or undefined if not found
287
+ * @see {@link video} For direct video stream access
288
+ * @see {@link audio} For direct audio stream access
229
289
  */
230
290
  findBestStream(type: AVMediaType): Stream | undefined;
231
291
  /**
232
- * Iterate over all packets in the container.
292
+ * Read packets from media as async generator.
233
293
  *
234
- * Allocates a single packet and reuses it for efficiency.
235
- * Automatically unreferences the packet between iterations.
294
+ * Yields demuxed packets for processing.
295
+ * Automatically handles packet memory management.
296
+ * Optionally filters packets by stream index.
236
297
  *
237
- * Uses av_read_frame() internally.
298
+ * Direct mapping to av_read_frame().
238
299
  *
239
- * @yields Packet from the container
300
+ * @param index - Optional stream index to filter
301
+ * @yields Demuxed packets (must be freed by caller)
302
+ * @throws {Error} If packet cloning fails
240
303
  *
241
304
  * @example
242
305
  * ```typescript
243
- * for await (const packet of media.packets()) {
244
- * if (packet.streamIndex === videoStream.index) {
245
- * // Process video packet
246
- * await decoder.decode(packet);
247
- * }
306
+ * // Read all packets
307
+ * for await (const packet of input.packets()) {
308
+ * console.log(`Packet: stream=${packet.streamIndex}, pts=${packet.pts}`);
309
+ * packet.free();
248
310
  * }
249
311
  * ```
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * // Read only video packets
316
+ * const videoStream = input.video();
317
+ * for await (const packet of input.packets(videoStream.index)) {
318
+ * // Process video packet
319
+ * packet.free();
320
+ * }
321
+ * ```
322
+ *
323
+ * @see {@link Decoder.frames} For decoding packets
250
324
  */
251
325
  packets(index?: number): AsyncGenerator<Packet>;
252
326
  /**
253
- * Seek to a specific timestamp.
327
+ * Seek to timestamp in media.
254
328
  *
255
- * Uses av_seek_frame() internally.
329
+ * Seeks to the specified position in seconds.
330
+ * Can seek in specific stream or globally.
256
331
  *
257
- * Converts seconds to microseconds for FFmpeg's AV_TIME_BASE.
332
+ * Direct mapping to av_seek_frame().
258
333
  *
259
- * @param timestamp - Target timestamp in seconds
260
- * @param streamIndex - Stream to seek in (-1 for default)
261
- * @param flags - Seek flags (0 for default)
334
+ * @param timestamp - Target position in seconds
335
+ * @param streamIndex - Stream index or -1 for global (default: -1)
336
+ * @param flags - Seek flags (default: AVFLAG_NONE)
337
+ * @returns 0 on success, negative on error
262
338
  *
263
- * @returns 0 on success, negative error code on failure
339
+ * @example
340
+ * ```typescript
341
+ * // Seek to 30 seconds
342
+ * const ret = await input.seek(30);
343
+ * FFmpegError.throwIfError(ret, 'seek failed');
344
+ * ```
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
349
+ *
350
+ * // Seek to keyframe before 60 seconds
351
+ * await input.seek(60, -1, AVSEEK_FLAG_BACKWARD);
352
+ * ```
353
+ *
354
+ * @see {@link AVSeekFlag} For seek flags
264
355
  */
265
356
  seek(timestamp: number, streamIndex?: number, flags?: AVSeekFlag): Promise<number>;
266
357
  /**
267
- * Close the input and free resources.
358
+ * Close media input and free resources.
268
359
  *
269
- * Uses avformat_close_input() internally.
360
+ * Releases format context and I/O context.
361
+ * Safe to call multiple times.
362
+ * Automatically called by Symbol.asyncDispose.
363
+ *
364
+ * Direct mapping to avformat_close_input().
365
+ *
366
+ * @example
367
+ * ```typescript
368
+ * const input = await MediaInput.open('video.mp4');
369
+ * try {
370
+ * // Use input
371
+ * } finally {
372
+ * await input.close();
373
+ * }
374
+ * ```
270
375
  *
271
- * Properly cleans up IOContext references before closing to prevent
272
- * use-after-free errors.
376
+ * @see {@link Symbol.asyncDispose} For automatic cleanup
273
377
  */
274
378
  close(): Promise<void>;
275
379
  /**
276
- * Get the low-level FormatContext.
380
+ * Get underlying format context.
277
381
  *
278
- * Internal method for advanced use cases.
382
+ * Returns the internal format context for advanced operations.
279
383
  *
280
- * Provides direct access to the underlying AVFormatContext.
281
- *
282
- * @returns FFmpeg FormatContext
384
+ * @returns Format context
283
385
  *
284
386
  * @internal
285
387
  */
286
388
  getFormatContext(): FormatContext;
287
389
  /**
288
- * Async cleanup when using 'await using' statement.
289
- *
290
- * Implements the AsyncDisposable interface for automatic cleanup.
390
+ * Dispose of media input.
291
391
  *
292
- * Calls close() to free all resources.
392
+ * Implements AsyncDisposable interface for automatic cleanup.
393
+ * Equivalent to calling close().
293
394
  *
294
395
  * @example
295
396
  * ```typescript
296
397
  * {
297
- * await using media = await MediaInput.open('video.mp4');
298
- * // Use media...
398
+ * await using input = await MediaInput.open('video.mp4');
399
+ * // Process media...
299
400
  * } // Automatically closed
300
401
  * ```
402
+ *
403
+ * @see {@link close} For manual cleanup
301
404
  */
302
405
  [Symbol.asyncDispose](): Promise<void>;
303
406
  }