node-av 6.0.0-beta.2 → 6.0.0-beta.4

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 (51) hide show
  1. package/dist/api/bitstream-filter.d.ts +110 -87
  2. package/dist/api/bitstream-filter.js +157 -100
  3. package/dist/api/bitstream-filter.js.map +1 -1
  4. package/dist/api/decoder.d.ts +9 -7
  5. package/dist/api/decoder.js.map +1 -1
  6. package/dist/api/demuxer.d.ts +27 -22
  7. package/dist/api/demuxer.js.map +1 -1
  8. package/dist/api/encoder.d.ts +9 -7
  9. package/dist/api/encoder.js +10 -4
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +27 -658
  12. package/dist/api/filter-presets.js +45 -838
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/fmp4-stream.js +1 -1
  15. package/dist/api/fmp4-stream.js.map +1 -1
  16. package/dist/api/muxer.d.ts +24 -15
  17. package/dist/api/muxer.js +27 -0
  18. package/dist/api/muxer.js.map +1 -1
  19. package/dist/api/pipeline.js +6 -6
  20. package/dist/api/pipeline.js.map +1 -1
  21. package/dist/api/rtp-stream.js +1 -1
  22. package/dist/api/rtp-stream.js.map +1 -1
  23. package/dist/constants/bsf-options.d.ts +333 -0
  24. package/dist/constants/bsf-options.js +7 -0
  25. package/dist/constants/bsf-options.js.map +1 -0
  26. package/dist/constants/decoders.d.ts +636 -618
  27. package/dist/constants/decoders.js +0 -2
  28. package/dist/constants/decoders.js.map +1 -1
  29. package/dist/constants/encoders.d.ts +300 -282
  30. package/dist/constants/encoders.js +0 -2
  31. package/dist/constants/encoders.js.map +1 -1
  32. package/dist/constants/filter-options.d.ts +10915 -0
  33. package/dist/constants/filter-options.js +7 -0
  34. package/dist/constants/filter-options.js.map +1 -0
  35. package/dist/constants/format-options.d.ts +3056 -0
  36. package/dist/constants/format-options.js +7 -0
  37. package/dist/constants/format-options.js.map +1 -0
  38. package/dist/constants/formats.d.ts +18 -0
  39. package/dist/constants/formats.js +7 -0
  40. package/dist/constants/formats.js.map +1 -0
  41. package/dist/constants/index.d.ts +5 -0
  42. package/dist/constants/options.d.ts +4073 -0
  43. package/dist/constants/options.js +7 -0
  44. package/dist/constants/options.js.map +1 -0
  45. package/dist/lib/codec.d.ts +26 -1
  46. package/dist/lib/codec.js +27 -0
  47. package/dist/lib/codec.js.map +1 -1
  48. package/dist/lib/dictionary.d.ts +1 -1
  49. package/dist/lib/dictionary.js.map +1 -1
  50. package/dist/lib/native-types.d.ts +18 -0
  51. package/package.json +17 -12
@@ -1,19 +1,25 @@
1
1
  import { Packet } from '../lib/packet.js';
2
+ import { Stream } from '../lib/stream.js';
3
+ import { Encoder } from './encoder.js';
2
4
  import { Muxer } from './muxer.js';
3
5
  import { Scheduler, SchedulerControl } from './utilities/scheduler.js';
4
- import type { Stream } from '../lib/stream.js';
6
+ import type { BsfName, BsfOptionsFor } from '../constants/index.js';
5
7
  /**
6
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.
7
12
  */
8
- export interface BitstreamFilterOptions {
13
+ export interface BitstreamFilterOptions<N extends string = string> {
9
14
  /**
10
15
  * Filter-specific options.
11
16
  *
12
- * Key-value pairs of FFmpeg bitstream filter options.
13
- * These are passed directly to the filter via av_opt_set().
14
- * Available options depend on the specific filter being used.
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.
15
21
  */
16
- options?: Record<string, string | number | boolean | bigint | undefined | null>;
22
+ options?: BsfOptionsFor<N>;
17
23
  /**
18
24
  * AbortSignal for cancellation.
19
25
  *
@@ -63,7 +69,8 @@ export interface BitstreamFilterOptions {
63
69
  export declare class BitStreamFilterAPI implements Disposable {
64
70
  private ctx;
65
71
  private bsf;
66
- private stream;
72
+ private source;
73
+ private initialized;
67
74
  private packet;
68
75
  private isClosed;
69
76
  private inputQueue;
@@ -77,63 +84,55 @@ export declare class BitStreamFilterAPI implements Disposable {
77
84
  *
78
85
  * @param ctx - Filter context
79
86
  *
80
- * @param stream - Associated stream
87
+ * @param source - Input source for lazy parameter resolution
81
88
  *
82
89
  * @internal
83
90
  */
84
91
  private constructor();
85
92
  /**
86
- * Create a bitstream filter for a stream.
93
+ * Create a bitstream filter.
94
+ *
95
+ * The input source provides the codec parameters the filter is configured with.
96
+ * Pass a {@link Stream} to filter its packets directly (stream copy), or an
97
+ * {@link Encoder} to filter that encoder's output (transcode) - parameters are
98
+ * derived from the encoder once it is open. Another {@link BitStreamFilterAPI}
99
+ * may be passed to chain filters.
87
100
  *
88
- * Initializes filter with stream codec parameters.
89
- * Configures time base and prepares for packet processing.
101
+ * Initialization is lazy: filter options are validated immediately, but the
102
+ * input parameters are bound and the filter is initialized on the first packet,
103
+ * so an `Encoder` source (opened lazily on its first frame) is ready in time.
90
104
  *
91
105
  * Direct mapping to av_bsf_get_by_name() and av_bsf_alloc().
92
106
  *
93
107
  * @param filterName - Name of the bitstream filter
94
108
  *
95
- * @param stream - Stream to apply filter to
109
+ * @param source - Input source: a `Stream` (copy), `Encoder` (transcode), or upstream filter (chain)
96
110
  *
97
111
  * @param filterOptions - Optional filter-specific options
98
112
  *
99
113
  * @returns Configured bitstream filter
100
114
  *
101
- * @throws {Error} If initialization fails
102
- *
103
- * @throws {FFmpegError} If allocation or initialization fails
115
+ * @throws {FFmpegError} If the filter is not found, allocation fails, or an option is invalid
104
116
  *
105
117
  * @example
106
118
  * ```typescript
107
- * // H.264 MP4 to Annex B conversion
119
+ * // Stream copy: H.264 MP4 to Annex B conversion
108
120
  * const filter = BitStreamFilterAPI.create('h264_mp4toannexb', videoStream);
109
121
  * ```
110
122
  *
111
123
  * @example
112
124
  * ```typescript
113
- * // AAC ADTS to ASC conversion
114
- * const filter = BitStreamFilterAPI.create('aac_adtstoasc', audioStream);
115
- * ```
116
- *
117
- * @example
118
- * ```typescript
119
- * // Remove AUDs from H.264 stream
120
- * const filter = BitStreamFilterAPI.create('h264_metadata', stream, {
121
- * options: { aud: 'remove' }
122
- * });
123
- * ```
124
- *
125
- * @example
126
- * ```typescript
127
- * // Set H.264 level
128
- * const filter = BitStreamFilterAPI.create('h264_metadata', stream, {
129
- * options: { level: 51 }
125
+ * // Transcode: derive parameters from the encoder's output
126
+ * const filter = BitStreamFilterAPI.create('h264_metadata', encoder, {
127
+ * options: { aud: 'remove', level: '4.1' },
130
128
  * });
129
+ * pipeline(input, decoder, encoder, filter, output);
131
130
  * ```
132
131
  *
133
132
  * @see {@link BitStreamFilter.getByName} For filter discovery
134
133
  * @see {@link BitstreamFilterOptions} For available options
135
134
  */
136
- static create(filterName: string, stream: Stream, filterOptions?: BitstreamFilterOptions): BitStreamFilterAPI;
135
+ static create<const N extends BsfName | (string & {}) = BsfName | (string & {})>(filterName: N, source: Stream | Encoder | BitStreamFilterAPI, filterOptions?: BitstreamFilterOptions<N>): BitStreamFilterAPI;
137
136
  /**
138
137
  * Get filter name.
139
138
  *
@@ -179,6 +178,38 @@ export declare class BitStreamFilterAPI implements Disposable {
179
178
  * ```
180
179
  */
181
180
  get isBitstreamFilterOpen(): boolean;
181
+ /**
182
+ * Check if the filter has been initialized.
183
+ *
184
+ * Initialization is lazy and happens on the first processed packet, after
185
+ * which {@link outputCodecParameters} reflect the filter's output.
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * if (filter.isInitialized) {
190
+ * const params = filter.outputCodecParameters;
191
+ * }
192
+ * ```
193
+ */
194
+ get isInitialized(): boolean;
195
+ /**
196
+ * Get associated stream.
197
+ *
198
+ * Returns the stream this filter was created for. Only available when the
199
+ * filter was created from a {@link Stream}; filters created from an `Encoder`
200
+ * derive their parameters from the encoder's output instead.
201
+ *
202
+ * @returns Associated stream
203
+ *
204
+ * @throws {Error} If the filter was not created from a stream
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const stream = filter.getStream();
209
+ * console.log(`Filtering stream ${stream.index}`);
210
+ * ```
211
+ */
212
+ getStream(): Stream;
182
213
  /**
183
214
  * Send a packet to the filter.
184
215
  *
@@ -637,6 +668,43 @@ export declare class BitStreamFilterAPI implements Disposable {
637
668
  * @see {@link receive} For async version
638
669
  */
639
670
  receiveSync(): Packet | null;
671
+ /**
672
+ * Pipe output to another bitstream filter.
673
+ *
674
+ * Starts background worker for packet processing.
675
+ * Packets flow through: input → this filter → target filter.
676
+ *
677
+ * @param target - Target bitstream filter
678
+ *
679
+ * @returns Scheduler for continued chaining
680
+ *
681
+ * @example
682
+ * ```typescript
683
+ * const filter1 = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
684
+ * const filter2 = BitStreamFilterAPI.create('dump_extra', stream);
685
+ * filter1.pipeTo(filter2).pipeTo(output, 0);
686
+ * ```
687
+ */
688
+ pipeTo(target: BitStreamFilterAPI): Scheduler<Packet>;
689
+ /**
690
+ * Pipe output to muxer.
691
+ *
692
+ * Terminal stage - writes filtered packets to output file.
693
+ *
694
+ * @param output - Muxer to write to
695
+ *
696
+ * @param streamIndex - Stream index in output
697
+ *
698
+ * @returns Control interface for pipeline
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
703
+ * const control = filter.pipeTo(output, 0);
704
+ * await control.send(packet);
705
+ * ```
706
+ */
707
+ pipeTo(output: Muxer, streamIndex: number): SchedulerControl<Packet>;
640
708
  /**
641
709
  * Flush all buffered packets as async generator.
642
710
  *
@@ -686,20 +754,6 @@ export declare class BitStreamFilterAPI implements Disposable {
686
754
  * @see {@link flushPackets} For async version
687
755
  */
688
756
  flushPacketsSync(): Generator<Packet>;
689
- /**
690
- * Get associated stream.
691
- *
692
- * Returns the stream this filter was created for.
693
- *
694
- * @returns Associated stream
695
- *
696
- * @example
697
- * ```typescript
698
- * const stream = filter.getStream();
699
- * console.log(`Filtering stream ${stream.index}`);
700
- * ```
701
- */
702
- getStream(): Stream;
703
757
  /**
704
758
  * Reset filter state.
705
759
  *
@@ -748,6 +802,12 @@ export declare class BitStreamFilterAPI implements Disposable {
748
802
  * @see {@link close} For manual cleanup
749
803
  */
750
804
  [Symbol.dispose](): void;
805
+ /**
806
+ * Bind input parameters from the source and initialize the filter.
807
+ *
808
+ * @internal
809
+ */
810
+ private ensureInitialized;
751
811
  /**
752
812
  * Send packet to input queue or flush the pipeline.
753
813
  *
@@ -765,7 +825,7 @@ export declare class BitStreamFilterAPI implements Disposable {
765
825
  *
766
826
  * @internal
767
827
  */
768
- sendToQueue(packet: Packet | null): Promise<void>;
828
+ private sendToQueue;
769
829
  /**
770
830
  * Receive packet from output queue.
771
831
  *
@@ -773,48 +833,11 @@ export declare class BitStreamFilterAPI implements Disposable {
773
833
  *
774
834
  * @internal
775
835
  */
776
- receiveFromQueue(): Promise<Packet | null>;
836
+ private receiveFromQueue;
777
837
  /**
778
838
  * Worker loop for push-based processing.
779
839
  *
780
840
  * @internal
781
841
  */
782
842
  private runWorker;
783
- /**
784
- * Pipe output to another bitstream filter.
785
- *
786
- * Starts background worker for packet processing.
787
- * Packets flow through: input → this filter → target filter.
788
- *
789
- * @param target - Target bitstream filter
790
- *
791
- * @returns Scheduler for continued chaining
792
- *
793
- * @example
794
- * ```typescript
795
- * const filter1 = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
796
- * const filter2 = BitStreamFilterAPI.create('dump_extra', stream);
797
- * filter1.pipeTo(filter2).pipeTo(output, 0);
798
- * ```
799
- */
800
- pipeTo(target: BitStreamFilterAPI): Scheduler<Packet>;
801
- /**
802
- * Pipe output to muxer.
803
- *
804
- * Terminal stage - writes filtered packets to output file.
805
- *
806
- * @param output - Muxer to write to
807
- *
808
- * @param streamIndex - Stream index in output
809
- *
810
- * @returns Control interface for pipeline
811
- *
812
- * @example
813
- * ```typescript
814
- * const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
815
- * const control = filter.pipeTo(output, 0);
816
- * await control.send(packet);
817
- * ```
818
- */
819
- pipeTo(output: Muxer, streamIndex: number): SchedulerControl<Packet>;
820
843
  }