prismcast 1.9.0 → 1.10.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/dist/app.d.ts +1 -1
- package/dist/app.js +27 -9
- package/dist/app.js.map +1 -1
- package/dist/browser/cdp.js +7 -7
- package/dist/browser/cdp.js.map +1 -1
- package/dist/browser/channelSelection.d.ts +41 -11
- package/dist/browser/channelSelection.js +75 -24
- package/dist/browser/channelSelection.js.map +1 -1
- package/dist/browser/display.d.ts +1 -1
- package/dist/browser/index.d.ts +8 -8
- package/dist/browser/index.js +42 -43
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/login.d.ts +2 -2
- package/dist/browser/login.js +1 -1
- package/dist/browser/manifestInterceptor.d.ts +77 -0
- package/dist/browser/manifestInterceptor.js +323 -0
- package/dist/browser/manifestInterceptor.js.map +1 -0
- package/dist/browser/precaching.js +4 -4
- package/dist/browser/tuning/comcastPolymer.d.ts +1 -1
- package/dist/browser/tuning/cox.d.ts +1 -1
- package/dist/browser/tuning/directv.d.ts +1 -1
- package/dist/browser/tuning/directv.js +61 -62
- package/dist/browser/tuning/directv.js.map +1 -1
- package/dist/browser/tuning/fox.d.ts +1 -1
- package/dist/browser/tuning/fox.js +171 -14
- package/dist/browser/tuning/fox.js.map +1 -1
- package/dist/browser/tuning/hbo.d.ts +1 -1
- package/dist/browser/tuning/hbo.js +6 -6
- package/dist/browser/tuning/hbo.js.map +1 -1
- package/dist/browser/tuning/hulu.d.ts +1 -1
- package/dist/browser/tuning/hulu.js +117 -110
- package/dist/browser/tuning/hulu.js.map +1 -1
- package/dist/browser/tuning/shared.d.ts +3 -3
- package/dist/browser/tuning/shared.js +5 -5
- package/dist/browser/tuning/sling.d.ts +1 -1
- package/dist/browser/tuning/sling.js +28 -28
- package/dist/browser/tuning/sling.js.map +1 -1
- package/dist/browser/tuning/spectrum.d.ts +1 -1
- package/dist/browser/tuning/spectrum.js +21 -22
- package/dist/browser/tuning/spectrum.js.map +1 -1
- package/dist/browser/tuning/thumbnailRow.d.ts +1 -1
- package/dist/browser/tuning/thumbnailRow.js +1 -1
- package/dist/browser/tuning/tileClick.d.ts +1 -1
- package/dist/browser/tuning/tileClick.js +5 -5
- package/dist/browser/tuning/xfinity.d.ts +1 -1
- package/dist/browser/tuning/youtubeTv.d.ts +1 -1
- package/dist/browser/tuning/youtubeTv.js +17 -18
- package/dist/browser/tuning/youtubeTv.js.map +1 -1
- package/dist/browser/video.d.ts +20 -6
- package/dist/browser/video.js +30 -38
- package/dist/browser/video.js.map +1 -1
- package/dist/channels/index.d.ts +1 -2
- package/dist/channels/index.js +73 -40
- package/dist/channels/index.js.map +1 -1
- package/dist/config/channelForm.d.ts +58 -0
- package/dist/config/channelForm.js +129 -0
- package/dist/config/channelForm.js.map +1 -0
- package/dist/config/consistencyProbe.d.ts +7 -0
- package/dist/config/consistencyProbe.js +143 -0
- package/dist/config/consistencyProbe.js.map +1 -0
- package/dist/config/health.d.ts +4 -3
- package/dist/config/health.js +75 -62
- package/dist/config/health.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +19 -12
- package/dist/config/index.js.map +1 -1
- package/dist/config/paths.d.ts +9 -3
- package/dist/config/paths.js +12 -4
- package/dist/config/paths.js.map +1 -1
- package/dist/config/persistence.context.d.ts +8 -0
- package/dist/config/persistence.context.js +30 -0
- package/dist/config/persistence.context.js.map +1 -0
- package/dist/config/persistence.d.ts +110 -12
- package/dist/config/persistence.js +351 -32
- package/dist/config/persistence.js.map +1 -1
- package/dist/config/presets.d.ts +14 -4
- package/dist/config/presets.js +84 -75
- package/dist/config/presets.js.map +1 -1
- package/dist/config/profiles.d.ts +2 -2
- package/dist/config/profiles.js +7 -9
- package/dist/config/profiles.js.map +1 -1
- package/dist/config/servicePacks.d.ts +2 -2
- package/dist/config/servicePacks.js +28 -28
- package/dist/config/servicePacks.js.map +1 -1
- package/dist/config/services.d.ts +62 -36
- package/dist/config/services.js +150 -136
- package/dist/config/services.js.map +1 -1
- package/dist/config/sites.d.ts +3 -3
- package/dist/config/sites.js +16 -16
- package/dist/config/sites.js.map +1 -1
- package/dist/config/userChannels.d.ts +500 -41
- package/dist/config/userChannels.js +1201 -312
- package/dist/config/userChannels.js.map +1 -1
- package/dist/config/userConfig.d.ts +103 -10
- package/dist/config/userConfig.js +277 -117
- package/dist/config/userConfig.js.map +1 -1
- package/dist/config/userProfiles.d.ts +4 -2
- package/dist/config/userProfiles.js +72 -26
- package/dist/config/userProfiles.js.map +1 -1
- package/dist/hdhr/channelMap.js +8 -11
- package/dist/hdhr/channelMap.js.map +1 -1
- package/dist/hdhr/deviceId.js +10 -9
- package/dist/hdhr/deviceId.js.map +1 -1
- package/dist/hdhr/discover.js +4 -5
- package/dist/hdhr/discover.js.map +1 -1
- package/dist/hdhr/index.js +6 -10
- package/dist/hdhr/index.js.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/native/codecInference.d.ts +44 -0
- package/dist/native/codecInference.js +327 -0
- package/dist/native/codecInference.js.map +1 -0
- package/dist/native/decrypt.d.ts +1 -1
- package/dist/native/index.d.ts +5 -5
- package/dist/native/index.js +42 -64
- package/dist/native/index.js.map +1 -1
- package/dist/native/probe.d.ts +27 -9
- package/dist/native/probe.js +158 -67
- package/dist/native/probe.js.map +1 -1
- package/dist/native/proxy.d.ts +4 -2
- package/dist/native/proxy.js +52 -49
- package/dist/native/proxy.js.map +1 -1
- package/dist/native/tokenExpiry.d.ts +22 -0
- package/dist/native/tokenExpiry.js +153 -0
- package/dist/native/tokenExpiry.js.map +1 -0
- package/dist/routes/auth.js +6 -10
- package/dist/routes/auth.js.map +1 -1
- package/dist/routes/components.js +2 -2
- package/dist/routes/components.js.map +1 -1
- package/dist/routes/config/channels/endpoints/browse.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/browse.js +195 -0
- package/dist/routes/config/channels/endpoints/browse.js.map +1 -0
- package/dist/routes/config/channels/endpoints/bulk.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/bulk.js +128 -0
- package/dist/routes/config/channels/endpoints/bulk.js.map +1 -0
- package/dist/routes/config/channels/endpoints/crud.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/crud.js +504 -0
- package/dist/routes/config/channels/endpoints/crud.js.map +1 -0
- package/dist/routes/config/channels/endpoints/importExport.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/importExport.js +131 -0
- package/dist/routes/config/channels/endpoints/importExport.js.map +1 -0
- package/dist/routes/config/channels/endpoints/predefined.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/predefined.js +78 -0
- package/dist/routes/config/channels/endpoints/predefined.js.map +1 -0
- package/dist/routes/config/channels/endpoints/prefs.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/prefs.js +58 -0
- package/dist/routes/config/channels/endpoints/prefs.js.map +1 -0
- package/dist/routes/config/channels/endpoints/service.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/service.js +149 -0
- package/dist/routes/config/channels/endpoints/service.js.map +1 -0
- package/dist/routes/config/channels/endpoints/tags.d.ts +6 -0
- package/dist/routes/config/channels/endpoints/tags.js +185 -0
- package/dist/routes/config/channels/endpoints/tags.js.map +1 -0
- package/dist/routes/config/channels/http/handler.d.ts +10 -0
- package/dist/routes/config/channels/http/handler.js +20 -0
- package/dist/routes/config/channels/http/handler.js.map +1 -0
- package/dist/routes/config/channels/http/playlistHint.d.ts +25 -0
- package/dist/routes/config/channels/http/playlistHint.js +40 -0
- package/dist/routes/config/channels/http/playlistHint.js.map +1 -0
- package/dist/routes/config/channels/http/serviceWarning.d.ts +10 -0
- package/dist/routes/config/channels/http/serviceWarning.js +28 -0
- package/dist/routes/config/channels/http/serviceWarning.js.map +1 -0
- package/dist/routes/config/channels/index.d.ts +3 -3
- package/dist/routes/config/channels/index.js +1 -1
- package/dist/routes/config/channels/index.js.map +1 -1
- package/dist/routes/config/channels/{routes.d.ts → setup.d.ts} +1 -1
- package/dist/routes/config/channels/setup.js +23 -0
- package/dist/routes/config/channels/setup.js.map +1 -0
- package/dist/routes/config/channels/table.d.ts +9 -9
- package/dist/routes/config/channels/table.js +124 -76
- package/dist/routes/config/channels/table.js.map +1 -1
- package/dist/routes/config/http/envelope.d.ts +111 -0
- package/dist/routes/config/http/envelope.js +103 -0
- package/dist/routes/config/http/envelope.js.map +1 -0
- package/dist/routes/config/index.d.ts +9 -9
- package/dist/routes/config/index.js +2 -2
- package/dist/routes/config/index.js.map +1 -1
- package/dist/routes/config/services.js +69 -68
- package/dist/routes/config/services.js.map +1 -1
- package/dist/routes/config/settings.d.ts +1 -1
- package/dist/routes/config/settings.js +45 -38
- package/dist/routes/config/settings.js.map +1 -1
- package/dist/routes/debug.js +12 -11
- package/dist/routes/debug.js.map +1 -1
- package/dist/routes/icons.js +2 -2
- package/dist/routes/icons.js.map +1 -1
- package/dist/routes/logs.js +19 -30
- package/dist/routes/logs.js.map +1 -1
- package/dist/routes/mpegts.js +1 -1
- package/dist/routes/playlist.d.ts +1 -1
- package/dist/routes/playlist.js +37 -26
- package/dist/routes/playlist.js.map +1 -1
- package/dist/routes/root/content.js +27 -6
- package/dist/routes/root/content.js.map +1 -1
- package/dist/routes/root/index.js +2 -5
- package/dist/routes/root/index.js.map +1 -1
- package/dist/routes/root/scripts/channels.js +16 -16
- package/dist/routes/root/scripts/channels.js.map +1 -1
- package/dist/routes/root/scripts/config.js +59 -59
- package/dist/routes/root/scripts/config.js.map +1 -1
- package/dist/routes/root/scripts/index.d.ts +4 -4
- package/dist/routes/root/scripts/shared.js +24 -10
- package/dist/routes/root/scripts/shared.js.map +1 -1
- package/dist/routes/root/scripts/status.d.ts +4 -0
- package/dist/routes/root/scripts/status.handlers.d.ts +182 -0
- package/dist/routes/root/scripts/status.handlers.js +713 -0
- package/dist/routes/root/scripts/status.handlers.js.map +1 -0
- package/dist/routes/root/scripts/status.js +86 -488
- package/dist/routes/root/scripts/status.js.map +1 -1
- package/dist/routes/root/styles.js +5 -5
- package/dist/routes/services.js +18 -15
- package/dist/routes/services.js.map +1 -1
- package/dist/routes/sse.d.ts +16 -0
- package/dist/routes/sse.js +29 -0
- package/dist/routes/sse.js.map +1 -0
- package/dist/routes/streams.js +10 -23
- package/dist/routes/streams.js.map +1 -1
- package/dist/routes/ui.d.ts +2 -2
- package/dist/routes/upgrade.js +6 -7
- package/dist/routes/upgrade.js.map +1 -1
- package/dist/service/commands.context.d.ts +6 -0
- package/dist/service/commands.context.js +47 -0
- package/dist/service/commands.context.js.map +1 -0
- package/dist/service/commands.d.ts +53 -8
- package/dist/service/commands.js +171 -188
- package/dist/service/commands.js.map +1 -1
- package/dist/service/generators.context.d.ts +6 -0
- package/dist/service/generators.context.js +45 -0
- package/dist/service/generators.context.js.map +1 -0
- package/dist/service/generators.d.ts +56 -16
- package/dist/service/generators.js +499 -383
- package/dist/service/generators.js.map +1 -1
- package/dist/service/index.d.ts +2 -2
- package/dist/streaming/clients.d.ts +2 -2
- package/dist/streaming/clients.js +2 -2
- package/dist/streaming/codec.d.ts +2 -2
- package/dist/streaming/codec.js +0 -1
- package/dist/streaming/codec.js.map +1 -1
- package/dist/streaming/fmp4Segmenter.d.ts +2 -2
- package/dist/streaming/fmp4Segmenter.js +12 -12
- package/dist/streaming/hls.d.ts +3 -3
- package/dist/streaming/hls.js +81 -70
- package/dist/streaming/hls.js.map +1 -1
- package/dist/streaming/hlsResume.d.ts +3 -3
- package/dist/streaming/hlsResume.js +5 -5
- package/dist/streaming/hlsSegments.d.ts +5 -2
- package/dist/streaming/hlsSegments.js +14 -9
- package/dist/streaming/hlsSegments.js.map +1 -1
- package/dist/streaming/monitor.d.ts +12 -12
- package/dist/streaming/monitor.js +80 -54
- package/dist/streaming/monitor.js.map +1 -1
- package/dist/streaming/mp4Parser.d.ts +34 -4
- package/dist/streaming/mp4Parser.js +111 -29
- package/dist/streaming/mp4Parser.js.map +1 -1
- package/dist/streaming/mpegts.d.ts +1 -1
- package/dist/streaming/mpegts.js +13 -10
- package/dist/streaming/mpegts.js.map +1 -1
- package/dist/streaming/playlistBuilder.d.ts +1 -1
- package/dist/streaming/playlistBuilder.js +2 -2
- package/dist/streaming/preroll.d.ts +9 -9
- package/dist/streaming/preroll.js +39 -41
- package/dist/streaming/preroll.js.map +1 -1
- package/dist/streaming/pretune.js +4 -4
- package/dist/streaming/pretune.js.map +1 -1
- package/dist/streaming/recovery.d.ts +3 -3
- package/dist/streaming/recovery.js +4 -4
- package/dist/streaming/registry.d.ts +6 -6
- package/dist/streaming/setup.d.ts +9 -8
- package/dist/streaming/setup.js +97 -49
- package/dist/streaming/setup.js.map +1 -1
- package/dist/streaming/showInfo.d.ts +9 -3
- package/dist/streaming/showInfo.js +26 -18
- package/dist/streaming/showInfo.js.map +1 -1
- package/dist/streaming/statusEmitter.d.ts +4 -4
- package/dist/streaming/statusEmitter.js +2 -2
- package/dist/types/channels.d.ts +133 -34
- package/dist/types/channels.js +39 -1
- package/dist/types/channels.js.map +1 -1
- package/dist/types/config.d.ts +20 -1
- package/dist/types/index.d.ts +9 -8
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/profiles.d.ts +5 -4
- package/dist/types/selection.d.ts +48 -4
- package/dist/types/streaming.d.ts +1 -1
- package/dist/upgrade/commands.context.d.ts +6 -0
- package/dist/upgrade/commands.context.js +29 -0
- package/dist/upgrade/commands.context.js.map +1 -0
- package/dist/upgrade/commands.d.ts +29 -2
- package/dist/upgrade/commands.js +87 -134
- package/dist/upgrade/commands.js.map +1 -1
- package/dist/upgrade/detection.context.d.ts +6 -0
- package/dist/upgrade/detection.context.js +24 -0
- package/dist/upgrade/detection.context.js.map +1 -0
- package/dist/upgrade/detection.d.ts +140 -10
- package/dist/upgrade/detection.js +153 -66
- package/dist/upgrade/detection.js.map +1 -1
- package/dist/upgrade/index.d.ts +2 -2
- package/dist/utils/chromeFetch.d.ts +1 -1
- package/dist/utils/chromeFetch.js +1 -1
- package/dist/utils/clock.d.ts +14 -0
- package/dist/utils/clock.js +28 -0
- package/dist/utils/clock.js.map +1 -0
- package/dist/utils/debugFilter.d.ts +1 -1
- package/dist/utils/debugFilter.js +6 -4
- package/dist/utils/debugFilter.js.map +1 -1
- package/dist/utils/delay.d.ts +2 -3
- package/dist/utils/delay.js +10 -16
- package/dist/utils/delay.js.map +1 -1
- package/dist/utils/evaluate.js +12 -14
- package/dist/utils/evaluate.js.map +1 -1
- package/dist/utils/ffmpeg.context.d.ts +6 -0
- package/dist/utils/ffmpeg.context.js +31 -0
- package/dist/utils/ffmpeg.context.js.map +1 -0
- package/dist/utils/ffmpeg.d.ts +85 -29
- package/dist/utils/ffmpeg.js +126 -129
- package/dist/utils/ffmpeg.js.map +1 -1
- package/dist/utils/fileLogger.d.ts +18 -2
- package/dist/utils/fileLogger.js +58 -30
- package/dist/utils/fileLogger.js.map +1 -1
- package/dist/utils/format.d.ts +1 -1
- package/dist/utils/format.js +2 -2
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/html.js +1 -3
- package/dist/utils/html.js.map +1 -1
- package/dist/utils/index.d.ts +21 -20
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.js +16 -20
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/m3u.d.ts +18 -3
- package/dist/utils/m3u.js +28 -14
- package/dist/utils/m3u.js.map +1 -1
- package/dist/utils/memo.d.ts +19 -0
- package/dist/utils/memo.js +53 -0
- package/dist/utils/memo.js.map +1 -0
- package/dist/utils/morganStream.js +2 -2
- package/dist/utils/morganStream.js.map +1 -1
- package/dist/utils/pid.d.ts +2 -2
- package/dist/utils/pid.js +2 -2
- package/dist/utils/platform.d.ts +1 -1
- package/dist/utils/platform.js +3 -3
- package/dist/utils/platform.js.map +1 -1
- package/dist/utils/retry.d.ts +2 -0
- package/dist/utils/retry.js +9 -7
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/sanitize.d.ts +2 -2
- package/dist/utils/sanitize.js +4 -4
- package/dist/utils/timing.d.ts +6 -3
- package/dist/utils/timing.js +10 -6
- package/dist/utils/timing.js.map +1 -1
- package/dist/utils/version.d.ts +3 -2
- package/dist/utils/version.js +14 -27
- package/dist/utils/version.js.map +1 -1
- package/package.json +13 -7
- package/dist/native/intercept.d.ts +0 -35
- package/dist/native/intercept.js +0 -181
- package/dist/native/intercept.js.map +0 -1
- package/dist/routes/config/channels/routes.js +0 -1505
- package/dist/routes/config/channels/routes.js.map +0 -1
package/dist/utils/ffmpeg.d.ts
CHANGED
|
@@ -1,18 +1,57 @@
|
|
|
1
1
|
import type { Readable, Writable } from "node:stream";
|
|
2
2
|
import type { ChildProcess } from "node:child_process";
|
|
3
|
+
/**
|
|
4
|
+
* The runtime context resolveFFmpegPath consumes. Models the I/O boundary used by path resolution: filesystem existence checks, the user's home directory, the
|
|
5
|
+
* detected platform, the spawn-based probe, and the bundled FFmpeg path from the ffmpeg-for-homebridge npm package. Production wires it through
|
|
6
|
+
* createDefaultFFmpegContext (in ffmpeg.context.ts); tests pass a context literal.
|
|
7
|
+
*/
|
|
8
|
+
export interface FFmpegContext {
|
|
9
|
+
readonly bundledPath: string | undefined;
|
|
10
|
+
readonly exists: (path: string) => boolean;
|
|
11
|
+
readonly homedir: () => string;
|
|
12
|
+
readonly platform: NodeJS.Platform;
|
|
13
|
+
readonly probe: (path: string) => Promise<boolean>;
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Returns the path to the bundled ffmpeg-for-homebridge binary if it exists on disk. This binary ships as an npm dependency and has a full encoder set (libx264,
|
|
5
17
|
* libx265, zoompan, overlay) regardless of what the user has installed. Used by preroll generation to guarantee HEVC encoding availability without depending on
|
|
6
18
|
* the Channels DVR FFmpeg (which has a minimal encoder set) or a system installation.
|
|
19
|
+
* @param ctx - The FFmpeg context. Defaults to createDefaultFFmpegContext() which wires real runtime I/O.
|
|
7
20
|
* @returns The absolute path to the bundled FFmpeg, or undefined if the package did not resolve or the binary is missing.
|
|
8
21
|
*/
|
|
9
|
-
export declare function getBundledFFmpegPath(): string | undefined;
|
|
22
|
+
export declare function getBundledFFmpegPath(ctx?: FFmpegContext): string | undefined;
|
|
10
23
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
24
|
+
* Probes the filesystem to find an FFmpeg executable. Pure algorithm over the supplied FFmpegContext: every disk check, every probe spawn, and every platform
|
|
25
|
+
* branch flows through ctx. No internal caching - each call re-probes - so tests can construct independent scenarios. The production-facing resolveFFmpegPath
|
|
26
|
+
* wraps this in a singleton memoizer.
|
|
27
|
+
*
|
|
28
|
+
* FFmpeg can be located in several places depending on how it was installed. We check in order of preference:
|
|
29
|
+
*
|
|
30
|
+
* 1. Channels DVR bundled FFmpeg:
|
|
31
|
+
* - macOS: ~/Library/Application Support/ChannelsDVR/latest/ffmpeg
|
|
32
|
+
* - Windows: C:\ProgramData\channelsdvr\latest\ffmpeg.exe
|
|
33
|
+
* - Linux: ~/channels-dvr/latest/ffmpeg, /usr/local/channels-dvr/latest/ffmpeg, /opt/channels-dvr/latest/ffmpeg
|
|
34
|
+
* 2. Bundled FFmpeg from the ffmpeg-for-homebridge package.
|
|
35
|
+
* 3. System PATH (standard installation via package manager or manual install).
|
|
36
|
+
*
|
|
37
|
+
* @param ctx - The FFmpeg context. Defaults to createDefaultFFmpegContext() which wires real runtime I/O.
|
|
13
38
|
* @returns Promise resolving to the FFmpeg path if found, or undefined if not available.
|
|
14
39
|
*/
|
|
15
|
-
export declare function
|
|
40
|
+
export declare function probeFFmpegPath(ctx?: FFmpegContext): Promise<string | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the FFmpeg executable path against the production filesystem. Memoized via memoizeAsync: first call probes; subsequent calls return the cached
|
|
43
|
+
* result. Used by production code paths (server startup, health checks, stream setup). Tests should use probeFFmpegPath against synthetic contexts instead -
|
|
44
|
+
* this function intentionally has no parameters and no test seam so its caching contract is sealed. The memoization correctness (single-shot probe,
|
|
45
|
+
* concurrent-caller dedup, sticky rejection) is exercised by memo.test.ts against the underlying primitive.
|
|
46
|
+
*
|
|
47
|
+
* Sticky-rejection caveat: memoizeAsync caches a probe rejection for the lifetime of the process - all future callers receive the same rejected promise
|
|
48
|
+
* without re-probing. probeFFmpegPath today returns undefined for the "not found" case rather than throwing, so this branch never fires in practice. Future
|
|
49
|
+
* maintainers: do NOT change probeFFmpegPath to throw on transient conditions (permission errors, EAGAIN, etc.) without first reconsidering the caching
|
|
50
|
+
* contract here. A throw-on-transient-failure path would permanently disable FFmpeg detection until restart, defeating the purpose of the cache. If the probe
|
|
51
|
+
* needs to surface real errors, either return them as a tagged value type or compose memoizeAsync with a retry-after-failure layer.
|
|
52
|
+
* @returns Promise resolving to the FFmpeg path if found, or undefined if not available.
|
|
53
|
+
*/
|
|
54
|
+
export declare const resolveFFmpegPath: () => Promise<string | undefined>;
|
|
16
55
|
/**
|
|
17
56
|
* Result from spawning an FFmpeg process.
|
|
18
57
|
*/
|
|
@@ -23,45 +62,62 @@ export interface FFmpegProcess {
|
|
|
23
62
|
stdout: Readable;
|
|
24
63
|
}
|
|
25
64
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
65
|
+
* Options for buildSpawnFFmpegArgs. Keeping the platform as an injected option (defaulting to process.platform) lets tests verify both the macOS and non-macOS
|
|
66
|
+
* branches independently rather than re-asserting whatever branch the host happens to take.
|
|
67
|
+
*/
|
|
68
|
+
export interface SpawnFFmpegOptions {
|
|
69
|
+
readonly comment?: string;
|
|
70
|
+
readonly platform?: NodeJS.Platform;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Builds the argv for an FFmpeg invocation that remuxes Matroska to fMP4. Pure: depends only on the supplied audioBitrate and options. The platform-conditional
|
|
74
|
+
* choice between Apple's AudioToolbox AAC encoder and FFmpeg's software encoder is parameterized via options.platform (defaulting to process.platform), so tests
|
|
75
|
+
* can verify both branches without depending on the host.
|
|
76
|
+
*
|
|
77
|
+
* Chrome's MediaRecorder outputs a Matroska container with video (H264 or HEVC depending on hardware capabilities) and Opus audio. HLS clients need fMP4 with
|
|
78
|
+
* AAC audio. The args copy video unchanged (no quality loss, minimal CPU), transcode audio from Opus to AAC, and rewrite the container as fragmented MP4 with
|
|
79
|
+
* streaming-friendly flags suitable for incremental segmentation.
|
|
29
80
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* -
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* -
|
|
81
|
+
* @param audioBitrate - Audio bitrate in bits per second (e.g., 256000 for 256 kbps).
|
|
82
|
+
* @param options - Optional comment metadata and platform override.
|
|
83
|
+
* @returns The FFmpeg argv array (excluding the binary itself).
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildSpawnFFmpegArgs(audioBitrate: number, options?: SpawnFFmpegOptions): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Builds the argv for an FFmpeg invocation that remuxes fMP4 input to MPEG-TS output with codec copy (no transcoding). Pure: takes no inputs and depends on no
|
|
88
|
+
* external state.
|
|
89
|
+
*
|
|
90
|
+
* The output flags emit ATSC-conventional MPEG-TS resembling a real HDHomeRun CONNECT DUO so Plex's transcoder makes the right assumptions about stream structure
|
|
91
|
+
* (PID assignments, PAT/PMT frequency). Container metadata only - the actual A/V data is untouched by -c copy.
|
|
92
|
+
*
|
|
93
|
+
* @returns The FFmpeg argv array (excluding the binary itself).
|
|
94
|
+
*/
|
|
95
|
+
export declare function buildMpegTsRemuxerArgs(): string[];
|
|
96
|
+
/**
|
|
97
|
+
* Spawns an FFmpeg process configured to remux Matroska to fMP4. The process reads from stdin and writes to stdout, allowing integration into a Node.js stream
|
|
98
|
+
* pipeline. Callers provide the resolved FFmpeg binary path; resolution is the caller's responsibility (typically via resolveFFmpegPath() at startup or stream
|
|
99
|
+
* setup) so this function stays a thin spawn() wrapper.
|
|
100
|
+
* @param ffmpegBin - The absolute path to the FFmpeg binary (typically the result of resolveFFmpegPath()).
|
|
40
101
|
* @param audioBitrate - Audio bitrate in bits per second (e.g., 256000 for 256 kbps).
|
|
41
102
|
* @param onError - Callback invoked when FFmpeg exits unexpectedly or encounters an error.
|
|
42
103
|
* @param streamId - Stream identifier for logging.
|
|
43
104
|
* @param comment - Optional comment metadata (channel name or domain) to embed in the output.
|
|
44
105
|
* @returns FFmpeg process wrapper with stdin, stdout, and kill function.
|
|
45
106
|
*/
|
|
46
|
-
export declare function spawnFFmpeg(audioBitrate: number, onError: (error: Error) => void, streamId?: string, comment?: string): FFmpegProcess;
|
|
107
|
+
export declare function spawnFFmpeg(ffmpegBin: string, audioBitrate: number, onError: (error: Error) => void, streamId?: string, comment?: string): FFmpegProcess;
|
|
47
108
|
/**
|
|
48
109
|
* Spawns an FFmpeg process configured to remux fMP4 input to MPEG-TS output with codec copy. The process reads a continuous fMP4 stream (init segment followed by
|
|
49
|
-
* media segments) from stdin and writes MPEG-TS to stdout. No transcoding occurs
|
|
50
|
-
*
|
|
51
|
-
* FFmpeg arguments:
|
|
52
|
-
* - `-hide_banner -loglevel warning`: Reduce noise, only show warnings/errors
|
|
53
|
-
* - `-probesize 16384`: Limit input probing to 16KB (fMP4 init segment is ~1.3KB) to minimize startup delay
|
|
54
|
-
* - `-f mp4 -i pipe:0`: Read fragmented MP4 from stdin
|
|
55
|
-
* - `-c copy`: Copy both video and audio codecs without transcoding
|
|
56
|
-
* - MPEG-TS output flags: See MPEGTS_OUTPUT_FLAGS for ATSC-conventional settings
|
|
57
|
-
* - `pipe:1`: Write output to stdout
|
|
110
|
+
* media segments) from stdin and writes MPEG-TS to stdout. No transcoding occurs - both video and audio are copied unchanged - so CPU usage is minimal.
|
|
111
|
+
* @param ffmpegBin - The absolute path to the FFmpeg binary (typically the result of resolveFFmpegPath()).
|
|
58
112
|
* @param onError - Callback invoked when FFmpeg exits unexpectedly or encounters an error.
|
|
59
113
|
* @param streamId - Optional stream identifier for logging.
|
|
60
114
|
* @returns FFmpeg process wrapper with stdin, stdout, and kill function.
|
|
61
115
|
*/
|
|
62
|
-
export declare function spawnMpegTsRemuxer(onError: (error: Error) => void, streamId?: string): FFmpegProcess;
|
|
116
|
+
export declare function spawnMpegTsRemuxer(ffmpegBin: string, onError: (error: Error) => void, streamId?: string): FFmpegProcess;
|
|
63
117
|
/**
|
|
64
|
-
* Checks if FFmpeg is available on the system.
|
|
118
|
+
* Checks if FFmpeg is available on the system. Wraps the production-cached resolveFFmpegPath, so first call probes the filesystem and subsequent calls return
|
|
119
|
+
* the memoized result. Tests should use probeFFmpegPath against synthetic contexts instead - this function delegates to the singleton resolver and has no test
|
|
120
|
+
* seam.
|
|
65
121
|
* @returns Promise resolving to true if FFmpeg is available, false otherwise.
|
|
66
122
|
*/
|
|
67
123
|
export declare function isFFmpegAvailable(): Promise<boolean>;
|
package/dist/utils/ffmpeg.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { LOG } from "./logger.js";
|
|
2
|
-
import {
|
|
3
|
-
import ffmpegForHomebridge from "ffmpeg-for-homebridge";
|
|
4
|
-
import { homedir } from "node:os";
|
|
2
|
+
import { createDefaultFFmpegContext } from "./ffmpeg.context.js";
|
|
5
3
|
import { join } from "node:path";
|
|
4
|
+
import { memoizeAsync } from "./memo.js";
|
|
6
5
|
import { spawn } from "node:child_process";
|
|
7
|
-
// The ffmpeg-for-homebridge package has incorrect type definitions (declares named export but JS uses default export). Cast to the correct type.
|
|
8
|
-
const ffmpegPath = ffmpegForHomebridge;
|
|
9
6
|
// FFmpeg stderr noise patterns that are suppressed from logging. The -nostats flag suppresses most progress output, but some FFmpeg builds or versions may still
|
|
10
7
|
// emit these patterns. The filter acts as a safety net to keep logs clean.
|
|
11
8
|
const FFMPEG_NOISE_PATTERNS = ["Press [q] to stop", "frame=", "size=", "time=", "bitrate=", "speed="];
|
|
@@ -13,114 +10,101 @@ const FFMPEG_NOISE_PATTERNS = ["Press [q] to stop", "frame=", "size=", "time=",
|
|
|
13
10
|
* Returns the path to the bundled ffmpeg-for-homebridge binary if it exists on disk. This binary ships as an npm dependency and has a full encoder set (libx264,
|
|
14
11
|
* libx265, zoompan, overlay) regardless of what the user has installed. Used by preroll generation to guarantee HEVC encoding availability without depending on
|
|
15
12
|
* the Channels DVR FFmpeg (which has a minimal encoder set) or a system installation.
|
|
13
|
+
* @param ctx - The FFmpeg context. Defaults to createDefaultFFmpegContext() which wires real runtime I/O.
|
|
16
14
|
* @returns The absolute path to the bundled FFmpeg, or undefined if the package did not resolve or the binary is missing.
|
|
17
15
|
*/
|
|
18
|
-
export function getBundledFFmpegPath() {
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
16
|
+
export function getBundledFFmpegPath(ctx = createDefaultFFmpegContext()) {
|
|
17
|
+
if (ctx.bundledPath && ctx.exists(ctx.bundledPath)) {
|
|
18
|
+
return ctx.bundledPath;
|
|
21
19
|
}
|
|
22
20
|
return undefined;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
// Common input-side flags shared by every FFmpeg spawner. They silence the banner and per-frame stats, restrict logging to warnings and errors, tolerate corrupt
|
|
23
|
+
// input frames rather than aborting on read errors, and cap input probing at 16KB so the encoder begins emitting output as soon as the first segment lands.
|
|
24
|
+
const FFMPEG_INPUT_FLAGS = [
|
|
25
|
+
"-hide_banner",
|
|
26
|
+
"-nostats",
|
|
27
|
+
"-loglevel", "warning",
|
|
28
|
+
"-fflags", "+discardcorrupt",
|
|
29
|
+
"-err_detect", "ignore_err",
|
|
30
|
+
"-probesize", "16384"
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Probes the filesystem to find an FFmpeg executable. Pure algorithm over the supplied FFmpegContext: every disk check, every probe spawn, and every platform
|
|
34
|
+
* branch flows through ctx. No internal caching - each call re-probes - so tests can construct independent scenarios. The production-facing resolveFFmpegPath
|
|
35
|
+
* wraps this in a singleton memoizer.
|
|
26
36
|
*
|
|
27
|
-
*
|
|
28
|
-
* - Audio: Transcoded from Opus to AAC - lightweight operation
|
|
29
|
-
* - Container: Converted from Matroska to fragmented MP4 with streaming-friendly flags
|
|
37
|
+
* FFmpeg can be located in several places depending on how it was installed. We check in order of preference:
|
|
30
38
|
*
|
|
31
|
-
* The FFmpeg process runs for the lifetime of the stream, reading Matroska from stdin and writing fMP4 to stdout. This output feeds directly into the existing fMP4
|
|
32
|
-
* segmenter.
|
|
33
|
-
*/
|
|
34
|
-
/* FFmpeg can be located in several places depending on how it was installed. We check in order of preference:
|
|
35
39
|
* 1. Channels DVR bundled FFmpeg:
|
|
36
40
|
* - macOS: ~/Library/Application Support/ChannelsDVR/latest/ffmpeg
|
|
37
41
|
* - Windows: C:\ProgramData\channelsdvr\latest\ffmpeg.exe
|
|
38
42
|
* - Linux: ~/channels-dvr/latest/ffmpeg, /usr/local/channels-dvr/latest/ffmpeg, /opt/channels-dvr/latest/ffmpeg
|
|
39
|
-
* 2. Bundled FFmpeg from ffmpeg-for-homebridge package
|
|
40
|
-
* 3. System PATH (standard installation via package manager or manual install)
|
|
43
|
+
* 2. Bundled FFmpeg from the ffmpeg-for-homebridge package.
|
|
44
|
+
* 3. System PATH (standard installation via package manager or manual install).
|
|
41
45
|
*
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
// Cached FFmpeg path after resolution. Null means not yet resolved, undefined means not found.
|
|
45
|
-
let cachedFFmpegPath = null;
|
|
46
|
-
/**
|
|
47
|
-
* Checks if FFmpeg exists at a specific path by attempting to run it.
|
|
48
|
-
* @param pathToCheck - Full path to the FFmpeg executable.
|
|
49
|
-
* @returns Promise resolving to true if FFmpeg runs successfully at this path.
|
|
50
|
-
*/
|
|
51
|
-
async function checkFFmpegAtPath(pathToCheck) {
|
|
52
|
-
return new Promise((resolve) => {
|
|
53
|
-
const ffmpeg = spawn(pathToCheck, ["-version"], {
|
|
54
|
-
stdio: ["ignore", "ignore", "ignore"]
|
|
55
|
-
});
|
|
56
|
-
ffmpeg.on("error", () => {
|
|
57
|
-
resolve(false);
|
|
58
|
-
});
|
|
59
|
-
ffmpeg.on("exit", (code) => {
|
|
60
|
-
resolve(code === 0);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Resolves the FFmpeg executable path. Checks Channels DVR (macOS, Windows, Linux), then the bundled ffmpeg-for-homebridge, then system PATH. The resolved path is
|
|
66
|
-
* cached for subsequent calls.
|
|
46
|
+
* @param ctx - The FFmpeg context. Defaults to createDefaultFFmpegContext() which wires real runtime I/O.
|
|
67
47
|
* @returns Promise resolving to the FFmpeg path if found, or undefined if not available.
|
|
68
48
|
*/
|
|
69
|
-
export async function
|
|
70
|
-
// Return cached result if already resolved.
|
|
71
|
-
if (cachedFFmpegPath !== null) {
|
|
72
|
-
return cachedFFmpegPath;
|
|
73
|
-
}
|
|
49
|
+
export async function probeFFmpegPath(ctx = createDefaultFFmpegContext()) {
|
|
74
50
|
// On macOS, check Channels DVR bundled FFmpeg first. Users of PrismCast with Channels DVR likely have this available.
|
|
75
|
-
if (
|
|
76
|
-
const channelsDvrPath = join(homedir(), "Library", "Application Support", "ChannelsDVR", "latest", "ffmpeg");
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
return cachedFFmpegPath;
|
|
51
|
+
if (ctx.platform === "darwin") {
|
|
52
|
+
const channelsDvrPath = join(ctx.homedir(), "Library", "Application Support", "ChannelsDVR", "latest", "ffmpeg");
|
|
53
|
+
if (ctx.exists(channelsDvrPath) && (await ctx.probe(channelsDvrPath))) {
|
|
54
|
+
return channelsDvrPath;
|
|
80
55
|
}
|
|
81
56
|
}
|
|
82
57
|
// On Windows, check Channels DVR bundled FFmpeg. Users of PrismCast with Channels DVR likely have this available.
|
|
83
|
-
if (
|
|
58
|
+
if (ctx.platform === "win32") {
|
|
84
59
|
const channelsDvrPath = join("C:", "ProgramData", "channelsdvr", "latest", "ffmpeg.exe");
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
return cachedFFmpegPath;
|
|
60
|
+
if (ctx.exists(channelsDvrPath) && (await ctx.probe(channelsDvrPath))) {
|
|
61
|
+
return channelsDvrPath;
|
|
88
62
|
}
|
|
89
63
|
}
|
|
90
64
|
// On Linux, check common Channels DVR installation paths. The Channels DVR setup script creates a channels-dvr directory in the current working directory when
|
|
91
65
|
// run. The official recommendation is ~/channels-dvr, but users also install to /usr/local/channels-dvr and /opt/channels-dvr.
|
|
92
|
-
if (
|
|
66
|
+
if (ctx.platform === "linux") {
|
|
93
67
|
const linuxChannelsDvrPaths = [
|
|
94
|
-
join(homedir(), "channels-dvr", "latest", "ffmpeg"),
|
|
68
|
+
join(ctx.homedir(), "channels-dvr", "latest", "ffmpeg"),
|
|
95
69
|
join("/usr", "local", "channels-dvr", "latest", "ffmpeg"),
|
|
96
70
|
join("/opt", "channels-dvr", "latest", "ffmpeg")
|
|
97
71
|
];
|
|
98
72
|
for (const channelsDvrPath of linuxChannelsDvrPaths) {
|
|
99
73
|
// eslint-disable-next-line no-await-in-loop
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
return cachedFFmpegPath;
|
|
74
|
+
if (ctx.exists(channelsDvrPath) && (await ctx.probe(channelsDvrPath))) {
|
|
75
|
+
return channelsDvrPath;
|
|
103
76
|
}
|
|
104
77
|
}
|
|
105
78
|
}
|
|
106
79
|
// Check ffmpeg-for-homebridge bundled FFmpeg. This provides a reliable fallback without requiring manual FFmpeg installation.
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
return cachedFFmpegPath;
|
|
80
|
+
if (ctx.bundledPath && ctx.exists(ctx.bundledPath) && (await ctx.probe(ctx.bundledPath))) {
|
|
81
|
+
return ctx.bundledPath;
|
|
110
82
|
}
|
|
111
83
|
// Finally, check if ffmpeg is available in the system PATH.
|
|
112
|
-
if (await
|
|
113
|
-
|
|
114
|
-
return cachedFFmpegPath;
|
|
84
|
+
if (await ctx.probe("ffmpeg")) {
|
|
85
|
+
return "ffmpeg";
|
|
115
86
|
}
|
|
116
87
|
// FFmpeg not found anywhere.
|
|
117
|
-
cachedFFmpegPath = undefined;
|
|
118
88
|
return undefined;
|
|
119
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolves the FFmpeg executable path against the production filesystem. Memoized via memoizeAsync: first call probes; subsequent calls return the cached
|
|
92
|
+
* result. Used by production code paths (server startup, health checks, stream setup). Tests should use probeFFmpegPath against synthetic contexts instead -
|
|
93
|
+
* this function intentionally has no parameters and no test seam so its caching contract is sealed. The memoization correctness (single-shot probe,
|
|
94
|
+
* concurrent-caller dedup, sticky rejection) is exercised by memo.test.ts against the underlying primitive.
|
|
95
|
+
*
|
|
96
|
+
* Sticky-rejection caveat: memoizeAsync caches a probe rejection for the lifetime of the process - all future callers receive the same rejected promise
|
|
97
|
+
* without re-probing. probeFFmpegPath today returns undefined for the "not found" case rather than throwing, so this branch never fires in practice. Future
|
|
98
|
+
* maintainers: do NOT change probeFFmpegPath to throw on transient conditions (permission errors, EAGAIN, etc.) without first reconsidering the caching
|
|
99
|
+
* contract here. A throw-on-transient-failure path would permanently disable FFmpeg detection until restart, defeating the purpose of the cache. If the probe
|
|
100
|
+
* needs to surface real errors, either return them as a tagged value type or compose memoizeAsync with a retry-after-failure layer.
|
|
101
|
+
* @returns Promise resolving to the FFmpeg path if found, or undefined if not available.
|
|
102
|
+
*/
|
|
103
|
+
export const resolveFFmpegPath = memoizeAsync(async () => probeFFmpegPath());
|
|
120
104
|
// MPEG-TS Output Flags.
|
|
121
105
|
/* MPEG-TS muxer flags for the fMP4-to-MPEG-TS remuxer. Tuned to produce output resembling a real HDHomeRun CONNECT DUO (HDTC-2US) ATSC transport stream.
|
|
122
106
|
* Plex's transcoder may make assumptions about stream structure based on the reported device model (PID assignments, PAT/PMT frequency). Using ATSC-conventional
|
|
123
|
-
* values avoids "Invalid argument" failures when Plex tries to transcode the live session for remote clients. These are pure container metadata changes
|
|
107
|
+
* values avoids "Invalid argument" failures when Plex tries to transcode the live session for remote clients. These are pure container metadata changes - the actual
|
|
124
108
|
* A/V data is untouched by -c copy.
|
|
125
109
|
*/
|
|
126
110
|
const MPEGTS_OUTPUT_FLAGS = [
|
|
@@ -135,15 +119,15 @@ const MPEGTS_OUTPUT_FLAGS = [
|
|
|
135
119
|
// Internal Helper.
|
|
136
120
|
/**
|
|
137
121
|
* Spawns an FFmpeg process with shared lifecycle management. Handles stderr logging with noise filtering, exit and error callbacks, and graceful shutdown for all
|
|
138
|
-
* FFmpeg use cases. Callers provide the FFmpeg arguments and a descriptive label; this helper handles everything else.
|
|
122
|
+
* FFmpeg use cases. Callers provide the binary path, the FFmpeg arguments, and a descriptive label; this helper handles everything else.
|
|
139
123
|
* @param options.args - FFmpeg command-line arguments.
|
|
124
|
+
* @param options.ffmpegBin - The absolute path to the FFmpeg binary (or "ffmpeg" to defer to PATH lookup at spawn time).
|
|
140
125
|
* @param options.label - Descriptive label for log messages and error strings (e.g., "FFmpeg", "MPEG-TS remuxer").
|
|
141
126
|
* @param options.onError - Callback invoked when FFmpeg exits unexpectedly or encounters an error.
|
|
142
127
|
* @param options.streamId - Optional stream identifier for log prefixing.
|
|
143
128
|
* @returns FFmpeg process wrapper with stdin, stdout, and kill function.
|
|
144
129
|
*/
|
|
145
|
-
function spawnFFmpegProcess({ args, label, onError, streamId }) {
|
|
146
|
-
const ffmpegBin = cachedFFmpegPath ?? "ffmpeg";
|
|
130
|
+
function spawnFFmpegProcess({ args, ffmpegBin, label, onError, streamId }) {
|
|
147
131
|
const ffmpeg = spawn(ffmpegBin, args, { stdio: ["pipe", "pipe", "pipe"] });
|
|
148
132
|
const logPrefix = streamId ? "[" + streamId + "] " : "";
|
|
149
133
|
// Track whether graceful shutdown has been initiated. When true, we suppress error callbacks because any exit (whether from SIGTERM or stdin close) is expected.
|
|
@@ -167,7 +151,7 @@ function spawnFFmpegProcess({ args, label, onError, streamId }) {
|
|
|
167
151
|
return;
|
|
168
152
|
}
|
|
169
153
|
if (signal === "SIGTERM") {
|
|
170
|
-
// Normal termination via kill()
|
|
154
|
+
// Normal termination via kill() - do not treat as error.
|
|
171
155
|
return;
|
|
172
156
|
}
|
|
173
157
|
if ((code !== null) && (code !== 0)) {
|
|
@@ -198,53 +182,84 @@ function spawnFFmpegProcess({ args, label, onError, streamId }) {
|
|
|
198
182
|
stdout: ffmpeg.stdout
|
|
199
183
|
};
|
|
200
184
|
}
|
|
201
|
-
// Public FFmpeg Spawners.
|
|
202
185
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
186
|
+
* Builds the argv for an FFmpeg invocation that remuxes Matroska to fMP4. Pure: depends only on the supplied audioBitrate and options. The platform-conditional
|
|
187
|
+
* choice between Apple's AudioToolbox AAC encoder and FFmpeg's software encoder is parameterized via options.platform (defaulting to process.platform), so tests
|
|
188
|
+
* can verify both branches without depending on the host.
|
|
189
|
+
*
|
|
190
|
+
* Chrome's MediaRecorder outputs a Matroska container with video (H264 or HEVC depending on hardware capabilities) and Opus audio. HLS clients need fMP4 with
|
|
191
|
+
* AAC audio. The args copy video unchanged (no quality loss, minimal CPU), transcode audio from Opus to AAC, and rewrite the container as fragmented MP4 with
|
|
192
|
+
* streaming-friendly flags suitable for incremental segmentation.
|
|
206
193
|
*
|
|
207
|
-
* FFmpeg arguments:
|
|
208
|
-
* - `-hide_banner -loglevel warning`: Reduce noise, only show warnings/errors
|
|
209
|
-
* - `-probesize 16384`: Limit input probing to 16KB (Chrome's Matroska header fits well under this) to minimize startup delay
|
|
210
|
-
* - `-i pipe:0`: Read input from stdin
|
|
211
|
-
* - `-c:v copy`: Copy video stream without re-encoding (passthrough)
|
|
212
|
-
* - `-c:a aac -b:a <bitrate>`: Transcode audio to AAC at specified bitrate
|
|
213
|
-
* - `-f mp4`: Output MP4 container format
|
|
214
|
-
* - `-movflags frag_keyframe+empty_moov+default_base_moof`: Streaming-friendly fMP4 flags
|
|
215
|
-
* - `-flush_packets 1`: Flush output immediately after each packet to minimize latency
|
|
216
|
-
* - `pipe:1`: Write output to stdout
|
|
217
194
|
* @param audioBitrate - Audio bitrate in bits per second (e.g., 256000 for 256 kbps).
|
|
218
|
-
* @param
|
|
219
|
-
* @
|
|
220
|
-
* @param comment - Optional comment metadata (channel name or domain) to embed in the output.
|
|
221
|
-
* @returns FFmpeg process wrapper with stdin, stdout, and kill function.
|
|
195
|
+
* @param options - Optional comment metadata and platform override.
|
|
196
|
+
* @returns The FFmpeg argv array (excluding the binary itself).
|
|
222
197
|
*/
|
|
223
|
-
export function
|
|
198
|
+
export function buildSpawnFFmpegArgs(audioBitrate, options = {}) {
|
|
199
|
+
const platform = options.platform ?? process.platform;
|
|
200
|
+
const comment = options.comment;
|
|
224
201
|
// Use Apple's AudioToolbox AAC encoder on macOS for better quality and performance. Fall back to FFmpeg's built-in AAC encoder on other platforms.
|
|
225
|
-
const aacEncoder =
|
|
202
|
+
const aacEncoder = platform === "darwin" ? "aac_at" : "aac";
|
|
226
203
|
const ffmpegArgs = [
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
"-loglevel", "warning",
|
|
230
|
-
"-fflags", "+discardcorrupt",
|
|
231
|
-
"-err_detect", "ignore_err",
|
|
232
|
-
"-probesize", "16384",
|
|
204
|
+
...FFMPEG_INPUT_FLAGS,
|
|
205
|
+
// Read Matroska from stdin.
|
|
233
206
|
"-i", "pipe:0",
|
|
207
|
+
// Pass video through unchanged (codec copy) and transcode audio to AAC at the requested bitrate. macOS uses Apple's hardware AAC encoder; other platforms fall
|
|
208
|
+
// back to FFmpeg's software encoder.
|
|
234
209
|
"-c:v", "copy",
|
|
235
210
|
"-c:a", aacEncoder,
|
|
236
211
|
"-b:a", String(audioBitrate),
|
|
212
|
+
// Emit fragmented MP4 with a moov-less header so HLS segmenters can consume the stream incrementally. skip_sidx and skip_trailer keep init-segment overhead low.
|
|
237
213
|
"-f", "mp4",
|
|
238
214
|
"-movflags", "frag_keyframe+empty_moov+default_base_moof+skip_sidx+skip_trailer",
|
|
215
|
+
// Flush each packet immediately to minimize the latency between MediaRecorder output and downstream segmentation.
|
|
239
216
|
"-flush_packets", "1"
|
|
240
217
|
];
|
|
241
218
|
// Add metadata comment if provided. This embeds "PrismCast - <channel>" in the output for identification.
|
|
242
219
|
if (comment) {
|
|
243
220
|
ffmpegArgs.push("-metadata", "comment=PrismCast - " + comment);
|
|
244
221
|
}
|
|
222
|
+
// Write output to stdout. This must come last so any preceding flags (including optional metadata) take effect on the output stream.
|
|
245
223
|
ffmpegArgs.push("pipe:1");
|
|
224
|
+
return ffmpegArgs;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Builds the argv for an FFmpeg invocation that remuxes fMP4 input to MPEG-TS output with codec copy (no transcoding). Pure: takes no inputs and depends on no
|
|
228
|
+
* external state.
|
|
229
|
+
*
|
|
230
|
+
* The output flags emit ATSC-conventional MPEG-TS resembling a real HDHomeRun CONNECT DUO so Plex's transcoder makes the right assumptions about stream structure
|
|
231
|
+
* (PID assignments, PAT/PMT frequency). Container metadata only - the actual A/V data is untouched by -c copy.
|
|
232
|
+
*
|
|
233
|
+
* @returns The FFmpeg argv array (excluding the binary itself).
|
|
234
|
+
*/
|
|
235
|
+
export function buildMpegTsRemuxerArgs() {
|
|
236
|
+
return [
|
|
237
|
+
...FFMPEG_INPUT_FLAGS,
|
|
238
|
+
// Read fragmented MP4 from stdin and copy both video and audio without transcoding.
|
|
239
|
+
"-f", "mp4",
|
|
240
|
+
"-i", "pipe:0",
|
|
241
|
+
"-c", "copy",
|
|
242
|
+
...MPEGTS_OUTPUT_FLAGS,
|
|
243
|
+
// Write MPEG-TS to stdout.
|
|
244
|
+
"pipe:1"
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
// Public FFmpeg Spawners.
|
|
248
|
+
/**
|
|
249
|
+
* Spawns an FFmpeg process configured to remux Matroska to fMP4. The process reads from stdin and writes to stdout, allowing integration into a Node.js stream
|
|
250
|
+
* pipeline. Callers provide the resolved FFmpeg binary path; resolution is the caller's responsibility (typically via resolveFFmpegPath() at startup or stream
|
|
251
|
+
* setup) so this function stays a thin spawn() wrapper.
|
|
252
|
+
* @param ffmpegBin - The absolute path to the FFmpeg binary (typically the result of resolveFFmpegPath()).
|
|
253
|
+
* @param audioBitrate - Audio bitrate in bits per second (e.g., 256000 for 256 kbps).
|
|
254
|
+
* @param onError - Callback invoked when FFmpeg exits unexpectedly or encounters an error.
|
|
255
|
+
* @param streamId - Stream identifier for logging.
|
|
256
|
+
* @param comment - Optional comment metadata (channel name or domain) to embed in the output.
|
|
257
|
+
* @returns FFmpeg process wrapper with stdin, stdout, and kill function.
|
|
258
|
+
*/
|
|
259
|
+
export function spawnFFmpeg(ffmpegBin, audioBitrate, onError, streamId, comment) {
|
|
246
260
|
return spawnFFmpegProcess({
|
|
247
|
-
args:
|
|
261
|
+
args: buildSpawnFFmpegArgs(audioBitrate, { comment }),
|
|
262
|
+
ffmpegBin,
|
|
248
263
|
label: "FFmpeg",
|
|
249
264
|
onError,
|
|
250
265
|
streamId
|
|
@@ -252,46 +267,28 @@ export function spawnFFmpeg(audioBitrate, onError, streamId, comment) {
|
|
|
252
267
|
}
|
|
253
268
|
/**
|
|
254
269
|
* Spawns an FFmpeg process configured to remux fMP4 input to MPEG-TS output with codec copy. The process reads a continuous fMP4 stream (init segment followed by
|
|
255
|
-
* media segments) from stdin and writes MPEG-TS to stdout. No transcoding occurs
|
|
256
|
-
*
|
|
257
|
-
* FFmpeg arguments:
|
|
258
|
-
* - `-hide_banner -loglevel warning`: Reduce noise, only show warnings/errors
|
|
259
|
-
* - `-probesize 16384`: Limit input probing to 16KB (fMP4 init segment is ~1.3KB) to minimize startup delay
|
|
260
|
-
* - `-f mp4 -i pipe:0`: Read fragmented MP4 from stdin
|
|
261
|
-
* - `-c copy`: Copy both video and audio codecs without transcoding
|
|
262
|
-
* - MPEG-TS output flags: See MPEGTS_OUTPUT_FLAGS for ATSC-conventional settings
|
|
263
|
-
* - `pipe:1`: Write output to stdout
|
|
270
|
+
* media segments) from stdin and writes MPEG-TS to stdout. No transcoding occurs - both video and audio are copied unchanged - so CPU usage is minimal.
|
|
271
|
+
* @param ffmpegBin - The absolute path to the FFmpeg binary (typically the result of resolveFFmpegPath()).
|
|
264
272
|
* @param onError - Callback invoked when FFmpeg exits unexpectedly or encounters an error.
|
|
265
273
|
* @param streamId - Optional stream identifier for logging.
|
|
266
274
|
* @returns FFmpeg process wrapper with stdin, stdout, and kill function.
|
|
267
275
|
*/
|
|
268
|
-
export function spawnMpegTsRemuxer(onError, streamId) {
|
|
269
|
-
const ffmpegArgs = [
|
|
270
|
-
"-hide_banner",
|
|
271
|
-
"-nostats",
|
|
272
|
-
"-loglevel", "warning",
|
|
273
|
-
"-fflags", "+discardcorrupt",
|
|
274
|
-
"-err_detect", "ignore_err",
|
|
275
|
-
"-probesize", "16384",
|
|
276
|
-
"-f", "mp4",
|
|
277
|
-
"-i", "pipe:0",
|
|
278
|
-
"-c", "copy",
|
|
279
|
-
...MPEGTS_OUTPUT_FLAGS,
|
|
280
|
-
"pipe:1"
|
|
281
|
-
];
|
|
276
|
+
export function spawnMpegTsRemuxer(ffmpegBin, onError, streamId) {
|
|
282
277
|
return spawnFFmpegProcess({
|
|
283
|
-
args:
|
|
278
|
+
args: buildMpegTsRemuxerArgs(),
|
|
279
|
+
ffmpegBin,
|
|
284
280
|
label: "MPEG-TS remuxer",
|
|
285
281
|
onError,
|
|
286
282
|
streamId
|
|
287
283
|
});
|
|
288
284
|
}
|
|
289
285
|
/**
|
|
290
|
-
* Checks if FFmpeg is available on the system.
|
|
286
|
+
* Checks if FFmpeg is available on the system. Wraps the production-cached resolveFFmpegPath, so first call probes the filesystem and subsequent calls return
|
|
287
|
+
* the memoized result. Tests should use probeFFmpegPath against synthetic contexts instead - this function delegates to the singleton resolver and has no test
|
|
288
|
+
* seam.
|
|
291
289
|
* @returns Promise resolving to true if FFmpeg is available, false otherwise.
|
|
292
290
|
*/
|
|
293
291
|
export async function isFFmpegAvailable() {
|
|
294
|
-
|
|
295
|
-
return ffmpegPath !== undefined;
|
|
292
|
+
return (await resolveFFmpegPath()) !== undefined;
|
|
296
293
|
}
|
|
297
294
|
//# sourceMappingURL=ffmpeg.js.map
|
package/dist/utils/ffmpeg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ffmpeg.js","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ffmpeg.js","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,iKAAiK;AACjK,2EAA2E;AAC3E,MAAM,qBAAqB,GAAG,CAAE,mBAAmB,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAE,CAAC;AAyBxG;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAqB,0BAA0B,EAAE;IAEpF,IAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QAElD,OAAO,GAAG,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iKAAiK;AACjK,4JAA4J;AAC5J,MAAM,kBAAkB,GAAsB;IAC5C,cAAc;IACd,UAAU;IACV,WAAW,EAAE,SAAS;IACtB,SAAS,EAAE,iBAAiB;IAC5B,aAAa,EAAE,YAAY;IAC3B,YAAY,EAAE,OAAO;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAqB,0BAA0B,EAAE;IAErF,sHA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
|
* Initializes the file logger. Creates the log file if it does not exist. Must be called after the data directory is ensured to exist.
|
|
3
5
|
* @param logPath - Absolute path to the log file, resolved by the caller via getLogFilePath().
|
|
@@ -8,10 +10,10 @@ export declare function initializeFileLogger(logPath: string, maxSize: number):
|
|
|
8
10
|
* Writes a log entry to the buffer. Entries are flushed to disk periodically.
|
|
9
11
|
* @param level - Log level ("info", "warn", "error", "debug").
|
|
10
12
|
* @param message - The formatted log message.
|
|
11
|
-
* @param color -
|
|
13
|
+
* @param color - Color name accepted by node:util.styleText, or null for the default terminal color.
|
|
12
14
|
* @param categoryTag - Optional debug category tag (e.g., "recovery:tab"). Appended to the level prefix as [DEBUG:category].
|
|
13
15
|
*/
|
|
14
|
-
export declare function writeLogEntry(level: string, message: string, color
|
|
16
|
+
export declare function writeLogEntry(level: string, message: string, color: LogColor, categoryTag?: string): void;
|
|
15
17
|
/**
|
|
16
18
|
* Flushes the write buffer to disk asynchronously. Called periodically by the flush timer.
|
|
17
19
|
*/
|
|
@@ -20,6 +22,20 @@ export declare function flushLogBuffer(): Promise<void>;
|
|
|
20
22
|
* Flushes the write buffer to disk synchronously. Used during shutdown to ensure final logs are written.
|
|
21
23
|
*/
|
|
22
24
|
export declare function flushLogBufferSync(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Pure trim logic: given the current log file content and the configured maximum size, returns the trimmed content (keeping complete lines from the file's tail)
|
|
27
|
+
* or null when no trim is needed (file is already at or below half maxSize). Extracted from trimLogFile so the cut-at-newline algorithm is testable in isolation
|
|
28
|
+
* without orchestrating real filesystem I/O - the surrounding read/write/rename chain is small enough to be exercised at the integration level.
|
|
29
|
+
*
|
|
30
|
+
* Algorithm: target half of maxSize as the post-trim file size, cut from (content.length - targetSize), then advance to the next newline so the trimmed file
|
|
31
|
+
* begins on a complete line. If no newline exists past the cut, the cut position is taken as-is (the trim still drops earlier content even if the kept tail is
|
|
32
|
+
* a single fragment line).
|
|
33
|
+
*
|
|
34
|
+
* @param content - The current log file content as a UTF-8 string.
|
|
35
|
+
* @param maxSize - The configured maximum log file size in bytes.
|
|
36
|
+
* @returns The trimmed content, or null when no trim is needed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function computeTrimmedLogContent(content: string, maxSize: number): Nullable<string>;
|
|
23
39
|
/**
|
|
24
40
|
* Shuts down the file logger, flushing any remaining buffer synchronously.
|
|
25
41
|
*/
|