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.
- package/README.md +88 -52
- package/binding.gyp +23 -11
- package/dist/api/audio-frame-buffer.d.ts +201 -0
- package/dist/api/audio-frame-buffer.js +275 -0
- package/dist/api/audio-frame-buffer.js.map +1 -0
- package/dist/api/bitstream-filter.d.ts +320 -78
- package/dist/api/bitstream-filter.js +684 -151
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/constants.d.ts +44 -0
- package/dist/api/constants.js +45 -0
- package/dist/api/constants.js.map +1 -0
- package/dist/api/data/test_av1.ivf +0 -0
- package/dist/api/data/test_mjpeg.mjpeg +0 -0
- package/dist/api/data/test_vp8.ivf +0 -0
- package/dist/api/data/test_vp9.ivf +0 -0
- package/dist/api/decoder.d.ts +454 -77
- package/dist/api/decoder.js +1081 -271
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/{media-input.d.ts → demuxer.d.ts} +295 -45
- package/dist/api/demuxer.js +1965 -0
- package/dist/api/demuxer.js.map +1 -0
- package/dist/api/encoder.d.ts +423 -132
- package/dist/api/encoder.js +1089 -240
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-complex.d.ts +769 -0
- package/dist/api/filter-complex.js +1596 -0
- package/dist/api/filter-complex.js.map +1 -0
- package/dist/api/filter-presets.d.ts +80 -5
- package/dist/api/filter-presets.js +117 -7
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +561 -125
- package/dist/api/filter.js +1083 -274
- package/dist/api/filter.js.map +1 -1
- package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
- package/dist/api/fmp4-stream.js +539 -0
- package/dist/api/fmp4-stream.js.map +1 -0
- package/dist/api/hardware.d.ts +58 -6
- package/dist/api/hardware.js +127 -11
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +8 -4
- package/dist/api/index.js +17 -8
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +6 -6
- package/dist/api/io-stream.js +5 -4
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/{media-output.d.ts → muxer.d.ts} +280 -66
- package/dist/api/muxer.js +1934 -0
- package/dist/api/muxer.js.map +1 -0
- package/dist/api/pipeline.d.ts +77 -29
- package/dist/api/pipeline.js +449 -439
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/rtp-stream.d.ts +312 -0
- package/dist/api/rtp-stream.js +630 -0
- package/dist/api/rtp-stream.js.map +1 -0
- package/dist/api/types.d.ts +533 -56
- package/dist/api/utilities/async-queue.d.ts +91 -0
- package/dist/api/utilities/async-queue.js +162 -0
- package/dist/api/utilities/async-queue.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +11 -1
- package/dist/api/utilities/audio-sample.js +10 -0
- package/dist/api/utilities/audio-sample.js.map +1 -1
- package/dist/api/utilities/channel-layout.d.ts +1 -0
- package/dist/api/utilities/channel-layout.js +1 -0
- package/dist/api/utilities/channel-layout.js.map +1 -1
- package/dist/api/utilities/image.d.ts +39 -1
- package/dist/api/utilities/image.js +38 -0
- package/dist/api/utilities/image.js.map +1 -1
- package/dist/api/utilities/index.d.ts +3 -0
- package/dist/api/utilities/index.js +6 -0
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/utilities/media-type.d.ts +2 -1
- package/dist/api/utilities/media-type.js +1 -0
- package/dist/api/utilities/media-type.js.map +1 -1
- package/dist/api/utilities/pixel-format.d.ts +4 -1
- package/dist/api/utilities/pixel-format.js +3 -0
- package/dist/api/utilities/pixel-format.js.map +1 -1
- package/dist/api/utilities/sample-format.d.ts +6 -1
- package/dist/api/utilities/sample-format.js +5 -0
- package/dist/api/utilities/sample-format.js.map +1 -1
- package/dist/api/utilities/scheduler.d.ts +138 -0
- package/dist/api/utilities/scheduler.js +98 -0
- package/dist/api/utilities/scheduler.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +105 -15
- package/dist/api/utilities/streaming.js +201 -12
- package/dist/api/utilities/streaming.js.map +1 -1
- package/dist/api/utilities/timestamp.d.ts +15 -1
- package/dist/api/utilities/timestamp.js +14 -0
- package/dist/api/utilities/timestamp.js.map +1 -1
- package/dist/api/utilities/whisper-model.d.ts +310 -0
- package/dist/api/utilities/whisper-model.js +528 -0
- package/dist/api/utilities/whisper-model.js.map +1 -0
- package/dist/api/webrtc-stream.d.ts +288 -0
- package/dist/api/webrtc-stream.js +440 -0
- package/dist/api/webrtc-stream.js.map +1 -0
- package/dist/api/whisper.d.ts +324 -0
- package/dist/api/whisper.js +362 -0
- package/dist/api/whisper.js.map +1 -0
- package/dist/constants/constants.d.ts +54 -2
- package/dist/constants/constants.js +48 -1
- package/dist/constants/constants.js.map +1 -1
- package/dist/constants/encoders.d.ts +2 -1
- package/dist/constants/encoders.js +4 -3
- package/dist/constants/encoders.js.map +1 -1
- package/dist/constants/hardware.d.ts +26 -0
- package/dist/constants/hardware.js +27 -0
- package/dist/constants/hardware.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/ffmpeg/index.d.ts +3 -3
- package/dist/ffmpeg/index.js +3 -3
- package/dist/ffmpeg/utils.d.ts +27 -0
- package/dist/ffmpeg/utils.js +28 -16
- package/dist/ffmpeg/utils.js.map +1 -1
- package/dist/lib/binding.d.ts +22 -11
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/codec-context.d.ts +87 -0
- package/dist/lib/codec-context.js +125 -4
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +229 -1
- package/dist/lib/codec-parameters.js +264 -0
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +23 -0
- package/dist/lib/codec-parser.js +25 -0
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +26 -4
- package/dist/lib/codec.js +35 -0
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.js +1 -0
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.js +1 -1
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/fifo.d.ts +416 -0
- package/dist/lib/fifo.js +453 -0
- package/dist/lib/fifo.js.map +1 -0
- package/dist/lib/filter-context.d.ts +52 -11
- package/dist/lib/filter-context.js +56 -12
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +9 -0
- package/dist/lib/filter-graph.js +13 -0
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter.d.ts +21 -0
- package/dist/lib/filter.js +28 -0
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +48 -14
- package/dist/lib/format-context.js +76 -7
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +264 -1
- package/dist/lib/frame.js +351 -1
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +3 -2
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +21 -0
- package/dist/lib/input-format.js +42 -2
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/native-types.d.ts +76 -27
- package/dist/lib/option.d.ts +25 -13
- package/dist/lib/option.js +28 -0
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +22 -1
- package/dist/lib/output-format.js +28 -0
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +35 -0
- package/dist/lib/packet.js +52 -2
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +18 -0
- package/dist/lib/rational.js +19 -0
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/stream.d.ts +126 -0
- package/dist/lib/stream.js +188 -5
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/sync-queue.d.ts +179 -0
- package/dist/lib/sync-queue.js +197 -0
- package/dist/lib/sync-queue.js.map +1 -0
- package/dist/lib/types.d.ts +49 -1
- package/dist/lib/utilities.d.ts +281 -53
- package/dist/lib/utilities.js +298 -55
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +2 -2
- package/package.json +37 -26
- package/dist/api/fmp4.js +0 -710
- package/dist/api/fmp4.js.map +0 -1
- package/dist/api/media-input.js +0 -1075
- package/dist/api/media-input.js.map +0 -1
- package/dist/api/media-output.js +0 -1040
- package/dist/api/media-output.js.map +0 -1
- package/dist/api/webrtc.d.ts +0 -664
- package/dist/api/webrtc.js +0 -1132
- package/dist/api/webrtc.js.map +0 -1
package/dist/lib/stream.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CodecParameters } from './codec-parameters.js';
|
|
2
|
+
import { CodecParser } from './codec-parser.js';
|
|
2
3
|
import { Dictionary } from './dictionary.js';
|
|
3
4
|
import { Rational } from './rational.js';
|
|
4
5
|
/**
|
|
@@ -44,7 +45,9 @@ import { Rational } from './rational.js';
|
|
|
44
45
|
*/
|
|
45
46
|
export class Stream {
|
|
46
47
|
native;
|
|
48
|
+
_metadata; // Cache for metadata wrapper
|
|
47
49
|
_codecpar; // Cache the wrapped codecpar
|
|
50
|
+
_parser; // Cache the wrapped parser
|
|
48
51
|
/**
|
|
49
52
|
* @param native - The native stream instance
|
|
50
53
|
*
|
|
@@ -242,6 +245,20 @@ export class Stream {
|
|
|
242
245
|
set rFrameRate(value) {
|
|
243
246
|
this.native.rFrameRate = { num: value.num, den: value.den };
|
|
244
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Number of bits for PTS wrap-around detection.
|
|
250
|
+
*
|
|
251
|
+
* Used for timestamp wrap-around correction in formats with limited timestamp bits.
|
|
252
|
+
* Common values: 33 (MPEG-TS), 31 (DVB), 64 (no wrapping).
|
|
253
|
+
*
|
|
254
|
+
* Direct mapping to AVStream->pts_wrap_bits.
|
|
255
|
+
*/
|
|
256
|
+
get ptsWrapBits() {
|
|
257
|
+
return this.native.ptsWrapBits;
|
|
258
|
+
}
|
|
259
|
+
set ptsWrapBits(value) {
|
|
260
|
+
this.native.ptsWrapBits = value;
|
|
261
|
+
}
|
|
245
262
|
/**
|
|
246
263
|
* Stream metadata.
|
|
247
264
|
*
|
|
@@ -251,14 +268,25 @@ export class Stream {
|
|
|
251
268
|
* Direct mapping to AVStream->metadata.
|
|
252
269
|
*/
|
|
253
270
|
get metadata() {
|
|
254
|
-
const
|
|
255
|
-
if (!
|
|
271
|
+
const native = this.native.metadata;
|
|
272
|
+
if (!native) {
|
|
273
|
+
// Clear cache if native is null
|
|
274
|
+
this._metadata = undefined;
|
|
256
275
|
return null;
|
|
257
276
|
}
|
|
258
|
-
|
|
277
|
+
// Return cached wrapper if available and still valid
|
|
278
|
+
if (this._metadata && this._metadata.native === native) {
|
|
279
|
+
return this._metadata;
|
|
280
|
+
}
|
|
281
|
+
// Create and cache new wrapper
|
|
282
|
+
const device = Object.create(Dictionary.prototype);
|
|
283
|
+
device.native = native;
|
|
284
|
+
this._metadata = device;
|
|
285
|
+
return device;
|
|
259
286
|
}
|
|
260
287
|
set metadata(value) {
|
|
261
288
|
this.native.metadata = value?.getNative() ?? null;
|
|
289
|
+
this._metadata = undefined;
|
|
262
290
|
}
|
|
263
291
|
/**
|
|
264
292
|
* Attached picture.
|
|
@@ -285,6 +313,45 @@ export class Stream {
|
|
|
285
313
|
set eventFlags(value) {
|
|
286
314
|
this.native.eventFlags = value;
|
|
287
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Get the codec parser attached to this stream.
|
|
318
|
+
*
|
|
319
|
+
* Returns the parser context if the stream has an active parser, null otherwise.
|
|
320
|
+
* Parsers are automatically created by FFmpeg for certain formats and codecs.
|
|
321
|
+
* Useful for accessing parser state like repeat_pict for interlaced video.
|
|
322
|
+
*
|
|
323
|
+
* Direct mapping to av_stream_get_parser().
|
|
324
|
+
*
|
|
325
|
+
* @returns Parser context or null if no parser attached
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const parser = stream.parser;
|
|
330
|
+
* if (parser) {
|
|
331
|
+
* const fields = 1 + parser.repeatPict;
|
|
332
|
+
* console.log(`Frame uses ${fields} fields`);
|
|
333
|
+
* }
|
|
334
|
+
* ```
|
|
335
|
+
*
|
|
336
|
+
* @see {@link CodecParser} For parser details
|
|
337
|
+
*/
|
|
338
|
+
get parser() {
|
|
339
|
+
const native = this.native.parser;
|
|
340
|
+
if (!native) {
|
|
341
|
+
// Clear cache if native is null
|
|
342
|
+
this._parser = undefined;
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
// Return cached wrapper if available and still valid
|
|
346
|
+
if (this._parser && this._parser.native === native) {
|
|
347
|
+
return this._parser;
|
|
348
|
+
}
|
|
349
|
+
// Create and cache new wrapper
|
|
350
|
+
const parser = Object.create(CodecParser.prototype);
|
|
351
|
+
parser.native = native;
|
|
352
|
+
this._parser = parser;
|
|
353
|
+
return parser;
|
|
354
|
+
}
|
|
288
355
|
/**
|
|
289
356
|
* Set stream event flags.
|
|
290
357
|
*
|
|
@@ -302,10 +369,13 @@ export class Stream {
|
|
|
302
369
|
* ```
|
|
303
370
|
*
|
|
304
371
|
* @see {@link clearEventFlags} To unset event flags
|
|
372
|
+
* @see {@link hasEventFlags} To check event flags
|
|
305
373
|
* @see {@link eventFlags} For direct event flag access
|
|
306
374
|
*/
|
|
307
375
|
setEventFlags(...flags) {
|
|
308
|
-
|
|
376
|
+
for (const flag of flags) {
|
|
377
|
+
this.native.eventFlags = (this.native.eventFlags | flag);
|
|
378
|
+
}
|
|
309
379
|
}
|
|
310
380
|
/**
|
|
311
381
|
* Clear stream event flags.
|
|
@@ -324,10 +394,123 @@ export class Stream {
|
|
|
324
394
|
* ```
|
|
325
395
|
*
|
|
326
396
|
* @see {@link setEventFlags} To set event flags
|
|
397
|
+
* @see {@link hasEventFlags} To check event flags
|
|
327
398
|
* @see {@link eventFlags} For direct event flag access
|
|
328
399
|
*/
|
|
329
400
|
clearEventFlags(...flags) {
|
|
330
|
-
|
|
401
|
+
for (const flag of flags) {
|
|
402
|
+
this.native.eventFlags = (this.native.eventFlags & ~flag);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Check if stream has specific event flags.
|
|
407
|
+
*
|
|
408
|
+
* Tests whether all specified event flags are set using bitwise AND.
|
|
409
|
+
*
|
|
410
|
+
* @param flags - One or more event flag values to check
|
|
411
|
+
*
|
|
412
|
+
* @returns true if all specified event flags are set, false otherwise
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* import { AVSTREAM_EVENT_FLAG_METADATA_UPDATED } from 'node-av/constants';
|
|
417
|
+
*
|
|
418
|
+
* if (stream.hasEventFlags(AVSTREAM_EVENT_FLAG_METADATA_UPDATED)) {
|
|
419
|
+
* console.log('Stream metadata was updated');
|
|
420
|
+
* }
|
|
421
|
+
* ```
|
|
422
|
+
*
|
|
423
|
+
* @see {@link setEventFlags} To set event flags
|
|
424
|
+
* @see {@link clearEventFlags} To unset event flags
|
|
425
|
+
* @see {@link eventFlags} For direct event flag access
|
|
426
|
+
*/
|
|
427
|
+
hasEventFlags(...flags) {
|
|
428
|
+
for (const flag of flags) {
|
|
429
|
+
if ((this.native.eventFlags & flag) !== flag) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Set stream disposition flags.
|
|
437
|
+
*
|
|
438
|
+
* Sets one or more disposition flags using bitwise OR. Allows setting multiple flags
|
|
439
|
+
* without manually performing bitwise operations.
|
|
440
|
+
*
|
|
441
|
+
* @param flags - One or more disposition flag values to set
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* import { AV_DISPOSITION_DEFAULT, AV_DISPOSITION_FORCED } from 'node-av/constants';
|
|
446
|
+
*
|
|
447
|
+
* // Set multiple disposition flags at once
|
|
448
|
+
* stream.setDisposition(AV_DISPOSITION_DEFAULT, AV_DISPOSITION_FORCED);
|
|
449
|
+
* ```
|
|
450
|
+
*
|
|
451
|
+
* @see {@link clearDisposition} To unset disposition flags
|
|
452
|
+
* @see {@link hasDisposition} To check disposition flags
|
|
453
|
+
* @see {@link disposition} For direct disposition flag access
|
|
454
|
+
*/
|
|
455
|
+
setDisposition(...flags) {
|
|
456
|
+
for (const flag of flags) {
|
|
457
|
+
this.native.disposition = (this.native.disposition | flag);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Clear stream disposition flags.
|
|
462
|
+
*
|
|
463
|
+
* Clears one or more disposition flags using bitwise AND NOT. Allows clearing multiple
|
|
464
|
+
* flags without manually performing bitwise operations.
|
|
465
|
+
*
|
|
466
|
+
* @param flags - One or more disposition flag values to clear
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* import { AV_DISPOSITION_FORCED } from 'node-av/constants';
|
|
471
|
+
*
|
|
472
|
+
* // Clear specific disposition flag
|
|
473
|
+
* stream.clearDisposition(AV_DISPOSITION_FORCED);
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @see {@link setDisposition} To set disposition flags
|
|
477
|
+
* @see {@link hasDisposition} To check disposition flags
|
|
478
|
+
* @see {@link disposition} For direct disposition flag access
|
|
479
|
+
*/
|
|
480
|
+
clearDisposition(...flags) {
|
|
481
|
+
for (const flag of flags) {
|
|
482
|
+
this.native.disposition = (this.native.disposition & ~flag);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Check if stream has specific disposition flags.
|
|
487
|
+
*
|
|
488
|
+
* Tests whether all specified disposition flags are set using bitwise AND.
|
|
489
|
+
*
|
|
490
|
+
* @param flags - One or more disposition flag values to check
|
|
491
|
+
*
|
|
492
|
+
* @returns true if all specified disposition flags are set, false otherwise
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* import { AV_DISPOSITION_DEFAULT } from 'node-av/constants';
|
|
497
|
+
*
|
|
498
|
+
* if (stream.hasDisposition(AV_DISPOSITION_DEFAULT)) {
|
|
499
|
+
* console.log('Stream is marked as default');
|
|
500
|
+
* }
|
|
501
|
+
* ```
|
|
502
|
+
*
|
|
503
|
+
* @see {@link setDisposition} To set disposition flags
|
|
504
|
+
* @see {@link clearDisposition} To unset disposition flags
|
|
505
|
+
* @see {@link disposition} For direct disposition flag access
|
|
506
|
+
*/
|
|
507
|
+
hasDisposition(...flags) {
|
|
508
|
+
for (const flag of flags) {
|
|
509
|
+
if ((this.native.disposition & flag) !== flag) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return true;
|
|
331
514
|
}
|
|
332
515
|
/**
|
|
333
516
|
* Get the underlying native Stream object.
|
package/dist/lib/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/lib/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAMzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,OAAO,MAAM;IACT,MAAM,CAAe;IACrB,SAAS,CAAmB,CAAC,6BAA6B;
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/lib/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA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AC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { NativeSyncQueue, NativeWrapper } from './native-types.js';
|
|
2
|
+
import type { Packet } from './packet.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sync Queue Type
|
|
5
|
+
*
|
|
6
|
+
* Determines the sync queue behavior for different media types.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum SyncQueueType {
|
|
9
|
+
/**
|
|
10
|
+
* Buffer packets based on their duration in time base units.
|
|
11
|
+
* Used for audio and video streams.
|
|
12
|
+
*/
|
|
13
|
+
PACKETS = 0,
|
|
14
|
+
/**
|
|
15
|
+
* Buffer frames based on their sample count.
|
|
16
|
+
* Used for audio frames where synchronization is sample-based.
|
|
17
|
+
*/
|
|
18
|
+
FRAMES = 1
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sync Queue for packet synchronization
|
|
22
|
+
*
|
|
23
|
+
* FFmpeg's native sync_queue from fftools that synchronizes packets from multiple
|
|
24
|
+
* streams before muxing. Prevents streams from getting ahead of each other and
|
|
25
|
+
* ensures proper interleaving for containers with strict timing requirements.
|
|
26
|
+
*
|
|
27
|
+
* This is the same synchronization mechanism used by FFmpeg CLI (fftools).
|
|
28
|
+
*
|
|
29
|
+
* Direct mapping to FFmpeg's SyncQueue from fftools/sync_queue.h.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { SyncQueue, SyncQueueType } from 'node-av';
|
|
34
|
+
*
|
|
35
|
+
* // Create sync queue with 1 second buffer
|
|
36
|
+
* const sq = SyncQueue.create(SyncQueueType.PACKETS, 1000000);
|
|
37
|
+
*
|
|
38
|
+
* // Add streams
|
|
39
|
+
* const videoIdx = sq.addStream(1); // 1 = limiting stream
|
|
40
|
+
* const audioIdx = sq.addStream(1);
|
|
41
|
+
*
|
|
42
|
+
* // Send packets to queue
|
|
43
|
+
* sq.send(videoIdx, videoPacket);
|
|
44
|
+
* sq.send(audioIdx, audioPacket);
|
|
45
|
+
*
|
|
46
|
+
* // Receive synchronized packets
|
|
47
|
+
* const result = sq.receive(-1); // -1 = any stream
|
|
48
|
+
* if (result.error === 0) {
|
|
49
|
+
* console.log(`Stream ${result.streamIdx}: ${result.packet}`);
|
|
50
|
+
* // Write packet to muxer...
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* // Cleanup
|
|
54
|
+
* sq.free();
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see [sync_queue.h](https://github.com/FFmpeg/FFmpeg/blob/master/fftools/sync_queue.h) - FFmpeg source
|
|
58
|
+
*/
|
|
59
|
+
export declare class SyncQueue implements Disposable, NativeWrapper<NativeSyncQueue> {
|
|
60
|
+
/** @internal */
|
|
61
|
+
native: NativeSyncQueue;
|
|
62
|
+
private constructor();
|
|
63
|
+
/**
|
|
64
|
+
* Create a new sync queue.
|
|
65
|
+
*
|
|
66
|
+
* @param type - Queue type (PACKETS or FRAMES)
|
|
67
|
+
*
|
|
68
|
+
* @param bufferSizeUs - Buffer size in microseconds (default: 100ms)
|
|
69
|
+
*
|
|
70
|
+
* @returns New SyncQueue instance
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // 500ms buffer for RTSP streams
|
|
75
|
+
* const sq = SyncQueue.create(SyncQueueType.PACKETS, 500000);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
static create(type?: SyncQueueType, bufferSizeUs?: number): SyncQueue;
|
|
79
|
+
/**
|
|
80
|
+
* Add a stream to the sync queue.
|
|
81
|
+
*
|
|
82
|
+
* @param limiting - Whether this stream should limit other streams (1 = yes, 0 = no).
|
|
83
|
+
* Limiting streams control the head position - other streams cannot get ahead.
|
|
84
|
+
*
|
|
85
|
+
* @returns Stream index in the sync queue
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const videoIdx = sq.addStream(1); // Video limits timing
|
|
90
|
+
* const audioIdx = sq.addStream(1); // Audio limits timing
|
|
91
|
+
* const subtitleIdx = sq.addStream(0); // Subtitles don't limit
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
addStream(limiting?: number): number;
|
|
95
|
+
/**
|
|
96
|
+
* Send a packet to the sync queue.
|
|
97
|
+
*
|
|
98
|
+
* The packet is cloned internally, so the original can be reused/freed.
|
|
99
|
+
*
|
|
100
|
+
* To signal EOF for a stream, pass null as the packet.
|
|
101
|
+
* This tells the sync queue that no more packets will be sent for this stream.
|
|
102
|
+
*
|
|
103
|
+
* @param streamIdx - Stream index returned from addStream()
|
|
104
|
+
*
|
|
105
|
+
* @param packet - Packet to send, or null to signal EOF
|
|
106
|
+
*
|
|
107
|
+
* @returns 0 on success, AVERROR_EOF if EOF, negative on error
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // Send normal packet
|
|
112
|
+
* const ret = sq.send(videoIdx, packet);
|
|
113
|
+
* if (ret === AVERROR_EOF) {
|
|
114
|
+
* console.log('Stream finished');
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* // Signal EOF for stream
|
|
118
|
+
* sq.send(videoIdx, null);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
send(streamIdx: number, packet: Packet | null): number;
|
|
122
|
+
/**
|
|
123
|
+
* Receive a packet from the sync queue.
|
|
124
|
+
*
|
|
125
|
+
* This will receive the next packet that should be written to maintain
|
|
126
|
+
* proper synchronization between streams. The packet parameter is filled
|
|
127
|
+
* with the received data.
|
|
128
|
+
*
|
|
129
|
+
* @param streamIdx - Stream index to receive from, or -1 for any stream
|
|
130
|
+
*
|
|
131
|
+
* @param packet - Packet to fill with received data (output parameter)
|
|
132
|
+
*
|
|
133
|
+
* @returns Stream index (>= 0) on success, or negative error code:
|
|
134
|
+
* - >= 0: Stream index that the packet belongs to
|
|
135
|
+
* - AVERROR(EAGAIN): No packets ready yet, more frames needed
|
|
136
|
+
* - AVERROR_EOF: All streams finished
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import { AVERROR } from 'node-av';
|
|
141
|
+
*
|
|
142
|
+
* // Receive from any stream (FFmpeg mux pattern)
|
|
143
|
+
* const packet = new Packet();
|
|
144
|
+
* while (true) {
|
|
145
|
+
* const ret = sq.receive(-1, packet);
|
|
146
|
+
* if (ret === AVERROR('EAGAIN')) {
|
|
147
|
+
* break; // No packets ready
|
|
148
|
+
* }
|
|
149
|
+
* if (ret === AVERROR_EOF) {
|
|
150
|
+
* break; // All streams finished
|
|
151
|
+
* }
|
|
152
|
+
* if (ret >= 0) {
|
|
153
|
+
* // ret is the stream index
|
|
154
|
+
* await muxer.interleavedWriteFrame(packet);
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
receive(streamIdx: number, packet: Packet): number;
|
|
160
|
+
/**
|
|
161
|
+
* Free the sync queue and all buffered packets.
|
|
162
|
+
* After calling this, the queue cannot be used anymore.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* sq.free();
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
free(): void;
|
|
170
|
+
/**
|
|
171
|
+
* Get the underlying native SyncQueue object.
|
|
172
|
+
*
|
|
173
|
+
* @returns The native SyncQueue binding object
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
getNative(): NativeSyncQueue;
|
|
178
|
+
[Symbol.dispose](): void;
|
|
179
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { bindings } from './binding.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sync Queue Type
|
|
4
|
+
*
|
|
5
|
+
* Determines the sync queue behavior for different media types.
|
|
6
|
+
*/
|
|
7
|
+
export var SyncQueueType;
|
|
8
|
+
(function (SyncQueueType) {
|
|
9
|
+
/**
|
|
10
|
+
* Buffer packets based on their duration in time base units.
|
|
11
|
+
* Used for audio and video streams.
|
|
12
|
+
*/
|
|
13
|
+
SyncQueueType[SyncQueueType["PACKETS"] = 0] = "PACKETS";
|
|
14
|
+
/**
|
|
15
|
+
* Buffer frames based on their sample count.
|
|
16
|
+
* Used for audio frames where synchronization is sample-based.
|
|
17
|
+
*/
|
|
18
|
+
SyncQueueType[SyncQueueType["FRAMES"] = 1] = "FRAMES";
|
|
19
|
+
})(SyncQueueType || (SyncQueueType = {}));
|
|
20
|
+
/**
|
|
21
|
+
* Sync Queue for packet synchronization
|
|
22
|
+
*
|
|
23
|
+
* FFmpeg's native sync_queue from fftools that synchronizes packets from multiple
|
|
24
|
+
* streams before muxing. Prevents streams from getting ahead of each other and
|
|
25
|
+
* ensures proper interleaving for containers with strict timing requirements.
|
|
26
|
+
*
|
|
27
|
+
* This is the same synchronization mechanism used by FFmpeg CLI (fftools).
|
|
28
|
+
*
|
|
29
|
+
* Direct mapping to FFmpeg's SyncQueue from fftools/sync_queue.h.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { SyncQueue, SyncQueueType } from 'node-av';
|
|
34
|
+
*
|
|
35
|
+
* // Create sync queue with 1 second buffer
|
|
36
|
+
* const sq = SyncQueue.create(SyncQueueType.PACKETS, 1000000);
|
|
37
|
+
*
|
|
38
|
+
* // Add streams
|
|
39
|
+
* const videoIdx = sq.addStream(1); // 1 = limiting stream
|
|
40
|
+
* const audioIdx = sq.addStream(1);
|
|
41
|
+
*
|
|
42
|
+
* // Send packets to queue
|
|
43
|
+
* sq.send(videoIdx, videoPacket);
|
|
44
|
+
* sq.send(audioIdx, audioPacket);
|
|
45
|
+
*
|
|
46
|
+
* // Receive synchronized packets
|
|
47
|
+
* const result = sq.receive(-1); // -1 = any stream
|
|
48
|
+
* if (result.error === 0) {
|
|
49
|
+
* console.log(`Stream ${result.streamIdx}: ${result.packet}`);
|
|
50
|
+
* // Write packet to muxer...
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* // Cleanup
|
|
54
|
+
* sq.free();
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see [sync_queue.h](https://github.com/FFmpeg/FFmpeg/blob/master/fftools/sync_queue.h) - FFmpeg source
|
|
58
|
+
*/
|
|
59
|
+
export class SyncQueue {
|
|
60
|
+
/** @internal */
|
|
61
|
+
native;
|
|
62
|
+
constructor(native) {
|
|
63
|
+
this.native = native;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a new sync queue.
|
|
67
|
+
*
|
|
68
|
+
* @param type - Queue type (PACKETS or FRAMES)
|
|
69
|
+
*
|
|
70
|
+
* @param bufferSizeUs - Buffer size in microseconds (default: 100ms)
|
|
71
|
+
*
|
|
72
|
+
* @returns New SyncQueue instance
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // 500ms buffer for RTSP streams
|
|
77
|
+
* const sq = SyncQueue.create(SyncQueueType.PACKETS, 500000);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
static create(type = SyncQueueType.PACKETS, bufferSizeUs = 100000) {
|
|
81
|
+
const native = bindings.SyncQueue.create(type, bufferSizeUs);
|
|
82
|
+
return new SyncQueue(native);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Add a stream to the sync queue.
|
|
86
|
+
*
|
|
87
|
+
* @param limiting - Whether this stream should limit other streams (1 = yes, 0 = no).
|
|
88
|
+
* Limiting streams control the head position - other streams cannot get ahead.
|
|
89
|
+
*
|
|
90
|
+
* @returns Stream index in the sync queue
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const videoIdx = sq.addStream(1); // Video limits timing
|
|
95
|
+
* const audioIdx = sq.addStream(1); // Audio limits timing
|
|
96
|
+
* const subtitleIdx = sq.addStream(0); // Subtitles don't limit
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
addStream(limiting = 1) {
|
|
100
|
+
return this.native.addStream(limiting);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Send a packet to the sync queue.
|
|
104
|
+
*
|
|
105
|
+
* The packet is cloned internally, so the original can be reused/freed.
|
|
106
|
+
*
|
|
107
|
+
* To signal EOF for a stream, pass null as the packet.
|
|
108
|
+
* This tells the sync queue that no more packets will be sent for this stream.
|
|
109
|
+
*
|
|
110
|
+
* @param streamIdx - Stream index returned from addStream()
|
|
111
|
+
*
|
|
112
|
+
* @param packet - Packet to send, or null to signal EOF
|
|
113
|
+
*
|
|
114
|
+
* @returns 0 on success, AVERROR_EOF if EOF, negative on error
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* // Send normal packet
|
|
119
|
+
* const ret = sq.send(videoIdx, packet);
|
|
120
|
+
* if (ret === AVERROR_EOF) {
|
|
121
|
+
* console.log('Stream finished');
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* // Signal EOF for stream
|
|
125
|
+
* sq.send(videoIdx, null);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
send(streamIdx, packet) {
|
|
129
|
+
return this.native.send(streamIdx, packet?.getNative() ?? null);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Receive a packet from the sync queue.
|
|
133
|
+
*
|
|
134
|
+
* This will receive the next packet that should be written to maintain
|
|
135
|
+
* proper synchronization between streams. The packet parameter is filled
|
|
136
|
+
* with the received data.
|
|
137
|
+
*
|
|
138
|
+
* @param streamIdx - Stream index to receive from, or -1 for any stream
|
|
139
|
+
*
|
|
140
|
+
* @param packet - Packet to fill with received data (output parameter)
|
|
141
|
+
*
|
|
142
|
+
* @returns Stream index (>= 0) on success, or negative error code:
|
|
143
|
+
* - >= 0: Stream index that the packet belongs to
|
|
144
|
+
* - AVERROR(EAGAIN): No packets ready yet, more frames needed
|
|
145
|
+
* - AVERROR_EOF: All streams finished
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* import { AVERROR } from 'node-av';
|
|
150
|
+
*
|
|
151
|
+
* // Receive from any stream (FFmpeg mux pattern)
|
|
152
|
+
* const packet = new Packet();
|
|
153
|
+
* while (true) {
|
|
154
|
+
* const ret = sq.receive(-1, packet);
|
|
155
|
+
* if (ret === AVERROR('EAGAIN')) {
|
|
156
|
+
* break; // No packets ready
|
|
157
|
+
* }
|
|
158
|
+
* if (ret === AVERROR_EOF) {
|
|
159
|
+
* break; // All streams finished
|
|
160
|
+
* }
|
|
161
|
+
* if (ret >= 0) {
|
|
162
|
+
* // ret is the stream index
|
|
163
|
+
* await muxer.interleavedWriteFrame(packet);
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
receive(streamIdx, packet) {
|
|
169
|
+
return this.native.receive(streamIdx, packet.getNative());
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Free the sync queue and all buffered packets.
|
|
173
|
+
* After calling this, the queue cannot be used anymore.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* sq.free();
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
free() {
|
|
181
|
+
this.native.free();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the underlying native SyncQueue object.
|
|
185
|
+
*
|
|
186
|
+
* @returns The native SyncQueue binding object
|
|
187
|
+
*
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
getNative() {
|
|
191
|
+
return this.native;
|
|
192
|
+
}
|
|
193
|
+
[Symbol.dispose]() {
|
|
194
|
+
this.free();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=sync-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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