node-av-light 0.0.0-stage → 7.1.0-beta.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.
- package/LICENSE.md +22 -0
- package/README.md +710 -2
- package/dist/api/audio-frame-buffer.d.ts +636 -0
- package/dist/api/audio-frame-buffer.js +1027 -0
- package/dist/api/audio-frame-buffer.js.map +1 -0
- package/dist/api/bitstream-filter.d.ts +938 -0
- package/dist/api/bitstream-filter.js +1427 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- 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_h264.h264 +0 -0
- package/dist/api/data/test_hevc.h265 +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 +1413 -0
- package/dist/api/decoder.js +2367 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/demuxer.d.ts +1295 -0
- package/dist/api/demuxer.js +2344 -0
- package/dist/api/demuxer.js.map +1 -0
- package/dist/api/device.d.ts +589 -0
- package/dist/api/device.js +964 -0
- package/dist/api/device.js.map +1 -0
- package/dist/api/encoder-pool.d.ts +262 -0
- package/dist/api/encoder-pool.js +397 -0
- package/dist/api/encoder-pool.js.map +1 -0
- package/dist/api/encoder.d.ts +1509 -0
- package/dist/api/encoder.js +2619 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter-complex.d.ts +828 -0
- package/dist/api/filter-complex.js +1661 -0
- package/dist/api/filter-complex.js.map +1 -0
- package/dist/api/filter-presets.d.ts +800 -0
- package/dist/api/filter-presets.js +1554 -0
- package/dist/api/filter-presets.js.map +1 -0
- package/dist/api/filter.d.ts +1339 -0
- package/dist/api/filter.js +2075 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/fmp4-stream.d.ts +797 -0
- package/dist/api/fmp4-stream.js +1428 -0
- package/dist/api/fmp4-stream.js.map +1 -0
- package/dist/api/hardware.d.ts +677 -0
- package/dist/api/hardware.js +1300 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +21 -0
- package/dist/api/index.js +38 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +308 -0
- package/dist/api/io-stream.js +358 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/muxer.d.ts +1311 -0
- package/dist/api/muxer.js +2672 -0
- package/dist/api/muxer.js.map +1 -0
- package/dist/api/pipeline.d.ts +801 -0
- package/dist/api/pipeline.js +1344 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/probe.d.ts +128 -0
- package/dist/api/probe.js +227 -0
- package/dist/api/probe.js.map +1 -0
- package/dist/api/rtp-stream.d.ts +497 -0
- package/dist/api/rtp-stream.js +1131 -0
- package/dist/api/rtp-stream.js.map +1 -0
- package/dist/api/scaler.d.ts +561 -0
- package/dist/api/scaler.js +918 -0
- package/dist/api/scaler.js.map +1 -0
- package/dist/api/types.d.ts +17 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/async-queue.d.ts +149 -0
- package/dist/api/utilities/async-queue.js +254 -0
- package/dist/api/utilities/async-queue.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +117 -0
- package/dist/api/utilities/audio-sample.js +112 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/audio-transcode.d.ts +20 -0
- package/dist/api/utilities/audio-transcode.js +27 -0
- package/dist/api/utilities/audio-transcode.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +76 -0
- package/dist/api/utilities/channel-layout.js +80 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/codec-format.d.ts +87 -0
- package/dist/api/utilities/codec-format.js +117 -0
- package/dist/api/utilities/codec-format.js.map +1 -0
- package/dist/api/utilities/context-options.d.ts +25 -0
- package/dist/api/utilities/context-options.js +23 -0
- package/dist/api/utilities/context-options.js.map +1 -0
- package/dist/api/utilities/electron-shared-texture.d.ts +368 -0
- package/dist/api/utilities/electron-shared-texture.js +540 -0
- package/dist/api/utilities/electron-shared-texture.js.map +1 -0
- package/dist/api/utilities/image.d.ts +207 -0
- package/dist/api/utilities/image.js +213 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +14 -0
- package/dist/api/utilities/index.js +27 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/live-decoding.d.ts +15 -0
- package/dist/api/utilities/live-decoding.js +32 -0
- package/dist/api/utilities/live-decoding.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +49 -0
- package/dist/api/utilities/media-type.js +53 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
- package/dist/api/utilities/packet-age-watchdog.js +594 -0
- package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +89 -0
- package/dist/api/utilities/pixel-format.js +97 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +129 -0
- package/dist/api/utilities/sample-format.js +141 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/scale-size.d.ts +51 -0
- package/dist/api/utilities/scale-size.js +55 -0
- package/dist/api/utilities/scale-size.js.map +1 -0
- 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 +186 -0
- package/dist/api/utilities/streaming.js +309 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +193 -0
- package/dist/api/utilities/timestamp.js +206 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utilities/video-transcode.d.ts +218 -0
- package/dist/api/utilities/video-transcode.js +624 -0
- package/dist/api/utilities/video-transcode.js.map +1 -0
- package/dist/api/utilities/whisper-model.d.ts +330 -0
- package/dist/api/utilities/whisper-model.js +587 -0
- package/dist/api/utilities/whisper-model.js.map +1 -0
- package/dist/api/utils.d.ts +19 -0
- package/dist/api/utils.js +39 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/api/webrtc-stream.d.ts +294 -0
- package/dist/api/webrtc-stream.js +546 -0
- package/dist/api/webrtc-stream.js.map +1 -0
- package/dist/api/whisper.d.ts +326 -0
- package/dist/api/whisper.js +402 -0
- package/dist/api/whisper.js.map +1 -0
- package/dist/constants/bsf-options.d.ts +364 -0
- package/dist/constants/bsf-options.js +7 -0
- package/dist/constants/bsf-options.js.map +1 -0
- package/dist/constants/channel-layouts.d.ts +53 -0
- package/dist/constants/channel-layouts.js +57 -0
- package/dist/constants/channel-layouts.js.map +1 -0
- package/dist/constants/constants.d.ts +2435 -0
- package/dist/constants/constants.js +1989 -0
- package/dist/constants/constants.js.map +1 -0
- package/dist/constants/decoders.d.ts +651 -0
- package/dist/constants/decoders.js +641 -0
- package/dist/constants/decoders.js.map +1 -0
- package/dist/constants/encoders.d.ts +314 -0
- package/dist/constants/encoders.js +309 -0
- package/dist/constants/encoders.js.map +1 -0
- package/dist/constants/filter-options.d.ts +12099 -0
- package/dist/constants/filter-options.js +7 -0
- package/dist/constants/filter-options.js.map +1 -0
- package/dist/constants/format-options.d.ts +4319 -0
- package/dist/constants/format-options.js +7 -0
- package/dist/constants/format-options.js.map +1 -0
- package/dist/constants/formats.d.ts +18 -0
- package/dist/constants/formats.js +7 -0
- package/dist/constants/formats.js.map +1 -0
- 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 +10 -0
- package/dist/constants/index.js +6 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/options.d.ts +6217 -0
- package/dist/constants/options.js +7 -0
- package/dist/constants/options.js.map +1 -0
- package/dist/ffmpeg/index.d.ts +101 -0
- package/dist/ffmpeg/index.js +161 -0
- package/dist/ffmpeg/index.js.map +1 -0
- package/dist/ffmpeg/version.d.ts +6 -0
- package/dist/ffmpeg/version.js +7 -0
- package/dist/ffmpeg/version.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +399 -0
- package/dist/lib/audio-fifo.js +431 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +242 -0
- package/dist/lib/binding.js +102 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +381 -0
- package/dist/lib/bitstream-filter-context.js +443 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +140 -0
- package/dist/lib/bitstream-filter.js +154 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/codec-context.d.ts +1069 -0
- package/dist/lib/codec-context.js +1336 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +664 -0
- package/dist/lib/codec-parameters.js +813 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +201 -0
- package/dist/lib/codec-parser.js +213 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +617 -0
- package/dist/lib/codec.js +746 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/device.d.ts +294 -0
- package/dist/lib/device.js +326 -0
- package/dist/lib/device.js.map +1 -0
- package/dist/lib/dictionary.d.ts +333 -0
- package/dist/lib/dictionary.js +372 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +311 -0
- package/dist/lib/error.js +395 -0
- package/dist/lib/error.js.map +1 -0
- 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 +714 -0
- package/dist/lib/filter-context.js +783 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph-segment.d.ts +161 -0
- package/dist/lib/filter-graph-segment.js +172 -0
- package/dist/lib/filter-graph-segment.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +641 -0
- package/dist/lib/filter-graph.js +704 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +202 -0
- package/dist/lib/filter-inout.js +261 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +243 -0
- package/dist/lib/filter.js +272 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +1335 -0
- package/dist/lib/format-context.js +1455 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame-utils.d.ts +116 -0
- package/dist/lib/frame-utils.js +98 -0
- package/dist/lib/frame-utils.js.map +1 -0
- package/dist/lib/frame.d.ts +1315 -0
- package/dist/lib/frame.js +1535 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +362 -0
- package/dist/lib/hardware-device-context.js +383 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +418 -0
- package/dist/lib/hardware-frames-context.js +471 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +35 -0
- package/dist/lib/index.js +60 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +249 -0
- package/dist/lib/input-format.js +306 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +698 -0
- package/dist/lib/io-context.js +771 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +174 -0
- package/dist/lib/log.js +184 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +1024 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +953 -0
- package/dist/lib/option.js +1607 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +222 -0
- package/dist/lib/output-format.js +259 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +521 -0
- package/dist/lib/packet.js +613 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +251 -0
- package/dist/lib/rational.js +278 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +552 -0
- package/dist/lib/software-resample-context.js +592 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +344 -0
- package/dist/lib/software-scale-context.js +366 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +383 -0
- package/dist/lib/stream.js +524 -0
- package/dist/lib/stream.js.map +1 -0
- 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 +34 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +1198 -0
- package/dist/lib/utilities.js +1302 -0
- package/dist/lib/utilities.js.map +1 -0
- package/dist/utils/electron.d.ts +49 -0
- package/dist/utils/electron.js +63 -0
- package/dist/utils/electron.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/libc.d.ts +11 -0
- package/dist/utils/libc.js +35 -0
- package/dist/utils/libc.js.map +1 -0
- package/dist/utils/variant.d.ts +26 -0
- package/dist/utils/variant.js +31 -0
- package/dist/utils/variant.js.map +1 -0
- package/dist/webrtc/index.d.ts +4 -0
- package/dist/webrtc/index.js +7 -0
- package/dist/webrtc/index.js.map +1 -0
- package/install/check.js +124 -0
- package/install/ffmpeg.js +66 -0
- package/package.json +167 -4
|
@@ -0,0 +1,938 @@
|
|
|
1
|
+
import { Packet } from '../lib/packet.js';
|
|
2
|
+
import { Stream } from '../lib/stream.js';
|
|
3
|
+
import { Encoder } from './encoder.js';
|
|
4
|
+
import { Muxer } from './muxer.js';
|
|
5
|
+
import { Scheduler, SchedulerControl } from './utilities/scheduler.js';
|
|
6
|
+
import type { BsfName, BsfOptionsFor } from '../constants/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Options for bitstream filter creation.
|
|
9
|
+
*
|
|
10
|
+
* @template N - The bitstream filter name; when a literal name is given,
|
|
11
|
+
* `options` is strongly typed to that filter's known options.
|
|
12
|
+
*/
|
|
13
|
+
export interface BitstreamFilterOptions<N extends string = string> {
|
|
14
|
+
/**
|
|
15
|
+
* Filter-specific options.
|
|
16
|
+
*
|
|
17
|
+
* Key-value pairs of FFmpeg bitstream filter options, passed directly to the
|
|
18
|
+
* filter via av_opt_set(). When created from a known filter name, these are
|
|
19
|
+
* strongly typed to that filter's options (autocomplete + validation);
|
|
20
|
+
* otherwise any string/number/boolean values are accepted.
|
|
21
|
+
*/
|
|
22
|
+
options?: BsfOptionsFor<N>;
|
|
23
|
+
/**
|
|
24
|
+
* AbortSignal for cancellation.
|
|
25
|
+
*
|
|
26
|
+
* When aborted, async generators stop yielding and async methods throw AbortError.
|
|
27
|
+
*/
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* High-level bitstream filter for packet processing.
|
|
32
|
+
*
|
|
33
|
+
* Provides simplified interface for applying bitstream filters to packets.
|
|
34
|
+
* Handles filter initialization, packet processing, and memory management.
|
|
35
|
+
* Supports both synchronous packet-by-packet filtering and async iteration over packets.
|
|
36
|
+
* Supports filters like h264_mp4toannexb, hevc_mp4toannexb, aac_adtstoasc.
|
|
37
|
+
* Essential for format conversion and stream compatibility in transcoding pipelines.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { BitStreamFilterAPI } from 'node-av/api';
|
|
42
|
+
*
|
|
43
|
+
* // Create H.264 Annex B converter
|
|
44
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
45
|
+
*
|
|
46
|
+
* // Filter packet
|
|
47
|
+
* const outputPackets = await filter.filterAll(inputPacket);
|
|
48
|
+
* for (const packet of outputPackets) {
|
|
49
|
+
* await output.writePacket(packet);
|
|
50
|
+
* packet.free();
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Filter packet stream
|
|
57
|
+
* const filter = BitStreamFilterAPI.create('hevc_mp4toannexb', videoStream);
|
|
58
|
+
*
|
|
59
|
+
* for await (const packet of filter.packets(input.packets())) {
|
|
60
|
+
* await output.writePacket(packet);
|
|
61
|
+
* packet.free();
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @see {@link BitStreamFilter} For available filters
|
|
66
|
+
* @see {@link BitStreamFilterContext} For low-level API
|
|
67
|
+
* @see {@link Muxer} For writing filtered packets
|
|
68
|
+
*/
|
|
69
|
+
export declare class BitStreamFilterAPI implements Disposable {
|
|
70
|
+
private ctx;
|
|
71
|
+
private bsf;
|
|
72
|
+
private source;
|
|
73
|
+
private initialized;
|
|
74
|
+
private packet;
|
|
75
|
+
private pendingOutput;
|
|
76
|
+
private isClosed;
|
|
77
|
+
private inputQueue;
|
|
78
|
+
private outputQueue;
|
|
79
|
+
private workerPromise;
|
|
80
|
+
private nextComponent;
|
|
81
|
+
private pipeToPromise;
|
|
82
|
+
private signal?;
|
|
83
|
+
/**
|
|
84
|
+
* @param bsf - Bitstream filter
|
|
85
|
+
*
|
|
86
|
+
* @param ctx - Filter context
|
|
87
|
+
*
|
|
88
|
+
* @param source - Input source for lazy parameter resolution
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
private constructor();
|
|
93
|
+
/**
|
|
94
|
+
* Create a bitstream filter.
|
|
95
|
+
*
|
|
96
|
+
* The input source provides the codec parameters the filter is configured with.
|
|
97
|
+
* Pass a {@link Stream} to filter its packets directly (stream copy), or an
|
|
98
|
+
* {@link Encoder} to filter that encoder's output (transcode) - parameters are
|
|
99
|
+
* derived from the encoder once it is open. Another {@link BitStreamFilterAPI}
|
|
100
|
+
* may be passed to chain filters.
|
|
101
|
+
*
|
|
102
|
+
* Initialization is lazy: filter options are validated immediately, but the
|
|
103
|
+
* input parameters are bound and the filter is initialized on the first packet,
|
|
104
|
+
* so an `Encoder` source (opened lazily on its first frame) is ready in time.
|
|
105
|
+
*
|
|
106
|
+
* Direct mapping to av_bsf_get_by_name() and av_bsf_alloc().
|
|
107
|
+
*
|
|
108
|
+
* @param filterName - Name of the bitstream filter
|
|
109
|
+
*
|
|
110
|
+
* @param source - Input source: a `Stream` (copy), `Encoder` (transcode), or upstream filter (chain)
|
|
111
|
+
*
|
|
112
|
+
* @param filterOptions - Optional filter-specific options
|
|
113
|
+
*
|
|
114
|
+
* @returns Configured bitstream filter
|
|
115
|
+
*
|
|
116
|
+
* @throws {FFmpegError} If the filter is not found, allocation fails, or an option is invalid
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // Stream copy: H.264 MP4 to Annex B conversion
|
|
121
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', videoStream);
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Transcode: derive parameters from the encoder's output
|
|
127
|
+
* const filter = BitStreamFilterAPI.create('h264_metadata', encoder, {
|
|
128
|
+
* options: { aud: 'remove', level: '4.1' },
|
|
129
|
+
* });
|
|
130
|
+
* pipeline(input, decoder, encoder, filter, output);
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @see {@link BitStreamFilter.getByName} For filter discovery
|
|
134
|
+
* @see {@link BitstreamFilterOptions} For available options
|
|
135
|
+
*/
|
|
136
|
+
static create<const N extends BsfName | (string & {}) = BsfName | (string & {})>(filterName: N, source: Stream | Encoder | BitStreamFilterAPI, filterOptions?: BitstreamFilterOptions<N>): BitStreamFilterAPI;
|
|
137
|
+
/**
|
|
138
|
+
* Get filter name.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* console.log(`Using filter: ${filter.name}`);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
get name(): string;
|
|
146
|
+
/**
|
|
147
|
+
* Get output codec parameters.
|
|
148
|
+
*
|
|
149
|
+
* Parameters after filter processing.
|
|
150
|
+
* May differ from input parameters.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const outputParams = filter.outputCodecParameters;
|
|
155
|
+
* console.log(`Output codec: ${outputParams?.codecId}`);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
get outputCodecParameters(): import("../index.js").CodecParameters | null;
|
|
159
|
+
/**
|
|
160
|
+
* Get output time base.
|
|
161
|
+
*
|
|
162
|
+
* Time base after filter processing.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const tb = filter.outputTimeBase;
|
|
167
|
+
* console.log(`Output timebase: ${tb?.num}/${tb?.den}`);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
get outputTimeBase(): import("../index.js").Rational | null;
|
|
171
|
+
/**
|
|
172
|
+
* Check if filter is open.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* if (filter.isBitstreamFilterOpen) {
|
|
177
|
+
* const packet = await filter.process(frame);
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
get isBitstreamFilterOpen(): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Check if the filter has been initialized.
|
|
184
|
+
*
|
|
185
|
+
* Initialization is lazy and happens on the first processed packet, after
|
|
186
|
+
* which {@link outputCodecParameters} reflect the filter's output.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* if (filter.isInitialized) {
|
|
191
|
+
* const params = filter.outputCodecParameters;
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
get isInitialized(): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Get associated stream.
|
|
198
|
+
*
|
|
199
|
+
* Returns the stream this filter was created for. Only available when the
|
|
200
|
+
* filter was created from a {@link Stream}; filters created from an `Encoder`
|
|
201
|
+
* derive their parameters from the encoder's output instead.
|
|
202
|
+
*
|
|
203
|
+
* @returns Associated stream
|
|
204
|
+
*
|
|
205
|
+
* @throws {Error} If the filter was not created from a stream
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const stream = filter.getStream();
|
|
210
|
+
* console.log(`Filtering stream ${stream.index}`);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
getStream(): Stream;
|
|
214
|
+
/**
|
|
215
|
+
* Send a packet to the filter.
|
|
216
|
+
*
|
|
217
|
+
* Sends a packet to the filter for processing.
|
|
218
|
+
* Does not return filtered packets - use {@link receive} to retrieve packets.
|
|
219
|
+
* A single packet can produce zero, one, or multiple packets depending on filter.
|
|
220
|
+
*
|
|
221
|
+
* **Important**: This method only SENDS the packet to the filter.
|
|
222
|
+
* You must call {@link receive} separately (potentially multiple times) to get filtered packets.
|
|
223
|
+
*
|
|
224
|
+
* Direct mapping to av_bsf_send_packet().
|
|
225
|
+
*
|
|
226
|
+
* @param packet - Packet to send to filter, or null to flush
|
|
227
|
+
*
|
|
228
|
+
* @throws {FFmpegError} If sending fails
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Send packet and receive filtered packets
|
|
233
|
+
* await filter.filter(inputPacket);
|
|
234
|
+
*
|
|
235
|
+
* // Receive all available filtered packets
|
|
236
|
+
* while (true) {
|
|
237
|
+
* const outPacket = await filter.receive();
|
|
238
|
+
* if (!outPacket) break;
|
|
239
|
+
* console.log(`Filtered packet with PTS: ${outPacket.pts}`);
|
|
240
|
+
* await output.writePacket(outPacket);
|
|
241
|
+
* outPacket.free();
|
|
242
|
+
* }
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* for await (const packet of input.packets()) {
|
|
248
|
+
* // packet is null at end of stream - automatically flushes filter
|
|
249
|
+
* await filter.filter(packet);
|
|
250
|
+
*
|
|
251
|
+
* // Receive available filtered packets
|
|
252
|
+
* let outPacket;
|
|
253
|
+
* while ((outPacket = await filter.receive())) {
|
|
254
|
+
* await output.writePacket(outPacket);
|
|
255
|
+
* outPacket.free();
|
|
256
|
+
* }
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* @see {@link receive} For receiving filtered packets
|
|
261
|
+
* @see {@link filterAll} For combined send+receive operation
|
|
262
|
+
* @see {@link packets} For automatic packet iteration
|
|
263
|
+
* @see {@link flush} For end-of-stream handling
|
|
264
|
+
* @see {@link filterSync} For synchronous version
|
|
265
|
+
*/
|
|
266
|
+
filter(packet: Packet | null): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Send a packet to the filter synchronously.
|
|
269
|
+
* Synchronous version of filter.
|
|
270
|
+
*
|
|
271
|
+
* Sends a packet to the filter for processing.
|
|
272
|
+
* Does not return filtered packets - use {@link receiveSync} to retrieve packets.
|
|
273
|
+
* A single packet can produce zero, one, or multiple packets depending on filter.
|
|
274
|
+
*
|
|
275
|
+
* **Important**: This method only SENDS the packet to the filter.
|
|
276
|
+
* You must call {@link receiveSync} separately (potentially multiple times) to get filtered packets.
|
|
277
|
+
*
|
|
278
|
+
* Direct mapping to av_bsf_send_packet().
|
|
279
|
+
*
|
|
280
|
+
* @param packet - Packet to send to filter, or null to flush
|
|
281
|
+
*
|
|
282
|
+
* @throws {FFmpegError} If sending fails
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* // Send packet and receive filtered packets
|
|
287
|
+
* filter.filterSync(inputPacket);
|
|
288
|
+
*
|
|
289
|
+
* // Receive all available filtered packets
|
|
290
|
+
* while (true) {
|
|
291
|
+
* const outPacket = filter.receiveSync();
|
|
292
|
+
* if (!outPacket) break;
|
|
293
|
+
* console.log(`Filtered packet with PTS: ${outPacket.pts}`);
|
|
294
|
+
* output.writePacketSync(outPacket);
|
|
295
|
+
* outPacket.free();
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* for (const packet of packets) {
|
|
302
|
+
* // packet is null at end of stream - automatically flushes filter
|
|
303
|
+
* filter.filterSync(packet);
|
|
304
|
+
*
|
|
305
|
+
* // Receive available filtered packets
|
|
306
|
+
* let outPacket;
|
|
307
|
+
* while ((outPacket = filter.receiveSync())) {
|
|
308
|
+
* output.writePacketSync(outPacket);
|
|
309
|
+
* outPacket.free();
|
|
310
|
+
* }
|
|
311
|
+
* }
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* @see {@link receiveSync} For receiving filtered packets
|
|
315
|
+
* @see {@link filterAllSync} For combined send+receive operation
|
|
316
|
+
* @see {@link packetsSync} For automatic packet iteration
|
|
317
|
+
* @see {@link flushSync} For end-of-stream handling
|
|
318
|
+
* @see {@link filter} For async version
|
|
319
|
+
*/
|
|
320
|
+
filterSync(packet: Packet | null): void;
|
|
321
|
+
/**
|
|
322
|
+
* Filter a packet to packets.
|
|
323
|
+
*
|
|
324
|
+
* Sends a packet to the filter and receives all available filtered packets.
|
|
325
|
+
* Returns array of packets - may be empty if filter needs more data.
|
|
326
|
+
* One packet can produce zero, one, or multiple packets depending on filter.
|
|
327
|
+
*
|
|
328
|
+
* Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
|
|
329
|
+
*
|
|
330
|
+
* @param packet - Packet to filter, or null to flush
|
|
331
|
+
*
|
|
332
|
+
* @returns Array of filtered packets (empty if more data needed or filter is closed)
|
|
333
|
+
*
|
|
334
|
+
* @throws {FFmpegError} If filtering fails
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const outputPackets = await filter.filterAll(inputPacket);
|
|
339
|
+
* for (const packet of outputPackets) {
|
|
340
|
+
* console.log(`Filtered packet: pts=${packet.pts}`);
|
|
341
|
+
* await output.writePacket(packet);
|
|
342
|
+
* packet.free();
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* // Flush remaining packets at end of stream
|
|
349
|
+
* const remaining = await filter.filterAll(null);
|
|
350
|
+
* for (const packet of remaining) {
|
|
351
|
+
* await output.writePacket(packet);
|
|
352
|
+
* packet.free();
|
|
353
|
+
* }
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* @see {@link filter} For single packet filtering
|
|
357
|
+
* @see {@link packets} For stream processing
|
|
358
|
+
* @see {@link flush} For end-of-stream handling
|
|
359
|
+
* @see {@link filterAllSync} For synchronous version
|
|
360
|
+
*/
|
|
361
|
+
filterAll(packet: Packet | null): Promise<Packet[]>;
|
|
362
|
+
/**
|
|
363
|
+
* Filter a packet to packets synchronously.
|
|
364
|
+
* Synchronous version of filterAll.
|
|
365
|
+
*
|
|
366
|
+
* Sends a packet to the filter and receives all available filtered packets.
|
|
367
|
+
* Returns array of packets - may be empty if filter needs more data.
|
|
368
|
+
* One packet can produce zero, one, or multiple packets depending on filter.
|
|
369
|
+
*
|
|
370
|
+
* Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
|
|
371
|
+
*
|
|
372
|
+
* @param packet - Packet to filter, or null to flush
|
|
373
|
+
*
|
|
374
|
+
* @returns Array of filtered packets (empty if more data needed or filter is closed)
|
|
375
|
+
*
|
|
376
|
+
* @throws {FFmpegError} If filtering fails
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* const outputPackets = filter.filterAllSync(inputPacket);
|
|
381
|
+
* for (const packet of outputPackets) {
|
|
382
|
+
* console.log(`Filtered packet: pts=${packet.pts}`);
|
|
383
|
+
* output.writePacketSync(packet);
|
|
384
|
+
* packet.free();
|
|
385
|
+
* }
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* // Flush remaining packets at end of stream
|
|
391
|
+
* const remaining = filter.filterAllSync(null);
|
|
392
|
+
* for (const packet of remaining) {
|
|
393
|
+
* output.writePacketSync(packet);
|
|
394
|
+
* packet.free();
|
|
395
|
+
* }
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* @see {@link filterSync} For single packet filtering
|
|
399
|
+
* @see {@link packetsSync} For stream processing
|
|
400
|
+
* @see {@link flushSync} For end-of-stream handling
|
|
401
|
+
* @see {@link filterAll} For async version
|
|
402
|
+
*/
|
|
403
|
+
filterAllSync(packet: Packet | null): Packet[];
|
|
404
|
+
/**
|
|
405
|
+
* Filter packet stream to filtered packet stream.
|
|
406
|
+
*
|
|
407
|
+
* High-level async generator for complete filtering pipeline.
|
|
408
|
+
* Filter is only flushed when EOF (null) signal is explicitly received.
|
|
409
|
+
* Primary interface for stream-based filtering.
|
|
410
|
+
*
|
|
411
|
+
* **EOF Handling:**
|
|
412
|
+
* - Send null to flush filter and get remaining buffered packets
|
|
413
|
+
* - Generator yields null after flushing when null is received
|
|
414
|
+
* - No automatic flushing - filter stays open until EOF or close()
|
|
415
|
+
*
|
|
416
|
+
* @param packets - Async iterable of packets, single packet, or null to flush
|
|
417
|
+
*
|
|
418
|
+
* @yields {Packet | null} Filtered packets, followed by null when explicitly flushed
|
|
419
|
+
*
|
|
420
|
+
* @throws {FFmpegError} If filtering fails
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```typescript
|
|
424
|
+
* // Stream of packets with automatic EOF propagation
|
|
425
|
+
* for await (const packet of filter.packets(input.packets())) {
|
|
426
|
+
* if (packet === null) {
|
|
427
|
+
* console.log('Filter flushed');
|
|
428
|
+
* break;
|
|
429
|
+
* }
|
|
430
|
+
* await output.writePacket(packet);
|
|
431
|
+
* packet.free(); // Must free output packets
|
|
432
|
+
* }
|
|
433
|
+
* ```
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* // Single packet - no automatic flush
|
|
438
|
+
* for await (const packet of filter.packets(singlePacket)) {
|
|
439
|
+
* await output.writePacket(packet);
|
|
440
|
+
* packet.free();
|
|
441
|
+
* }
|
|
442
|
+
* // Filter remains open, buffered packets not flushed
|
|
443
|
+
* ```
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* // Explicit flush with EOF
|
|
448
|
+
* for await (const packet of filter.packets(null)) {
|
|
449
|
+
* if (packet === null) {
|
|
450
|
+
* console.log('All buffered packets flushed');
|
|
451
|
+
* break;
|
|
452
|
+
* }
|
|
453
|
+
* console.log('Buffered packet:', packet.pts);
|
|
454
|
+
* await output.writePacket(packet);
|
|
455
|
+
* packet.free();
|
|
456
|
+
* }
|
|
457
|
+
* ```
|
|
458
|
+
*
|
|
459
|
+
* @see {@link filter} For single packet filtering
|
|
460
|
+
* @see {@link Demuxer.packets} For packet source
|
|
461
|
+
* @see {@link packetsSync} For sync version
|
|
462
|
+
*/
|
|
463
|
+
packets(packets: AsyncIterable<Packet | null> | Packet | null): AsyncGenerator<Packet | null>;
|
|
464
|
+
/**
|
|
465
|
+
* Filter packet stream to filtered packet stream synchronously.
|
|
466
|
+
* Synchronous version of packets.
|
|
467
|
+
*
|
|
468
|
+
* High-level sync generator for complete filtering pipeline.
|
|
469
|
+
* Filter is only flushed when EOF (null) signal is explicitly received.
|
|
470
|
+
* Primary interface for stream-based filtering.
|
|
471
|
+
*
|
|
472
|
+
* **EOF Handling:**
|
|
473
|
+
* - Send null to flush filter and get remaining buffered packets
|
|
474
|
+
* - Generator yields null after flushing when null is received
|
|
475
|
+
* - No automatic flushing - filter stays open until EOF or close()
|
|
476
|
+
*
|
|
477
|
+
* @param packets - Iterable of packets, single packet, or null to flush
|
|
478
|
+
*
|
|
479
|
+
* @yields {Packet | null} Filtered packets, followed by null when explicitly flushed
|
|
480
|
+
*
|
|
481
|
+
* @throws {FFmpegError} If filtering fails
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```typescript
|
|
485
|
+
* // Stream of packets with automatic EOF propagation
|
|
486
|
+
* for (const packet of filter.packetsSync(inputPackets)) {
|
|
487
|
+
* if (packet === null) {
|
|
488
|
+
* console.log('Filter flushed');
|
|
489
|
+
* break;
|
|
490
|
+
* }
|
|
491
|
+
* output.writePacketSync(packet);
|
|
492
|
+
* packet.free(); // Must free output packets
|
|
493
|
+
* }
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* // Single packet - no automatic flush
|
|
499
|
+
* for (const packet of filter.packetsSync(singlePacket)) {
|
|
500
|
+
* output.writePacketSync(packet);
|
|
501
|
+
* packet.free();
|
|
502
|
+
* }
|
|
503
|
+
* // Filter remains open, buffered packets not flushed
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* // Explicit flush with EOF
|
|
509
|
+
* for (const packet of filter.packetsSync(null)) {
|
|
510
|
+
* if (packet === null) {
|
|
511
|
+
* console.log('All buffered packets flushed');
|
|
512
|
+
* break;
|
|
513
|
+
* }
|
|
514
|
+
* console.log('Buffered packet:', packet.pts);
|
|
515
|
+
* output.writePacketSync(packet);
|
|
516
|
+
* packet.free();
|
|
517
|
+
* }
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* @see {@link filterSync} For single packet filtering
|
|
521
|
+
* @see {@link packets} For async version
|
|
522
|
+
*/
|
|
523
|
+
packetsSync(packets: Iterable<Packet | null> | Packet | null): Generator<Packet | null>;
|
|
524
|
+
/**
|
|
525
|
+
* Flush filter and signal end-of-stream.
|
|
526
|
+
*
|
|
527
|
+
* Sends null packet to filter to signal end-of-stream.
|
|
528
|
+
* Does nothing if filter is closed.
|
|
529
|
+
* Must call receive() or flushPackets() to get remaining buffered packets.
|
|
530
|
+
* Does not reset filter state - use {@link reset} for that.
|
|
531
|
+
*
|
|
532
|
+
* Direct mapping to av_bsf_send_packet(NULL).
|
|
533
|
+
*
|
|
534
|
+
* @throws {FFmpegError} If flush fails
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* // Signal end of stream
|
|
539
|
+
* await filter.flush();
|
|
540
|
+
*
|
|
541
|
+
* // Then get remaining packets
|
|
542
|
+
* let packet;
|
|
543
|
+
* while ((packet = await filter.receive()) !== null) {
|
|
544
|
+
* console.log('Got buffered packet');
|
|
545
|
+
* await output.writePacket(packet);
|
|
546
|
+
* packet.free();
|
|
547
|
+
* }
|
|
548
|
+
* ```
|
|
549
|
+
*
|
|
550
|
+
* @see {@link flushPackets} For async iteration
|
|
551
|
+
* @see {@link receive} For getting buffered packets
|
|
552
|
+
* @see {@link reset} For state reset only
|
|
553
|
+
* @see {@link flushSync} For synchronous version
|
|
554
|
+
*/
|
|
555
|
+
flush(): Promise<void>;
|
|
556
|
+
/**
|
|
557
|
+
* Flush filter and signal end-of-stream synchronously.
|
|
558
|
+
* Synchronous version of flush.
|
|
559
|
+
*
|
|
560
|
+
* Sends null packet to filter to signal end-of-stream.
|
|
561
|
+
* Does nothing if filter is closed.
|
|
562
|
+
* Must call receiveSync() or flushPacketsSync() to get remaining buffered packets.
|
|
563
|
+
* Does not reset filter state - use {@link reset} for that.
|
|
564
|
+
*
|
|
565
|
+
* Direct mapping to av_bsf_send_packet(NULL).
|
|
566
|
+
*
|
|
567
|
+
* @throws {FFmpegError} If flush fails
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* ```typescript
|
|
571
|
+
* // Signal end of stream
|
|
572
|
+
* filter.flushSync();
|
|
573
|
+
*
|
|
574
|
+
* // Then get remaining packets
|
|
575
|
+
* let packet;
|
|
576
|
+
* while ((packet = filter.receiveSync()) !== null) {
|
|
577
|
+
* console.log('Got buffered packet');
|
|
578
|
+
* output.writePacketSync(packet);
|
|
579
|
+
* packet.free();
|
|
580
|
+
* }
|
|
581
|
+
* ```
|
|
582
|
+
*
|
|
583
|
+
* @see {@link flushPacketsSync} For sync iteration
|
|
584
|
+
* @see {@link receiveSync} For getting buffered packets
|
|
585
|
+
* @see {@link reset} For state reset only
|
|
586
|
+
* @see {@link flush} For async version
|
|
587
|
+
*/
|
|
588
|
+
flushSync(): void;
|
|
589
|
+
/**
|
|
590
|
+
* Receive packet from filter.
|
|
591
|
+
*
|
|
592
|
+
* Gets filtered packets from the filter's internal buffer.
|
|
593
|
+
* Handles packet allocation and error checking.
|
|
594
|
+
* Returns null if filter is closed or no packets available.
|
|
595
|
+
* Call repeatedly until null to drain all buffered packets.
|
|
596
|
+
*
|
|
597
|
+
* Direct mapping to av_bsf_receive_packet().
|
|
598
|
+
*
|
|
599
|
+
* @returns Cloned packet or null if no packets available
|
|
600
|
+
*
|
|
601
|
+
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
602
|
+
*
|
|
603
|
+
* @throws {Error} If packet cloning fails (out of memory)
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```typescript
|
|
607
|
+
* const packet = await filter.receive();
|
|
608
|
+
* if (packet) {
|
|
609
|
+
* console.log('Got filtered packet');
|
|
610
|
+
* await output.writePacket(packet);
|
|
611
|
+
* packet.free();
|
|
612
|
+
* }
|
|
613
|
+
* ```
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* // Drain all buffered packets
|
|
618
|
+
* let packet;
|
|
619
|
+
* while ((packet = await filter.receive()) !== null) {
|
|
620
|
+
* console.log(`Packet PTS: ${packet.pts}`);
|
|
621
|
+
* await output.writePacket(packet);
|
|
622
|
+
* packet.free();
|
|
623
|
+
* }
|
|
624
|
+
* ```
|
|
625
|
+
*
|
|
626
|
+
* @see {@link filter} For filtering packets
|
|
627
|
+
* @see {@link flush} For signaling end-of-stream
|
|
628
|
+
* @see {@link receiveSync} For synchronous version
|
|
629
|
+
*/
|
|
630
|
+
receive(): Promise<Packet | null>;
|
|
631
|
+
/**
|
|
632
|
+
* Receive packet from filter synchronously.
|
|
633
|
+
* Synchronous version of receive.
|
|
634
|
+
*
|
|
635
|
+
* Gets filtered packets from the filter's internal buffer.
|
|
636
|
+
* Handles packet allocation and error checking.
|
|
637
|
+
* Returns null if filter is closed or no packets available.
|
|
638
|
+
* Call repeatedly until null to drain all buffered packets.
|
|
639
|
+
*
|
|
640
|
+
* Direct mapping to av_bsf_receive_packet().
|
|
641
|
+
*
|
|
642
|
+
* @returns Cloned packet or null if no packets available
|
|
643
|
+
*
|
|
644
|
+
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
645
|
+
*
|
|
646
|
+
* @throws {Error} If packet cloning fails (out of memory)
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```typescript
|
|
650
|
+
* const packet = filter.receiveSync();
|
|
651
|
+
* if (packet) {
|
|
652
|
+
* console.log('Got filtered packet');
|
|
653
|
+
* output.writePacketSync(packet);
|
|
654
|
+
* packet.free();
|
|
655
|
+
* }
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```typescript
|
|
660
|
+
* // Drain all buffered packets
|
|
661
|
+
* let packet;
|
|
662
|
+
* while ((packet = filter.receiveSync()) !== null) {
|
|
663
|
+
* console.log(`Packet PTS: ${packet.pts}`);
|
|
664
|
+
* output.writePacketSync(packet);
|
|
665
|
+
* packet.free();
|
|
666
|
+
* }
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* @see {@link filterSync} For filtering packets
|
|
670
|
+
* @see {@link flushSync} For signaling end-of-stream
|
|
671
|
+
* @see {@link receive} For async version
|
|
672
|
+
*/
|
|
673
|
+
receiveSync(): Packet | null;
|
|
674
|
+
/**
|
|
675
|
+
* Pipe output to another bitstream filter.
|
|
676
|
+
*
|
|
677
|
+
* Starts background worker for packet processing.
|
|
678
|
+
* Packets flow through: input → this filter → target filter.
|
|
679
|
+
*
|
|
680
|
+
* @param target - Target bitstream filter
|
|
681
|
+
*
|
|
682
|
+
* @returns Scheduler for continued chaining
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```typescript
|
|
686
|
+
* const filter1 = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
687
|
+
* const filter2 = BitStreamFilterAPI.create('dump_extra', stream);
|
|
688
|
+
* filter1.pipeTo(filter2).pipeTo(output, 0);
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
pipeTo(target: BitStreamFilterAPI): Scheduler<Packet>;
|
|
692
|
+
/**
|
|
693
|
+
* Pipe output to muxer.
|
|
694
|
+
*
|
|
695
|
+
* Terminal stage - writes filtered packets to output file.
|
|
696
|
+
*
|
|
697
|
+
* @param output - Muxer to write to
|
|
698
|
+
*
|
|
699
|
+
* @param streamIndex - Stream index in output
|
|
700
|
+
*
|
|
701
|
+
* @returns Control interface for pipeline
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
706
|
+
* const control = filter.pipeTo(output, 0);
|
|
707
|
+
* await control.send(packet);
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
pipeTo(output: Muxer, streamIndex: number): SchedulerControl<Packet>;
|
|
711
|
+
/**
|
|
712
|
+
* Flush all buffered packets as async generator.
|
|
713
|
+
*
|
|
714
|
+
* Convenient async iteration over remaining packets.
|
|
715
|
+
* Automatically sends flush signal and retrieves buffered packets.
|
|
716
|
+
* Useful for end-of-stream processing.
|
|
717
|
+
*
|
|
718
|
+
* @yields {Packet} Buffered packets
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* ```typescript
|
|
722
|
+
* // Flush at end of filtering
|
|
723
|
+
* for await (const packet of filter.flushPackets()) {
|
|
724
|
+
* console.log('Processing buffered packet');
|
|
725
|
+
* await output.writePacket(packet);
|
|
726
|
+
* packet.free();
|
|
727
|
+
* }
|
|
728
|
+
* ```
|
|
729
|
+
*
|
|
730
|
+
* @see {@link filter} For filtering packets
|
|
731
|
+
* @see {@link flush} For signaling end-of-stream
|
|
732
|
+
* @see {@link flushPacketsSync} For synchronous version
|
|
733
|
+
*/
|
|
734
|
+
flushPackets(): AsyncGenerator<Packet>;
|
|
735
|
+
/**
|
|
736
|
+
* Flush all buffered packets as generator synchronously.
|
|
737
|
+
* Synchronous version of flushPackets.
|
|
738
|
+
*
|
|
739
|
+
* Convenient sync iteration over remaining packets.
|
|
740
|
+
* Automatically sends flush signal and retrieves buffered packets.
|
|
741
|
+
* Useful for end-of-stream processing.
|
|
742
|
+
*
|
|
743
|
+
* @yields {Packet} Buffered packets
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```typescript
|
|
747
|
+
* // Flush at end of filtering
|
|
748
|
+
* for (const packet of filter.flushPacketsSync()) {
|
|
749
|
+
* console.log('Processing buffered packet');
|
|
750
|
+
* output.writePacketSync(packet);
|
|
751
|
+
* packet.free();
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
754
|
+
*
|
|
755
|
+
* @see {@link filterSync} For filtering packets
|
|
756
|
+
* @see {@link flushSync} For signaling end-of-stream
|
|
757
|
+
* @see {@link flushPackets} For async version
|
|
758
|
+
*/
|
|
759
|
+
flushPacketsSync(): Generator<Packet>;
|
|
760
|
+
/**
|
|
761
|
+
* Reset filter state.
|
|
762
|
+
*
|
|
763
|
+
* Clears internal buffers and resets filter.
|
|
764
|
+
* Does not dispose resources.
|
|
765
|
+
*
|
|
766
|
+
* Direct mapping to av_bsf_flush().
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* ```typescript
|
|
770
|
+
* // Reset for new segment
|
|
771
|
+
* filter.reset();
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* @see {@link flush} For end-of-stream signaling with packet retrieval
|
|
775
|
+
*/
|
|
776
|
+
reset(): void;
|
|
777
|
+
/**
|
|
778
|
+
* Close filter and free resources.
|
|
779
|
+
*
|
|
780
|
+
* Releases filter context and marks as closed.
|
|
781
|
+
* Safe to call multiple times.
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```typescript
|
|
785
|
+
* filter.close();
|
|
786
|
+
* ```
|
|
787
|
+
*
|
|
788
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
789
|
+
*/
|
|
790
|
+
close(): void;
|
|
791
|
+
/**
|
|
792
|
+
* Dispose of filter.
|
|
793
|
+
*
|
|
794
|
+
* Implements Disposable interface for automatic cleanup.
|
|
795
|
+
* Equivalent to calling dispose().
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* ```typescript
|
|
799
|
+
* {
|
|
800
|
+
* using filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
801
|
+
* // Use filter...
|
|
802
|
+
* } // Automatically disposed
|
|
803
|
+
* ```
|
|
804
|
+
*
|
|
805
|
+
* @see {@link close} For manual cleanup
|
|
806
|
+
*/
|
|
807
|
+
[Symbol.dispose](): void;
|
|
808
|
+
/**
|
|
809
|
+
* Bind input parameters from the source and initialize the filter.
|
|
810
|
+
*
|
|
811
|
+
* @internal
|
|
812
|
+
*/
|
|
813
|
+
private ensureInitialized;
|
|
814
|
+
/**
|
|
815
|
+
* Send a packet to the filter context, retrying once on EAGAIN.
|
|
816
|
+
*
|
|
817
|
+
* av_bsf_send_packet() returning EAGAIN means the packet was NOT consumed:
|
|
818
|
+
* the filter holds output that must be received before it accepts more
|
|
819
|
+
* input. That output is drained into pendingOutput (delivered by subsequent
|
|
820
|
+
* receive() calls in FIFO order) and the send is retried, mirroring how the
|
|
821
|
+
* FFmpeg CLI interleaves send/receive.
|
|
822
|
+
*
|
|
823
|
+
* @param packet - Packet to send, or null to signal EOF
|
|
824
|
+
*
|
|
825
|
+
* @throws {FFmpegError} If sending fails
|
|
826
|
+
*
|
|
827
|
+
* @internal
|
|
828
|
+
*/
|
|
829
|
+
private sendPacketWithRetry;
|
|
830
|
+
/**
|
|
831
|
+
* Send a packet to the filter context, retrying once on EAGAIN.
|
|
832
|
+
* Synchronous version of sendPacketWithRetry.
|
|
833
|
+
*
|
|
834
|
+
* @param packet - Packet to send, or null to signal EOF
|
|
835
|
+
*
|
|
836
|
+
* @throws {FFmpegError} If sending fails
|
|
837
|
+
*
|
|
838
|
+
* @internal
|
|
839
|
+
*/
|
|
840
|
+
private sendPacketWithRetrySync;
|
|
841
|
+
/**
|
|
842
|
+
* Receive one packet directly from the filter context.
|
|
843
|
+
*
|
|
844
|
+
* Bypasses pendingOutput so an EAGAIN drain can buffer packets without
|
|
845
|
+
* re-reading them.
|
|
846
|
+
*
|
|
847
|
+
* @returns Cloned packet or null if no packets available
|
|
848
|
+
*
|
|
849
|
+
* @throws {FFmpegError} If receive fails
|
|
850
|
+
*
|
|
851
|
+
* @throws {Error} If packet cloning fails (out of memory)
|
|
852
|
+
*
|
|
853
|
+
* @internal
|
|
854
|
+
*/
|
|
855
|
+
private receiveFromContext;
|
|
856
|
+
/**
|
|
857
|
+
* Receive one packet directly from the filter context.
|
|
858
|
+
* Synchronous version of receiveFromContext.
|
|
859
|
+
*
|
|
860
|
+
* @returns Cloned packet or null if no packets available
|
|
861
|
+
*
|
|
862
|
+
* @throws {FFmpegError} If receive fails
|
|
863
|
+
*
|
|
864
|
+
* @throws {Error} If packet cloning fails (out of memory)
|
|
865
|
+
*
|
|
866
|
+
* @internal
|
|
867
|
+
*/
|
|
868
|
+
private receiveFromContextSync;
|
|
869
|
+
/**
|
|
870
|
+
* Convert a receive return code into a cloned output packet.
|
|
871
|
+
*
|
|
872
|
+
* @param recvRet - Return code of av_bsf_receive_packet()
|
|
873
|
+
*
|
|
874
|
+
* @returns Cloned packet, or null on EAGAIN/EOF
|
|
875
|
+
*
|
|
876
|
+
* @throws {FFmpegError} If the return code is any other error
|
|
877
|
+
*
|
|
878
|
+
* @throws {Error} If packet cloning fails (out of memory)
|
|
879
|
+
*
|
|
880
|
+
* @internal
|
|
881
|
+
*/
|
|
882
|
+
private consumeReceived;
|
|
883
|
+
/**
|
|
884
|
+
* Free and clear any packets buffered by an EAGAIN drain.
|
|
885
|
+
*
|
|
886
|
+
* @internal
|
|
887
|
+
*/
|
|
888
|
+
private clearPendingOutput;
|
|
889
|
+
/**
|
|
890
|
+
* Send packet to input queue or flush the pipeline.
|
|
891
|
+
*
|
|
892
|
+
* When packet is provided, queues it for filtering.
|
|
893
|
+
* When null is provided, triggers flush sequence:
|
|
894
|
+
* - Closes input queue
|
|
895
|
+
* - Waits for worker completion
|
|
896
|
+
* - Closes output queue (no buffering, bitstream filters are stateless)
|
|
897
|
+
* - Waits for pipeTo task completion
|
|
898
|
+
* - Propagates flush to next component (if any)
|
|
899
|
+
*
|
|
900
|
+
* Used by scheduler system for pipeline control.
|
|
901
|
+
*
|
|
902
|
+
* @param packet - Packet to send, or null to flush
|
|
903
|
+
*
|
|
904
|
+
* @internal
|
|
905
|
+
*/
|
|
906
|
+
private sendToQueue;
|
|
907
|
+
/**
|
|
908
|
+
* Receive packet from output queue.
|
|
909
|
+
*
|
|
910
|
+
* @returns Packet from queue or null if closed
|
|
911
|
+
*
|
|
912
|
+
* @internal
|
|
913
|
+
*/
|
|
914
|
+
private receiveFromQueue;
|
|
915
|
+
/**
|
|
916
|
+
* Worker loop for push-based processing.
|
|
917
|
+
*
|
|
918
|
+
* @internal
|
|
919
|
+
*/
|
|
920
|
+
private runWorker;
|
|
921
|
+
/**
|
|
922
|
+
* Fold a filtered packet's new-extradata side data into the output parameters.
|
|
923
|
+
*
|
|
924
|
+
* Bitstream filters that adapt a stream's container framing — `aac_adtstoasc`,
|
|
925
|
+
* `extract_extradata`, `dump_extra`, `*_mp4toannexb` — emit the resulting global
|
|
926
|
+
* headers as {@link AV_PKT_DATA_NEW_EXTRADATA} side data on their output packets
|
|
927
|
+
* rather than on `par_out`, matching FFmpeg's mid-stream extradata model. Without
|
|
928
|
+
* this, {@link outputCodecParameters} would never reflect that extradata, so a
|
|
929
|
+
* stream copy that relies on it (including {@link Muxer}'s `bsf` option) emits a
|
|
930
|
+
* header with no codec configuration. Lifting it onto `par_out` keeps
|
|
931
|
+
* `outputCodecParameters` current while leaving the side data on the packet too.
|
|
932
|
+
*
|
|
933
|
+
* @param packet - A freshly received filtered packet.
|
|
934
|
+
*
|
|
935
|
+
* @internal
|
|
936
|
+
*/
|
|
937
|
+
private foldNewExtradata;
|
|
938
|
+
}
|