@tmhs/screencast-mcp 0.39.0 → 0.45.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 (344) hide show
  1. package/README.md +95 -17
  2. package/assets/icon.png +0 -0
  3. package/assets/ui/player.html +47 -302
  4. package/assets/ui/player.js +402 -0
  5. package/dist/context.js +0 -5
  6. package/dist/index.js +17 -21
  7. package/dist/prompts.js +18 -8
  8. package/dist/resources.js +2 -14
  9. package/dist/server.js +49 -11
  10. package/dist/tools/addMarker.js +89 -0
  11. package/dist/tools/assembleHighlights.js +12 -7
  12. package/dist/tools/backdrop.js +89 -0
  13. package/dist/tools/bugReport.js +266 -0
  14. package/dist/tools/burnSubtitles.js +12 -6
  15. package/dist/tools/callout.js +32 -16
  16. package/dist/tools/chapters.js +156 -0
  17. package/dist/tools/clip.js +12 -9
  18. package/dist/tools/compress.js +10 -5
  19. package/dist/tools/concat.js +16 -15
  20. package/dist/tools/contactSheet.js +39 -33
  21. package/dist/tools/convert.js +12 -6
  22. package/dist/tools/crop.js +12 -7
  23. package/dist/tools/cutIdle.js +15 -9
  24. package/dist/tools/denoise.js +12 -6
  25. package/dist/tools/doctor.js +133 -0
  26. package/dist/tools/exportGif.js +14 -10
  27. package/dist/tools/exportPreset.js +11 -8
  28. package/dist/tools/extractAudio.js +10 -8
  29. package/dist/tools/findText.js +52 -98
  30. package/dist/tools/getMediaInfo.js +17 -3
  31. package/dist/tools/getSession.js +15 -3
  32. package/dist/tools/keystrokeOverlay.js +131 -0
  33. package/dist/tools/listAudioDevices.js +14 -7
  34. package/dist/tools/listSessions.js +13 -3
  35. package/dist/tools/listTargets.js +76 -0
  36. package/dist/tools/musicBed.js +14 -10
  37. package/dist/tools/normalizeAudio.js +12 -8
  38. package/dist/tools/overlay.js +16 -12
  39. package/dist/tools/pipeline.js +86 -25
  40. package/dist/tools/readEvents.js +21 -12
  41. package/dist/tools/redactRegion.js +19 -17
  42. package/dist/tools/reframe.js +9 -5
  43. package/dist/tools/reviewRecording.js +75 -22
  44. package/dist/tools/sampleFrames.js +33 -40
  45. package/dist/tools/saveReplay.js +90 -0
  46. package/dist/tools/scale.js +9 -3
  47. package/dist/tools/screenDiff.js +23 -17
  48. package/dist/tools/screenshot.js +21 -17
  49. package/dist/tools/speed.js +15 -4
  50. package/dist/tools/startRecording.js +96 -59
  51. package/dist/tools/stopRecording.js +35 -10
  52. package/dist/tools/titleCard.js +19 -11
  53. package/dist/tools/transcribe.js +13 -7
  54. package/dist/tools/trim.js +11 -10
  55. package/dist/tools/waitForChange.js +37 -22
  56. package/dist/tools/xfadeTransition.js +12 -8
  57. package/dist/tools/zoom.js +26 -29
  58. package/dist/utils/anim.js +1 -21
  59. package/dist/utils/animExport.js +5 -10
  60. package/dist/utils/audio.js +4 -33
  61. package/dist/utils/audioDevices.js +1 -48
  62. package/dist/utils/backdrop.js +151 -0
  63. package/dist/utils/bugReport.js +246 -0
  64. package/dist/utils/callout.js +1 -19
  65. package/dist/utils/calloutAssets.js +21 -11
  66. package/dist/utils/capabilities.js +95 -0
  67. package/dist/utils/captions.js +9 -26
  68. package/dist/utils/chapters.js +222 -0
  69. package/dist/utils/consent.js +29 -0
  70. package/dist/utils/diff.js +0 -46
  71. package/dist/utils/errors.js +5 -13
  72. package/dist/utils/events.js +21 -77
  73. package/dist/utils/expr.js +11 -0
  74. package/dist/utils/ffmpeg.js +119 -48
  75. package/dist/utils/fontCoverage.js +177 -0
  76. package/dist/utils/fonts.js +139 -23
  77. package/dist/utils/idle.js +12 -24
  78. package/dist/utils/images.js +0 -17
  79. package/dist/utils/jobs.js +42 -41
  80. package/dist/utils/keystrokes.js +170 -0
  81. package/dist/utils/lifecycle.js +11 -31
  82. package/dist/utils/logging.js +75 -0
  83. package/dist/utils/media.js +16 -124
  84. package/dist/utils/monitors.js +7 -43
  85. package/dist/utils/ocr.js +53 -71
  86. package/dist/utils/ocrScan.js +77 -0
  87. package/dist/utils/paths.js +68 -31
  88. package/dist/utils/pipeline.js +39 -25
  89. package/dist/utils/player.js +50 -27
  90. package/dist/utils/produce.js +6 -66
  91. package/dist/utils/replay.js +278 -0
  92. package/dist/utils/resolveTarget.js +0 -19
  93. package/dist/utils/retention.js +1 -15
  94. package/dist/utils/roots.js +42 -0
  95. package/dist/utils/sessions.js +195 -160
  96. package/dist/utils/sheet.js +0 -19
  97. package/dist/utils/still.js +0 -15
  98. package/dist/utils/targetList.js +63 -0
  99. package/dist/utils/targets.js +5 -70
  100. package/dist/utils/toolSpec.js +25 -0
  101. package/dist/utils/toolsets.js +122 -0
  102. package/dist/utils/validate.js +0 -22
  103. package/dist/utils/wgc.js +0 -46
  104. package/dist/utils/windows.js +5 -50
  105. package/dist/utils/zoom.js +55 -85
  106. package/dist/wgcRecorder.js +1 -30
  107. package/package.json +7 -3
  108. package/dist/context.d.ts +0 -9
  109. package/dist/context.d.ts.map +0 -1
  110. package/dist/context.js.map +0 -1
  111. package/dist/index.d.ts +0 -3
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.js.map +0 -1
  114. package/dist/prompts.d.ts +0 -10
  115. package/dist/prompts.d.ts.map +0 -1
  116. package/dist/prompts.js.map +0 -1
  117. package/dist/resources.d.ts +0 -3
  118. package/dist/resources.d.ts.map +0 -1
  119. package/dist/resources.js.map +0 -1
  120. package/dist/server.d.ts +0 -3
  121. package/dist/server.d.ts.map +0 -1
  122. package/dist/server.js.map +0 -1
  123. package/dist/tools/assembleHighlights.d.ts +0 -3
  124. package/dist/tools/assembleHighlights.d.ts.map +0 -1
  125. package/dist/tools/assembleHighlights.js.map +0 -1
  126. package/dist/tools/burnSubtitles.d.ts +0 -3
  127. package/dist/tools/burnSubtitles.d.ts.map +0 -1
  128. package/dist/tools/burnSubtitles.js.map +0 -1
  129. package/dist/tools/callout.d.ts +0 -37
  130. package/dist/tools/callout.d.ts.map +0 -1
  131. package/dist/tools/callout.js.map +0 -1
  132. package/dist/tools/clip.d.ts +0 -3
  133. package/dist/tools/clip.d.ts.map +0 -1
  134. package/dist/tools/clip.js.map +0 -1
  135. package/dist/tools/compress.d.ts +0 -3
  136. package/dist/tools/compress.d.ts.map +0 -1
  137. package/dist/tools/compress.js.map +0 -1
  138. package/dist/tools/concat.d.ts +0 -3
  139. package/dist/tools/concat.d.ts.map +0 -1
  140. package/dist/tools/concat.js.map +0 -1
  141. package/dist/tools/contactSheet.d.ts +0 -3
  142. package/dist/tools/contactSheet.d.ts.map +0 -1
  143. package/dist/tools/contactSheet.js.map +0 -1
  144. package/dist/tools/convert.d.ts +0 -3
  145. package/dist/tools/convert.d.ts.map +0 -1
  146. package/dist/tools/convert.js.map +0 -1
  147. package/dist/tools/crop.d.ts +0 -3
  148. package/dist/tools/crop.d.ts.map +0 -1
  149. package/dist/tools/crop.js.map +0 -1
  150. package/dist/tools/cutIdle.d.ts +0 -3
  151. package/dist/tools/cutIdle.d.ts.map +0 -1
  152. package/dist/tools/cutIdle.js.map +0 -1
  153. package/dist/tools/denoise.d.ts +0 -3
  154. package/dist/tools/denoise.d.ts.map +0 -1
  155. package/dist/tools/denoise.js.map +0 -1
  156. package/dist/tools/exportGif.d.ts +0 -3
  157. package/dist/tools/exportGif.d.ts.map +0 -1
  158. package/dist/tools/exportGif.js.map +0 -1
  159. package/dist/tools/exportPreset.d.ts +0 -3
  160. package/dist/tools/exportPreset.d.ts.map +0 -1
  161. package/dist/tools/exportPreset.js.map +0 -1
  162. package/dist/tools/extractAudio.d.ts +0 -3
  163. package/dist/tools/extractAudio.d.ts.map +0 -1
  164. package/dist/tools/extractAudio.js.map +0 -1
  165. package/dist/tools/findText.d.ts +0 -6
  166. package/dist/tools/findText.d.ts.map +0 -1
  167. package/dist/tools/findText.js.map +0 -1
  168. package/dist/tools/getMediaInfo.d.ts +0 -3
  169. package/dist/tools/getMediaInfo.d.ts.map +0 -1
  170. package/dist/tools/getMediaInfo.js.map +0 -1
  171. package/dist/tools/getSession.d.ts +0 -3
  172. package/dist/tools/getSession.d.ts.map +0 -1
  173. package/dist/tools/getSession.js.map +0 -1
  174. package/dist/tools/listAudioDevices.d.ts +0 -3
  175. package/dist/tools/listAudioDevices.d.ts.map +0 -1
  176. package/dist/tools/listAudioDevices.js.map +0 -1
  177. package/dist/tools/listSessions.d.ts +0 -3
  178. package/dist/tools/listSessions.d.ts.map +0 -1
  179. package/dist/tools/listSessions.js.map +0 -1
  180. package/dist/tools/musicBed.d.ts +0 -3
  181. package/dist/tools/musicBed.d.ts.map +0 -1
  182. package/dist/tools/musicBed.js.map +0 -1
  183. package/dist/tools/normalizeAudio.d.ts +0 -3
  184. package/dist/tools/normalizeAudio.d.ts.map +0 -1
  185. package/dist/tools/normalizeAudio.js.map +0 -1
  186. package/dist/tools/overlay.d.ts +0 -3
  187. package/dist/tools/overlay.d.ts.map +0 -1
  188. package/dist/tools/overlay.js.map +0 -1
  189. package/dist/tools/pipeline.d.ts +0 -3
  190. package/dist/tools/pipeline.d.ts.map +0 -1
  191. package/dist/tools/pipeline.js.map +0 -1
  192. package/dist/tools/readEvents.d.ts +0 -6
  193. package/dist/tools/readEvents.d.ts.map +0 -1
  194. package/dist/tools/readEvents.js.map +0 -1
  195. package/dist/tools/redactRegion.d.ts +0 -13
  196. package/dist/tools/redactRegion.d.ts.map +0 -1
  197. package/dist/tools/redactRegion.js.map +0 -1
  198. package/dist/tools/reframe.d.ts +0 -3
  199. package/dist/tools/reframe.d.ts.map +0 -1
  200. package/dist/tools/reframe.js.map +0 -1
  201. package/dist/tools/reviewRecording.d.ts +0 -5
  202. package/dist/tools/reviewRecording.d.ts.map +0 -1
  203. package/dist/tools/reviewRecording.js.map +0 -1
  204. package/dist/tools/sampleFrames.d.ts +0 -3
  205. package/dist/tools/sampleFrames.d.ts.map +0 -1
  206. package/dist/tools/sampleFrames.js.map +0 -1
  207. package/dist/tools/scale.d.ts +0 -3
  208. package/dist/tools/scale.d.ts.map +0 -1
  209. package/dist/tools/scale.js.map +0 -1
  210. package/dist/tools/screenDiff.d.ts +0 -3
  211. package/dist/tools/screenDiff.d.ts.map +0 -1
  212. package/dist/tools/screenDiff.js.map +0 -1
  213. package/dist/tools/screenshot.d.ts +0 -3
  214. package/dist/tools/screenshot.d.ts.map +0 -1
  215. package/dist/tools/screenshot.js.map +0 -1
  216. package/dist/tools/speed.d.ts +0 -3
  217. package/dist/tools/speed.d.ts.map +0 -1
  218. package/dist/tools/speed.js.map +0 -1
  219. package/dist/tools/startRecording.d.ts +0 -3
  220. package/dist/tools/startRecording.d.ts.map +0 -1
  221. package/dist/tools/startRecording.js.map +0 -1
  222. package/dist/tools/stopRecording.d.ts +0 -3
  223. package/dist/tools/stopRecording.d.ts.map +0 -1
  224. package/dist/tools/stopRecording.js.map +0 -1
  225. package/dist/tools/titleCard.d.ts +0 -3
  226. package/dist/tools/titleCard.d.ts.map +0 -1
  227. package/dist/tools/titleCard.js.map +0 -1
  228. package/dist/tools/transcribe.d.ts +0 -3
  229. package/dist/tools/transcribe.d.ts.map +0 -1
  230. package/dist/tools/transcribe.js.map +0 -1
  231. package/dist/tools/trim.d.ts +0 -3
  232. package/dist/tools/trim.d.ts.map +0 -1
  233. package/dist/tools/trim.js.map +0 -1
  234. package/dist/tools/waitForChange.d.ts +0 -3
  235. package/dist/tools/waitForChange.d.ts.map +0 -1
  236. package/dist/tools/waitForChange.js.map +0 -1
  237. package/dist/tools/xfadeTransition.d.ts +0 -3
  238. package/dist/tools/xfadeTransition.d.ts.map +0 -1
  239. package/dist/tools/xfadeTransition.js.map +0 -1
  240. package/dist/tools/zoom.d.ts +0 -15
  241. package/dist/tools/zoom.d.ts.map +0 -1
  242. package/dist/tools/zoom.js.map +0 -1
  243. package/dist/utils/anim.d.ts +0 -33
  244. package/dist/utils/anim.d.ts.map +0 -1
  245. package/dist/utils/anim.js.map +0 -1
  246. package/dist/utils/animExport.d.ts +0 -27
  247. package/dist/utils/animExport.d.ts.map +0 -1
  248. package/dist/utils/animExport.js.map +0 -1
  249. package/dist/utils/audio.d.ts +0 -49
  250. package/dist/utils/audio.d.ts.map +0 -1
  251. package/dist/utils/audio.js.map +0 -1
  252. package/dist/utils/audioDevices.d.ts +0 -33
  253. package/dist/utils/audioDevices.d.ts.map +0 -1
  254. package/dist/utils/audioDevices.js.map +0 -1
  255. package/dist/utils/callout.d.ts +0 -72
  256. package/dist/utils/callout.d.ts.map +0 -1
  257. package/dist/utils/callout.js.map +0 -1
  258. package/dist/utils/calloutAssets.d.ts +0 -3
  259. package/dist/utils/calloutAssets.d.ts.map +0 -1
  260. package/dist/utils/calloutAssets.js.map +0 -1
  261. package/dist/utils/captions.d.ts +0 -26
  262. package/dist/utils/captions.d.ts.map +0 -1
  263. package/dist/utils/captions.js.map +0 -1
  264. package/dist/utils/diff.d.ts +0 -112
  265. package/dist/utils/diff.d.ts.map +0 -1
  266. package/dist/utils/diff.js.map +0 -1
  267. package/dist/utils/errors.d.ts +0 -33
  268. package/dist/utils/errors.d.ts.map +0 -1
  269. package/dist/utils/errors.js.map +0 -1
  270. package/dist/utils/events.d.ts +0 -143
  271. package/dist/utils/events.d.ts.map +0 -1
  272. package/dist/utils/events.js.map +0 -1
  273. package/dist/utils/ffmpeg.d.ts +0 -50
  274. package/dist/utils/ffmpeg.d.ts.map +0 -1
  275. package/dist/utils/ffmpeg.js.map +0 -1
  276. package/dist/utils/fonts.d.ts +0 -17
  277. package/dist/utils/fonts.d.ts.map +0 -1
  278. package/dist/utils/fonts.js.map +0 -1
  279. package/dist/utils/idle.d.ts +0 -23
  280. package/dist/utils/idle.d.ts.map +0 -1
  281. package/dist/utils/idle.js.map +0 -1
  282. package/dist/utils/images.d.ts +0 -21
  283. package/dist/utils/images.d.ts.map +0 -1
  284. package/dist/utils/images.js.map +0 -1
  285. package/dist/utils/jobs.d.ts +0 -44
  286. package/dist/utils/jobs.d.ts.map +0 -1
  287. package/dist/utils/jobs.js.map +0 -1
  288. package/dist/utils/lifecycle.d.ts +0 -29
  289. package/dist/utils/lifecycle.d.ts.map +0 -1
  290. package/dist/utils/lifecycle.js.map +0 -1
  291. package/dist/utils/media.d.ts +0 -272
  292. package/dist/utils/media.d.ts.map +0 -1
  293. package/dist/utils/media.js.map +0 -1
  294. package/dist/utils/monitors.d.ts +0 -47
  295. package/dist/utils/monitors.d.ts.map +0 -1
  296. package/dist/utils/monitors.js.map +0 -1
  297. package/dist/utils/ocr.d.ts +0 -50
  298. package/dist/utils/ocr.d.ts.map +0 -1
  299. package/dist/utils/ocr.js.map +0 -1
  300. package/dist/utils/paths.d.ts +0 -28
  301. package/dist/utils/paths.d.ts.map +0 -1
  302. package/dist/utils/paths.js.map +0 -1
  303. package/dist/utils/pipeline.d.ts +0 -69
  304. package/dist/utils/pipeline.d.ts.map +0 -1
  305. package/dist/utils/pipeline.js.map +0 -1
  306. package/dist/utils/player.d.ts +0 -30
  307. package/dist/utils/player.d.ts.map +0 -1
  308. package/dist/utils/player.js.map +0 -1
  309. package/dist/utils/produce.d.ts +0 -126
  310. package/dist/utils/produce.d.ts.map +0 -1
  311. package/dist/utils/produce.js.map +0 -1
  312. package/dist/utils/resolveTarget.d.ts +0 -32
  313. package/dist/utils/resolveTarget.d.ts.map +0 -1
  314. package/dist/utils/resolveTarget.js.map +0 -1
  315. package/dist/utils/retention.d.ts +0 -10
  316. package/dist/utils/retention.d.ts.map +0 -1
  317. package/dist/utils/retention.js.map +0 -1
  318. package/dist/utils/sessions.d.ts +0 -154
  319. package/dist/utils/sessions.d.ts.map +0 -1
  320. package/dist/utils/sessions.js.map +0 -1
  321. package/dist/utils/sheet.d.ts +0 -26
  322. package/dist/utils/sheet.d.ts.map +0 -1
  323. package/dist/utils/sheet.js.map +0 -1
  324. package/dist/utils/still.d.ts +0 -7
  325. package/dist/utils/still.d.ts.map +0 -1
  326. package/dist/utils/still.js.map +0 -1
  327. package/dist/utils/targets.d.ts +0 -113
  328. package/dist/utils/targets.d.ts.map +0 -1
  329. package/dist/utils/targets.js.map +0 -1
  330. package/dist/utils/validate.d.ts +0 -15
  331. package/dist/utils/validate.d.ts.map +0 -1
  332. package/dist/utils/validate.js.map +0 -1
  333. package/dist/utils/wgc.d.ts +0 -46
  334. package/dist/utils/wgc.d.ts.map +0 -1
  335. package/dist/utils/wgc.js.map +0 -1
  336. package/dist/utils/windows.d.ts +0 -94
  337. package/dist/utils/windows.d.ts.map +0 -1
  338. package/dist/utils/windows.js.map +0 -1
  339. package/dist/utils/zoom.d.ts +0 -95
  340. package/dist/utils/zoom.d.ts.map +0 -1
  341. package/dist/utils/zoom.js.map +0 -1
  342. package/dist/wgcRecorder.d.ts +0 -2
  343. package/dist/wgcRecorder.d.ts.map +0 -1
  344. package/dist/wgcRecorder.js.map +0 -1
@@ -1,26 +1,17 @@
1
- /**
2
- * Recording stop sequence, shared by stop_recording and server shutdown.
3
- *
4
- * Graceful first: ffmpeg quits cleanly (and finalizes the mp4) on 'q' over
5
- * stdin. If it does not exit in time, or the live handle was lost (a
6
- * cross-restart stop), the process is terminated by pid; the fragmented-mp4
7
- * muxing keeps a killed recording playable either way.
8
- */
9
1
  import { existsSync, rmSync, writeFileSync } from "node:fs";
10
- import { runCapture } from "./ffmpeg.js";
2
+ import { requireFfmpeg, runCapture } from "./ffmpeg.js";
3
+ import { finishReplay } from "./replay.js";
11
4
  import { whenFinalized } from "./events.js";
12
5
  import { buildProbeArgs, parseMediaInfo } from "./media.js";
13
6
  import { ScreencastError } from "./errors.js";
14
7
  import { wgcStopFile } from "./wgc.js";
15
8
  import { expectedImage, isAlive, isRecorderProcess, killPid, } from "./sessions.js";
16
- /** Poll until a pid is gone (process fully exited, file handles released). */
17
9
  async function waitForPidExit(pid, ms) {
18
10
  const deadline = Date.now() + ms;
19
11
  while (Date.now() < deadline && isAlive(pid)) {
20
12
  await new Promise((r) => setTimeout(r, 100));
21
13
  }
22
14
  }
23
- /** Wait up to ms for a child to exit; resolve true if it did. */
24
15
  export function waitForExit(child, ms) {
25
16
  return new Promise((resolve) => {
26
17
  if (child.exitCode !== null || child.signalCode !== null)
@@ -32,7 +23,6 @@ export function waitForExit(child, ms) {
32
23
  });
33
24
  });
34
25
  }
35
- /** Probe a finished file's duration, or null if it is missing/unreadable. */
36
26
  export async function probeDuration(ffprobe, path) {
37
27
  if (!existsSync(path))
38
28
  return null;
@@ -46,11 +36,6 @@ export async function probeDuration(ffprobe, path) {
46
36
  return null;
47
37
  }
48
38
  }
49
- /**
50
- * Stop every recording this instance owns (server shutdown, #76). Stops run in
51
- * parallel and the whole pass is capped at `capMs` so a wedged ffmpeg cannot
52
- * hold the process open; never throws. Returns the ids it attempted.
53
- */
54
39
  export async function stopAll(store, probe, capMs = 10_000) {
55
40
  const ids = store.activeIds();
56
41
  const stops = ids.map(async (id) => {
@@ -72,12 +57,7 @@ export async function stopAll(store, probe, capMs = 10_000) {
72
57
  clearTimeout(timer);
73
58
  return ids;
74
59
  }
75
- /** Stops in flight, per store and session id. A second stop of the same
76
- * session (an agent retry, or shutdown racing stop_recording) joins the first
77
- * instead of force-killing a recording that is still finalizing (#181). */
78
60
  const inFlight = new WeakMap();
79
- /** Stop an active recording and record its final state. The caller has already
80
- * checked the record exists and is "recording". */
81
61
  export function stopSession(store, record, opts) {
82
62
  let stops = inFlight.get(store);
83
63
  if (!stops)
@@ -105,12 +85,8 @@ async function runStop(store, record, opts) {
105
85
  }
106
86
  }
107
87
  else if (record.pid !== null && isAlive(record.pid)) {
108
- // Cross-restart stop: no stdin handle. Act on the pid only while it is
109
- // still the recorder this record started (never a recycled, unrelated
110
- // process); the wgc recorder runs under node, not ffmpeg (#182).
111
88
  if (isRecorderProcess(record.pid, expectedImage(record))) {
112
89
  if (stopFile) {
113
- // The wgc recorder finalizes when its stop file appears.
114
90
  writeFileSync(stopFile, "");
115
91
  await waitForPidExit(record.pid, opts.gracefulMs ?? 8000);
116
92
  graceful = !isAlive(record.pid);
@@ -125,19 +101,24 @@ async function runStop(store, record, opts) {
125
101
  }
126
102
  }
127
103
  store.detachChild(record.id);
128
- // The input event log converts once ffmpeg has exited (#118).
129
104
  await whenFinalized(record.id);
105
+ const replay = record.replay
106
+ ? await finishReplay(record.replay, {
107
+ save: opts.saveReplay ?? false,
108
+ output: record.outputPath,
109
+ quality: record.quality,
110
+ tools: requireFfmpeg,
111
+ })
112
+ : undefined;
130
113
  const durationSec = await opts.probe(record.outputPath);
131
114
  const updated = store.update(record.id, {
132
115
  status: "stopped",
133
116
  stoppedAt: new Date().toISOString(),
134
117
  durationSec: durationSec ?? undefined,
135
118
  endReason: opts.reason,
136
- // A forced kill can transiently mark the record "failed" via the crash
137
- // detector in start_recording; a deliberate stop is not a failure.
138
119
  error: undefined,
139
120
  });
140
- return { record: updated, graceful, durationSec };
121
+ return { record: updated, graceful, durationSec, ...(replay ? { replay } : {}) };
141
122
  }
142
123
  finally {
143
124
  if (stopFile)
@@ -145,4 +126,3 @@ async function runStop(store, record, opts) {
145
126
  store.clearStopping(record.id);
146
127
  }
147
128
  }
148
- //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,75 @@
1
+ export const LOGGER_NAME = "screencast-mcp";
2
+ const servers = new Set();
3
+ export function attachLogging(server) {
4
+ servers.add(server);
5
+ }
6
+ export function logMessage(level, message, data = {}) {
7
+ for (const server of servers) {
8
+ if (!server.isConnected())
9
+ continue;
10
+ server
11
+ .sendLoggingMessage({ level, logger: LOGGER_NAME, data: { message, ...data } })
12
+ .catch(() => { });
13
+ }
14
+ }
15
+ const PROGRESS = /^\s*(?:frame|size)=/;
16
+ const WARNING = /\b(?:warning|deprecated|dropp(?:ed|ing)|too full|discard\w*|non[- ]?monoton\w*|past duration|could not|cannot|failed|invalid|corrupt\w*|missing|error)\b/i;
17
+ const BENIGN = /^\s*configuration:|deprecated pixel format used/i;
18
+ export const MAX_WARNINGS = 20;
19
+ function isWarning(line) {
20
+ return !PROGRESS.test(line) && WARNING.test(line) && !BENIGN.test(line);
21
+ }
22
+ export function ffmpegWarnings(stderr) {
23
+ const out = new Set();
24
+ for (const raw of stderr.split(/[\r\n]+/)) {
25
+ const line = raw.trim();
26
+ if (line && isWarning(line))
27
+ out.add(line);
28
+ if (out.size >= MAX_WARNINGS)
29
+ break;
30
+ }
31
+ return [...out];
32
+ }
33
+ export function logFfmpegWarnings(stderr, data = {}) {
34
+ const warnings = ffmpegWarnings(stderr);
35
+ if (warnings.length > 0)
36
+ logMessage("warning", "ffmpeg reported warnings.", { ...data, warnings });
37
+ }
38
+ export const DROP_REPORT_INTERVAL_MS = 10_000;
39
+ export class StderrWatch {
40
+ data;
41
+ send;
42
+ now;
43
+ partial = "";
44
+ seen = new Set();
45
+ dropped = 0;
46
+ lastDropReport = -Infinity;
47
+ constructor(data, send = logMessage, now = Date.now) {
48
+ this.data = data;
49
+ this.send = send;
50
+ this.now = now;
51
+ }
52
+ feed(chunk) {
53
+ const parts = (this.partial + chunk).split(/[\r\n]/);
54
+ this.partial = parts.pop() ?? "";
55
+ for (const raw of parts)
56
+ this.line(raw.trim());
57
+ }
58
+ line(line) {
59
+ if (!line)
60
+ return;
61
+ if (PROGRESS.test(line)) {
62
+ const drop = Number(/\bdrop=\s*(\d+)/.exec(line)?.[1] ?? 0);
63
+ if (drop > this.dropped && this.now() - this.lastDropReport >= DROP_REPORT_INTERVAL_MS) {
64
+ this.lastDropReport = this.now();
65
+ this.dropped = drop;
66
+ this.send("warning", `The recording has dropped ${drop} frame(s) so far.`, { ...this.data(), dropped: drop });
67
+ }
68
+ return;
69
+ }
70
+ if (!isWarning(line) || this.seen.has(line) || this.seen.size >= MAX_WARNINGS)
71
+ return;
72
+ this.seen.add(line);
73
+ this.send("warning", line, { ...this.data(), source: "ffmpeg" });
74
+ }
75
+ }
@@ -1,15 +1,8 @@
1
- /**
2
- * ffprobe parsing and the Phase 1 edit/watch argument builders.
3
- *
4
- * All functions here are pure (string in, args/strings out) so the edit and
5
- * watch surfaces are unit-tested without ffmpeg present.
6
- */
7
1
  import { extname } from "node:path";
8
2
  import { ScreencastError } from "./errors.js";
9
3
  import { resolveQuality } from "./targets.js";
10
4
  import { validateColor, validateEvenDimension } from "./validate.js";
11
5
  import { stillOutput } from "./paths.js";
12
- /** Edit re-encodes default to the same preset as a standard capture. */
13
6
  const DEFAULT_EDIT_QUALITY = "standard";
14
7
  function numberOrNull(v) {
15
8
  if (v === undefined)
@@ -17,7 +10,6 @@ function numberOrNull(v) {
17
10
  const n = Number(v);
18
11
  return Number.isFinite(n) ? n : null;
19
12
  }
20
- /** Parse an `avg_frame_rate` / `r_frame_rate` rational ("30000/1001") to fps. */
21
13
  export function parseFrameRate(value) {
22
14
  if (!value)
23
15
  return null;
@@ -30,15 +22,12 @@ export function parseFrameRate(value) {
30
22
  return null;
31
23
  return Math.round((n / d) * 1000) / 1000;
32
24
  }
33
- /** The display rotation of a video stream in degrees (display-matrix side
34
- * data, or the older `rotate` tag), or null. */
35
25
  function streamRotation(video) {
36
26
  const side = video?.side_data_list?.find((d) => d.rotation !== undefined)?.rotation;
37
27
  const raw = side ?? video?.tags?.rotate;
38
28
  const n = raw === undefined ? NaN : Number(raw);
39
29
  return Number.isFinite(n) ? Math.round(n) % 360 : null;
40
30
  }
41
- /** Reduce a parsed ffprobe JSON document to a flat MediaInfo. */
42
31
  export function parseMediaInfo(probe) {
43
32
  const streams = probe.streams ?? [];
44
33
  const video = streams.find((s) => s.codec_type === "video");
@@ -47,7 +36,6 @@ export function parseMediaInfo(probe) {
47
36
  const size = probe.format?.size;
48
37
  const durationSec = duration !== undefined ? Number(duration) : null;
49
38
  const rotation = streamRotation(video);
50
- // ffmpeg auto-rotates on decode, so a 90-degree file filters as height x width.
51
39
  const turned = rotation !== null && Math.abs(rotation) % 180 === 90;
52
40
  return {
53
41
  durationSec,
@@ -81,13 +69,8 @@ function validatePositive(value, label) {
81
69
  }
82
70
  return value;
83
71
  }
84
- /** Default and ceiling for how many frames one sample_frames call may write. */
85
72
  export const DEFAULT_MAX_FRAMES = 100;
86
73
  export const MAX_FRAMES_CEILING = 1000;
87
- /** Fit a requested sampling rate under a frame cap (#80). When duration * fps
88
- * would exceed maxFrames, lower the rate so the frames still span the whole
89
- * video instead of stopping partway. An unknown duration leaves the rate as
90
- * asked; the -frames:v backstop in buildSampleByFpsArgs still applies. */
91
74
  export function planFpsSampling(durationSec, fps, maxFrames) {
92
75
  validatePositive(fps, "fps");
93
76
  if (durationSec === null || !(durationSec > 0)) {
@@ -96,29 +79,22 @@ export function planFpsSampling(durationSec, fps, maxFrames) {
96
79
  const requested = Math.ceil(durationSec * fps);
97
80
  if (requested <= maxFrames)
98
81
  return { fps, requestedFrames: requested, clamped: false };
99
- // Round down to 4 decimals so the clamped rate never overshoots the cap.
100
82
  const clampedFps = Math.max(1e-4, Math.floor((maxFrames / durationSec) * 10_000) / 10_000);
101
83
  return { fps: clampedFps, requestedFrames: requested, clamped: true };
102
84
  }
103
- /** Sample frames at a fixed rate: ffmpeg -i in -vf fps=N -frames:v MAX
104
- * outdir/frame_%05d.png. -frames:v is a hard backstop on the frame count. */
105
- export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFAULT_MAX_FRAMES, dedupe = false) {
85
+ export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFAULT_MAX_FRAMES, dedupe = false, range) {
106
86
  validatePositive(fps, "fps");
107
- // dedupe (#114): mpdecimate drops frames nearly identical to the previous
108
- // kept one, and -fps_mode vfr stops the muxer re-inserting them.
109
87
  const vf = dedupe ? `fps=${fps},mpdecimate` : `fps=${fps}`;
88
+ const seek = range
89
+ ? ["-ss", String(range.start), ...(range.duration !== undefined ? ["-t", String(range.duration)] : [])]
90
+ : [];
110
91
  return [
111
- "-y", "-i", input, "-vf", vf,
92
+ "-y", ...seek, "-i", input, "-vf", vf,
112
93
  ...(dedupe ? ["-fps_mode", "vfr"] : []),
113
94
  "-frames:v", String(maxFrames), outputPattern,
114
95
  ];
115
96
  }
116
- /** Default scene-change threshold for UI content (#114). Screen recordings
117
- * change in small regions, so this is lower than the 0.3-0.4 usual for film. */
118
97
  export const DEFAULT_SCENE_THRESHOLD = 0.1;
119
- /** Scan a video for scene changes: a cheap pass on a 320 px-wide copy that
120
- * prints each frame whose scene score exceeds `threshold` (pts_time + score)
121
- * to stdout. Frames are then grabbed at full size at those timestamps. */
122
98
  export function buildSceneScanArgs(input, threshold = DEFAULT_SCENE_THRESHOLD) {
123
99
  if (!Number.isFinite(threshold) || threshold <= 0 || threshold >= 1) {
124
100
  throw new ScreencastError("sceneThreshold must be between 0 and 1 (exclusive).");
@@ -129,7 +105,6 @@ export function buildSceneScanArgs(input, threshold = DEFAULT_SCENE_THRESHOLD) {
129
105
  "-f", "null", "-",
130
106
  ];
131
107
  }
132
- /** Parse `metadata=print` output into (time, score) pairs. Pure. */
133
108
  export function parseSceneScan(stdout) {
134
109
  const out = [];
135
110
  let time = null;
@@ -147,9 +122,6 @@ export function parseSceneScan(stdout) {
147
122
  }
148
123
  return out;
149
124
  }
150
- /** Choose which frames to keep: always the opening frame (t=0), then the
151
- * strongest scene changes up to maxFrames total, returned in time order.
152
- * Pure. */
153
125
  export function pickSceneFrames(changes, maxFrames) {
154
126
  const strongest = [...changes]
155
127
  .filter((c) => c.timeSec > 0)
@@ -158,32 +130,24 @@ export function pickSceneFrames(changes, maxFrames) {
158
130
  .map((c) => c.timeSec);
159
131
  return [0, ...strongest].sort((a, b) => a - b);
160
132
  }
161
- /** Build one ffmpeg invocation per timestamp (accurate single-frame seek). */
162
133
  export function buildSampleAtTimestampArgs(input, timestampSec, output) {
163
134
  if (!Number.isFinite(timestampSec) || timestampSec < 0) {
164
135
  throw new ScreencastError("timestamp must be a non-negative number.");
165
136
  }
166
137
  return ["-y", "-ss", String(timestampSec), "-i", input, "-frames:v", "1", ...stillOutput(output)];
167
138
  }
168
- /** The default output extension for an edit that encodes libx264/AAC: the
169
- * input's own container when it can hold those codecs, else .mp4 (a WebM
170
- * cannot, #187). */
171
139
  export function editOutputExt(input, opts = {}) {
172
140
  const ext = extname(input).toLowerCase();
173
141
  if (ext === ".mp4" || ext === ".mkv" || ext === ".mov")
174
142
  return ext;
175
- // Audio tools also keep an audio-only container they can encode to.
176
143
  if (opts.audio && AUDIO_ONLY_EXTS.has(ext))
177
144
  return ext;
178
145
  return ".mp4";
179
146
  }
180
147
  const AUDIO_ONLY_EXTS = new Set([".wav", ".mp3", ".m4a"]);
181
- /** True when the output path is an audio-only container (.wav/.mp3/.m4a). */
182
148
  export function isAudioOnlyPath(path) {
183
149
  return AUDIO_ONLY_EXTS.has(extname(path).toLowerCase());
184
150
  }
185
- /** Refuse an explicit output path whose container cannot hold the H.264/AAC
186
- * an edit writes, instead of ffmpeg's cryptic "Nothing was written" (#187). */
187
151
  export function assertEditContainer(output) {
188
152
  if (output === undefined)
189
153
  return;
@@ -193,9 +157,6 @@ export function assertEditContainer(output) {
193
157
  `output, then convert (format: "webm") or export_gif the result.`);
194
158
  }
195
159
  }
196
- /** Trim by start + (end | duration). Re-encodes by default so the file holds
197
- * nothing from before `start`; `exact: false` stream-copies, which is fast but
198
- * keeps the GOP before `start` in the file, hidden behind an edit list (#203). */
199
160
  export function buildTrimArgs(input, output, opts) {
200
161
  const start = opts.start;
201
162
  if (!Number.isFinite(start) || start < 0) {
@@ -212,8 +173,6 @@ export function buildTrimArgs(input, output, opts) {
212
173
  if (opts.end <= start) {
213
174
  throw new ScreencastError("end must be greater than start.");
214
175
  }
215
- // Input-side -ss resets output timestamps to 0, so an output -to would be
216
- // read as a duration (#75). Emit the real length instead.
217
176
  args.push("-t", String(Math.round((opts.end - start) * 1000) / 1000));
218
177
  }
219
178
  else {
@@ -225,7 +184,6 @@ export function buildTrimArgs(input, output, opts) {
225
184
  args.push(...resolveQuality(DEFAULT_EDIT_QUALITY), "-c:a", "aac", output);
226
185
  return args;
227
186
  }
228
- /** Build the concat-demuxer list file content for a set of inputs. */
229
187
  export function buildConcatListContent(inputs) {
230
188
  if (inputs.length < 2) {
231
189
  throw new ScreencastError("concat requires at least two input files.");
@@ -237,18 +195,12 @@ export function buildConcatListContent(inputs) {
237
195
  export function buildConcatArgs(listFile, output) {
238
196
  return ["-y", "-f", "concat", "-safe", "0", "-i", listFile, "-c", "copy", output];
239
197
  }
240
- /** True when a file holds noticeably more video packets than its duration
241
- * plays: frames hidden behind an edit list, as a stream-copy trim leaves
242
- * them (#203). A stream-copy concat would carry them into the join. */
243
198
  export function hasHiddenFrames(info) {
244
199
  const { videoFrames: n, videoDurationSec: d, fps } = info;
245
200
  if (n === null || d === null || fps === null)
246
201
  return false;
247
202
  return n > d * fps * 1.05 + 2;
248
203
  }
249
- /** Why a set of inputs cannot be joined by stream copy, or null when they
250
- * can: the concat demuxer needs identical codecs, size, pixel format, frame
251
- * rate and audio layout, and silently writes a broken file otherwise (#206). */
252
204
  export function concatCopyBlocker(paths, infos) {
253
205
  const fields = [
254
206
  ["videoCodec", "video codec"],
@@ -261,27 +213,25 @@ export function concatCopyBlocker(paths, infos) {
261
213
  ["channels", "audio channels"],
262
214
  ];
263
215
  const first = infos[0];
264
- for (let i = 0; i < infos.length; i++) {
265
- if (hasHiddenFrames(infos[i]))
216
+ for (const [i, info] of infos.entries()) {
217
+ if (hasHiddenFrames(info))
266
218
  return `${paths[i]} holds hidden frames behind an edit list`;
267
- if (i === 0)
219
+ if (i === 0 || !first)
268
220
  continue;
269
221
  for (const [key, label] of fields) {
270
- if (infos[i][key] !== first[key]) {
271
- return `${label} differs: ${paths[0]} has ${first[key] ?? "none"}, ${paths[i]} has ${infos[i][key] ?? "none"}`;
222
+ if (info[key] !== first[key]) {
223
+ return `${label} differs: ${paths[0]} has ${first[key] ?? "none"}, ${paths[i]} has ${info[key] ?? "none"}`;
272
224
  }
273
225
  }
274
226
  }
275
227
  return null;
276
228
  }
277
- /** Build conversion args for mp4 <-> gif/webm. gif uses a single-pass
278
- * palette-quality filter; webm uses VP9; mp4 uses H.264. */
279
229
  export function buildConvertArgs(input, output, format, opts = {}) {
280
230
  switch (format) {
281
231
  case "gif": {
282
232
  const fps = opts.fps ?? 12;
283
233
  const width = opts.width ?? 720;
284
- const filter = `fps=${fps},scale=${width}:-1:flags=lanczos,split[s0][s1];` +
234
+ const filter = `fps=${fps},scale='min(${width},iw)':-1:flags=lanczos,split[s0][s1];` +
285
235
  `[s0]palettegen[p];[s1][p]paletteuse`;
286
236
  return ["-y", "-i", input, "-vf", filter, output];
287
237
  }
@@ -289,7 +239,7 @@ export function buildConvertArgs(input, output, format, opts = {}) {
289
239
  return [
290
240
  "-y", "-i", input,
291
241
  "-c:v", "libvpx-vp9", "-b:v", "0", "-crf", "30",
292
- "-row-mt", "1",
242
+ "-deadline", "good", "-cpu-used", "4", "-row-mt", "1",
293
243
  output,
294
244
  ];
295
245
  case "mp4":
@@ -304,11 +254,6 @@ export function buildConvertArgs(input, output, format, opts = {}) {
304
254
  throw new ScreencastError(`Unsupported convert format "${format}".`);
305
255
  }
306
256
  }
307
- // --- Phase 2 edit surface -------------------------------------------------
308
- //
309
- // Every tool below RE-ENCODES (a filter rewrites pixels, so stream copy is not
310
- // an option). They reuse resolveQuality() so the draft/standard/high presets
311
- // are identical to capture. Audio is copied unless a filter forces a re-encode.
312
257
  function requireNonNegativeInt(value, label) {
313
258
  if (!Number.isInteger(value) || value < 0) {
314
259
  throw new ScreencastError(`${label} must be a non-negative integer.`);
@@ -321,7 +266,6 @@ function requirePositiveInt(value, label) {
321
266
  }
322
267
  return value;
323
268
  }
324
- /** Build a libavfilter `enable=` timeline expression, or "" for always-on. */
325
269
  export function enableExpr(start, end) {
326
270
  if (start !== undefined && end !== undefined) {
327
271
  if (end <= start)
@@ -334,10 +278,6 @@ export function enableExpr(start, end) {
334
278
  return `lte(t,${end})`;
335
279
  return "";
336
280
  }
337
- /** Crop to a pixel rectangle. If frame dims are supplied, a rectangle that
338
- * runs off the frame is rejected rather than silently clamped by ffmpeg. */
339
- /** The crop filter for a rectangle, validated against the frame when known.
340
- * Shared by crop and pipeline. */
341
281
  export function cropFilter(rect, dims) {
342
282
  const x = requireNonNegativeInt(rect.x, "crop x");
343
283
  const y = requireNonNegativeInt(rect.y, "crop y");
@@ -360,8 +300,6 @@ export function buildCropArgs(input, output, rect, dims, quality = DEFAULT_EDIT_
360
300
  output,
361
301
  ];
362
302
  }
363
- /** Scale to a width and/or height. A missing side uses -2 (keep aspect, even
364
- * dimension as required by yuv420p). */
365
303
  export function scaleFilter(opts) {
366
304
  if (opts.width === undefined && opts.height === undefined) {
367
305
  throw new ScreencastError("scale requires width or height (or both).");
@@ -374,8 +312,6 @@ export function scaleFilter(opts) {
374
312
  }
375
313
  return `scale=${opts.width ?? -2}:${opts.height ?? -2}`;
376
314
  }
377
- /** The frame size scaleFilter produces from a W x H source (-2 keeps aspect
378
- * and rounds to an even size, as ffmpeg does). */
379
315
  export function scaledSize(W, H, opts) {
380
316
  const even = (v) => Math.max(2, Math.round(v / 2) * 2);
381
317
  if (opts.width !== undefined && opts.height !== undefined)
@@ -393,8 +329,6 @@ export function buildScaleArgs(input, output, opts, quality = DEFAULT_EDIT_QUALI
393
329
  output,
394
330
  ];
395
331
  }
396
- /** Decompose a tempo factor into an atempo chain (each atempo is limited to
397
- * the 0.5 - 2.0 range, so larger changes are multiplied across stages). */
398
332
  export function atempoChain(factor) {
399
333
  let remaining = factor;
400
334
  const parts = [];
@@ -406,11 +340,9 @@ export function atempoChain(factor) {
406
340
  parts.push("atempo=0.5");
407
341
  remaining /= 0.5;
408
342
  }
409
- parts.push(`atempo=${Math.round(remaining * 1000) / 1000}`);
343
+ parts.push(`atempo=${Number(remaining.toFixed(6))}`);
410
344
  return parts.join(",");
411
345
  }
412
- /** Change playback speed. factor > 1 is faster, < 1 is slower. Video uses
413
- * setpts; audio is retempo'd when present and dropped otherwise. */
414
346
  export function buildSpeedArgs(input, output, factor, hasAudio, quality = DEFAULT_EDIT_QUALITY) {
415
347
  if (!Number.isFinite(factor) || factor <= 0) {
416
348
  throw new ScreencastError("speed factor must be a positive number.");
@@ -428,11 +360,6 @@ export function buildSpeedArgs(input, output, factor, hasAudio, quality = DEFAUL
428
360
  args.push(output);
429
361
  return args;
430
362
  }
431
- /** Composite an overlay image or video onto the input at (x, y), optionally
432
- * scaled and optionally limited to a time window. The overlay's clock is
433
- * shifted to `start`, so a video plays from its first frame inside the window
434
- * and holds its last frame if it ends early (#230). The output keeps the main
435
- * input's audio and length (#188). */
436
363
  export function buildOverlayArgs(input, overlay, output, opts, quality = DEFAULT_EDIT_QUALITY) {
437
364
  const x = requireNonNegativeInt(opts.x, "overlay x");
438
365
  const y = requireNonNegativeInt(opts.y, "overlay y");
@@ -457,7 +384,6 @@ export function buildOverlayArgs(input, overlay, output, opts, quality = DEFAULT
457
384
  "-map", "[v]", "-map", "0:a?",
458
385
  ...resolveQuality(quality),
459
386
  "-c:a", "copy",
460
- // A longer overlay video would otherwise run the output past the main clip.
461
387
  ...(dur != null && dur > 0 ? ["-t", String(dur)] : []),
462
388
  output,
463
389
  ];
@@ -467,8 +393,6 @@ const COMPRESS_CRF = {
467
393
  medium: 28,
468
394
  heavy: 32,
469
395
  };
470
- /** Re-encode to a smaller file with a CRF ladder and an optional width cap.
471
- * The width cap only ever downscales (min of the source width and maxWidth). */
472
396
  export function buildCompressArgs(input, output, opts = {}) {
473
397
  const level = opts.level ?? "medium";
474
398
  const crf = COMPRESS_CRF[level];
@@ -477,7 +401,6 @@ export function buildCompressArgs(input, output, opts = {}) {
477
401
  const args = ["-y", "-i", input];
478
402
  if (opts.maxWidth !== undefined) {
479
403
  requirePositiveInt(opts.maxWidth, "maxWidth");
480
- // Always even and never an upscale: libx264 rejects an odd width (#239).
481
404
  args.push("-vf", `scale='trunc(min(${opts.maxWidth},iw)/2)*2':-2`);
482
405
  }
483
406
  args.push("-c:v", "libx264", "-preset", "slow", "-crf", String(crf), "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart", output);
@@ -489,11 +412,6 @@ const AUDIO_CODEC = {
489
412
  wav: ["-c:a", "pcm_s16le"],
490
413
  copy: ["-c:a", "copy"],
491
414
  };
492
- /** Strip video and write the audio track on its own (mp3 / aac / wav / copy). */
493
- /** Container extension that can hold a stream-copied audio codec. m4a (the old
494
- * blanket choice) rejects opus/vorbis/etc at header-write time, leaving a
495
- * broken file; Matroska audio (.mka) is the catch-all that accepts nearly any
496
- * codec. Pure so the mapping is unit-tested. */
497
415
  export function copyAudioExtension(codec) {
498
416
  switch (codec) {
499
417
  case "aac":
@@ -518,9 +436,6 @@ export function buildExtractAudioArgs(input, output, format) {
518
436
  throw new ScreencastError(`Unknown audio format "${format}".`);
519
437
  return ["-y", "-i", input, "-vn", ...codec, output];
520
438
  }
521
- /** Extract one frame-accurate sub-segment. Unlike trim (stream copy, snaps to a
522
- * keyframe), clip re-encodes so the cut lands exactly on start/end. Output -ss
523
- * plus -t (a duration) avoids the -to seek ambiguity. */
524
439
  export function buildClipArgs(input, output, seg, quality = DEFAULT_EDIT_QUALITY) {
525
440
  if (!Number.isFinite(seg.start) || seg.start < 0) {
526
441
  throw new ScreencastError("clip start must be a non-negative number.");
@@ -537,9 +452,6 @@ export function buildClipArgs(input, output, seg, quality = DEFAULT_EDIT_QUALITY
537
452
  output,
538
453
  ];
539
454
  }
540
- /** Validate each region against the frame, then apply an optional pad (dilation)
541
- * clamped to the frame edges. The unpadded region is what gets bounds-checked,
542
- * so a clearly off-frame request is rejected before any padding math. */
543
455
  function normalizeRegions(regions, pad, dims) {
544
456
  return regions.map((r, i) => {
545
457
  const x0 = requireNonNegativeInt(r.x, `region[${i}] x`);
@@ -563,35 +475,21 @@ function normalizeRegions(regions, pad, dims) {
563
475
  return { x, y, w: right - x, h: bottom - y, enable: enableExpr(r.start, r.end) };
564
476
  });
565
477
  }
566
- /** Smallest blur radius in px, where the region allows it (#204). */
567
478
  export const MIN_BLUR_RADIUS = 8;
568
- /** Times the box blur is applied: three passes approach a Gaussian, so the
569
- * blur is several times stronger than its radius suggests. */
570
479
  export const BLUR_PASSES = 3;
571
- /** Smallest pixelate block in px: about two characters of UI text (#204). */
572
480
  export const MIN_PIXEL_BLOCK = 16;
573
- /** boxblur settings for a region: a radius of at least MIN_BLUR_RADIUS (a
574
- * thin text line used to get 4, which stayed readable), applied BLUR_PASSES
575
- * times. A radius must stay within half the plane's smaller side, and the
576
- * yuv420p chroma plane is half the size, so it gets its own radius (#188). */
577
481
  export function blurRadius(r) {
578
482
  const m = Math.min(r.w, r.h);
579
483
  const lr = Math.min(Math.floor(m / 2), Math.max(MIN_BLUR_RADIUS, Math.min(20, Math.floor(m / 4))));
580
484
  const cr = Math.min(lr, Math.floor(Math.ceil(m / 2) / 2));
581
485
  return `lr=${lr}:lp=${BLUR_PASSES}:cr=${cr}:cp=${BLUR_PASSES}`;
582
486
  }
583
- /** The pixelate filter for a region: square blocks of at least
584
- * MIN_PIXEL_BLOCK px (and at most 16 across the longer side), instead of 16
585
- * across whatever the width was, which left a 64 px secret in 4 px blocks. */
586
487
  export function pixelateFilter(r) {
587
488
  const block = Math.max(MIN_PIXEL_BLOCK, Math.ceil(Math.max(r.w, r.h) / 16));
588
489
  const cols = Math.max(1, Math.round(r.w / block));
589
490
  const rows = Math.max(1, Math.round(r.h / block));
590
491
  return `scale=${cols}:${rows}:flags=area,scale=${r.w}:${r.h}:flags=neighbor`;
591
492
  }
592
- /** Filter steps that redact regions of the stream labelled `input` (e.g.
593
- * "[0:v]"); labels are prefixed with `tag` so several can share one graph.
594
- * Returns the steps and the output label. Shared by redact_region and pipeline. */
595
493
  export function redactSteps(regions, opts, dims, input, tag) {
596
494
  if (regions.length === 0) {
597
495
  throw new ScreencastError("redact_region requires at least one region.");
@@ -612,8 +510,6 @@ export function redactSteps(regions, opts, dims, input, tag) {
612
510
  .join(",");
613
511
  return { steps: [`${input}${boxes}[${tag}out]`], out: `[${tag}out]` };
614
512
  }
615
- // blur / pixelate: split the source, soften each cropped region, then overlay
616
- // the softened patches back over the base in order.
617
513
  const n = rs.length;
618
514
  const steps = [];
619
515
  const splitOuts = [`${tag}base`, ...rs.map((_, i) => `${tag}s${i}`)];
@@ -634,14 +530,11 @@ export function redactSteps(regions, opts, dims, input, tag) {
634
530
  });
635
531
  return { steps, out: `[${tag}out]` };
636
532
  }
637
- /** Redact declared rectangles. `box` (default) draws an irreversible solid fill;
638
- * `blur` and `pixelate` composite a softened crop back over each region. */
639
533
  export function buildRedactArgs(input, output, regions, opts = {}, dims) {
640
534
  const { steps, out } = redactSteps(regions, opts, dims, "[0:v]", "");
641
- // A crisp re-encode keeps the redaction edges sharp.
642
- if ((opts.style ?? "box") === "box") {
643
- // One linear chain: a plain -vf, without the graph labels.
644
- const vf = steps[0].slice("[0:v]".length, -out.length);
535
+ const [chain] = steps;
536
+ if ((opts.style ?? "box") === "box" && chain !== undefined) {
537
+ const vf = chain.slice("[0:v]".length, -out.length);
645
538
  return ["-y", "-i", input, "-vf", vf, ...resolveQuality("high"), "-c:a", "copy", output];
646
539
  }
647
540
  return [
@@ -653,4 +546,3 @@ export function buildRedactArgs(input, output, regions, opts = {}, dims) {
653
546
  output,
654
547
  ];
655
548
  }
656
- //# sourceMappingURL=media.js.map