node-av 6.2.0-beta.9 → 7.0.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.
Files changed (116) hide show
  1. package/README.md +7 -19
  2. package/dist/api/audio-frame-buffer.d.ts +378 -19
  3. package/dist/api/audio-frame-buffer.js +715 -101
  4. package/dist/api/audio-frame-buffer.js.map +1 -1
  5. package/dist/api/data/test_av1.ivf +0 -0
  6. package/dist/api/data/test_hevc.h265 +0 -0
  7. package/dist/api/data/test_vp9.ivf +0 -0
  8. package/dist/api/decoder.d.ts +117 -2
  9. package/dist/api/decoder.js +290 -23
  10. package/dist/api/decoder.js.map +1 -1
  11. package/dist/api/demuxer.d.ts +19 -3
  12. package/dist/api/demuxer.js +95 -29
  13. package/dist/api/demuxer.js.map +1 -1
  14. package/dist/api/encoder-pool.js +9 -1
  15. package/dist/api/encoder-pool.js.map +1 -1
  16. package/dist/api/encoder.d.ts +100 -6
  17. package/dist/api/encoder.js +249 -108
  18. package/dist/api/encoder.js.map +1 -1
  19. package/dist/api/filter-presets.d.ts +25 -1
  20. package/dist/api/filter-presets.js +67 -5
  21. package/dist/api/filter-presets.js.map +1 -1
  22. package/dist/api/filter.d.ts +62 -3
  23. package/dist/api/filter.js +118 -36
  24. package/dist/api/filter.js.map +1 -1
  25. package/dist/api/fmp4-stream.d.ts +179 -15
  26. package/dist/api/fmp4-stream.js +341 -120
  27. package/dist/api/fmp4-stream.js.map +1 -1
  28. package/dist/api/hardware.d.ts +2 -0
  29. package/dist/api/hardware.js +33 -10
  30. package/dist/api/hardware.js.map +1 -1
  31. package/dist/api/index.d.ts +2 -2
  32. package/dist/api/index.js.map +1 -1
  33. package/dist/api/io-stream.d.ts +3 -2
  34. package/dist/api/io-stream.js +23 -7
  35. package/dist/api/io-stream.js.map +1 -1
  36. package/dist/api/muxer.d.ts +276 -7
  37. package/dist/api/muxer.js +649 -116
  38. package/dist/api/muxer.js.map +1 -1
  39. package/dist/api/pipeline.d.ts +22 -0
  40. package/dist/api/pipeline.js +53 -0
  41. package/dist/api/pipeline.js.map +1 -1
  42. package/dist/api/rtp-stream.d.ts +54 -33
  43. package/dist/api/rtp-stream.js +232 -153
  44. package/dist/api/rtp-stream.js.map +1 -1
  45. package/dist/api/scaler.d.ts +39 -6
  46. package/dist/api/scaler.js +72 -18
  47. package/dist/api/scaler.js.map +1 -1
  48. package/dist/api/utilities/live-decoding.d.ts +15 -0
  49. package/dist/api/utilities/live-decoding.js +32 -0
  50. package/dist/api/utilities/live-decoding.js.map +1 -0
  51. package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
  52. package/dist/api/utilities/packet-age-watchdog.js +594 -0
  53. package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
  54. package/dist/api/utilities/scale-size.d.ts +51 -0
  55. package/dist/api/utilities/scale-size.js +55 -0
  56. package/dist/api/utilities/scale-size.js.map +1 -0
  57. package/dist/api/utilities/video-transcode.d.ts +218 -0
  58. package/dist/api/utilities/video-transcode.js +624 -0
  59. package/dist/api/utilities/video-transcode.js.map +1 -0
  60. package/dist/constants/bsf-options.d.ts +32 -8
  61. package/dist/constants/constants.d.ts +36 -114
  62. package/dist/constants/constants.js +32 -95
  63. package/dist/constants/constants.js.map +1 -1
  64. package/dist/constants/decoders.d.ts +74 -74
  65. package/dist/constants/decoders.js +79 -77
  66. package/dist/constants/decoders.js.map +1 -1
  67. package/dist/constants/encoders.d.ts +20 -21
  68. package/dist/constants/encoders.js +25 -24
  69. package/dist/constants/encoders.js.map +1 -1
  70. package/dist/constants/filter-options.d.ts +1378 -194
  71. package/dist/constants/format-options.d.ts +1342 -83
  72. package/dist/constants/formats.d.ts +2 -2
  73. package/dist/constants/options.d.ts +2261 -125
  74. package/dist/ffmpeg/utils.js +7 -4
  75. package/dist/ffmpeg/utils.js.map +1 -1
  76. package/dist/ffmpeg/version.d.ts +1 -1
  77. package/dist/ffmpeg/version.js +1 -1
  78. package/dist/ffmpeg/version.js.map +1 -1
  79. package/dist/lib/binding.d.ts +10 -1
  80. package/dist/lib/binding.js +25 -16
  81. package/dist/lib/binding.js.map +1 -1
  82. package/dist/lib/bitstream-filter-context.d.ts +2 -0
  83. package/dist/lib/bitstream-filter-context.js +2 -0
  84. package/dist/lib/bitstream-filter-context.js.map +1 -1
  85. package/dist/lib/filter-context.d.ts +3 -0
  86. package/dist/lib/filter-context.js +3 -0
  87. package/dist/lib/filter-context.js.map +1 -1
  88. package/dist/lib/filter-graph-segment.d.ts +3 -2
  89. package/dist/lib/filter-graph-segment.js +3 -2
  90. package/dist/lib/filter-graph-segment.js.map +1 -1
  91. package/dist/lib/filter-graph.d.ts +4 -4
  92. package/dist/lib/filter-graph.js +4 -4
  93. package/dist/lib/filter-inout.d.ts +4 -0
  94. package/dist/lib/filter-inout.js +4 -0
  95. package/dist/lib/filter-inout.js.map +1 -1
  96. package/dist/lib/format-context.d.ts +27 -3
  97. package/dist/lib/format-context.js +30 -6
  98. package/dist/lib/format-context.js.map +1 -1
  99. package/dist/lib/frame.d.ts +6 -2
  100. package/dist/lib/frame.js +11 -3
  101. package/dist/lib/frame.js.map +1 -1
  102. package/dist/lib/io-context.d.ts +4 -2
  103. package/dist/lib/io-context.js +4 -2
  104. package/dist/lib/io-context.js.map +1 -1
  105. package/dist/lib/native-types.d.ts +7 -3
  106. package/dist/lib/output-format.d.ts +42 -0
  107. package/dist/lib/output-format.js +46 -0
  108. package/dist/lib/output-format.js.map +1 -1
  109. package/dist/lib/stream.d.ts +5 -0
  110. package/dist/lib/stream.js +5 -0
  111. package/dist/lib/stream.js.map +1 -1
  112. package/dist/lib/utilities.d.ts +26 -0
  113. package/dist/lib/utilities.js +28 -0
  114. package/dist/lib/utilities.js.map +1 -1
  115. package/install/check.js +14 -16
  116. package/package.json +28 -44
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Resolve a scale target where -1 keeps the source aspect ratio.
3
+ *
4
+ * Like the scale filter's -2: the derived side is rounded to an even number so
5
+ * 4:2:0 encoders accept it. Both sides -1 keeps the source size.
6
+ *
7
+ * @param srcWidth - Source width
8
+ *
9
+ * @param srcHeight - Source height
10
+ *
11
+ * @param width - Target width, or -1 to derive it from the height
12
+ *
13
+ * @param height - Target height, or -1 to derive it from the width
14
+ *
15
+ * @returns The target size
16
+ *
17
+ * @internal
18
+ */
19
+ export function resolveScaleSize(srcWidth, srcHeight, width, height) {
20
+ if (width < 0 && height < 0) {
21
+ return { width: srcWidth, height: srcHeight };
22
+ }
23
+ if (width < 0) {
24
+ return { width: Math.max(2, Math.round((height * srcWidth) / srcHeight / 2) * 2), height };
25
+ }
26
+ if (height < 0) {
27
+ return { width, height: Math.max(2, Math.round((width * srcHeight) / srcWidth / 2) * 2) };
28
+ }
29
+ return { width, height };
30
+ }
31
+ /**
32
+ * Scale target and output size of a transcode, never larger than the source.
33
+ *
34
+ * A requested width or height above the source keeps the source size, since a
35
+ * bigger picture only raises the bitrate.
36
+ *
37
+ * @param srcWidth - Source width, 0 when unknown before the first frame
38
+ *
39
+ * @param srcHeight - Source height, 0 when unknown before the first frame
40
+ *
41
+ * @param width - Requested width, or -1 to derive it from the height
42
+ *
43
+ * @param height - Requested height, or -1 to derive it from the width
44
+ *
45
+ * @returns The target for the scale filter (-1 follows the source) and the
46
+ * resolved output size, undefined while the source size is unknown
47
+ *
48
+ * @internal
49
+ */
50
+ export function transcodeScale(srcWidth, srcHeight, width = -1, height = -1) {
51
+ const known = srcWidth > 0 && srcHeight > 0;
52
+ const target = known && (width > srcWidth || height > srcHeight) ? { width: -1, height: -1 } : { width, height };
53
+ return { target, output: known ? resolveScaleSize(srcWidth, srcHeight, target.width, target.height) : undefined };
54
+ }
55
+ //# sourceMappingURL=scale-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale-size.js","sourceRoot":"","sources":["../../../src/api/utilities/scale-size.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,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CAAC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACpH,CAAC"}
@@ -0,0 +1,218 @@
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 { CodecContext } from '../../lib/codec-context.js';
7
+ import type { Stream } from '../../lib/stream.js';
8
+ import type { DecoderOptions } from '../decoder.js';
9
+ import type { EncoderOptions } from '../encoder.js';
10
+ import type { BaseCodecName, HardwareContext } from '../hardware.js';
11
+ /**
12
+ * What the video encoder of a transcode has to receive.
13
+ *
14
+ * @internal
15
+ */
16
+ export interface VideoTranscodeTarget {
17
+ /** Output width, -1 to keep the source width or follow the height */
18
+ width: number;
19
+ /** Output height, -1 to keep the source height or follow the width */
20
+ height: number;
21
+ /** Output frame rate, when it changes */
22
+ fps?: number;
23
+ /** The encoder */
24
+ encoder: Codec;
25
+ /** The device the frames are decoded and filtered on */
26
+ hardware?: HardwareContext | null;
27
+ }
28
+ /**
29
+ * A frame as the transcode graph sees it.
30
+ *
31
+ * @internal
32
+ */
33
+ export interface VideoGraphInput {
34
+ /** The frame lives on a device */
35
+ hw: boolean;
36
+ /** The frame lives on the transcode's device */
37
+ onDevice: boolean;
38
+ /** Pixel format, the software format of device frames */
39
+ format: AVPixelFormat;
40
+ width: number;
41
+ height: number;
42
+ }
43
+ /**
44
+ * Filters a device has for a transcode.
45
+ *
46
+ * @internal
47
+ */
48
+ export interface DeviceFilters {
49
+ /** Scales and converts the pixel format on the device */
50
+ scaler: boolean;
51
+ /** Uploads software frames well enough to scale them there instead of on the CPU */
52
+ upload: boolean;
53
+ }
54
+ /**
55
+ * Build the filter graph that brings a decoded frame to the video encoder of a transcode.
56
+ *
57
+ * Frames stay on the device whenever the encoder takes them there, and scaling
58
+ * and format conversion run on the device whenever it has a scaler. Hardware
59
+ * encoders get 8-bit 4:2:0 in NV12: VAAPI decodes JPEG into planar or 4:2:2
60
+ * surfaces and 10-bit sources come as P010, which H.264 hardware encoders reject.
61
+ * Software encoders get yuv420p when the frames have to be converted anyway, it
62
+ * is the layout every browser and HomeKit decodes (unlike the 4:2:2 profile x264
63
+ * picks for a 4:2:2 JPEG camera). Packed sources such as yuyv422 are converted
64
+ * too, swscale cannot scale them in place.
65
+ *
66
+ * Decided per frame, not per stream: a hardware decoder falls back to software
67
+ * frames for input it cannot handle, e.g. 4:2:2 JPEG on NVDEC.
68
+ *
69
+ * @param input - The frame
70
+ *
71
+ * @param target - The encoder's needs
72
+ *
73
+ * @param filters - What the target's device has, see {@link findDeviceFilters}
74
+ *
75
+ * @returns The filter description, `null` when the frame can go to the encoder as it is
76
+ *
77
+ * @internal
78
+ */
79
+ export declare function videoTranscodeGraph(input: VideoGraphInput, target: VideoTranscodeTarget, filters: DeviceFilters): string;
80
+ /**
81
+ * Describe a decoded frame for {@link videoTranscodeGraph}.
82
+ *
83
+ * @param frame - The frame
84
+ *
85
+ * @param hardware - The transcode's device, if any
86
+ *
87
+ * @returns Where the frame lives, its format and size
88
+ *
89
+ * @internal
90
+ */
91
+ export declare function describeVideoFrame(frame: Frame, hardware?: HardwareContext | null): VideoGraphInput;
92
+ /**
93
+ * Create the filter between the video decoder (or frame source) and the encoder of a transcode.
94
+ *
95
+ * The graph is built by {@link videoTranscodeGraph} from the first frame and
96
+ * again whenever the frames change, e.g. when the decoder falls back to software.
97
+ * A graph whose device filters fail to configure is replaced by one that
98
+ * converts in software.
99
+ *
100
+ * @param target - The encoder's needs
101
+ *
102
+ * @param filters - The device's filters, found by default
103
+ *
104
+ * @returns The filter
105
+ *
106
+ * @internal
107
+ */
108
+ export declare function createVideoTranscodeFilter(target: VideoTranscodeTarget, filters?: DeviceFilters): FilterAPI;
109
+ /**
110
+ * Open the video decoder of a transcode, on the device unless it fails to open there.
111
+ *
112
+ * A device decoder that opens but then produces nothing moves to software on
113
+ * its own ({@link DecoderOptions.hardwareFallback}).
114
+ *
115
+ * @param stream - The video stream
116
+ *
117
+ * @param hardware - The device to decode on, if any
118
+ *
119
+ * @param options - Decoder options besides the device
120
+ *
121
+ * @returns The decoder
122
+ *
123
+ * @throws {FFmpegError} If no software decoder opens either
124
+ *
125
+ * @internal
126
+ */
127
+ export declare function openTranscodeDecoder(stream: Stream, hardware: HardwareContext | null | undefined, options: DecoderOptions): Promise<Decoder>;
128
+ /**
129
+ * Set the video bitrate on the encoder context.
130
+ *
131
+ * Sets the target bitrate together with a VBV cap (maxrate + a 1s buffer).
132
+ * Encoder.create() always seeds a default target bitrate (1 Mbps for video),
133
+ * so the target MUST be set along with the cap, a cap above the seeded target
134
+ * changes nothing. Without a bitrate the target follows the picture size and
135
+ * frame rate, see {@link defaultVideoBitrate}.
136
+ *
137
+ * @param ctx - Encoder codec context
138
+ *
139
+ * @param bitrate - Maximum bitrate in bits per second, or undefined
140
+ *
141
+ * @internal
142
+ */
143
+ export declare function applyVideoBitrate(ctx: CodecContext, bitrate: number | undefined): void;
144
+ /**
145
+ * Find the software encoder for a codec.
146
+ *
147
+ * FFmpeg picks the first encoder registered for a codec. The Linux arm64
148
+ * builds register the Rockchip MPP encoders ahead of libx264 and libx265, and
149
+ * those fail to open on every other arm64 machine, e.g. a Raspberry Pi.
150
+ *
151
+ * @param codecId - The codec to encode
152
+ *
153
+ * @returns The first encoder for the codec that is no hardware encoder, FFmpeg's pick when there is none
154
+ *
155
+ * @internal
156
+ */
157
+ export declare function findSoftwareEncoder(codecId: AVCodecID): Codec | null;
158
+ /**
159
+ * Find the device's encoder for a codec, if it works on this machine.
160
+ *
161
+ * @param hardware - The device, if any
162
+ *
163
+ * @param codec - The codec to encode
164
+ *
165
+ * @param options - Encoder options the encoder will get, some drivers need them to open (e.g. `low_power`)
166
+ *
167
+ * @param size - The size it will encode, hardware encoders have a maximum that differs per GPU
168
+ *
169
+ * @param size.width - Width
170
+ *
171
+ * @param size.height - Height
172
+ *
173
+ * @returns The hardware encoder, or null to encode in software
174
+ *
175
+ * @internal
176
+ */
177
+ export declare function findUsableHardwareEncoder(hardware: HardwareContext | null | undefined, codec: BaseCodecName | AVCodecID, options?: EncoderOptions['options'], size?: {
178
+ width: number;
179
+ height: number;
180
+ }): Promise<Codec | null>;
181
+ /**
182
+ * Check whether a hardware encoder works on this machine, by encoding a test frame once.
183
+ *
184
+ * Finding an encoder says nothing about the driver: NVENC refuses to open
185
+ * when the driver is older than the API it was built against, many GPUs have
186
+ * no encoder at all. A failed encoder is passed over for a minute, then tried
187
+ * again. Concurrent callers share one test.
188
+ *
189
+ * @param encoder - The hardware encoder
190
+ *
191
+ * @param hardware - The device it encodes on
192
+ *
193
+ * @param options - Encoder options the encoder will get
194
+ *
195
+ * @param size - Size of the test frame
196
+ *
197
+ * @param size.width - Width
198
+ *
199
+ * @param size.height - Height
200
+ *
201
+ * @returns Whether it encoded the frame
202
+ *
203
+ * @internal
204
+ */
205
+ export declare function canEncodeOnDevice(encoder: Codec, hardware: HardwareContext, options?: EncoderOptions['options'], size?: {
206
+ width: number;
207
+ height: number;
208
+ }): Promise<boolean>;
209
+ /**
210
+ * Find out which transcode filters a device has in this FFmpeg build.
211
+ *
212
+ * @param hardware - The device, if any
213
+ *
214
+ * @returns Its filters, none without a device
215
+ *
216
+ * @internal
217
+ */
218
+ export declare function findDeviceFilters(hardware: HardwareContext | null | undefined): DeviceFilters;