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.
Files changed (360) hide show
  1. package/dist/app.d.ts +1 -1
  2. package/dist/app.js +27 -9
  3. package/dist/app.js.map +1 -1
  4. package/dist/browser/cdp.js +7 -7
  5. package/dist/browser/cdp.js.map +1 -1
  6. package/dist/browser/channelSelection.d.ts +41 -11
  7. package/dist/browser/channelSelection.js +75 -24
  8. package/dist/browser/channelSelection.js.map +1 -1
  9. package/dist/browser/display.d.ts +1 -1
  10. package/dist/browser/index.d.ts +8 -8
  11. package/dist/browser/index.js +42 -43
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/browser/login.d.ts +2 -2
  14. package/dist/browser/login.js +1 -1
  15. package/dist/browser/manifestInterceptor.d.ts +77 -0
  16. package/dist/browser/manifestInterceptor.js +323 -0
  17. package/dist/browser/manifestInterceptor.js.map +1 -0
  18. package/dist/browser/precaching.js +4 -4
  19. package/dist/browser/tuning/comcastPolymer.d.ts +1 -1
  20. package/dist/browser/tuning/cox.d.ts +1 -1
  21. package/dist/browser/tuning/directv.d.ts +1 -1
  22. package/dist/browser/tuning/directv.js +61 -62
  23. package/dist/browser/tuning/directv.js.map +1 -1
  24. package/dist/browser/tuning/fox.d.ts +1 -1
  25. package/dist/browser/tuning/fox.js +171 -14
  26. package/dist/browser/tuning/fox.js.map +1 -1
  27. package/dist/browser/tuning/hbo.d.ts +1 -1
  28. package/dist/browser/tuning/hbo.js +6 -6
  29. package/dist/browser/tuning/hbo.js.map +1 -1
  30. package/dist/browser/tuning/hulu.d.ts +1 -1
  31. package/dist/browser/tuning/hulu.js +117 -110
  32. package/dist/browser/tuning/hulu.js.map +1 -1
  33. package/dist/browser/tuning/shared.d.ts +3 -3
  34. package/dist/browser/tuning/shared.js +5 -5
  35. package/dist/browser/tuning/sling.d.ts +1 -1
  36. package/dist/browser/tuning/sling.js +28 -28
  37. package/dist/browser/tuning/sling.js.map +1 -1
  38. package/dist/browser/tuning/spectrum.d.ts +1 -1
  39. package/dist/browser/tuning/spectrum.js +21 -22
  40. package/dist/browser/tuning/spectrum.js.map +1 -1
  41. package/dist/browser/tuning/thumbnailRow.d.ts +1 -1
  42. package/dist/browser/tuning/thumbnailRow.js +1 -1
  43. package/dist/browser/tuning/tileClick.d.ts +1 -1
  44. package/dist/browser/tuning/tileClick.js +5 -5
  45. package/dist/browser/tuning/xfinity.d.ts +1 -1
  46. package/dist/browser/tuning/youtubeTv.d.ts +1 -1
  47. package/dist/browser/tuning/youtubeTv.js +17 -18
  48. package/dist/browser/tuning/youtubeTv.js.map +1 -1
  49. package/dist/browser/video.d.ts +20 -6
  50. package/dist/browser/video.js +30 -38
  51. package/dist/browser/video.js.map +1 -1
  52. package/dist/channels/index.d.ts +1 -2
  53. package/dist/channels/index.js +73 -40
  54. package/dist/channels/index.js.map +1 -1
  55. package/dist/config/channelForm.d.ts +58 -0
  56. package/dist/config/channelForm.js +129 -0
  57. package/dist/config/channelForm.js.map +1 -0
  58. package/dist/config/consistencyProbe.d.ts +7 -0
  59. package/dist/config/consistencyProbe.js +143 -0
  60. package/dist/config/consistencyProbe.js.map +1 -0
  61. package/dist/config/health.d.ts +4 -3
  62. package/dist/config/health.js +75 -62
  63. package/dist/config/health.js.map +1 -1
  64. package/dist/config/index.d.ts +1 -1
  65. package/dist/config/index.js +19 -12
  66. package/dist/config/index.js.map +1 -1
  67. package/dist/config/paths.d.ts +9 -3
  68. package/dist/config/paths.js +12 -4
  69. package/dist/config/paths.js.map +1 -1
  70. package/dist/config/persistence.context.d.ts +8 -0
  71. package/dist/config/persistence.context.js +30 -0
  72. package/dist/config/persistence.context.js.map +1 -0
  73. package/dist/config/persistence.d.ts +110 -12
  74. package/dist/config/persistence.js +351 -32
  75. package/dist/config/persistence.js.map +1 -1
  76. package/dist/config/presets.d.ts +14 -4
  77. package/dist/config/presets.js +84 -75
  78. package/dist/config/presets.js.map +1 -1
  79. package/dist/config/profiles.d.ts +2 -2
  80. package/dist/config/profiles.js +7 -9
  81. package/dist/config/profiles.js.map +1 -1
  82. package/dist/config/servicePacks.d.ts +2 -2
  83. package/dist/config/servicePacks.js +28 -28
  84. package/dist/config/servicePacks.js.map +1 -1
  85. package/dist/config/services.d.ts +62 -36
  86. package/dist/config/services.js +150 -136
  87. package/dist/config/services.js.map +1 -1
  88. package/dist/config/sites.d.ts +3 -3
  89. package/dist/config/sites.js +16 -16
  90. package/dist/config/sites.js.map +1 -1
  91. package/dist/config/userChannels.d.ts +500 -41
  92. package/dist/config/userChannels.js +1201 -312
  93. package/dist/config/userChannels.js.map +1 -1
  94. package/dist/config/userConfig.d.ts +103 -10
  95. package/dist/config/userConfig.js +277 -117
  96. package/dist/config/userConfig.js.map +1 -1
  97. package/dist/config/userProfiles.d.ts +4 -2
  98. package/dist/config/userProfiles.js +72 -26
  99. package/dist/config/userProfiles.js.map +1 -1
  100. package/dist/hdhr/channelMap.js +8 -11
  101. package/dist/hdhr/channelMap.js.map +1 -1
  102. package/dist/hdhr/deviceId.js +10 -9
  103. package/dist/hdhr/deviceId.js.map +1 -1
  104. package/dist/hdhr/discover.js +4 -5
  105. package/dist/hdhr/discover.js.map +1 -1
  106. package/dist/hdhr/index.js +6 -10
  107. package/dist/hdhr/index.js.map +1 -1
  108. package/dist/index.js +12 -12
  109. package/dist/index.js.map +1 -1
  110. package/dist/native/codecInference.d.ts +44 -0
  111. package/dist/native/codecInference.js +327 -0
  112. package/dist/native/codecInference.js.map +1 -0
  113. package/dist/native/decrypt.d.ts +1 -1
  114. package/dist/native/index.d.ts +5 -5
  115. package/dist/native/index.js +42 -64
  116. package/dist/native/index.js.map +1 -1
  117. package/dist/native/probe.d.ts +27 -9
  118. package/dist/native/probe.js +158 -67
  119. package/dist/native/probe.js.map +1 -1
  120. package/dist/native/proxy.d.ts +4 -2
  121. package/dist/native/proxy.js +52 -49
  122. package/dist/native/proxy.js.map +1 -1
  123. package/dist/native/tokenExpiry.d.ts +22 -0
  124. package/dist/native/tokenExpiry.js +153 -0
  125. package/dist/native/tokenExpiry.js.map +1 -0
  126. package/dist/routes/auth.js +6 -10
  127. package/dist/routes/auth.js.map +1 -1
  128. package/dist/routes/components.js +2 -2
  129. package/dist/routes/components.js.map +1 -1
  130. package/dist/routes/config/channels/endpoints/browse.d.ts +6 -0
  131. package/dist/routes/config/channels/endpoints/browse.js +195 -0
  132. package/dist/routes/config/channels/endpoints/browse.js.map +1 -0
  133. package/dist/routes/config/channels/endpoints/bulk.d.ts +6 -0
  134. package/dist/routes/config/channels/endpoints/bulk.js +128 -0
  135. package/dist/routes/config/channels/endpoints/bulk.js.map +1 -0
  136. package/dist/routes/config/channels/endpoints/crud.d.ts +6 -0
  137. package/dist/routes/config/channels/endpoints/crud.js +504 -0
  138. package/dist/routes/config/channels/endpoints/crud.js.map +1 -0
  139. package/dist/routes/config/channels/endpoints/importExport.d.ts +6 -0
  140. package/dist/routes/config/channels/endpoints/importExport.js +131 -0
  141. package/dist/routes/config/channels/endpoints/importExport.js.map +1 -0
  142. package/dist/routes/config/channels/endpoints/predefined.d.ts +6 -0
  143. package/dist/routes/config/channels/endpoints/predefined.js +78 -0
  144. package/dist/routes/config/channels/endpoints/predefined.js.map +1 -0
  145. package/dist/routes/config/channels/endpoints/prefs.d.ts +6 -0
  146. package/dist/routes/config/channels/endpoints/prefs.js +58 -0
  147. package/dist/routes/config/channels/endpoints/prefs.js.map +1 -0
  148. package/dist/routes/config/channels/endpoints/service.d.ts +6 -0
  149. package/dist/routes/config/channels/endpoints/service.js +149 -0
  150. package/dist/routes/config/channels/endpoints/service.js.map +1 -0
  151. package/dist/routes/config/channels/endpoints/tags.d.ts +6 -0
  152. package/dist/routes/config/channels/endpoints/tags.js +185 -0
  153. package/dist/routes/config/channels/endpoints/tags.js.map +1 -0
  154. package/dist/routes/config/channels/http/handler.d.ts +10 -0
  155. package/dist/routes/config/channels/http/handler.js +20 -0
  156. package/dist/routes/config/channels/http/handler.js.map +1 -0
  157. package/dist/routes/config/channels/http/playlistHint.d.ts +25 -0
  158. package/dist/routes/config/channels/http/playlistHint.js +40 -0
  159. package/dist/routes/config/channels/http/playlistHint.js.map +1 -0
  160. package/dist/routes/config/channels/http/serviceWarning.d.ts +10 -0
  161. package/dist/routes/config/channels/http/serviceWarning.js +28 -0
  162. package/dist/routes/config/channels/http/serviceWarning.js.map +1 -0
  163. package/dist/routes/config/channels/index.d.ts +3 -3
  164. package/dist/routes/config/channels/index.js +1 -1
  165. package/dist/routes/config/channels/index.js.map +1 -1
  166. package/dist/routes/config/channels/{routes.d.ts → setup.d.ts} +1 -1
  167. package/dist/routes/config/channels/setup.js +23 -0
  168. package/dist/routes/config/channels/setup.js.map +1 -0
  169. package/dist/routes/config/channels/table.d.ts +9 -9
  170. package/dist/routes/config/channels/table.js +124 -76
  171. package/dist/routes/config/channels/table.js.map +1 -1
  172. package/dist/routes/config/http/envelope.d.ts +111 -0
  173. package/dist/routes/config/http/envelope.js +103 -0
  174. package/dist/routes/config/http/envelope.js.map +1 -0
  175. package/dist/routes/config/index.d.ts +9 -9
  176. package/dist/routes/config/index.js +2 -2
  177. package/dist/routes/config/index.js.map +1 -1
  178. package/dist/routes/config/services.js +69 -68
  179. package/dist/routes/config/services.js.map +1 -1
  180. package/dist/routes/config/settings.d.ts +1 -1
  181. package/dist/routes/config/settings.js +45 -38
  182. package/dist/routes/config/settings.js.map +1 -1
  183. package/dist/routes/debug.js +12 -11
  184. package/dist/routes/debug.js.map +1 -1
  185. package/dist/routes/icons.js +2 -2
  186. package/dist/routes/icons.js.map +1 -1
  187. package/dist/routes/logs.js +19 -30
  188. package/dist/routes/logs.js.map +1 -1
  189. package/dist/routes/mpegts.js +1 -1
  190. package/dist/routes/playlist.d.ts +1 -1
  191. package/dist/routes/playlist.js +37 -26
  192. package/dist/routes/playlist.js.map +1 -1
  193. package/dist/routes/root/content.js +27 -6
  194. package/dist/routes/root/content.js.map +1 -1
  195. package/dist/routes/root/index.js +2 -5
  196. package/dist/routes/root/index.js.map +1 -1
  197. package/dist/routes/root/scripts/channels.js +16 -16
  198. package/dist/routes/root/scripts/channels.js.map +1 -1
  199. package/dist/routes/root/scripts/config.js +59 -59
  200. package/dist/routes/root/scripts/config.js.map +1 -1
  201. package/dist/routes/root/scripts/index.d.ts +4 -4
  202. package/dist/routes/root/scripts/shared.js +24 -10
  203. package/dist/routes/root/scripts/shared.js.map +1 -1
  204. package/dist/routes/root/scripts/status.d.ts +4 -0
  205. package/dist/routes/root/scripts/status.handlers.d.ts +182 -0
  206. package/dist/routes/root/scripts/status.handlers.js +713 -0
  207. package/dist/routes/root/scripts/status.handlers.js.map +1 -0
  208. package/dist/routes/root/scripts/status.js +86 -488
  209. package/dist/routes/root/scripts/status.js.map +1 -1
  210. package/dist/routes/root/styles.js +5 -5
  211. package/dist/routes/services.js +18 -15
  212. package/dist/routes/services.js.map +1 -1
  213. package/dist/routes/sse.d.ts +16 -0
  214. package/dist/routes/sse.js +29 -0
  215. package/dist/routes/sse.js.map +1 -0
  216. package/dist/routes/streams.js +10 -23
  217. package/dist/routes/streams.js.map +1 -1
  218. package/dist/routes/ui.d.ts +2 -2
  219. package/dist/routes/upgrade.js +6 -7
  220. package/dist/routes/upgrade.js.map +1 -1
  221. package/dist/service/commands.context.d.ts +6 -0
  222. package/dist/service/commands.context.js +47 -0
  223. package/dist/service/commands.context.js.map +1 -0
  224. package/dist/service/commands.d.ts +53 -8
  225. package/dist/service/commands.js +171 -188
  226. package/dist/service/commands.js.map +1 -1
  227. package/dist/service/generators.context.d.ts +6 -0
  228. package/dist/service/generators.context.js +45 -0
  229. package/dist/service/generators.context.js.map +1 -0
  230. package/dist/service/generators.d.ts +56 -16
  231. package/dist/service/generators.js +499 -383
  232. package/dist/service/generators.js.map +1 -1
  233. package/dist/service/index.d.ts +2 -2
  234. package/dist/streaming/clients.d.ts +2 -2
  235. package/dist/streaming/clients.js +2 -2
  236. package/dist/streaming/codec.d.ts +2 -2
  237. package/dist/streaming/codec.js +0 -1
  238. package/dist/streaming/codec.js.map +1 -1
  239. package/dist/streaming/fmp4Segmenter.d.ts +2 -2
  240. package/dist/streaming/fmp4Segmenter.js +12 -12
  241. package/dist/streaming/hls.d.ts +3 -3
  242. package/dist/streaming/hls.js +81 -70
  243. package/dist/streaming/hls.js.map +1 -1
  244. package/dist/streaming/hlsResume.d.ts +3 -3
  245. package/dist/streaming/hlsResume.js +5 -5
  246. package/dist/streaming/hlsSegments.d.ts +5 -2
  247. package/dist/streaming/hlsSegments.js +14 -9
  248. package/dist/streaming/hlsSegments.js.map +1 -1
  249. package/dist/streaming/monitor.d.ts +12 -12
  250. package/dist/streaming/monitor.js +80 -54
  251. package/dist/streaming/monitor.js.map +1 -1
  252. package/dist/streaming/mp4Parser.d.ts +34 -4
  253. package/dist/streaming/mp4Parser.js +111 -29
  254. package/dist/streaming/mp4Parser.js.map +1 -1
  255. package/dist/streaming/mpegts.d.ts +1 -1
  256. package/dist/streaming/mpegts.js +13 -10
  257. package/dist/streaming/mpegts.js.map +1 -1
  258. package/dist/streaming/playlistBuilder.d.ts +1 -1
  259. package/dist/streaming/playlistBuilder.js +2 -2
  260. package/dist/streaming/preroll.d.ts +9 -9
  261. package/dist/streaming/preroll.js +39 -41
  262. package/dist/streaming/preroll.js.map +1 -1
  263. package/dist/streaming/pretune.js +4 -4
  264. package/dist/streaming/pretune.js.map +1 -1
  265. package/dist/streaming/recovery.d.ts +3 -3
  266. package/dist/streaming/recovery.js +4 -4
  267. package/dist/streaming/registry.d.ts +6 -6
  268. package/dist/streaming/setup.d.ts +9 -8
  269. package/dist/streaming/setup.js +97 -49
  270. package/dist/streaming/setup.js.map +1 -1
  271. package/dist/streaming/showInfo.d.ts +9 -3
  272. package/dist/streaming/showInfo.js +26 -18
  273. package/dist/streaming/showInfo.js.map +1 -1
  274. package/dist/streaming/statusEmitter.d.ts +4 -4
  275. package/dist/streaming/statusEmitter.js +2 -2
  276. package/dist/types/channels.d.ts +133 -34
  277. package/dist/types/channels.js +39 -1
  278. package/dist/types/channels.js.map +1 -1
  279. package/dist/types/config.d.ts +20 -1
  280. package/dist/types/index.d.ts +9 -8
  281. package/dist/types/index.js +1 -0
  282. package/dist/types/index.js.map +1 -1
  283. package/dist/types/profiles.d.ts +5 -4
  284. package/dist/types/selection.d.ts +48 -4
  285. package/dist/types/streaming.d.ts +1 -1
  286. package/dist/upgrade/commands.context.d.ts +6 -0
  287. package/dist/upgrade/commands.context.js +29 -0
  288. package/dist/upgrade/commands.context.js.map +1 -0
  289. package/dist/upgrade/commands.d.ts +29 -2
  290. package/dist/upgrade/commands.js +87 -134
  291. package/dist/upgrade/commands.js.map +1 -1
  292. package/dist/upgrade/detection.context.d.ts +6 -0
  293. package/dist/upgrade/detection.context.js +24 -0
  294. package/dist/upgrade/detection.context.js.map +1 -0
  295. package/dist/upgrade/detection.d.ts +140 -10
  296. package/dist/upgrade/detection.js +153 -66
  297. package/dist/upgrade/detection.js.map +1 -1
  298. package/dist/upgrade/index.d.ts +2 -2
  299. package/dist/utils/chromeFetch.d.ts +1 -1
  300. package/dist/utils/chromeFetch.js +1 -1
  301. package/dist/utils/clock.d.ts +14 -0
  302. package/dist/utils/clock.js +28 -0
  303. package/dist/utils/clock.js.map +1 -0
  304. package/dist/utils/debugFilter.d.ts +1 -1
  305. package/dist/utils/debugFilter.js +6 -4
  306. package/dist/utils/debugFilter.js.map +1 -1
  307. package/dist/utils/delay.d.ts +2 -3
  308. package/dist/utils/delay.js +10 -16
  309. package/dist/utils/delay.js.map +1 -1
  310. package/dist/utils/evaluate.js +12 -14
  311. package/dist/utils/evaluate.js.map +1 -1
  312. package/dist/utils/ffmpeg.context.d.ts +6 -0
  313. package/dist/utils/ffmpeg.context.js +31 -0
  314. package/dist/utils/ffmpeg.context.js.map +1 -0
  315. package/dist/utils/ffmpeg.d.ts +85 -29
  316. package/dist/utils/ffmpeg.js +126 -129
  317. package/dist/utils/ffmpeg.js.map +1 -1
  318. package/dist/utils/fileLogger.d.ts +18 -2
  319. package/dist/utils/fileLogger.js +58 -30
  320. package/dist/utils/fileLogger.js.map +1 -1
  321. package/dist/utils/format.d.ts +1 -1
  322. package/dist/utils/format.js +2 -2
  323. package/dist/utils/format.js.map +1 -1
  324. package/dist/utils/html.js +1 -3
  325. package/dist/utils/html.js.map +1 -1
  326. package/dist/utils/index.d.ts +21 -20
  327. package/dist/utils/index.js +1 -0
  328. package/dist/utils/index.js.map +1 -1
  329. package/dist/utils/logger.js +16 -20
  330. package/dist/utils/logger.js.map +1 -1
  331. package/dist/utils/m3u.d.ts +18 -3
  332. package/dist/utils/m3u.js +28 -14
  333. package/dist/utils/m3u.js.map +1 -1
  334. package/dist/utils/memo.d.ts +19 -0
  335. package/dist/utils/memo.js +53 -0
  336. package/dist/utils/memo.js.map +1 -0
  337. package/dist/utils/morganStream.js +2 -2
  338. package/dist/utils/morganStream.js.map +1 -1
  339. package/dist/utils/pid.d.ts +2 -2
  340. package/dist/utils/pid.js +2 -2
  341. package/dist/utils/platform.d.ts +1 -1
  342. package/dist/utils/platform.js +3 -3
  343. package/dist/utils/platform.js.map +1 -1
  344. package/dist/utils/retry.d.ts +2 -0
  345. package/dist/utils/retry.js +9 -7
  346. package/dist/utils/retry.js.map +1 -1
  347. package/dist/utils/sanitize.d.ts +2 -2
  348. package/dist/utils/sanitize.js +4 -4
  349. package/dist/utils/timing.d.ts +6 -3
  350. package/dist/utils/timing.js +10 -6
  351. package/dist/utils/timing.js.map +1 -1
  352. package/dist/utils/version.d.ts +3 -2
  353. package/dist/utils/version.js +14 -27
  354. package/dist/utils/version.js.map +1 -1
  355. package/package.json +13 -7
  356. package/dist/native/intercept.d.ts +0 -35
  357. package/dist/native/intercept.js +0 -181
  358. package/dist/native/intercept.js.map +0 -1
  359. package/dist/routes/config/channels/routes.js +0 -1505
  360. package/dist/routes/config/channels/routes.js.map +0 -1
@@ -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
- * Resolves the FFmpeg executable path. Checks Channels DVR (macOS, Windows, Linux), then the bundled ffmpeg-for-homebridge, then system PATH. The resolved path is
12
- * cached for subsequent calls.
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 resolveFFmpegPath(): Promise<string | undefined>;
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
- * Spawns an FFmpeg process configured to remux Matroska to fMP4. Video is passed through unchanged (codec copy); audio is transcoded from Opus to AAC for HLS
27
- * compatibility. The video codec (H264 or HEVC) is determined by Chrome's MediaRecorder based on hardware capabilities. The process reads from stdin and writes
28
- * to stdout, allowing it to be integrated into a Node.js stream pipeline.
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
- * FFmpeg arguments:
31
- * - `-hide_banner -loglevel warning`: Reduce noise, only show warnings/errors
32
- * - `-probesize 16384`: Limit input probing to 16KB (Chrome's Matroska header fits well under this) to minimize startup delay
33
- * - `-i pipe:0`: Read input from stdin
34
- * - `-c:v copy`: Copy video stream without re-encoding (passthrough)
35
- * - `-c:a aac -b:a <bitrate>`: Transcode audio to AAC at specified bitrate
36
- * - `-f mp4`: Output MP4 container format
37
- * - `-movflags frag_keyframe+empty_moov+default_base_moof`: Streaming-friendly fMP4 flags
38
- * - `-flush_packets 1`: Flush output immediately after each packet to minimize latency
39
- * - `pipe:1`: Write output to stdout
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 — both video and audio are copied unchanged — so CPU usage is minimal.
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. This resolves the FFmpeg path and caches it for use by spawnFFmpeg().
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>;
@@ -1,11 +1,8 @@
1
1
  import { LOG } from "./logger.js";
2
- import { existsSync } from "node:fs";
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 (ffmpegPath && existsSync(ffmpegPath)) {
20
- return ffmpegPath;
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
- /* When using Matroska capture mode, Chrome's MediaRecorder outputs a Matroska container with video (H264 or HEVC depending on hardware capabilities) and Opus audio.
25
- * For HLS compatibility, we need an fMP4 container with AAC audio. FFmpeg handles this conversion:
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
- * - Video: Passed through unchanged (copy codec) - no quality loss, minimal CPU
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
- * The resolved path is cached after the first successful lookup to avoid repeated filesystem checks.
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 resolveFFmpegPath() {
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 (process.platform === "darwin") {
76
- const channelsDvrPath = join(homedir(), "Library", "Application Support", "ChannelsDVR", "latest", "ffmpeg");
77
- if (existsSync(channelsDvrPath) && (await checkFFmpegAtPath(channelsDvrPath))) {
78
- cachedFFmpegPath = channelsDvrPath;
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 (process.platform === "win32") {
58
+ if (ctx.platform === "win32") {
84
59
  const channelsDvrPath = join("C:", "ProgramData", "channelsdvr", "latest", "ffmpeg.exe");
85
- if (existsSync(channelsDvrPath) && (await checkFFmpegAtPath(channelsDvrPath))) {
86
- cachedFFmpegPath = channelsDvrPath;
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 (process.platform === "linux") {
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 (existsSync(channelsDvrPath) && (await checkFFmpegAtPath(channelsDvrPath))) {
101
- cachedFFmpegPath = channelsDvrPath;
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 (ffmpegPath && existsSync(ffmpegPath) && (await checkFFmpegAtPath(ffmpegPath))) {
108
- cachedFFmpegPath = ffmpegPath;
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 checkFFmpegAtPath("ffmpeg")) {
113
- cachedFFmpegPath = "ffmpeg";
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 — the actual
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() — do not treat as error.
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
- * Spawns an FFmpeg process configured to remux Matroska to fMP4. Video is passed through unchanged (codec copy); audio is transcoded from Opus to AAC for HLS
204
- * compatibility. The video codec (H264 or HEVC) is determined by Chrome's MediaRecorder based on hardware capabilities. The process reads from stdin and writes
205
- * to stdout, allowing it to be integrated into a Node.js stream pipeline.
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 onError - Callback invoked when FFmpeg exits unexpectedly or encounters an error.
219
- * @param streamId - Stream identifier for logging.
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 spawnFFmpeg(audioBitrate, onError, streamId, comment) {
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 = process.platform === "darwin" ? "aac_at" : "aac";
202
+ const aacEncoder = platform === "darwin" ? "aac_at" : "aac";
226
203
  const ffmpegArgs = [
227
- "-hide_banner",
228
- "-nostats",
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: ffmpegArgs,
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 — both video and audio are copied unchanged — so CPU usage is minimal.
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: ffmpegArgs,
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. This resolves the FFmpeg path and caches it for use by spawnFFmpeg().
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
- const ffmpegPath = await resolveFFmpegPath();
295
- return ffmpegPath !== undefined;
292
+ return (await resolveFFmpegPath()) !== undefined;
296
293
  }
297
294
  //# sourceMappingURL=ffmpeg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ffmpeg.js","sourceRoot":"","sources":["../../src/utils/ffmpeg.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,iJAAiJ;AACjJ,MAAM,UAAU,GAAG,mBAAoD,CAAC;AAExE,iKAAiK;AACjK,2EAA2E;AAC3E,MAAM,qBAAqB,GAAG,CAAE,mBAAmB,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAE,CAAC;AAExG;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB;IAElC,IAAG,UAAU,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAExC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AAEH,+FAA+F;AAC/F,IAAI,gBAAgB,GAAiC,IAAI,CAAC;AAE1D;;;;GAIG;AACH,KAAK,UAAU,iBAAiB,CAAC,WAAmB;IAElD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAE7B,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE;YAE9C,KAAK,EAAE,CAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAE;SACxC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,E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AACH,MAAM,UAAU,sBAAsB;IAEpC,OAAO;QACL,GAAG,kBAAkB;QACrB,oFAAoF;QACpF,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,MAAM;QACZ,GAAG,mBAAmB;QACtB,2BAA2B;QAC3B,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,0BAA0B;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,YAAoB,EAAE,OAA+B,EAAE,QAAiB,EAAE,OAAgB;IAEvI,OAAO,kBAAkB,CAAC;QAExB,IAAI,EAAE,oBAAoB,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC;QACrD,SAAS;QACT,KAAK,EAAE,QAAQ;QACf,OAAO;QACP,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB,EAAE,OAA+B,EAAE,QAAiB;IAEtG,OAAO,kBAAkB,CAAC;QAExB,IAAI,EAAE,sBAAsB,EAAE;QAC9B,SAAS;QACT,KAAK,EAAE,iBAAiB;QACxB,OAAO;QACP,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB;IAErC,OAAO,CAAC,MAAM,iBAAiB,EAAE,CAAC,KAAK,SAAS,CAAC;AACnD,CAAC"}
@@ -1,3 +1,5 @@
1
+ import type { Nullable } from "../types/index.ts";
2
+ export type LogColor = "cyan" | "red" | "yellow" | null;
1
3
  /**
2
4
  * 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 - Optional ANSI color code to apply to the level prefix and message.
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?: string, categoryTag?: string): void;
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
  */