node-av 3.1.3 → 5.0.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 (192) hide show
  1. package/README.md +88 -52
  2. package/binding.gyp +23 -11
  3. package/dist/api/audio-frame-buffer.d.ts +201 -0
  4. package/dist/api/audio-frame-buffer.js +275 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +320 -78
  7. package/dist/api/bitstream-filter.js +684 -151
  8. package/dist/api/bitstream-filter.js.map +1 -1
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  14. package/dist/api/data/test_vp8.ivf +0 -0
  15. package/dist/api/data/test_vp9.ivf +0 -0
  16. package/dist/api/decoder.d.ts +454 -77
  17. package/dist/api/decoder.js +1081 -271
  18. package/dist/api/decoder.js.map +1 -1
  19. package/dist/api/{media-input.d.ts → demuxer.d.ts} +295 -45
  20. package/dist/api/demuxer.js +1965 -0
  21. package/dist/api/demuxer.js.map +1 -0
  22. package/dist/api/encoder.d.ts +423 -132
  23. package/dist/api/encoder.js +1089 -240
  24. package/dist/api/encoder.js.map +1 -1
  25. package/dist/api/filter-complex.d.ts +769 -0
  26. package/dist/api/filter-complex.js +1596 -0
  27. package/dist/api/filter-complex.js.map +1 -0
  28. package/dist/api/filter-presets.d.ts +80 -5
  29. package/dist/api/filter-presets.js +117 -7
  30. package/dist/api/filter-presets.js.map +1 -1
  31. package/dist/api/filter.d.ts +561 -125
  32. package/dist/api/filter.js +1083 -274
  33. package/dist/api/filter.js.map +1 -1
  34. package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
  35. package/dist/api/fmp4-stream.js +539 -0
  36. package/dist/api/fmp4-stream.js.map +1 -0
  37. package/dist/api/hardware.d.ts +58 -6
  38. package/dist/api/hardware.js +127 -11
  39. package/dist/api/hardware.js.map +1 -1
  40. package/dist/api/index.d.ts +8 -4
  41. package/dist/api/index.js +17 -8
  42. package/dist/api/index.js.map +1 -1
  43. package/dist/api/io-stream.d.ts +6 -6
  44. package/dist/api/io-stream.js +5 -4
  45. package/dist/api/io-stream.js.map +1 -1
  46. package/dist/api/{media-output.d.ts → muxer.d.ts} +280 -66
  47. package/dist/api/muxer.js +1934 -0
  48. package/dist/api/muxer.js.map +1 -0
  49. package/dist/api/pipeline.d.ts +77 -29
  50. package/dist/api/pipeline.js +449 -439
  51. package/dist/api/pipeline.js.map +1 -1
  52. package/dist/api/rtp-stream.d.ts +312 -0
  53. package/dist/api/rtp-stream.js +630 -0
  54. package/dist/api/rtp-stream.js.map +1 -0
  55. package/dist/api/types.d.ts +533 -56
  56. package/dist/api/utilities/async-queue.d.ts +91 -0
  57. package/dist/api/utilities/async-queue.js +162 -0
  58. package/dist/api/utilities/async-queue.js.map +1 -0
  59. package/dist/api/utilities/audio-sample.d.ts +11 -1
  60. package/dist/api/utilities/audio-sample.js +10 -0
  61. package/dist/api/utilities/audio-sample.js.map +1 -1
  62. package/dist/api/utilities/channel-layout.d.ts +1 -0
  63. package/dist/api/utilities/channel-layout.js +1 -0
  64. package/dist/api/utilities/channel-layout.js.map +1 -1
  65. package/dist/api/utilities/image.d.ts +39 -1
  66. package/dist/api/utilities/image.js +38 -0
  67. package/dist/api/utilities/image.js.map +1 -1
  68. package/dist/api/utilities/index.d.ts +3 -0
  69. package/dist/api/utilities/index.js +6 -0
  70. package/dist/api/utilities/index.js.map +1 -1
  71. package/dist/api/utilities/media-type.d.ts +2 -1
  72. package/dist/api/utilities/media-type.js +1 -0
  73. package/dist/api/utilities/media-type.js.map +1 -1
  74. package/dist/api/utilities/pixel-format.d.ts +4 -1
  75. package/dist/api/utilities/pixel-format.js +3 -0
  76. package/dist/api/utilities/pixel-format.js.map +1 -1
  77. package/dist/api/utilities/sample-format.d.ts +6 -1
  78. package/dist/api/utilities/sample-format.js +5 -0
  79. package/dist/api/utilities/sample-format.js.map +1 -1
  80. package/dist/api/utilities/scheduler.d.ts +138 -0
  81. package/dist/api/utilities/scheduler.js +98 -0
  82. package/dist/api/utilities/scheduler.js.map +1 -0
  83. package/dist/api/utilities/streaming.d.ts +105 -15
  84. package/dist/api/utilities/streaming.js +201 -12
  85. package/dist/api/utilities/streaming.js.map +1 -1
  86. package/dist/api/utilities/timestamp.d.ts +15 -1
  87. package/dist/api/utilities/timestamp.js +14 -0
  88. package/dist/api/utilities/timestamp.js.map +1 -1
  89. package/dist/api/utilities/whisper-model.d.ts +310 -0
  90. package/dist/api/utilities/whisper-model.js +528 -0
  91. package/dist/api/utilities/whisper-model.js.map +1 -0
  92. package/dist/api/webrtc-stream.d.ts +288 -0
  93. package/dist/api/webrtc-stream.js +440 -0
  94. package/dist/api/webrtc-stream.js.map +1 -0
  95. package/dist/api/whisper.d.ts +324 -0
  96. package/dist/api/whisper.js +362 -0
  97. package/dist/api/whisper.js.map +1 -0
  98. package/dist/constants/constants.d.ts +54 -2
  99. package/dist/constants/constants.js +48 -1
  100. package/dist/constants/constants.js.map +1 -1
  101. package/dist/constants/encoders.d.ts +2 -1
  102. package/dist/constants/encoders.js +4 -3
  103. package/dist/constants/encoders.js.map +1 -1
  104. package/dist/constants/hardware.d.ts +26 -0
  105. package/dist/constants/hardware.js +27 -0
  106. package/dist/constants/hardware.js.map +1 -0
  107. package/dist/constants/index.d.ts +1 -0
  108. package/dist/constants/index.js +1 -0
  109. package/dist/constants/index.js.map +1 -1
  110. package/dist/ffmpeg/index.d.ts +3 -3
  111. package/dist/ffmpeg/index.js +3 -3
  112. package/dist/ffmpeg/utils.d.ts +27 -0
  113. package/dist/ffmpeg/utils.js +28 -16
  114. package/dist/ffmpeg/utils.js.map +1 -1
  115. package/dist/lib/binding.d.ts +22 -11
  116. package/dist/lib/binding.js.map +1 -1
  117. package/dist/lib/codec-context.d.ts +87 -0
  118. package/dist/lib/codec-context.js +125 -4
  119. package/dist/lib/codec-context.js.map +1 -1
  120. package/dist/lib/codec-parameters.d.ts +229 -1
  121. package/dist/lib/codec-parameters.js +264 -0
  122. package/dist/lib/codec-parameters.js.map +1 -1
  123. package/dist/lib/codec-parser.d.ts +23 -0
  124. package/dist/lib/codec-parser.js +25 -0
  125. package/dist/lib/codec-parser.js.map +1 -1
  126. package/dist/lib/codec.d.ts +26 -4
  127. package/dist/lib/codec.js +35 -0
  128. package/dist/lib/codec.js.map +1 -1
  129. package/dist/lib/dictionary.js +1 -0
  130. package/dist/lib/dictionary.js.map +1 -1
  131. package/dist/lib/error.js +1 -1
  132. package/dist/lib/error.js.map +1 -1
  133. package/dist/lib/fifo.d.ts +416 -0
  134. package/dist/lib/fifo.js +453 -0
  135. package/dist/lib/fifo.js.map +1 -0
  136. package/dist/lib/filter-context.d.ts +52 -11
  137. package/dist/lib/filter-context.js +56 -12
  138. package/dist/lib/filter-context.js.map +1 -1
  139. package/dist/lib/filter-graph.d.ts +9 -0
  140. package/dist/lib/filter-graph.js +13 -0
  141. package/dist/lib/filter-graph.js.map +1 -1
  142. package/dist/lib/filter.d.ts +21 -0
  143. package/dist/lib/filter.js +28 -0
  144. package/dist/lib/filter.js.map +1 -1
  145. package/dist/lib/format-context.d.ts +48 -14
  146. package/dist/lib/format-context.js +76 -7
  147. package/dist/lib/format-context.js.map +1 -1
  148. package/dist/lib/frame.d.ts +264 -1
  149. package/dist/lib/frame.js +351 -1
  150. package/dist/lib/frame.js.map +1 -1
  151. package/dist/lib/hardware-device-context.d.ts +3 -2
  152. package/dist/lib/hardware-device-context.js.map +1 -1
  153. package/dist/lib/index.d.ts +2 -0
  154. package/dist/lib/index.js +4 -0
  155. package/dist/lib/index.js.map +1 -1
  156. package/dist/lib/input-format.d.ts +21 -0
  157. package/dist/lib/input-format.js +42 -2
  158. package/dist/lib/input-format.js.map +1 -1
  159. package/dist/lib/native-types.d.ts +76 -27
  160. package/dist/lib/option.d.ts +25 -13
  161. package/dist/lib/option.js +28 -0
  162. package/dist/lib/option.js.map +1 -1
  163. package/dist/lib/output-format.d.ts +22 -1
  164. package/dist/lib/output-format.js +28 -0
  165. package/dist/lib/output-format.js.map +1 -1
  166. package/dist/lib/packet.d.ts +35 -0
  167. package/dist/lib/packet.js +52 -2
  168. package/dist/lib/packet.js.map +1 -1
  169. package/dist/lib/rational.d.ts +18 -0
  170. package/dist/lib/rational.js +19 -0
  171. package/dist/lib/rational.js.map +1 -1
  172. package/dist/lib/stream.d.ts +126 -0
  173. package/dist/lib/stream.js +188 -5
  174. package/dist/lib/stream.js.map +1 -1
  175. package/dist/lib/sync-queue.d.ts +179 -0
  176. package/dist/lib/sync-queue.js +197 -0
  177. package/dist/lib/sync-queue.js.map +1 -0
  178. package/dist/lib/types.d.ts +49 -1
  179. package/dist/lib/utilities.d.ts +281 -53
  180. package/dist/lib/utilities.js +298 -55
  181. package/dist/lib/utilities.js.map +1 -1
  182. package/install/check.js +2 -2
  183. package/package.json +37 -26
  184. package/dist/api/fmp4.js +0 -710
  185. package/dist/api/fmp4.js.map +0 -1
  186. package/dist/api/media-input.js +0 -1075
  187. package/dist/api/media-input.js.map +0 -1
  188. package/dist/api/media-output.js +0 -1040
  189. package/dist/api/media-output.js.map +0 -1
  190. package/dist/api/webrtc.d.ts +0 -664
  191. package/dist/api/webrtc.js +0 -1132
  192. package/dist/api/webrtc.js.map +0 -1
@@ -0,0 +1,288 @@
1
+ import { RTCRtpCodecParameters } from 'werift';
2
+ import type { AVCodecID } from '../constants/index.js';
3
+ import type { RTPStreamOptions } from './rtp-stream.js';
4
+ /**
5
+ * Codec information for WebRTC streaming.
6
+ *
7
+ * Contains RTP codec parameters and FFmpeg codec IDs for video and audio streams.
8
+ * Used for codec negotiation in WebRTC peer connections.
9
+ */
10
+ export interface WebRTCCodecInfo {
11
+ /**
12
+ * Video codec configuration.
13
+ * Combines RTP parameters (mimeType, clockRate, etc.) with FFmpeg codec ID.
14
+ */
15
+ video?: Partial<RTCRtpCodecParameters> & {
16
+ codecId: AVCodecID;
17
+ };
18
+ /**
19
+ * Optional audio codec configuration.
20
+ * Combines RTP parameters (mimeType, clockRate, channels) with FFmpeg codec ID.
21
+ */
22
+ audio?: Partial<RTCRtpCodecParameters> & {
23
+ codecId: AVCodecID;
24
+ };
25
+ }
26
+ /**
27
+ * Options for configuring WebRTC session with werift integration.
28
+ */
29
+ export interface WebRTCStreamOptions extends Omit<RTPStreamOptions, 'onVideoPacket' | 'onAudioPacket' | 'supportedVideoCodecs' | 'supportedAudioCodecs'> {
30
+ /**
31
+ * ICE servers for NAT traversal and STUN/TURN configuration.
32
+ *
33
+ * @default []
34
+ */
35
+ iceServers?: {
36
+ urls: string;
37
+ }[];
38
+ /**
39
+ * Callback invoked when a new ICE candidate is discovered.
40
+ * Send this candidate to the remote peer via signaling channel.
41
+ *
42
+ * @param candidate - ICE candidate string to send to remote peer
43
+ */
44
+ onIceCandidate?: (candidate: string) => void;
45
+ }
46
+ /**
47
+ * Complete WebRTC session management with werift integration.
48
+ *
49
+ * Provides end-to-end WebRTC streaming with automatic SDP negotiation,
50
+ * ICE candidate handling, and peer connection management.
51
+ * Built on top of {@link RTPStream} for generic RTP streaming with WebRTC-specific
52
+ * protocol details handled automatically.
53
+ * Integrates with werift library for RTCPeerConnection and media track handling.
54
+ * Ideal for building complete WebRTC streaming applications with minimal code.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { WebRTCStream } from 'node-av/api';
59
+ *
60
+ * // Create session from media source
61
+ * const session = await WebRTCStream.create('rtsp://camera.local/stream', {
62
+ * mtu: 1200,
63
+ * hardware: 'auto',
64
+ * iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
65
+ * onIceCandidate: (candidate) => {
66
+ * sendToClient({ type: 'candidate', value: candidate });
67
+ * }
68
+ * });
69
+ *
70
+ * // Process SDP offer from client
71
+ * const answer = await session.setOffer(clientOffer);
72
+ * sendToClient({ type: 'answer', value: answer });
73
+ *
74
+ * // Start streaming
75
+ * await session.start();
76
+ * ```
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * // Complete WebSocket signaling server
81
+ * import { WebSocket } from 'ws';
82
+ *
83
+ * ws.on('message', async (data) => {
84
+ * const msg = JSON.parse(data);
85
+ *
86
+ * if (msg.type === 'offer') {
87
+ * const session = await WebRTCStream.create(msg.url, {
88
+ * hardware: 'auto',
89
+ * onIceCandidate: (candidate) => {
90
+ * ws.send(JSON.stringify({ type: 'candidate', value: candidate }));
91
+ * }
92
+ * });
93
+ *
94
+ * const answer = await session.setOffer(msg.value);
95
+ * ws.send(JSON.stringify({ type: 'answer', value: answer }));
96
+ *
97
+ * await session.start();
98
+ * } else if (msg.type === 'candidate') {
99
+ * session.addIceCandidate(msg.value);
100
+ * }
101
+ * });
102
+ * ```
103
+ *
104
+ * @see {@link RTPStream} For library-agnostic RTP streaming
105
+ * @see {@link Demuxer} For input media handling
106
+ * @see {@link HardwareContext} For GPU acceleration
107
+ */
108
+ export declare class WebRTCStream {
109
+ private stream;
110
+ private pc;
111
+ private videoTrack;
112
+ private audioTrack;
113
+ private options;
114
+ private pendingIceCandidates;
115
+ /**
116
+ * @param options - Session configuration options
117
+ *
118
+ * Use {@link create} factory method
119
+ *
120
+ * @internal
121
+ */
122
+ private constructor();
123
+ /**
124
+ * Create a WebRTC session from a media source.
125
+ *
126
+ * Opens the input media, creates internal streaming components, and prepares
127
+ * for WebRTC peer connection negotiation. Does not start streaming yet.
128
+ * Call {@link setOffer} to negotiate SDP and {@link start} to begin streaming.
129
+ *
130
+ * @param inputUrl - Media source URL (RTSP, file path, HTTP, etc.)
131
+ *
132
+ * @param options - Session configuration options
133
+ *
134
+ * @returns Configured WebRTC session instance
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const session = await WebRTCStream.create('rtsp://camera.local/stream', {
139
+ * mtu: 1200,
140
+ * hardware: 'auto',
141
+ * iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
142
+ * });
143
+ * ```
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Session from file with hardware acceleration
148
+ * const session = await WebRTCStream.create('video.mp4', {
149
+ * hardware: {
150
+ * deviceType: AV_HWDEVICE_TYPE_CUDA
151
+ * }
152
+ * });
153
+ * ```
154
+ */
155
+ static create(inputUrl: string, options?: WebRTCStreamOptions): WebRTCStream;
156
+ /**
157
+ * Start streaming media to WebRTC peer connection.
158
+ *
159
+ * Begins the media processing pipeline, reading packets from input,
160
+ * transcoding if necessary, and sending RTP packets to media tracks.
161
+ * Note: The stream is automatically started by {@link setOffer}, so calling
162
+ * this method explicitly is optional. This method is provided for cases where
163
+ * you need explicit control over when streaming begins.
164
+ *
165
+ * @returns Promise that resolves when streaming completes
166
+ *
167
+ * @throws {FFmpegError} If transcoding or muxing fails
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const session = await WebRTCStream.create('input.mp4');
172
+ * session.onIceCandidate = (c) => sendToRemote(c);
173
+ *
174
+ * const answer = await session.setOffer(remoteOffer);
175
+ * sendToRemote(answer);
176
+ * // Stream is already started by setOffer
177
+ * ```
178
+ */
179
+ start(): Promise<void>;
180
+ /**
181
+ * Stop streaming gracefully and clean up all resources.
182
+ *
183
+ * Stops the stream, closes peer connection, and releases all resources.
184
+ * Safe to call multiple times. After stopping, you can call start() again
185
+ * to restart the session.
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const session = await WebRTCStream.create('input.mp4');
190
+ * await session.start();
191
+ *
192
+ * // Stop after 10 seconds
193
+ * setTimeout(async () => await session.stop(), 10000);
194
+ * ```
195
+ */
196
+ stop(): Promise<void>;
197
+ /**
198
+ * Get detected codec information.
199
+ *
200
+ * Returns RTP codec parameters and FFmpeg codec IDs for video and audio.
201
+ * Useful for inspecting what codecs will be used in the WebRTC session.
202
+ * The input is automatically opened during {@link create}, so codecs can be
203
+ * detected immediately after session creation.
204
+ *
205
+ * @returns Codec configuration for video and audio streams
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const session = await WebRTCStream.create('input.mp4');
210
+ * const codecs = session.getCodecs();
211
+ *
212
+ * console.log('Video:', codecs.video.mimeType);
213
+ * console.log('Audio:', codecs.audio?.mimeType);
214
+ * ```
215
+ */
216
+ getCodecs(): WebRTCCodecInfo;
217
+ /**
218
+ * Process SDP offer from remote peer and generate SDP answer.
219
+ *
220
+ * Creates RTCPeerConnection with detected codecs, sets up media tracks,
221
+ * processes the remote SDP offer, and generates a local SDP answer.
222
+ * Also configures ICE candidate handling via {@link onIceCandidate} callback.
223
+ * Must be called before {@link start}.
224
+ *
225
+ * @param offerSdp - SDP offer string from remote WebRTC peer
226
+ *
227
+ * @returns SDP answer string to send back to remote peer
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const session = await WebRTCStream.create('input.mp4');
232
+ *
233
+ * // Setup ICE candidate handler first
234
+ * session.onIceCandidate = (candidate) => {
235
+ * sendToRemote({ type: 'candidate', value: candidate });
236
+ * };
237
+ *
238
+ * // Process offer and send answer
239
+ * const answer = await session.setOffer(remoteOffer);
240
+ * sendToRemote({ type: 'answer', value: answer });
241
+ *
242
+ * // Start streaming
243
+ * await session.start();
244
+ * ```
245
+ */
246
+ setOffer(offerSdp: string): Promise<string>;
247
+ /**
248
+ * Add ICE candidate from remote peer.
249
+ *
250
+ * Processes ICE candidates received from the remote peer via signaling channel.
251
+ * Should be called whenever a new candidate message arrives from remote peer.
252
+ * Can be called multiple times as candidates are discovered.
253
+ *
254
+ * Supports ICE trickling: If called before {@link setOffer}, candidates are buffered
255
+ * and applied automatically once the remote description is set.
256
+ *
257
+ * @param candidate - ICE candidate string from remote peer
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * // In signaling message handler
262
+ * if (msg.type === 'candidate') {
263
+ * session.addIceCandidate(msg.value);
264
+ * }
265
+ * ```
266
+ */
267
+ addIceCandidate(candidate: string): void;
268
+ /**
269
+ * Get video codec configuration from input stream.
270
+ *
271
+ * @param codecId - FFmpeg codec ID
272
+ *
273
+ * @returns RTP codec parameters with codec ID or undefined if unsupported
274
+ *
275
+ * @internal
276
+ */
277
+ private getVideoCodecConfig;
278
+ /**
279
+ * Get audio codec configuration from input stream.
280
+ *
281
+ * @param codecId - FFmpeg codec ID
282
+ *
283
+ * @returns RTP codec parameters with codec ID or undefined if unsupported
284
+ *
285
+ * @internal
286
+ */
287
+ private getAudioCodecConfig;
288
+ }