node-av 6.2.0-beta.31 → 6.2.0-beta.33

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 (48) hide show
  1. package/README.md +0 -10
  2. package/dist/api/data/test_av1.ivf +0 -0
  3. package/dist/api/data/test_hevc.h265 +0 -0
  4. package/dist/api/data/test_vp9.ivf +0 -0
  5. package/dist/api/decoder.d.ts +117 -2
  6. package/dist/api/decoder.js +289 -22
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +26 -3
  9. package/dist/api/encoder.js +142 -76
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +25 -1
  12. package/dist/api/filter-presets.js +63 -3
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +62 -3
  15. package/dist/api/filter.js +118 -36
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/fmp4-stream.d.ts +1 -0
  18. package/dist/api/fmp4-stream.js +34 -49
  19. package/dist/api/fmp4-stream.js.map +1 -1
  20. package/dist/api/hardware.js +12 -9
  21. package/dist/api/hardware.js.map +1 -1
  22. package/dist/api/muxer.js +33 -24
  23. package/dist/api/muxer.js.map +1 -1
  24. package/dist/api/rtp-stream.d.ts +10 -0
  25. package/dist/api/rtp-stream.js +70 -67
  26. package/dist/api/rtp-stream.js.map +1 -1
  27. package/dist/api/scaler.d.ts +17 -1
  28. package/dist/api/scaler.js +41 -10
  29. package/dist/api/scaler.js.map +1 -1
  30. package/dist/api/utilities/live-decoding.d.ts +15 -0
  31. package/dist/api/utilities/live-decoding.js +32 -0
  32. package/dist/api/utilities/live-decoding.js.map +1 -0
  33. package/dist/api/utilities/scale-size.d.ts +22 -0
  34. package/dist/api/utilities/scale-size.js +31 -0
  35. package/dist/api/utilities/scale-size.js.map +1 -0
  36. package/dist/api/utilities/video-transcode.d.ts +183 -0
  37. package/dist/api/utilities/video-transcode.js +567 -0
  38. package/dist/api/utilities/video-transcode.js.map +1 -0
  39. package/dist/lib/binding.d.ts +1 -0
  40. package/dist/lib/binding.js.map +1 -1
  41. package/dist/lib/native-types.d.ts +2 -0
  42. package/dist/lib/output-format.d.ts +42 -0
  43. package/dist/lib/output-format.js +46 -0
  44. package/dist/lib/output-format.js.map +1 -1
  45. package/dist/lib/utilities.d.ts +26 -0
  46. package/dist/lib/utilities.js +28 -0
  47. package/dist/lib/utilities.js.map +1 -1
  48. package/package.json +7 -18
@@ -0,0 +1,183 @@
1
+ import { Codec } from '../../lib/codec.js';
2
+ import { Frame } from '../../lib/frame.js';
3
+ import { Decoder } from '../decoder.js';
4
+ import { FilterAPI } from '../filter.js';
5
+ import type { AVCodecID, AVPixelFormat } from '../../constants/index.js';
6
+ import type { Stream } from '../../lib/stream.js';
7
+ import type { DecoderOptions } from '../decoder.js';
8
+ import type { EncoderOptions } from '../encoder.js';
9
+ import type { BaseCodecName, HardwareContext } from '../hardware.js';
10
+ /**
11
+ * What the video encoder of a transcode has to receive.
12
+ *
13
+ * @internal
14
+ */
15
+ export interface VideoTranscodeTarget {
16
+ /** Output width, -1 to keep the source width or follow the height */
17
+ width: number;
18
+ /** Output height, -1 to keep the source height or follow the width */
19
+ height: number;
20
+ /** Output frame rate, when it changes */
21
+ fps?: number;
22
+ /** The encoder */
23
+ encoder: Codec;
24
+ /** The device the frames are decoded and filtered on */
25
+ hardware?: HardwareContext | null;
26
+ }
27
+ /**
28
+ * A frame as the transcode graph sees it.
29
+ *
30
+ * @internal
31
+ */
32
+ export interface VideoGraphInput {
33
+ /** The frame lives on a device */
34
+ hw: boolean;
35
+ /** The frame lives on the transcode's device */
36
+ onDevice: boolean;
37
+ /** Pixel format, the software format of device frames */
38
+ format: AVPixelFormat;
39
+ width: number;
40
+ height: number;
41
+ }
42
+ /**
43
+ * Filters a device has for a transcode.
44
+ *
45
+ * @internal
46
+ */
47
+ export interface DeviceFilters {
48
+ /** Scales and converts the pixel format on the device */
49
+ scaler: boolean;
50
+ /** Uploads software frames well enough to scale them there instead of on the CPU */
51
+ upload: boolean;
52
+ }
53
+ /**
54
+ * Build the filter graph that brings a decoded frame to the video encoder of a transcode.
55
+ *
56
+ * Frames stay on the device whenever the encoder takes them there, and scaling
57
+ * and format conversion run on the device whenever it has a scaler. Hardware
58
+ * encoders get 8-bit 4:2:0 in NV12: VAAPI decodes JPEG into planar or 4:2:2
59
+ * surfaces and 10-bit sources come as P010, which H.264 hardware encoders reject.
60
+ * Software encoders get yuv420p when the frames have to be converted anyway, it
61
+ * is the layout every browser and HomeKit decodes (unlike the 4:2:2 profile x264
62
+ * picks for a 4:2:2 JPEG camera). Packed sources such as yuyv422 are converted
63
+ * too, swscale cannot scale them in place.
64
+ *
65
+ * Decided per frame, not per stream: a hardware decoder falls back to software
66
+ * frames for input it cannot handle, e.g. 4:2:2 JPEG on NVDEC.
67
+ *
68
+ * @param input - The frame
69
+ *
70
+ * @param target - The encoder's needs
71
+ *
72
+ * @param filters - What the target's device has, see {@link findDeviceFilters}
73
+ *
74
+ * @returns The filter description, `null` when the frame can go to the encoder as it is
75
+ *
76
+ * @internal
77
+ */
78
+ export declare function videoTranscodeGraph(input: VideoGraphInput, target: VideoTranscodeTarget, filters: DeviceFilters): string;
79
+ /**
80
+ * Describe a decoded frame for {@link videoTranscodeGraph}.
81
+ *
82
+ * @param frame - The frame
83
+ *
84
+ * @param hardware - The transcode's device, if any
85
+ *
86
+ * @returns Where the frame lives, its format and size
87
+ *
88
+ * @internal
89
+ */
90
+ export declare function describeVideoFrame(frame: Frame, hardware?: HardwareContext | null): VideoGraphInput;
91
+ /**
92
+ * Create the filter between the video decoder (or frame source) and the encoder of a transcode.
93
+ *
94
+ * The graph is built by {@link videoTranscodeGraph} from the first frame and
95
+ * again whenever the frames change, e.g. when the decoder falls back to software.
96
+ * A graph whose device filters fail to configure is replaced by one that
97
+ * converts in software.
98
+ *
99
+ * @param target - The encoder's needs
100
+ *
101
+ * @param filters - The device's filters, found by default
102
+ *
103
+ * @returns The filter
104
+ *
105
+ * @internal
106
+ */
107
+ export declare function createVideoTranscodeFilter(target: VideoTranscodeTarget, filters?: DeviceFilters): FilterAPI;
108
+ /**
109
+ * Open the video decoder of a transcode, on the device unless it fails to open there.
110
+ *
111
+ * A device decoder that opens but then produces nothing moves to software on
112
+ * its own ({@link DecoderOptions.hardwareFallback}).
113
+ *
114
+ * @param stream - The video stream
115
+ *
116
+ * @param hardware - The device to decode on, if any
117
+ *
118
+ * @param options - Decoder options besides the device
119
+ *
120
+ * @returns The decoder
121
+ *
122
+ * @throws {FFmpegError} If no software decoder opens either
123
+ *
124
+ * @internal
125
+ */
126
+ export declare function openTranscodeDecoder(stream: Stream, hardware: HardwareContext | null | undefined, options: DecoderOptions): Promise<Decoder>;
127
+ /**
128
+ * Find the software encoder for a codec.
129
+ *
130
+ * FFmpeg picks the first encoder registered for a codec. The Linux arm64
131
+ * builds register the Rockchip MPP encoders ahead of libx264 and libx265, and
132
+ * those fail to open on every other arm64 machine, e.g. a Raspberry Pi.
133
+ *
134
+ * @param codecId - The codec to encode
135
+ *
136
+ * @returns The first encoder for the codec that is no hardware encoder, FFmpeg's pick when there is none
137
+ *
138
+ * @internal
139
+ */
140
+ export declare function findSoftwareEncoder(codecId: AVCodecID): Codec | null;
141
+ /**
142
+ * Find the device's encoder for a codec, if it works on this machine.
143
+ *
144
+ * @param hardware - The device, if any
145
+ *
146
+ * @param codec - The codec to encode
147
+ *
148
+ * @param options - Encoder options the encoder will get, some drivers need them to open (e.g. `low_power`)
149
+ *
150
+ * @returns The hardware encoder, or null to encode in software
151
+ *
152
+ * @internal
153
+ */
154
+ export declare function findUsableHardwareEncoder(hardware: HardwareContext | null | undefined, codec: BaseCodecName | AVCodecID, options?: EncoderOptions['options']): Promise<Codec | null>;
155
+ /**
156
+ * Check whether a hardware encoder works on this machine, by encoding a test frame once.
157
+ *
158
+ * Finding an encoder says nothing about the driver: NVENC refuses to open
159
+ * when the driver is older than the API it was built against, many GPUs have
160
+ * no encoder at all. A failed encoder is passed over for a minute, then tried
161
+ * again. Concurrent callers share one test.
162
+ *
163
+ * @param encoder - The hardware encoder
164
+ *
165
+ * @param hardware - The device it encodes on
166
+ *
167
+ * @param options - Encoder options the encoder will get
168
+ *
169
+ * @returns Whether it encoded the frame
170
+ *
171
+ * @internal
172
+ */
173
+ export declare function canEncodeOnDevice(encoder: Codec, hardware: HardwareContext, options?: EncoderOptions['options']): Promise<boolean>;
174
+ /**
175
+ * Find out which transcode filters a device has in this FFmpeg build.
176
+ *
177
+ * @param hardware - The device, if any
178
+ *
179
+ * @returns Its filters, none without a device
180
+ *
181
+ * @internal
182
+ */
183
+ export declare function findDeviceFilters(hardware: HardwareContext | null | undefined): DeviceFilters;