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,274 @@
1
+ /**
2
+ * MediaOutput - Unified Output Handler for FFmpeg
3
+ *
4
+ * Provides a high-level interface for writing media to various destinations.
5
+ * Supports files, streams, and custom IO with automatic format configuration.
6
+ *
7
+ * Central entry point for all media output operations.
8
+ * Manages FormatContext lifecycle and provides stream management.
9
+ *
10
+ * @module api/media-output
11
+ */
12
+ import { FormatContext } from '../lib/index.js';
13
+ import { Encoder } from './encoder.js';
14
+ import type { IRational, Packet, Stream } from '../lib/index.js';
15
+ import type { IOOutputCallbacks, MediaOutputOptions } from './types.js';
16
+ interface StreamInfo {
17
+ stream: Stream;
18
+ timeBase: IRational;
19
+ isStreamCopy: boolean;
20
+ sourceTimeBase?: IRational;
21
+ }
22
+ /**
23
+ * MediaOutput - High-level media output handler.
24
+ *
25
+ * Creates and manages media containers for writing encoded streams.
26
+ * Automatically handles format setup and stream configuration.
27
+ *
28
+ * Manages the FormatContext and provides convenient methods for
29
+ * adding streams, writing packets, and finalizing output.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { MediaOutput, Encoder } from 'node-av/api';
34
+ *
35
+ * // Open output file
36
+ * const output = await MediaOutput.open('output.mp4');
37
+ *
38
+ * // Add encoder stream
39
+ * const encoder = await Encoder.create('libx264', {
40
+ * width: 1920,
41
+ * height: 1080,
42
+ * pixelFormat: AV_PIX_FMT_YUV420P
43
+ * });
44
+ * const streamIdx = output.addStream(encoder);
45
+ *
46
+ * // Write header, packets, trailer
47
+ * await output.writeHeader();
48
+ * await output.writePacket(packet, streamIdx);
49
+ * await output.writeTrailer();
50
+ * await output.close();
51
+ * ```
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // Stream copy without re-encoding
56
+ * const input = await MediaInput.open('input.mp4');
57
+ * const output = await MediaOutput.open('output.mkv');
58
+ *
59
+ * const videoStream = input.video();
60
+ * const streamIdx = output.addStream(videoStream);
61
+ *
62
+ * await output.writeHeader();
63
+ * for await (const packet of input.packets()) {
64
+ * if (packet.streamIndex === videoStream.index) {
65
+ * await output.writePacket(packet, streamIdx);
66
+ * }
67
+ * }
68
+ * await output.writeTrailer();
69
+ * ```
70
+ */
71
+ export declare class MediaOutput implements AsyncDisposable {
72
+ private formatContext;
73
+ private streams;
74
+ private ioContext?;
75
+ private headerWritten;
76
+ private trailerWritten;
77
+ private closed;
78
+ /**
79
+ * Private constructor - use MediaOutput.open() instead.
80
+ *
81
+ * Initializes the output with a new FormatContext.
82
+ * The actual format setup happens in the static factory method.
83
+ */
84
+ private constructor();
85
+ /**
86
+ * Opens a media output for writing with custom IO callbacks or stream URL or file output
87
+ *
88
+ * Creates a FormatContext and prepares the output for writing.
89
+ * Automatically detects format from filename/URL if not specified.
90
+ *
91
+ * If io callbacks is used, it creates a FormatContext with custom IO handling.
92
+ * Format must be explicitly specified for custom IO.
93
+ *
94
+ * Uses avformat_alloc_output_context2() and avio_alloc_context() internally.
95
+ *
96
+ * @param target - File path or stream URL or custom IO callbacks
97
+ * @param options - Optional configuration
98
+ *
99
+ * @returns Promise resolving to MediaOutput instance
100
+ *
101
+ * @throws {Error} If format not specified or context allocation fails
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const callbacks = {
106
+ * write: (buffer) => myStream.write(buffer),
107
+ * seek: (offset, whence) => offset
108
+ * };
109
+ * const output = await MediaOutput.open(callbacks, { format: 'mp4' });
110
+ * ```
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const output = await MediaOutput.open('output.mp4');
115
+ * ```
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const output = await MediaOutput.open('rtmp://server/live/streamkey', { format: 'flv' });
120
+ * ```
121
+ */
122
+ static open(target: string | IOOutputCallbacks, options?: MediaOutputOptions): Promise<MediaOutput>;
123
+ /**
124
+ * Adds a stream to the output container.
125
+ *
126
+ * Creates a new stream in the output format context.
127
+ * Copies codec parameters from encoder or input stream.
128
+ *
129
+ * Uses avformat_new_stream() and avcodec_parameters_copy() internally.
130
+ *
131
+ * @param source - Encoder for transcoding or Stream for copying
132
+ * @param options - Optional stream configuration
133
+ * @param options.timeBase - Custom output timebase for the stream.
134
+ * If not specified, uses the source's timebase.
135
+ * When set, packets will be automatically rescaled
136
+ * from source timebase to this output timebase.
137
+ *
138
+ * @returns Stream index for packet writing
139
+ *
140
+ * @throws {Error} If called after header is written or output is closed
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // Add encoder stream (transcoding) - uses encoder's timebase
145
+ * const encoder = await Encoder.create('libx264', { width: 1920, height: 1080 });
146
+ * const streamIdx = output.addStream(encoder);
147
+ * ```
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Add stream for direct copy - uses input stream's timebase
152
+ * const inputStream = input.video();
153
+ * const streamIdx = output.addStream(inputStream);
154
+ * ```
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Custom output timebase (e.g., for format requirements)
159
+ * const streamIdx = output.addStream(encoder, {
160
+ * timeBase: { num: 1, den: 90000 } // MPEG-TS standard
161
+ * });
162
+ * // Packets from encoder will be automatically rescaled to 1/90000
163
+ * ```
164
+ */
165
+ addStream(source: Encoder | Stream, options?: {
166
+ timeBase?: IRational;
167
+ }): number;
168
+ /**
169
+ * Writes a packet to the output container.
170
+ *
171
+ * Writes an encoded packet to the specified stream.
172
+ * Automatically sets the stream index on the packet.
173
+ *
174
+ * Uses av_interleaved_write_frame() internally.
175
+ *
176
+ * @param packet - Packet to write
177
+ * @param streamIndex - Target stream index
178
+ *
179
+ * @throws {Error} If header not written, trailer already written, or invalid stream
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const encoded = await encoder.encode(frame);
184
+ * if (encoded) {
185
+ * await output.writePacket(encoded, streamIdx);
186
+ * encoded.free();
187
+ * }
188
+ * ```
189
+ */
190
+ writePacket(packet: Packet, streamIndex: number): Promise<void>;
191
+ /**
192
+ * Writes the output file header.
193
+ *
194
+ * Writes the container header with stream information.
195
+ * Must be called before writing any packets.
196
+ *
197
+ * Uses avformat_write_header() internally.
198
+ *
199
+ * @param options - Optional header options (format-specific)
200
+ *
201
+ * @throws {Error} If header already written or output is closed
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * await output.writeHeader();
206
+ * ```
207
+ */
208
+ writeHeader(): Promise<void>;
209
+ /**
210
+ * Writes the output file trailer.
211
+ *
212
+ * Finalizes the output file with necessary metadata.
213
+ * Should be called after all packets have been written.
214
+ *
215
+ * Uses av_write_trailer() internally.
216
+ *
217
+ * @throws {Error} If header not written, trailer already written, or output is closed
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * await output.writeTrailer();
222
+ * ```
223
+ */
224
+ writeTrailer(): Promise<void>;
225
+ /**
226
+ * Closes the output and releases all resources.
227
+ *
228
+ * Writes trailer if needed, closes IO context, and frees format context.
229
+ * Safe to call multiple times.
230
+ *
231
+ * Uses av_write_trailer(), avio_closep(), and avformat_free_context() internally.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * await output.close();
236
+ * ```
237
+ */
238
+ close(): Promise<void>;
239
+ /**
240
+ * Gets information about a specific stream.
241
+ */
242
+ getStreamInfo(streamIndex: number): StreamInfo | undefined;
243
+ /**
244
+ * Gets all stream indices.
245
+ */
246
+ getStreamIndices(): number[];
247
+ /**
248
+ * Checks if header has been written.
249
+ */
250
+ isHeaderWritten(): boolean;
251
+ /**
252
+ * Checks if trailer has been written.
253
+ */
254
+ isTrailerWritten(): boolean;
255
+ /**
256
+ * Gets the underlying format context.
257
+ *
258
+ * For advanced use cases requiring direct format context access.
259
+ */
260
+ getFormatContext(): FormatContext;
261
+ /**
262
+ * AsyncDisposable implementation for using statement.
263
+ *
264
+ * Enables automatic resource cleanup with await using syntax.
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * await using output = await MediaOutput.open('output.mp4');
269
+ * // Output automatically closes when scope ends
270
+ * ```
271
+ */
272
+ [Symbol.asyncDispose](): Promise<void>;
273
+ }
274
+ export {};