@tmhs/screencast-mcp 0.9.1 → 0.28.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 (219) hide show
  1. package/README.md +59 -12
  2. package/dist/index.js +67 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/prompts.d.ts +10 -0
  5. package/dist/prompts.d.ts.map +1 -0
  6. package/dist/prompts.js +72 -0
  7. package/dist/prompts.js.map +1 -0
  8. package/dist/resources.d.ts +3 -0
  9. package/dist/resources.d.ts.map +1 -0
  10. package/dist/resources.js +71 -0
  11. package/dist/resources.js.map +1 -0
  12. package/dist/tools/assembleHighlights.d.ts.map +1 -1
  13. package/dist/tools/assembleHighlights.js +4 -3
  14. package/dist/tools/assembleHighlights.js.map +1 -1
  15. package/dist/tools/burnSubtitles.d.ts +3 -0
  16. package/dist/tools/burnSubtitles.d.ts.map +1 -0
  17. package/dist/tools/burnSubtitles.js +48 -0
  18. package/dist/tools/burnSubtitles.js.map +1 -0
  19. package/dist/tools/callout.d.ts +3 -0
  20. package/dist/tools/callout.d.ts.map +1 -0
  21. package/dist/tools/callout.js +106 -0
  22. package/dist/tools/callout.js.map +1 -0
  23. package/dist/tools/clip.d.ts.map +1 -1
  24. package/dist/tools/clip.js +4 -3
  25. package/dist/tools/clip.js.map +1 -1
  26. package/dist/tools/compress.d.ts.map +1 -1
  27. package/dist/tools/compress.js +4 -3
  28. package/dist/tools/compress.js.map +1 -1
  29. package/dist/tools/concat.d.ts.map +1 -1
  30. package/dist/tools/concat.js +6 -3
  31. package/dist/tools/concat.js.map +1 -1
  32. package/dist/tools/contactSheet.d.ts +3 -0
  33. package/dist/tools/contactSheet.d.ts.map +1 -0
  34. package/dist/tools/contactSheet.js +128 -0
  35. package/dist/tools/contactSheet.js.map +1 -0
  36. package/dist/tools/convert.d.ts.map +1 -1
  37. package/dist/tools/convert.js +4 -3
  38. package/dist/tools/convert.js.map +1 -1
  39. package/dist/tools/crop.d.ts.map +1 -1
  40. package/dist/tools/crop.js +5 -4
  41. package/dist/tools/crop.js.map +1 -1
  42. package/dist/tools/cutIdle.d.ts +3 -0
  43. package/dist/tools/cutIdle.d.ts.map +1 -0
  44. package/dist/tools/cutIdle.js +77 -0
  45. package/dist/tools/cutIdle.js.map +1 -0
  46. package/dist/tools/denoise.d.ts +3 -0
  47. package/dist/tools/denoise.d.ts.map +1 -0
  48. package/dist/tools/denoise.js +53 -0
  49. package/dist/tools/denoise.js.map +1 -0
  50. package/dist/tools/exportGif.d.ts +3 -0
  51. package/dist/tools/exportGif.d.ts.map +1 -0
  52. package/dist/tools/exportGif.js +100 -0
  53. package/dist/tools/exportGif.js.map +1 -0
  54. package/dist/tools/exportPreset.d.ts.map +1 -1
  55. package/dist/tools/exportPreset.js +4 -3
  56. package/dist/tools/exportPreset.js.map +1 -1
  57. package/dist/tools/extractAudio.d.ts.map +1 -1
  58. package/dist/tools/extractAudio.js +4 -3
  59. package/dist/tools/extractAudio.js.map +1 -1
  60. package/dist/tools/findText.d.ts +3 -0
  61. package/dist/tools/findText.d.ts.map +1 -0
  62. package/dist/tools/findText.js +120 -0
  63. package/dist/tools/findText.js.map +1 -0
  64. package/dist/tools/musicBed.d.ts.map +1 -1
  65. package/dist/tools/musicBed.js +4 -3
  66. package/dist/tools/musicBed.js.map +1 -1
  67. package/dist/tools/normalizeAudio.d.ts +3 -0
  68. package/dist/tools/normalizeAudio.d.ts.map +1 -0
  69. package/dist/tools/normalizeAudio.js +55 -0
  70. package/dist/tools/normalizeAudio.js.map +1 -0
  71. package/dist/tools/overlay.d.ts.map +1 -1
  72. package/dist/tools/overlay.js +4 -3
  73. package/dist/tools/overlay.js.map +1 -1
  74. package/dist/tools/readEvents.d.ts +6 -0
  75. package/dist/tools/readEvents.d.ts.map +1 -0
  76. package/dist/tools/readEvents.js +79 -0
  77. package/dist/tools/readEvents.js.map +1 -0
  78. package/dist/tools/redactRegion.d.ts.map +1 -1
  79. package/dist/tools/redactRegion.js +5 -4
  80. package/dist/tools/redactRegion.js.map +1 -1
  81. package/dist/tools/reframe.d.ts.map +1 -1
  82. package/dist/tools/reframe.js +4 -3
  83. package/dist/tools/reframe.js.map +1 -1
  84. package/dist/tools/sampleFrames.d.ts.map +1 -1
  85. package/dist/tools/sampleFrames.js +125 -12
  86. package/dist/tools/sampleFrames.js.map +1 -1
  87. package/dist/tools/scale.d.ts.map +1 -1
  88. package/dist/tools/scale.js +4 -3
  89. package/dist/tools/scale.js.map +1 -1
  90. package/dist/tools/screenDiff.d.ts +3 -0
  91. package/dist/tools/screenDiff.d.ts.map +1 -0
  92. package/dist/tools/screenDiff.js +72 -0
  93. package/dist/tools/screenDiff.js.map +1 -0
  94. package/dist/tools/screenshot.d.ts.map +1 -1
  95. package/dist/tools/screenshot.js +39 -7
  96. package/dist/tools/screenshot.js.map +1 -1
  97. package/dist/tools/speed.d.ts.map +1 -1
  98. package/dist/tools/speed.js +5 -4
  99. package/dist/tools/speed.js.map +1 -1
  100. package/dist/tools/startRecording.d.ts.map +1 -1
  101. package/dist/tools/startRecording.js +100 -9
  102. package/dist/tools/startRecording.js.map +1 -1
  103. package/dist/tools/stopRecording.d.ts.map +1 -1
  104. package/dist/tools/stopRecording.js +12 -66
  105. package/dist/tools/stopRecording.js.map +1 -1
  106. package/dist/tools/titleCard.d.ts.map +1 -1
  107. package/dist/tools/titleCard.js +5 -4
  108. package/dist/tools/titleCard.js.map +1 -1
  109. package/dist/tools/transcribe.d.ts +3 -0
  110. package/dist/tools/transcribe.d.ts.map +1 -0
  111. package/dist/tools/transcribe.js +59 -0
  112. package/dist/tools/transcribe.js.map +1 -0
  113. package/dist/tools/trim.d.ts.map +1 -1
  114. package/dist/tools/trim.js +8 -3
  115. package/dist/tools/trim.js.map +1 -1
  116. package/dist/tools/waitForChange.d.ts +3 -0
  117. package/dist/tools/waitForChange.d.ts.map +1 -0
  118. package/dist/tools/waitForChange.js +127 -0
  119. package/dist/tools/waitForChange.js.map +1 -0
  120. package/dist/tools/xfadeTransition.d.ts.map +1 -1
  121. package/dist/tools/xfadeTransition.js +4 -3
  122. package/dist/tools/xfadeTransition.js.map +1 -1
  123. package/dist/tools/zoom.d.ts +3 -0
  124. package/dist/tools/zoom.d.ts.map +1 -0
  125. package/dist/tools/zoom.js +94 -0
  126. package/dist/tools/zoom.js.map +1 -0
  127. package/dist/utils/anim.d.ts +33 -0
  128. package/dist/utils/anim.d.ts.map +1 -0
  129. package/dist/utils/anim.js +74 -0
  130. package/dist/utils/anim.js.map +1 -0
  131. package/dist/utils/audio.d.ts +49 -0
  132. package/dist/utils/audio.d.ts.map +1 -0
  133. package/dist/utils/audio.js +128 -0
  134. package/dist/utils/audio.js.map +1 -0
  135. package/dist/utils/callout.d.ts +63 -0
  136. package/dist/utils/callout.d.ts.map +1 -0
  137. package/dist/utils/callout.js +95 -0
  138. package/dist/utils/callout.js.map +1 -0
  139. package/dist/utils/captions.d.ts +26 -0
  140. package/dist/utils/captions.d.ts.map +1 -0
  141. package/dist/utils/captions.js +105 -0
  142. package/dist/utils/captions.js.map +1 -0
  143. package/dist/utils/diff.d.ts +66 -0
  144. package/dist/utils/diff.d.ts.map +1 -0
  145. package/dist/utils/diff.js +176 -0
  146. package/dist/utils/diff.js.map +1 -0
  147. package/dist/utils/errors.d.ts +17 -9
  148. package/dist/utils/errors.d.ts.map +1 -1
  149. package/dist/utils/errors.js +7 -6
  150. package/dist/utils/errors.js.map +1 -1
  151. package/dist/utils/events.d.ts +109 -0
  152. package/dist/utils/events.d.ts.map +1 -0
  153. package/dist/utils/events.js +289 -0
  154. package/dist/utils/events.js.map +1 -0
  155. package/dist/utils/ffmpeg.d.ts +14 -1
  156. package/dist/utils/ffmpeg.d.ts.map +1 -1
  157. package/dist/utils/ffmpeg.js +105 -5
  158. package/dist/utils/ffmpeg.js.map +1 -1
  159. package/dist/utils/idle.d.ts +23 -0
  160. package/dist/utils/idle.d.ts.map +1 -0
  161. package/dist/utils/idle.js +96 -0
  162. package/dist/utils/idle.js.map +1 -0
  163. package/dist/utils/images.d.ts +21 -0
  164. package/dist/utils/images.d.ts.map +1 -0
  165. package/dist/utils/images.js +55 -0
  166. package/dist/utils/images.js.map +1 -0
  167. package/dist/utils/jobs.d.ts +44 -0
  168. package/dist/utils/jobs.d.ts.map +1 -0
  169. package/dist/utils/jobs.js +135 -0
  170. package/dist/utils/jobs.js.map +1 -0
  171. package/dist/utils/lifecycle.d.ts +29 -0
  172. package/dist/utils/lifecycle.d.ts.map +1 -0
  173. package/dist/utils/lifecycle.js +116 -0
  174. package/dist/utils/lifecycle.js.map +1 -0
  175. package/dist/utils/media.d.ts +35 -2
  176. package/dist/utils/media.d.ts.map +1 -1
  177. package/dist/utils/media.js +75 -3
  178. package/dist/utils/media.js.map +1 -1
  179. package/dist/utils/monitors.d.ts +18 -2
  180. package/dist/utils/monitors.d.ts.map +1 -1
  181. package/dist/utils/monitors.js +50 -12
  182. package/dist/utils/monitors.js.map +1 -1
  183. package/dist/utils/ocr.d.ts +44 -0
  184. package/dist/utils/ocr.d.ts.map +1 -0
  185. package/dist/utils/ocr.js +215 -0
  186. package/dist/utils/ocr.js.map +1 -0
  187. package/dist/utils/produce.d.ts +1 -0
  188. package/dist/utils/produce.d.ts.map +1 -1
  189. package/dist/utils/produce.js +3 -2
  190. package/dist/utils/produce.js.map +1 -1
  191. package/dist/utils/resolveTarget.d.ts +5 -1
  192. package/dist/utils/resolveTarget.d.ts.map +1 -1
  193. package/dist/utils/resolveTarget.js +4 -4
  194. package/dist/utils/resolveTarget.js.map +1 -1
  195. package/dist/utils/sessions.d.ts +47 -0
  196. package/dist/utils/sessions.d.ts.map +1 -1
  197. package/dist/utils/sessions.js +170 -15
  198. package/dist/utils/sessions.js.map +1 -1
  199. package/dist/utils/sheet.d.ts +26 -0
  200. package/dist/utils/sheet.d.ts.map +1 -0
  201. package/dist/utils/sheet.js +77 -0
  202. package/dist/utils/sheet.js.map +1 -0
  203. package/dist/utils/still.d.ts +4 -0
  204. package/dist/utils/still.d.ts.map +1 -0
  205. package/dist/utils/still.js +28 -0
  206. package/dist/utils/still.js.map +1 -0
  207. package/dist/utils/targets.d.ts +27 -0
  208. package/dist/utils/targets.d.ts.map +1 -1
  209. package/dist/utils/targets.js +64 -1
  210. package/dist/utils/targets.js.map +1 -1
  211. package/dist/utils/windows.d.ts +25 -6
  212. package/dist/utils/windows.d.ts.map +1 -1
  213. package/dist/utils/windows.js +59 -20
  214. package/dist/utils/windows.js.map +1 -1
  215. package/dist/utils/zoom.d.ts +60 -0
  216. package/dist/utils/zoom.d.ts.map +1 -0
  217. package/dist/utils/zoom.js +167 -0
  218. package/dist/utils/zoom.js.map +1 -0
  219. package/package.json +6 -5
@@ -0,0 +1,49 @@
1
+ export type LoudnessPreset = "youtube" | "podcast" | "broadcast";
2
+ export interface LoudnessTarget {
3
+ /** Integrated loudness, LUFS. */
4
+ i: number;
5
+ /** True peak ceiling, dBTP. */
6
+ tp: number;
7
+ /** Loudness range, LU. */
8
+ lra: number;
9
+ }
10
+ /** Common delivery targets: YouTube/streaming, spoken-word podcasts, and EBU
11
+ * R128 broadcast. */
12
+ export declare const LOUDNESS_PRESETS: Record<LoudnessPreset, LoudnessTarget>;
13
+ /** Resolve a preset name or a LUFS number to a full target. Pure. */
14
+ export declare function loudnessTarget(target: LoudnessPreset | number | undefined): LoudnessTarget;
15
+ /** Pass 1: measure the input; the JSON block lands on stderr. */
16
+ export declare function buildLoudnessMeasureArgs(input: string, t: LoudnessTarget): string[];
17
+ export interface LoudnessMeasurement {
18
+ input_i: number;
19
+ input_tp: number;
20
+ input_lra: number;
21
+ input_thresh: number;
22
+ target_offset: number;
23
+ output_i?: number;
24
+ }
25
+ /** Pull the last loudnorm JSON block out of ffmpeg's stderr. Pure. */
26
+ export declare function parseLoudnorm(stderr: string): LoudnessMeasurement;
27
+ /** Audio encoder for an output path: PCM for .wav, MP3 for .mp3, else AAC. */
28
+ export declare function audioCodecFor(output: string): string[];
29
+ /** Pass 2: apply a linear correction from the measurement. loudnorm works at
30
+ * 192 kHz internally, so the output rate is set back to 48 kHz. */
31
+ export declare function buildLoudnessApplyArgs(input: string, output: string, t: LoudnessTarget, m: LoudnessMeasurement): string[];
32
+ export type DenoiseStrength = "light" | "medium" | "strong";
33
+ /** afftdn noise-reduction amount (dB) per strength. */
34
+ export declare const DENOISE_NR: Record<DenoiseStrength, number>;
35
+ /** Measure the audio's RMS level in 100 ms windows (printed to stdout), to
36
+ * estimate its noise floor. */
37
+ export declare function buildNoiseFloorArgs(input: string): string[];
38
+ /** The noise floor: the 10th-percentile window RMS (dBFS), i.e. the level of
39
+ * the quietest moments, which are mostly noise. Null for silence. Pure. */
40
+ export declare function parseNoiseFloor(stdout: string): number | null;
41
+ /** afftdn's `nf` for a measured floor. afftdn only removes what it believes is
42
+ * at or under nf, so a fixed value misses most real noise: white noise at
43
+ * -25 dBFS was untouched with nf=-25 but cut 12-20 dB with nf set 5 dB above
44
+ * the measured floor. Clamped to afftdn's range [-80, -20]. Pure. */
45
+ export declare function noiseFloorSetting(floorDb: number | null): number;
46
+ /** Reduce steady background noise (fans, hum, hiss) with afftdn, using the
47
+ * floor measured by buildNoiseFloorArgs. Pure. */
48
+ export declare function buildDenoiseArgs(input: string, output: string, strength?: DenoiseStrength, noiseFloorDb?: number | null): string[];
49
+ //# sourceMappingURL=audio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/utils/audio.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb;AAED;qBACqB;AACrB,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,cAAc,EAAE,cAAc,CAInE,CAAC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EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,eAA0B,EACpC,YAAY,GAAE,MAAM,GAAG,IAAW,GACjC,MAAM,EAAE,CAWV"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Audio polish (#123): EBU R128 loudness normalization and noise reduction.
3
+ *
4
+ * Normalization is two-pass loudnorm: the first pass measures the input, the
5
+ * second applies a linear gain using those measurements, so the result hits
6
+ * the target without the pumping of single-pass (dynamic) mode. Video, when
7
+ * present, is stream-copied. Builders and the parser are pure.
8
+ */
9
+ import { extname } from "node:path";
10
+ import { ScreencastError } from "./errors.js";
11
+ /** Common delivery targets: YouTube/streaming, spoken-word podcasts, and EBU
12
+ * R128 broadcast. */
13
+ export const LOUDNESS_PRESETS = {
14
+ youtube: { i: -14, tp: -1, lra: 11 },
15
+ podcast: { i: -16, tp: -1.5, lra: 11 },
16
+ broadcast: { i: -23, tp: -1, lra: 7 },
17
+ };
18
+ /** Resolve a preset name or a LUFS number to a full target. Pure. */
19
+ export function loudnessTarget(target) {
20
+ if (target === undefined)
21
+ return LOUDNESS_PRESETS.youtube;
22
+ if (typeof target === "number") {
23
+ if (!Number.isFinite(target) || target < -70 || target > -5) {
24
+ throw new ScreencastError("target LUFS must be between -70 and -5 (e.g. -14).");
25
+ }
26
+ return { i: target, tp: -1, lra: 11 };
27
+ }
28
+ const p = LOUDNESS_PRESETS[target];
29
+ if (!p)
30
+ throw new ScreencastError(`Unknown loudness target "${target}".`);
31
+ return p;
32
+ }
33
+ const filterTarget = (t) => `I=${t.i}:TP=${t.tp}:LRA=${t.lra}`;
34
+ /** Pass 1: measure the input; the JSON block lands on stderr. */
35
+ export function buildLoudnessMeasureArgs(input, t) {
36
+ return ["-hide_banner", "-nostats", "-i", input, "-vn", "-af", `loudnorm=${filterTarget(t)}:print_format=json`, "-f", "null", "-"];
37
+ }
38
+ /** Pull the last loudnorm JSON block out of ffmpeg's stderr. Pure. */
39
+ export function parseLoudnorm(stderr) {
40
+ const blocks = stderr.match(/\{[^{}]*"input_i"[^{}]*\}/g);
41
+ if (!blocks)
42
+ throw new ScreencastError("Could not measure loudness (no loudnorm report). Does the file have audio?");
43
+ const raw = JSON.parse(blocks[blocks.length - 1]);
44
+ const num = (k) => Number(raw[k]);
45
+ const m = {
46
+ input_i: num("input_i"),
47
+ input_tp: num("input_tp"),
48
+ input_lra: num("input_lra"),
49
+ input_thresh: num("input_thresh"),
50
+ target_offset: num("target_offset"),
51
+ ...(raw.output_i !== undefined ? { output_i: num("output_i") } : {}),
52
+ };
53
+ if (!Number.isFinite(m.input_i)) {
54
+ throw new ScreencastError("The audio is silent (loudness is -inf), so there is nothing to normalize.");
55
+ }
56
+ return m;
57
+ }
58
+ /** Audio encoder for an output path: PCM for .wav, MP3 for .mp3, else AAC. */
59
+ export function audioCodecFor(output) {
60
+ switch (extname(output).toLowerCase()) {
61
+ case ".wav":
62
+ return ["-c:a", "pcm_s16le"];
63
+ case ".mp3":
64
+ return ["-c:a", "libmp3lame", "-b:a", "192k"];
65
+ default:
66
+ return ["-c:a", "aac", "-b:a", "192k"];
67
+ }
68
+ }
69
+ /** Pass 2: apply a linear correction from the measurement. loudnorm works at
70
+ * 192 kHz internally, so the output rate is set back to 48 kHz. */
71
+ export function buildLoudnessApplyArgs(input, output, t, m) {
72
+ const measured = `measured_I=${m.input_i}:measured_TP=${m.input_tp}:measured_LRA=${m.input_lra}:` +
73
+ `measured_thresh=${m.input_thresh}:offset=${m.target_offset}`;
74
+ return [
75
+ "-y", "-hide_banner", "-i", input,
76
+ "-map", "0:v?", "-map", "0:a:0",
77
+ "-c:v", "copy",
78
+ "-af", `loudnorm=${filterTarget(t)}:${measured}:linear=true:print_format=json`,
79
+ "-ar", "48000",
80
+ ...audioCodecFor(output),
81
+ output,
82
+ ];
83
+ }
84
+ /** afftdn noise-reduction amount (dB) per strength. */
85
+ export const DENOISE_NR = { light: 6, medium: 12, strong: 20 };
86
+ /** Measure the audio's RMS level in 100 ms windows (printed to stdout), to
87
+ * estimate its noise floor. */
88
+ export function buildNoiseFloorArgs(input) {
89
+ return [
90
+ "-hide_banner", "-nostats", "-i", input, "-vn",
91
+ "-af", "aresample=48000,asetnsamples=4800,astats=metadata=1:reset=1,ametadata=print:key=lavfi.astats.Overall.RMS_level:file=-",
92
+ "-f", "null", "-",
93
+ ];
94
+ }
95
+ /** The noise floor: the 10th-percentile window RMS (dBFS), i.e. the level of
96
+ * the quietest moments, which are mostly noise. Null for silence. Pure. */
97
+ export function parseNoiseFloor(stdout) {
98
+ const levels = [...stdout.matchAll(/RMS_level=(-?[\d.]+)/g)].map((m) => Number(m[1])).filter(Number.isFinite);
99
+ if (levels.length === 0)
100
+ return null;
101
+ levels.sort((a, b) => a - b);
102
+ return levels[Math.floor(levels.length * 0.1)];
103
+ }
104
+ /** afftdn's `nf` for a measured floor. afftdn only removes what it believes is
105
+ * at or under nf, so a fixed value misses most real noise: white noise at
106
+ * -25 dBFS was untouched with nf=-25 but cut 12-20 dB with nf set 5 dB above
107
+ * the measured floor. Clamped to afftdn's range [-80, -20]. Pure. */
108
+ export function noiseFloorSetting(floorDb) {
109
+ if (floorDb === null)
110
+ return -50;
111
+ return Math.max(-80, Math.min(-20, Math.round(floorDb + 5)));
112
+ }
113
+ /** Reduce steady background noise (fans, hum, hiss) with afftdn, using the
114
+ * floor measured by buildNoiseFloorArgs. Pure. */
115
+ export function buildDenoiseArgs(input, output, strength = "medium", noiseFloorDb = null) {
116
+ const nr = DENOISE_NR[strength];
117
+ if (nr === undefined)
118
+ throw new ScreencastError(`Unknown denoise strength "${strength}".`);
119
+ return [
120
+ "-y", "-i", input,
121
+ "-map", "0:v?", "-map", "0:a:0",
122
+ "-c:v", "copy",
123
+ "-af", `afftdn=nr=${nr}:nf=${noiseFloorSetting(noiseFloorDb)}`,
124
+ ...audioCodecFor(output),
125
+ output,
126
+ ];
127
+ }
128
+ //# sourceMappingURL=audio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio.js","source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Ae,CAAC,6BAA6B,QAAQ,IAAI,CAAC,CAAC;IAC3F,OAAO;QACL,IAAI,EAAE,IAAI,EAAE,KAAK;QACjB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;QAC/B,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,aAAa,EAAE,OAAO,iBAAiB,CAAC,YAAY,CAAC,EAAE;QAC9D,GAAG,aAAa,CAAC,MAAM,CAAC;QACxB,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { type Quality } from "./targets.js";
2
+ interface Timed {
3
+ /** Show from this second (default: start of video). */
4
+ from?: number;
5
+ /** Hide after this second (default: end of video). */
6
+ to?: number;
7
+ color?: string;
8
+ }
9
+ export interface BoxCallout extends Timed {
10
+ type: "box";
11
+ x: number;
12
+ y: number;
13
+ width: number;
14
+ height: number;
15
+ /** Outline thickness in px (default 4); ignored when fill is set. */
16
+ thickness?: number;
17
+ /** Fill the box instead of outlining it. */
18
+ fill?: boolean;
19
+ }
20
+ export interface TextCallout extends Timed {
21
+ type: "text";
22
+ x: number;
23
+ y: number;
24
+ text: string;
25
+ /** Font size in px (default 32). */
26
+ size?: number;
27
+ /** Draw a translucent dark panel behind the text (default true). */
28
+ background?: boolean;
29
+ }
30
+ export interface ArrowCallout extends Timed {
31
+ type: "arrow";
32
+ /** Tail. */
33
+ x1: number;
34
+ y1: number;
35
+ /** Head (the point the arrow points at). */
36
+ x2: number;
37
+ y2: number;
38
+ /** Shaft thickness in px (default 8). */
39
+ thickness?: number;
40
+ }
41
+ export type Callout = BoxCallout | TextCallout | ArrowCallout;
42
+ /** Geometry of an arrow image: its length, thickness, rotation (radians,
43
+ * clockwise in screen coordinates), and centre. Pure. */
44
+ export declare function arrowGeometry(a: ArrowCallout): {
45
+ length: number;
46
+ thickness: number;
47
+ angle: number;
48
+ cx: number;
49
+ cy: number;
50
+ };
51
+ /** Render one arrow, already rotated, as a transparent PNG. Pure args. */
52
+ export declare function buildArrowImageArgs(a: ArrowCallout, output: string): string[];
53
+ export interface CalloutAssets {
54
+ fontFile: string;
55
+ /** Per item: the text file for a text callout, else null. */
56
+ textFiles: Array<string | null>;
57
+ /** Per item: the rendered arrow PNG for an arrow callout, else null. */
58
+ arrowFiles: Array<string | null>;
59
+ }
60
+ /** Draw every callout in order (later items on top). Pure. */
61
+ export declare function buildCalloutArgs(input: string, output: string, items: Callout[], assets: CalloutAssets, quality?: Quality): string[];
62
+ export {};
63
+ //# sourceMappingURL=callout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/utils/callout.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5D,UAAU,KAAK;IACb,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,IAAI,EAAE,KAAK,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AACD,MAAM,WAAW,YAAa,SAAQ,KAAK;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;AAY9D;yDACyD;AACzD,wBAAgB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAO3H;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAe7E;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChC,wEAAwE;IACxE,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAClC;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EAAE,EAChB,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,OAAoB,GAC5B,MAAM,EAAE,CA0CV"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Timed annotations (#121): boxes, text labels, and arrows that appear over a
3
+ * video between two timestamps. Boxes and text are drawbox / drawtext with an
4
+ * `enable` window. ffmpeg cannot draw an arbitrary line, so an arrow is drawn
5
+ * as an image (a shaft plus a triangular head, via geq), rotated to its angle,
6
+ * and overlaid centred on the arrow's midpoint. Builders are pure.
7
+ */
8
+ import { ScreencastError } from "./errors.js";
9
+ import { escapeFilterPath } from "./fonts.js";
10
+ import { enableExpr } from "./media.js";
11
+ import { resolveQuality } from "./targets.js";
12
+ import { validateColor } from "./validate.js";
13
+ const nonNeg = (v, label) => {
14
+ if (!Number.isFinite(v) || v < 0)
15
+ throw new ScreencastError(`${label} must be a non-negative number.`);
16
+ return Math.round(v);
17
+ };
18
+ function enable(c) {
19
+ const e = enableExpr(c.from, c.to);
20
+ return e ? `:enable='${e}'` : "";
21
+ }
22
+ /** Geometry of an arrow image: its length, thickness, rotation (radians,
23
+ * clockwise in screen coordinates), and centre. Pure. */
24
+ export function arrowGeometry(a) {
25
+ const dx = a.x2 - a.x1;
26
+ const dy = a.y2 - a.y1;
27
+ const length = Math.round(Math.hypot(dx, dy));
28
+ const thickness = Math.max(2, Math.round(a.thickness ?? 8));
29
+ if (length < thickness * 3)
30
+ throw new ScreencastError("An arrow must be at least three times as long as it is thick.");
31
+ return { length, thickness, angle: Math.atan2(dy, dx), cx: (a.x1 + a.x2) / 2, cy: (a.y1 + a.y2) / 2 };
32
+ }
33
+ /** Render one arrow, already rotated, as a transparent PNG. Pure args. */
34
+ export function buildArrowImageArgs(a, output) {
35
+ const { length, thickness, angle } = arrowGeometry(a);
36
+ const color = validateColor(a.color ?? "red");
37
+ const head = thickness * 3;
38
+ const ang = angle.toFixed(6);
39
+ // Opaque where: the shaft (|y - mid| < t/2 before the head), or inside the
40
+ // triangular head (|y - mid| < remaining length / 2).
41
+ const alpha = `if(lt(X,W-H),if(lt(abs(Y-H/2),${thickness}/2),255,0),if(lt(abs(Y-H/2),(W-X)/2),255,0))`;
42
+ return [
43
+ "-y", "-v", "error",
44
+ "-f", "lavfi", "-i", `color=c=${color}:s=${length}x${head}`,
45
+ "-vf", `format=rgba,geq=r='r(X,Y)':g='g(X,Y)':b='b(X,Y)':a='${alpha}',rotate=a=${ang}:ow=rotw(${ang}):oh=roth(${ang}):c=none`,
46
+ "-frames:v", "1",
47
+ output,
48
+ ];
49
+ }
50
+ /** Draw every callout in order (later items on top). Pure. */
51
+ export function buildCalloutArgs(input, output, items, assets, quality = "standard") {
52
+ if (items.length === 0)
53
+ throw new ScreencastError("Give at least one callout.");
54
+ const extraInputs = [];
55
+ const steps = [];
56
+ let cur = "[0:v]";
57
+ items.forEach((c, i) => {
58
+ const out = `[c${i}]`;
59
+ if (c.type === "box") {
60
+ const color = validateColor(c.color ?? "red");
61
+ const t = c.fill ? "fill" : String(Math.max(1, Math.round(c.thickness ?? 4)));
62
+ steps.push(`${cur}drawbox=x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:w=${nonNeg(c.width, "width")}:h=${nonNeg(c.height, "height")}` +
63
+ `:color=${color}:t=${t}${enable(c)}${out}`);
64
+ }
65
+ else if (c.type === "text") {
66
+ const file = assets.textFiles[i];
67
+ if (!file)
68
+ throw new ScreencastError("Internal: missing text file for a text callout.");
69
+ const color = validateColor(c.color ?? "white");
70
+ const size = Math.max(8, Math.round(c.size ?? 32));
71
+ const panel = c.background === false ? "" : `:box=1:boxcolor=black@0.6:boxborderw=${Math.round(size / 3)}`;
72
+ steps.push(`${cur}drawtext=fontfile=${escapeFilterPath(assets.fontFile)}:textfile=${escapeFilterPath(file)}:expansion=none` +
73
+ `:x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:fontsize=${size}:fontcolor=${color}${panel}${enable(c)}${out}`);
74
+ }
75
+ else {
76
+ const file = assets.arrowFiles[i];
77
+ if (!file)
78
+ throw new ScreencastError("Internal: missing image for an arrow callout.");
79
+ const { cx, cy } = arrowGeometry(c);
80
+ const n = 1 + extraInputs.length / 4;
81
+ extraInputs.push("-loop", "1", "-i", file);
82
+ steps.push(`${cur}[${n}:v]overlay=x=${cx.toFixed(1)}-w/2:y=${cy.toFixed(1)}-h/2:shortest=1${enable(c)}${out}`);
83
+ }
84
+ cur = out;
85
+ });
86
+ return [
87
+ "-y", "-i", input, ...extraInputs,
88
+ "-filter_complex", steps.join(";"),
89
+ "-map", cur, "-map", "0:a?",
90
+ ...resolveQuality(quality),
91
+ "-c:a", "copy",
92
+ output,
93
+ ];
94
+ }
95
+ //# sourceMappingURL=callout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout.js","sourceRoot":"","sources":["../../src/utils/callout.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA2C9C,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,KAAa,EAAE,EAAE;IAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,eAAe,CAAC,GAAG,KAAK,iCAAiC,CAAC,CAAC;IACvG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF,SAAS,MAAM,CAAC,CAAQ;IACtB,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACnC,CAAC;AAED;yDACyD;AACzD,MAAM,UAAU,aAAa,CAAC,CAAe;IAC3C,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IACvB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IACvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAA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E,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3C,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;QACjH,CAAC;QACD,GAAG,GAAG,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,WAAW;QACjC,iBAAiB,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QAClC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM;QAC3B,GAAG,cAAc,CAAC,OAAO,CAAC;QAC1B,MAAM,EAAE,MAAM;QACd,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type Quality } from "./targets.js";
2
+ /** Env var naming the default whisper.cpp model file. */
3
+ export declare const WHISPER_MODEL_ENV = "SCREENCAST_WHISPER_MODEL";
4
+ /** The model to use: the argument, else the env var. It must exist. */
5
+ export declare function resolveWhisperModel(arg: string | undefined, env?: NodeJS.ProcessEnv): string;
6
+ /** Transcribe the input's audio to an SRT file (whisper wants 16 kHz). */
7
+ export declare function buildTranscribeArgs(input: string, model: string, srtOut: string, language?: string): string[];
8
+ export interface Cue {
9
+ start: number;
10
+ end: number;
11
+ text: string;
12
+ }
13
+ /** Parse SRT into cues (tolerant of CRLF, 0-based numbering, blank lines). */
14
+ export declare function parseSrt(srt: string): Cue[];
15
+ /** Renumber from 1, sort by start, and end each cue no later than the next
16
+ * one starts, so cues never overlap. Pure. */
17
+ export declare function normalizeCues(cues: Cue[]): Cue[];
18
+ export declare function formatSrt(cues: Cue[]): string;
19
+ export type CaptionStyle = "clean" | "social";
20
+ /** libass force_style overrides. SRT is laid out on a 288 px-tall canvas, so
21
+ * sizes are relative to that: "clean" is a modest outlined line at the bottom;
22
+ * "social" is large, bold, on a dark box, raised clear of app UI. */
23
+ export declare const CAPTION_STYLES: Record<CaptionStyle, string>;
24
+ /** Burn an SRT/ASS file into the video with the bundled font. */
25
+ export declare function buildBurnSubtitlesArgs(input: string, subtitles: string, output: string, fontsDir: string, style?: CaptionStyle, quality?: Quality): string[];
26
+ //# sourceMappingURL=captions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captions.d.ts","sourceRoot":"","sources":["../../src/utils/captions.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5D,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAM5D,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAOzG;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAS,GAAG,MAAM,EAAE,CAW7G;AAED,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAaD,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,CAc3C;AAED;8CAC8C;AAC9C,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAShD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,CAE7C;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;qEAEqE;AACrE,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAGvD,CAAC;AAEF,iEAAiE;AACjE,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,YAAsB,EAC7B,OAAO,GAAE,OAAoB,GAC5B,MAAM,EAAE,CAUV"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Captions (#120): transcribe speech to SRT with FFmpeg 8's built-in whisper
3
+ * filter (whisper.cpp, runs locally), and burn subtitles into a video.
4
+ *
5
+ * Whisper's SRT needs tidying: it numbers cues from 0 and lets consecutive
6
+ * cues overlap (one starting before the previous ends), which some players
7
+ * render as two stacked lines. normalizeSrt fixes both. Builders and the SRT
8
+ * handling are pure.
9
+ */
10
+ import { existsSync } from "node:fs";
11
+ import { ScreencastError } from "./errors.js";
12
+ import { escapeFilterPath } from "./fonts.js";
13
+ import { resolveQuality } from "./targets.js";
14
+ /** Env var naming the default whisper.cpp model file. */
15
+ export const WHISPER_MODEL_ENV = "SCREENCAST_WHISPER_MODEL";
16
+ const MODEL_HINT = `Download a whisper.cpp model (ggml-base.en.bin is a good start; ggml-tiny.en.bin is fastest) from ` +
17
+ `https://huggingface.co/ggerganov/whisper.cpp and pass its path as model, or set ${WHISPER_MODEL_ENV}.`;
18
+ /** The model to use: the argument, else the env var. It must exist. */
19
+ export function resolveWhisperModel(arg, env = process.env) {
20
+ const model = arg ?? env[WHISPER_MODEL_ENV];
21
+ if (!model || model.trim().length === 0) {
22
+ throw new ScreencastError("No whisper model given.", MODEL_HINT);
23
+ }
24
+ if (!existsSync(model))
25
+ throw new ScreencastError(`Whisper model not found: ${model}`, MODEL_HINT);
26
+ return model;
27
+ }
28
+ /** Transcribe the input's audio to an SRT file (whisper wants 16 kHz). */
29
+ export function buildTranscribeArgs(input, model, srtOut, language = "auto") {
30
+ if (!/^[a-z]{2,3}$|^auto$/.test(language)) {
31
+ throw new ScreencastError(`language must be a code like "en" or "auto", got "${language}".`);
32
+ }
33
+ return [
34
+ "-y", "-v", "error", "-i", input, "-vn",
35
+ "-af",
36
+ `aresample=16000,whisper=model=${escapeFilterPath(model)}:language=${language}:format=srt:` +
37
+ `destination=${escapeFilterPath(srtOut)}:use_gpu=false`,
38
+ "-f", "null", "-",
39
+ ];
40
+ }
41
+ const TIME = /(\d+):(\d{2}):(\d{2})[,.](\d{3})/;
42
+ const toSec = (m) => Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4]) / 1000;
43
+ function fmt(sec) {
44
+ const ms = Math.round(sec * 1000);
45
+ const h = Math.floor(ms / 3_600_000);
46
+ const m = Math.floor((ms % 3_600_000) / 60_000);
47
+ const s = Math.floor((ms % 60_000) / 1000);
48
+ const pad = (n, w = 2) => String(n).padStart(w, "0");
49
+ return `${pad(h)}:${pad(m)}:${pad(s)},${pad(ms % 1000, 3)}`;
50
+ }
51
+ /** Parse SRT into cues (tolerant of CRLF, 0-based numbering, blank lines). */
52
+ export function parseSrt(srt) {
53
+ const cues = [];
54
+ for (const block of srt.replace(/\r\n/g, "\n").split(/\n\s*\n/)) {
55
+ const lines = block.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
56
+ const i = lines.findIndex((l) => l.includes("-->"));
57
+ if (i === -1)
58
+ continue;
59
+ const [a, b] = lines[i].split("-->");
60
+ const sa = a.match(TIME);
61
+ const sb = b?.match(TIME);
62
+ if (!sa || !sb)
63
+ continue;
64
+ const text = lines.slice(i + 1).join("\n");
65
+ if (text)
66
+ cues.push({ start: toSec(sa), end: toSec(sb), text });
67
+ }
68
+ return cues;
69
+ }
70
+ /** Renumber from 1, sort by start, and end each cue no later than the next
71
+ * one starts, so cues never overlap. Pure. */
72
+ export function normalizeCues(cues) {
73
+ const sorted = [...cues].sort((p, q) => p.start - q.start);
74
+ return sorted
75
+ .map((c, i) => {
76
+ const next = sorted[i + 1];
77
+ const end = next ? Math.min(c.end, next.start) : c.end;
78
+ return { ...c, end };
79
+ })
80
+ .filter((c) => c.end > c.start);
81
+ }
82
+ export function formatSrt(cues) {
83
+ return cues.map((c, i) => `${i + 1}\n${fmt(c.start)} --> ${fmt(c.end)}\n${c.text}\n`).join("\n");
84
+ }
85
+ /** libass force_style overrides. SRT is laid out on a 288 px-tall canvas, so
86
+ * sizes are relative to that: "clean" is a modest outlined line at the bottom;
87
+ * "social" is large, bold, on a dark box, raised clear of app UI. */
88
+ export const CAPTION_STYLES = {
89
+ clean: "FontName=Inter,FontSize=16,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=1.5,Shadow=0,MarginV=16",
90
+ social: "FontName=Inter,Bold=1,FontSize=22,PrimaryColour=&H00FFFFFF,BackColour=&H99000000,BorderStyle=3,Outline=6,Shadow=0,MarginV=40",
91
+ };
92
+ /** Burn an SRT/ASS file into the video with the bundled font. */
93
+ export function buildBurnSubtitlesArgs(input, subtitles, output, fontsDir, style = "clean", quality = "standard") {
94
+ const force = CAPTION_STYLES[style];
95
+ if (!force)
96
+ throw new ScreencastError(`Unknown caption style "${style}".`);
97
+ return [
98
+ "-y", "-i", input,
99
+ "-vf", `subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}:force_style='${force}'`,
100
+ ...resolveQuality(quality),
101
+ "-c:a", "copy",
102
+ output,
103
+ ];
104
+ }
105
+ //# sourceMappingURL=captions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captions.js","sourceRoot":"","sources":["../../src/utils/captions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D,yDAAyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GA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C;QAC1B,MAAM,EAAE,MAAM;QACd,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { Monitor } from "./monitors.js";
2
+ import { type Target } from "./targets.js";
3
+ /** Width frames are analysed at. */
4
+ export declare const ANALYSIS_WIDTH = 320;
5
+ /** Cell size in analysis pixels. */
6
+ export declare const CELL = 8;
7
+ /** A cell's mean |a - b| (0-255) above this counts as changed. Low enough to
8
+ * catch a text caret or a button highlight, high enough to ignore encoder noise. */
9
+ export declare const DEFAULT_PIXEL_THRESHOLD = 12;
10
+ export interface Rect {
11
+ x: number;
12
+ y: number;
13
+ width: number;
14
+ height: number;
15
+ }
16
+ /** Analysis size for a source of `width` x `height`: at most ANALYSIS_WIDTH
17
+ * wide, aspect kept, both sides even and at least 2. */
18
+ export declare function analysisSize(width: number, height: number): {
19
+ width: number;
20
+ height: number;
21
+ };
22
+ /** Pixel size of a resolved capture target (`full` is the union of monitors). */
23
+ export declare function targetSize(target: Target, monitors: Monitor[]): Rect;
24
+ /** Mean |a - b| over two equal-size grayscale bitmaps, as a 0-1 fraction. */
25
+ export declare function meanDifference(a: Uint8Array, b: Uint8Array): number;
26
+ export interface DiffResult {
27
+ /** Mean absolute difference, 0 (identical) to 1. */
28
+ meanDiff: number;
29
+ /** Share of grid cells that changed, 0-1. */
30
+ changedFraction: number;
31
+ /** Bounding boxes of changed areas, in source pixels (offset by `origin`). */
32
+ regions: Rect[];
33
+ }
34
+ /** Compare two `width` x `height` grayscale bitmaps. `scale` maps analysis
35
+ * pixels to source pixels; `origin` offsets the boxes (e.g. a region's x/y). */
36
+ export declare function diffFrames(a: Uint8Array, b: Uint8Array, width: number, height: number, opts?: {
37
+ scale?: number;
38
+ origin?: {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ pixelThreshold?: number;
43
+ maxRegions?: number;
44
+ }): DiffResult;
45
+ /** Grab args that decode one frame of a still or video file to a raw gray
46
+ * bitmap at the analysis size on stdout. */
47
+ export declare function buildRawFrameArgs(input: string, size: {
48
+ width: number;
49
+ height: number;
50
+ }): string[];
51
+ /** Grab one live frame of a resolved target as a raw gray bitmap at the
52
+ * analysis size on stdout (gdigrab at 30 fps; see SCREENSHOT_GRAB_FPS). */
53
+ export declare function buildRawGrabArgs(target: Target, monitors: Monitor[], size: {
54
+ width: number;
55
+ height: number;
56
+ }): string[];
57
+ /** SSIM between two images, both scaled to `size`; score printed to stderr. */
58
+ export declare function buildSsimArgs(a: string, b: string, size: {
59
+ width: number;
60
+ height: number;
61
+ }): string[];
62
+ /** Draw each changed region as a red outline on `input`, for a quick visual. */
63
+ export declare function buildHighlightArgs(input: string, regions: Rect[], output: string): string[];
64
+ /** Parse the `All:` score from ffmpeg's ssim filter output, or null. */
65
+ export declare function parseSsim(stderr: string): number | null;
66
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/utils/diff.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAwC,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAEjF,oCAAoC;AACpC,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,oCAAoC;AACpC,eAAO,MAAM,IAAI,IAAI,CAAC;AACtB;oFACoF;AACpF,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;wDACwD;AACxD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAK7F;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,MAAM,EAAE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