homebridge-plugin-utils 1.15.2 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/build/eslint-rules.mjs +1 -0
- package/dist/featureoptions.d.ts +83 -5
- package/dist/featureoptions.js +65 -6
- package/dist/featureoptions.js.map +1 -1
- package/dist/ffmpeg/codecs.d.ts +172 -0
- package/dist/ffmpeg/codecs.js +374 -0
- package/dist/ffmpeg/codecs.js.map +1 -0
- package/dist/ffmpeg/exec.d.ts +108 -0
- package/dist/ffmpeg/exec.js +122 -0
- package/dist/ffmpeg/exec.js.map +1 -0
- package/dist/ffmpeg/index.d.ts +8 -0
- package/dist/ffmpeg/index.js +13 -0
- package/dist/ffmpeg/index.js.map +1 -0
- package/dist/ffmpeg/options.d.ts +345 -0
- package/dist/ffmpeg/options.js +750 -0
- package/dist/ffmpeg/options.js.map +1 -0
- package/dist/ffmpeg/process.d.ts +155 -0
- package/dist/ffmpeg/process.js +344 -0
- package/dist/ffmpeg/process.js.map +1 -0
- package/dist/ffmpeg/record.d.ts +230 -0
- package/dist/ffmpeg/record.js +504 -0
- package/dist/ffmpeg/record.js.map +1 -0
- package/dist/ffmpeg/rtp.d.ts +205 -0
- package/dist/ffmpeg/rtp.js +335 -0
- package/dist/ffmpeg/rtp.js.map +1 -0
- package/dist/ffmpeg/settings.d.ts +6 -0
- package/dist/ffmpeg/settings.js +17 -0
- package/dist/ffmpeg/settings.js.map +1 -0
- package/dist/ffmpeg/stream.d.ts +143 -0
- package/dist/ffmpeg/stream.js +186 -0
- package/dist/ffmpeg/stream.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mqttclient.d.ts +161 -1
- package/dist/mqttclient.js +161 -9
- package/dist/mqttclient.js.map +1 -1
- package/dist/service.d.ts +9 -2
- package/dist/service.js +6 -0
- package/dist/service.js.map +1 -1
- package/dist/ui/featureoptions.js +65 -6
- package/dist/ui/featureoptions.js.map +1 -1
- package/dist/ui/webUi-featureoptions.mjs +5 -4
- package/dist/util.d.ts +203 -12
- package/dist/util.js +95 -12
- package/dist/util.js.map +1 -1
- package/package.json +13 -9
- package/dist/rtp.d.ts +0 -32
- package/dist/rtp.js +0 -178
- package/dist/rtp.js.map +0 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Homebridge FFmpeg transcoding, decoding, and encoding options, selecting codecs, pixel formats, and hardware acceleration for the host system.
|
|
3
|
+
*
|
|
4
|
+
* This module defines interfaces and classes for specifying, adapting, and generating FFmpeg command-line arguments tailored to the host system’s capabilities. It
|
|
5
|
+
* automates the selection of codecs, pixel formats, hardware encoders/decoders, and streaming profiles for maximum compatibility and performance.
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
*
|
|
9
|
+
* - Encapsulates all FFmpeg transcoding and streaming options (including bitrate, resolution, framerate, H.264 profiles/levels, and quality optimizations).
|
|
10
|
+
* - Detects and configures hardware-accelerated encoding and decoding (macOS VideoToolbox, Intel Quick Sync Video, and Raspberry Pi 4), falling back to software
|
|
11
|
+
* processing when required.
|
|
12
|
+
* - Dynamically generates the appropriate FFmpeg command-line arguments for livestreaming, HomeKit Secure Video (HKSV) event recording, and crop filters.
|
|
13
|
+
* - Provides strong TypeScript types and interfaces for reliable integration and extensibility in Homebridge.
|
|
14
|
+
*
|
|
15
|
+
* This module is intended for plugin authors and advanced users who need precise, robust control over FFmpeg processing pipelines, with platform-aware optimizations and
|
|
16
|
+
* safe fallbacks.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { H264Level, H264Profile, type Logging } from "homebridge";
|
|
21
|
+
import type { FfmpegCodecs } from "./codecs.js";
|
|
22
|
+
import type { HomebridgePluginLogging } from "../util.js";
|
|
23
|
+
/**
|
|
24
|
+
* Configuration options for `FfmpegOptions`, defining transcoding, decoding, logging, and hardware acceleration settings.
|
|
25
|
+
*
|
|
26
|
+
* @property codecSupport - FFmpeg codec capabilities and hardware support.
|
|
27
|
+
* @property crop - Optional. Cropping rectangle for output video.
|
|
28
|
+
* @property debug - Enable debug logging.
|
|
29
|
+
* @property hardwareDecoding - Enable hardware-accelerated video decoding if available.
|
|
30
|
+
* @property hardwareTranscoding - Enable hardware-accelerated video encoding if available.
|
|
31
|
+
* @property log - Logging interface for output and errors.
|
|
32
|
+
* @property name - Function returning the name or label for this options set.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const optionsConfig: FfmpegOptionsConfig = {
|
|
38
|
+
*
|
|
39
|
+
* codecSupport: ffmpegCodecs,
|
|
40
|
+
* crop: { width: 1, height: 1, x: 0, y: 0 },
|
|
41
|
+
* debug: false,
|
|
42
|
+
* hardwareDecoding: true,
|
|
43
|
+
* hardwareTranscoding: true,
|
|
44
|
+
* log,
|
|
45
|
+
* name: () => "Camera"
|
|
46
|
+
* };
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see FfmpegOptions
|
|
50
|
+
*
|
|
51
|
+
* @category FFmpeg
|
|
52
|
+
*/
|
|
53
|
+
export interface FfmpegOptionsConfig {
|
|
54
|
+
codecSupport: FfmpegCodecs;
|
|
55
|
+
crop?: {
|
|
56
|
+
height: number;
|
|
57
|
+
width: number;
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
};
|
|
61
|
+
debug: boolean;
|
|
62
|
+
hardwareDecoding: boolean;
|
|
63
|
+
hardwareTranscoding: boolean;
|
|
64
|
+
log: HomebridgePluginLogging | Logging;
|
|
65
|
+
name: () => string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Options used for configuring video encoding in FFmpeg operations.
|
|
69
|
+
*
|
|
70
|
+
* These options control output bitrate, framerate, resolution, H.264 profile and level, input framerate, and smart quality optimizations.
|
|
71
|
+
*
|
|
72
|
+
* @property bitrate - Target video bitrate, in kilobits per second.
|
|
73
|
+
* @property fps - Target output frames per second.
|
|
74
|
+
* @property height - Output video height, in pixels.
|
|
75
|
+
* @property idrInterval - Interval (in seconds) between keyframes (IDR frames).
|
|
76
|
+
* @property inputFps - Input (source) frames per second.
|
|
77
|
+
* @property level - H.264 profile level for output.
|
|
78
|
+
* @property profile - H.264 profile for output.
|
|
79
|
+
* @property useSmartQuality - Optional. If `true`, enables smart quality and variable bitrate optimizations. Defaults to `true`.
|
|
80
|
+
* @property width - Output video width, in pixels.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const encoderOptions: EncoderOptions = {
|
|
86
|
+
*
|
|
87
|
+
* bitrate: 3000,
|
|
88
|
+
* fps: 30,
|
|
89
|
+
* height: 1080,
|
|
90
|
+
* idrInterval: 2,
|
|
91
|
+
* inputFps: 30,
|
|
92
|
+
* level: H264Level.LEVEL4_0,
|
|
93
|
+
* profile: H264Profile.HIGH,
|
|
94
|
+
* useSmartQuality: true,
|
|
95
|
+
* width: 1920
|
|
96
|
+
* };
|
|
97
|
+
*
|
|
98
|
+
* // Use with FfmpegOptions for transcoding or streaming.
|
|
99
|
+
* const ffmpegOpts = new FfmpegOptions(optionsConfig);
|
|
100
|
+
* const args = ffmpegOpts.streamEncoder(encoderOptions);
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @see FfmpegOptions
|
|
104
|
+
* @see {@link https://ffmpeg.org/ffmpeg-codecs.html | FFmpeg Codecs Documentation}
|
|
105
|
+
*
|
|
106
|
+
* @category FFmpeg
|
|
107
|
+
*/
|
|
108
|
+
export interface EncoderOptions {
|
|
109
|
+
bitrate: number;
|
|
110
|
+
fps: number;
|
|
111
|
+
height: number;
|
|
112
|
+
idrInterval: number;
|
|
113
|
+
inputFps: number;
|
|
114
|
+
level: H264Level;
|
|
115
|
+
profile: H264Profile;
|
|
116
|
+
useSmartQuality?: boolean;
|
|
117
|
+
width: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Provides Homebridge FFmpeg transcoding, decoding, and encoding options, selecting codecs, pixel formats, and hardware acceleration for the host system.
|
|
121
|
+
*
|
|
122
|
+
* This class generates and adapts FFmpeg command-line arguments for livestreaming and event recording, optimizing for system hardware and codec availability.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* const ffmpegOpts = new FfmpegOptions(optionsConfig);
|
|
128
|
+
*
|
|
129
|
+
* // Generate video encoder arguments for streaming.
|
|
130
|
+
* const encoderOptions: EncoderOptions = {
|
|
131
|
+
*
|
|
132
|
+
* bitrate: 3000,
|
|
133
|
+
* fps: 30,
|
|
134
|
+
* height: 1080,
|
|
135
|
+
* idrInterval: 2,
|
|
136
|
+
* inputFps: 30,
|
|
137
|
+
* level: H264Level.LEVEL4_0,
|
|
138
|
+
* profile: H264Profile.HIGH,
|
|
139
|
+
* useSmartQuality: true,
|
|
140
|
+
* width: 1920
|
|
141
|
+
* };
|
|
142
|
+
* const args = ffmpegOpts.streamEncoder(encoderOptions);
|
|
143
|
+
*
|
|
144
|
+
* // Generate crop filter string, if cropping is enabled.
|
|
145
|
+
* const crop = ffmpegOpts.cropFilter;
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @see EncoderOptions
|
|
149
|
+
* @see FfmpegCodecs
|
|
150
|
+
* @see {@link https://ffmpeg.org/ffmpeg.html | FFmpeg Documentation}
|
|
151
|
+
*
|
|
152
|
+
* @category FFmpeg
|
|
153
|
+
*/
|
|
154
|
+
export declare class FfmpegOptions {
|
|
155
|
+
/**
|
|
156
|
+
* FFmpeg codec and hardware capabilities for the current host.
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
codecSupport: FfmpegCodecs;
|
|
160
|
+
/**
|
|
161
|
+
* Indicates if debug logging is enabled.
|
|
162
|
+
*/
|
|
163
|
+
readonly debug: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Logging interface for output and errors.
|
|
166
|
+
*/
|
|
167
|
+
readonly log: HomebridgePluginLogging | Logging;
|
|
168
|
+
/**
|
|
169
|
+
* Function returning the name for this options instance to be used for logging.
|
|
170
|
+
*/
|
|
171
|
+
readonly name: () => string;
|
|
172
|
+
/**
|
|
173
|
+
* The original options used to initialize this instance.
|
|
174
|
+
*/
|
|
175
|
+
readonly options: FfmpegOptionsConfig;
|
|
176
|
+
private readonly hwPixelFormat;
|
|
177
|
+
/**
|
|
178
|
+
* Creates an instance of Homebridge FFmpeg encoding and decoding options.
|
|
179
|
+
*
|
|
180
|
+
* @param options - FFmpeg options configuration.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* const ffmpegOpts = new FfmpegOptions(optionsConfig);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
constructor(options: FfmpegOptionsConfig);
|
|
189
|
+
/**
|
|
190
|
+
* Determines and configures hardware-accelerated video decoding and transcoding for the host system.
|
|
191
|
+
*
|
|
192
|
+
* This internal method checks for the availability of hardware codecs and accelerators based on the host platform and updates
|
|
193
|
+
* FFmpeg options to use the best available hardware or falls back to software processing when necessary.
|
|
194
|
+
* It logs warnings or errors if required codecs or hardware acceleration are unavailable.
|
|
195
|
+
*
|
|
196
|
+
* This method is called automatically by the `FfmpegOptions` constructor and is not intended to be called directly.
|
|
197
|
+
*
|
|
198
|
+
* @returns `true` if hardware-accelerated transcoding is enabled after configuration, otherwise `false`.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* // This method is invoked by the FfmpegOptions constructor:
|
|
204
|
+
* const ffmpegOpts = new FfmpegOptions(optionsConfig);
|
|
205
|
+
*
|
|
206
|
+
* // Hardware acceleration configuration occurs automatically.
|
|
207
|
+
* // Developers typically do not need to call configureHwAccel() directly.
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @see FfmpegCodecs
|
|
211
|
+
* @see FfmpegOptions
|
|
212
|
+
*/
|
|
213
|
+
private configureHwAccel;
|
|
214
|
+
/**
|
|
215
|
+
* Returns the audio encoder arguments to use when transcoding.
|
|
216
|
+
*
|
|
217
|
+
* @returns Array of FFmpeg command-line arguments for audio encoding.
|
|
218
|
+
*/
|
|
219
|
+
get audioEncoder(): string[];
|
|
220
|
+
/**
|
|
221
|
+
* Returns the audio decoder to use when decoding.
|
|
222
|
+
*
|
|
223
|
+
* @returns The FFmpeg audio decoder string.
|
|
224
|
+
*/
|
|
225
|
+
get audioDecoder(): string;
|
|
226
|
+
/**
|
|
227
|
+
* Returns the video decoder arguments to use for decoding video.
|
|
228
|
+
*
|
|
229
|
+
* @param codec - Optional. Codec to decode ("h264" or "hevc").
|
|
230
|
+
* @returns Array of FFmpeg command-line arguments for video decoding.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
*
|
|
234
|
+
* ```ts
|
|
235
|
+
* const args = ffmpegOpts.videoDecoder("h264");
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
videoDecoder(codec?: string): string[];
|
|
239
|
+
/**
|
|
240
|
+
* Returns the FFmpeg crop filter string, or a default no-op filter if cropping is disabled.
|
|
241
|
+
*
|
|
242
|
+
* @returns The crop filter string for FFmpeg.
|
|
243
|
+
*/
|
|
244
|
+
get cropFilter(): string;
|
|
245
|
+
/**
|
|
246
|
+
* Generates the default set of FFmpeg video encoder arguments for software transcoding using libx264.
|
|
247
|
+
*
|
|
248
|
+
* This method builds command-line options for the FFmpeg libx264 encoder based on the provided encoder options, including bitrate, H.264 profile and level, pixel
|
|
249
|
+
* format, frame rate, buffer size, and optional smart quality settings. It is used internally when hardware-accelerated transcoding is not enabled or supported.
|
|
250
|
+
*
|
|
251
|
+
* @param options - The encoder options to use for generating FFmpeg arguments.
|
|
252
|
+
*
|
|
253
|
+
* @returns An array of FFmpeg command-line arguments for software video encoding.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
*
|
|
257
|
+
* ```ts
|
|
258
|
+
* const encoderOptions: EncoderOptions = {
|
|
259
|
+
*
|
|
260
|
+
* bitrate: 2000,
|
|
261
|
+
* fps: 30,
|
|
262
|
+
* height: 720,
|
|
263
|
+
* idrInterval: 2,
|
|
264
|
+
* inputFps: 30,
|
|
265
|
+
* level: H264Level.LEVEL3_1,
|
|
266
|
+
* profile: H264Profile.MAIN,
|
|
267
|
+
* useSmartQuality: true,
|
|
268
|
+
* width: 1280
|
|
269
|
+
* };
|
|
270
|
+
*
|
|
271
|
+
* const args = ffmpegOpts['defaultVideoEncoderOptions'](encoderOptions);
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @see EncoderOptions
|
|
275
|
+
*/
|
|
276
|
+
private defaultVideoEncoderOptions;
|
|
277
|
+
/**
|
|
278
|
+
* Returns the video encoder options to use for HomeKit Secure Video (HKSV) event recording.
|
|
279
|
+
*
|
|
280
|
+
* @param options - Encoder options to use.
|
|
281
|
+
* @returns Array of FFmpeg command-line arguments for video encoding.
|
|
282
|
+
*/
|
|
283
|
+
recordEncoder(options: EncoderOptions): string[];
|
|
284
|
+
/**
|
|
285
|
+
* Returns the video encoder options to use when transcoding for livestreaming.
|
|
286
|
+
*
|
|
287
|
+
* @param options - Encoder options to use.
|
|
288
|
+
* @returns Array of FFmpeg command-line arguments for video encoding.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
*
|
|
292
|
+
* ```ts
|
|
293
|
+
* const args = ffmpegOpts.streamEncoder(encoderOptions);
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
streamEncoder(options: EncoderOptions): string[];
|
|
297
|
+
/**
|
|
298
|
+
* Returns the maximum pixel count supported by a specific hardware encoder on the host system, or `Infinity` if not limited.
|
|
299
|
+
*
|
|
300
|
+
* @returns Maximum supported pixel count.
|
|
301
|
+
*/
|
|
302
|
+
get hostSystemMaxPixels(): number;
|
|
303
|
+
/**
|
|
304
|
+
* Converts a HomeKit H.264 level enum value to the corresponding FFmpeg string or numeric representation.
|
|
305
|
+
*
|
|
306
|
+
* This helper is used to translate between HomeKit’s `H264Level` enum and the string or numeric format expected by FFmpeg’s `-level:v` argument.
|
|
307
|
+
*
|
|
308
|
+
* @param level - The H.264 level to translate.
|
|
309
|
+
* @param numeric - Optional. If `true`, returns the numeric representation (e.g., "31"). If `false` or omitted, returns the standard string format (e.g., "3.1").
|
|
310
|
+
*
|
|
311
|
+
* @returns The FFmpeg-compatible H.264 level string or numeric value.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
*
|
|
315
|
+
* ```ts
|
|
316
|
+
* ffmpegOpts['getH264Level'](H264Level.LEVEL3_1); // "3.1"
|
|
317
|
+
*
|
|
318
|
+
* ffmpegOpts['getH264Level'](H264Level.LEVEL4_0, true); // "40"
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @see H264Level
|
|
322
|
+
*/
|
|
323
|
+
private getH264Level;
|
|
324
|
+
/**
|
|
325
|
+
* Converts a HomeKit H.264 profile enum value to the corresponding FFmpeg string or numeric representation.
|
|
326
|
+
*
|
|
327
|
+
* This helper is used to translate between HomeKit’s `H264Profile` enum and the string or numeric format expected by FFmpeg’s `-profile:v` argument.
|
|
328
|
+
*
|
|
329
|
+
* @param profile - The H.264 profile to translate.
|
|
330
|
+
* @param numeric - Optional. If `true`, returns the numeric representation (e.g., "100"). If `false` or omitted, returns the standard string format (e.g., "high").
|
|
331
|
+
*
|
|
332
|
+
* @returns The FFmpeg-compatible H.264 profile string or numeric value.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
*
|
|
336
|
+
* ```ts
|
|
337
|
+
* ffmpegOpts['getH264Profile'](H264Profile.HIGH); // "high"
|
|
338
|
+
*
|
|
339
|
+
* ffmpegOpts['getH264Profile'](H264Profile.BASELINE, true); // "66"
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
342
|
+
* @see H264Profile
|
|
343
|
+
*/
|
|
344
|
+
private getH264Profile;
|
|
345
|
+
}
|