@tmhs/screencast-mcp 0.39.0 → 0.44.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -14
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +38 -302
- package/assets/ui/player.js +382 -0
- package/dist/context.js +0 -5
- package/dist/index.js +5 -21
- package/dist/prompts.js +0 -7
- package/dist/resources.js +2 -14
- package/dist/server.js +37 -11
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- package/dist/tools/clip.js +12 -9
- package/dist/tools/compress.js +10 -5
- package/dist/tools/concat.js +16 -15
- package/dist/tools/contactSheet.js +26 -22
- package/dist/tools/convert.js +12 -6
- package/dist/tools/crop.js +12 -7
- package/dist/tools/cutIdle.js +15 -9
- package/dist/tools/denoise.js +12 -6
- package/dist/tools/doctor.js +133 -0
- package/dist/tools/exportGif.js +14 -10
- package/dist/tools/exportPreset.js +11 -8
- package/dist/tools/extractAudio.js +10 -8
- package/dist/tools/findText.js +69 -65
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- package/dist/tools/listAudioDevices.js +14 -7
- package/dist/tools/listSessions.js +13 -3
- package/dist/tools/listTargets.js +76 -0
- package/dist/tools/musicBed.js +14 -10
- package/dist/tools/normalizeAudio.js +12 -8
- package/dist/tools/overlay.js +16 -12
- package/dist/tools/pipeline.js +31 -22
- package/dist/tools/readEvents.js +21 -12
- package/dist/tools/redactRegion.js +19 -17
- package/dist/tools/reframe.js +9 -5
- package/dist/tools/reviewRecording.js +63 -22
- package/dist/tools/sampleFrames.js +33 -40
- package/dist/tools/scale.js +9 -3
- package/dist/tools/screenDiff.js +23 -17
- package/dist/tools/screenshot.js +21 -17
- package/dist/tools/speed.js +15 -4
- package/dist/tools/startRecording.js +48 -52
- package/dist/tools/stopRecording.js +10 -9
- package/dist/tools/titleCard.js +19 -11
- package/dist/tools/transcribe.js +13 -7
- package/dist/tools/trim.js +11 -10
- package/dist/tools/waitForChange.js +37 -22
- package/dist/tools/xfadeTransition.js +12 -8
- package/dist/tools/zoom.js +26 -29
- package/dist/utils/anim.js +1 -21
- package/dist/utils/animExport.js +5 -10
- package/dist/utils/audio.js +4 -33
- package/dist/utils/audioDevices.js +1 -48
- package/dist/utils/callout.js +1 -19
- package/dist/utils/calloutAssets.js +21 -11
- package/dist/utils/capabilities.js +95 -0
- package/dist/utils/captions.js +9 -26
- package/dist/utils/consent.js +29 -0
- package/dist/utils/diff.js +0 -46
- package/dist/utils/errors.js +5 -13
- package/dist/utils/events.js +21 -77
- package/dist/utils/expr.js +11 -0
- package/dist/utils/ffmpeg.js +119 -48
- package/dist/utils/fontCoverage.js +177 -0
- package/dist/utils/fonts.js +139 -23
- package/dist/utils/idle.js +12 -24
- package/dist/utils/images.js +0 -17
- package/dist/utils/jobs.js +42 -41
- package/dist/utils/lifecycle.js +0 -29
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +11 -122
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +0 -23
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- package/dist/utils/resolveTarget.js +0 -19
- package/dist/utils/retention.js +1 -15
- package/dist/utils/roots.js +42 -0
- package/dist/utils/sessions.js +195 -160
- package/dist/utils/sheet.js +0 -19
- package/dist/utils/still.js +0 -15
- package/dist/utils/targetList.js +63 -0
- package/dist/utils/targets.js +5 -70
- package/dist/utils/toolSpec.js +25 -0
- package/dist/utils/toolsets.js +102 -0
- package/dist/utils/validate.js +0 -22
- package/dist/utils/wgc.js +0 -46
- package/dist/utils/windows.js +5 -50
- package/dist/utils/zoom.js +55 -85
- package/dist/wgcRecorder.js +1 -30
- package/package.json +7 -3
- package/dist/context.d.ts +0 -9
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts +0 -10
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js.map +0 -1
- package/dist/resources.d.ts +0 -3
- package/dist/resources.d.ts.map +0 -1
- package/dist/resources.js.map +0 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tools/assembleHighlights.d.ts +0 -3
- package/dist/tools/assembleHighlights.d.ts.map +0 -1
- package/dist/tools/assembleHighlights.js.map +0 -1
- package/dist/tools/burnSubtitles.d.ts +0 -3
- package/dist/tools/burnSubtitles.d.ts.map +0 -1
- package/dist/tools/burnSubtitles.js.map +0 -1
- package/dist/tools/callout.d.ts +0 -37
- package/dist/tools/callout.d.ts.map +0 -1
- package/dist/tools/callout.js.map +0 -1
- package/dist/tools/clip.d.ts +0 -3
- package/dist/tools/clip.d.ts.map +0 -1
- package/dist/tools/clip.js.map +0 -1
- package/dist/tools/compress.d.ts +0 -3
- package/dist/tools/compress.d.ts.map +0 -1
- package/dist/tools/compress.js.map +0 -1
- package/dist/tools/concat.d.ts +0 -3
- package/dist/tools/concat.d.ts.map +0 -1
- package/dist/tools/concat.js.map +0 -1
- package/dist/tools/contactSheet.d.ts +0 -3
- package/dist/tools/contactSheet.d.ts.map +0 -1
- package/dist/tools/contactSheet.js.map +0 -1
- package/dist/tools/convert.d.ts +0 -3
- package/dist/tools/convert.d.ts.map +0 -1
- package/dist/tools/convert.js.map +0 -1
- package/dist/tools/crop.d.ts +0 -3
- package/dist/tools/crop.d.ts.map +0 -1
- package/dist/tools/crop.js.map +0 -1
- package/dist/tools/cutIdle.d.ts +0 -3
- package/dist/tools/cutIdle.d.ts.map +0 -1
- package/dist/tools/cutIdle.js.map +0 -1
- package/dist/tools/denoise.d.ts +0 -3
- package/dist/tools/denoise.d.ts.map +0 -1
- package/dist/tools/denoise.js.map +0 -1
- package/dist/tools/exportGif.d.ts +0 -3
- package/dist/tools/exportGif.d.ts.map +0 -1
- package/dist/tools/exportGif.js.map +0 -1
- package/dist/tools/exportPreset.d.ts +0 -3
- package/dist/tools/exportPreset.d.ts.map +0 -1
- package/dist/tools/exportPreset.js.map +0 -1
- package/dist/tools/extractAudio.d.ts +0 -3
- package/dist/tools/extractAudio.d.ts.map +0 -1
- package/dist/tools/extractAudio.js.map +0 -1
- package/dist/tools/findText.d.ts +0 -6
- package/dist/tools/findText.d.ts.map +0 -1
- package/dist/tools/findText.js.map +0 -1
- package/dist/tools/getMediaInfo.d.ts +0 -3
- package/dist/tools/getMediaInfo.d.ts.map +0 -1
- package/dist/tools/getMediaInfo.js.map +0 -1
- package/dist/tools/getSession.d.ts +0 -3
- package/dist/tools/getSession.d.ts.map +0 -1
- package/dist/tools/getSession.js.map +0 -1
- package/dist/tools/listAudioDevices.d.ts +0 -3
- package/dist/tools/listAudioDevices.d.ts.map +0 -1
- package/dist/tools/listAudioDevices.js.map +0 -1
- package/dist/tools/listSessions.d.ts +0 -3
- package/dist/tools/listSessions.d.ts.map +0 -1
- package/dist/tools/listSessions.js.map +0 -1
- package/dist/tools/musicBed.d.ts +0 -3
- package/dist/tools/musicBed.d.ts.map +0 -1
- package/dist/tools/musicBed.js.map +0 -1
- package/dist/tools/normalizeAudio.d.ts +0 -3
- package/dist/tools/normalizeAudio.d.ts.map +0 -1
- package/dist/tools/normalizeAudio.js.map +0 -1
- package/dist/tools/overlay.d.ts +0 -3
- package/dist/tools/overlay.d.ts.map +0 -1
- package/dist/tools/overlay.js.map +0 -1
- package/dist/tools/pipeline.d.ts +0 -3
- package/dist/tools/pipeline.d.ts.map +0 -1
- package/dist/tools/pipeline.js.map +0 -1
- package/dist/tools/readEvents.d.ts +0 -6
- package/dist/tools/readEvents.d.ts.map +0 -1
- package/dist/tools/readEvents.js.map +0 -1
- package/dist/tools/redactRegion.d.ts +0 -13
- package/dist/tools/redactRegion.d.ts.map +0 -1
- package/dist/tools/redactRegion.js.map +0 -1
- package/dist/tools/reframe.d.ts +0 -3
- package/dist/tools/reframe.d.ts.map +0 -1
- package/dist/tools/reframe.js.map +0 -1
- package/dist/tools/reviewRecording.d.ts +0 -5
- package/dist/tools/reviewRecording.d.ts.map +0 -1
- package/dist/tools/reviewRecording.js.map +0 -1
- package/dist/tools/sampleFrames.d.ts +0 -3
- package/dist/tools/sampleFrames.d.ts.map +0 -1
- package/dist/tools/sampleFrames.js.map +0 -1
- package/dist/tools/scale.d.ts +0 -3
- package/dist/tools/scale.d.ts.map +0 -1
- package/dist/tools/scale.js.map +0 -1
- package/dist/tools/screenDiff.d.ts +0 -3
- package/dist/tools/screenDiff.d.ts.map +0 -1
- package/dist/tools/screenDiff.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -3
- package/dist/tools/screenshot.d.ts.map +0 -1
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/speed.d.ts +0 -3
- package/dist/tools/speed.d.ts.map +0 -1
- package/dist/tools/speed.js.map +0 -1
- package/dist/tools/startRecording.d.ts +0 -3
- package/dist/tools/startRecording.d.ts.map +0 -1
- package/dist/tools/startRecording.js.map +0 -1
- package/dist/tools/stopRecording.d.ts +0 -3
- package/dist/tools/stopRecording.d.ts.map +0 -1
- package/dist/tools/stopRecording.js.map +0 -1
- package/dist/tools/titleCard.d.ts +0 -3
- package/dist/tools/titleCard.d.ts.map +0 -1
- package/dist/tools/titleCard.js.map +0 -1
- package/dist/tools/transcribe.d.ts +0 -3
- package/dist/tools/transcribe.d.ts.map +0 -1
- package/dist/tools/transcribe.js.map +0 -1
- package/dist/tools/trim.d.ts +0 -3
- package/dist/tools/trim.d.ts.map +0 -1
- package/dist/tools/trim.js.map +0 -1
- package/dist/tools/waitForChange.d.ts +0 -3
- package/dist/tools/waitForChange.d.ts.map +0 -1
- package/dist/tools/waitForChange.js.map +0 -1
- package/dist/tools/xfadeTransition.d.ts +0 -3
- package/dist/tools/xfadeTransition.d.ts.map +0 -1
- package/dist/tools/xfadeTransition.js.map +0 -1
- package/dist/tools/zoom.d.ts +0 -15
- package/dist/tools/zoom.d.ts.map +0 -1
- package/dist/tools/zoom.js.map +0 -1
- package/dist/utils/anim.d.ts +0 -33
- package/dist/utils/anim.d.ts.map +0 -1
- package/dist/utils/anim.js.map +0 -1
- package/dist/utils/animExport.d.ts +0 -27
- package/dist/utils/animExport.d.ts.map +0 -1
- package/dist/utils/animExport.js.map +0 -1
- package/dist/utils/audio.d.ts +0 -49
- package/dist/utils/audio.d.ts.map +0 -1
- package/dist/utils/audio.js.map +0 -1
- package/dist/utils/audioDevices.d.ts +0 -33
- package/dist/utils/audioDevices.d.ts.map +0 -1
- package/dist/utils/audioDevices.js.map +0 -1
- package/dist/utils/callout.d.ts +0 -72
- package/dist/utils/callout.d.ts.map +0 -1
- package/dist/utils/callout.js.map +0 -1
- package/dist/utils/calloutAssets.d.ts +0 -3
- package/dist/utils/calloutAssets.d.ts.map +0 -1
- package/dist/utils/calloutAssets.js.map +0 -1
- package/dist/utils/captions.d.ts +0 -26
- package/dist/utils/captions.d.ts.map +0 -1
- package/dist/utils/captions.js.map +0 -1
- package/dist/utils/diff.d.ts +0 -112
- package/dist/utils/diff.d.ts.map +0 -1
- package/dist/utils/diff.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -33
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/events.d.ts +0 -143
- package/dist/utils/events.d.ts.map +0 -1
- package/dist/utils/events.js.map +0 -1
- package/dist/utils/ffmpeg.d.ts +0 -50
- package/dist/utils/ffmpeg.d.ts.map +0 -1
- package/dist/utils/ffmpeg.js.map +0 -1
- package/dist/utils/fonts.d.ts +0 -17
- package/dist/utils/fonts.d.ts.map +0 -1
- package/dist/utils/fonts.js.map +0 -1
- package/dist/utils/idle.d.ts +0 -23
- package/dist/utils/idle.d.ts.map +0 -1
- package/dist/utils/idle.js.map +0 -1
- package/dist/utils/images.d.ts +0 -21
- package/dist/utils/images.d.ts.map +0 -1
- package/dist/utils/images.js.map +0 -1
- package/dist/utils/jobs.d.ts +0 -44
- package/dist/utils/jobs.d.ts.map +0 -1
- package/dist/utils/jobs.js.map +0 -1
- package/dist/utils/lifecycle.d.ts +0 -29
- package/dist/utils/lifecycle.d.ts.map +0 -1
- package/dist/utils/lifecycle.js.map +0 -1
- package/dist/utils/media.d.ts +0 -272
- package/dist/utils/media.d.ts.map +0 -1
- package/dist/utils/media.js.map +0 -1
- package/dist/utils/monitors.d.ts +0 -47
- package/dist/utils/monitors.d.ts.map +0 -1
- package/dist/utils/monitors.js.map +0 -1
- package/dist/utils/ocr.d.ts +0 -50
- package/dist/utils/ocr.d.ts.map +0 -1
- package/dist/utils/ocr.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -28
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/pipeline.d.ts +0 -69
- package/dist/utils/pipeline.d.ts.map +0 -1
- package/dist/utils/pipeline.js.map +0 -1
- package/dist/utils/player.d.ts +0 -30
- package/dist/utils/player.d.ts.map +0 -1
- package/dist/utils/player.js.map +0 -1
- package/dist/utils/produce.d.ts +0 -126
- package/dist/utils/produce.d.ts.map +0 -1
- package/dist/utils/produce.js.map +0 -1
- package/dist/utils/resolveTarget.d.ts +0 -32
- package/dist/utils/resolveTarget.d.ts.map +0 -1
- package/dist/utils/resolveTarget.js.map +0 -1
- package/dist/utils/retention.d.ts +0 -10
- package/dist/utils/retention.d.ts.map +0 -1
- package/dist/utils/retention.js.map +0 -1
- package/dist/utils/sessions.d.ts +0 -154
- package/dist/utils/sessions.d.ts.map +0 -1
- package/dist/utils/sessions.js.map +0 -1
- package/dist/utils/sheet.d.ts +0 -26
- package/dist/utils/sheet.d.ts.map +0 -1
- package/dist/utils/sheet.js.map +0 -1
- package/dist/utils/still.d.ts +0 -7
- package/dist/utils/still.d.ts.map +0 -1
- package/dist/utils/still.js.map +0 -1
- package/dist/utils/targets.d.ts +0 -113
- package/dist/utils/targets.d.ts.map +0 -1
- package/dist/utils/targets.js.map +0 -1
- package/dist/utils/validate.d.ts +0 -15
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js.map +0 -1
- package/dist/utils/wgc.d.ts +0 -46
- package/dist/utils/wgc.d.ts.map +0 -1
- package/dist/utils/wgc.js.map +0 -1
- package/dist/utils/windows.d.ts +0 -94
- package/dist/utils/windows.d.ts.map +0 -1
- package/dist/utils/windows.js.map +0 -1
- package/dist/utils/zoom.d.ts +0 -95
- package/dist/utils/zoom.d.ts.map +0 -1
- package/dist/utils/zoom.js.map +0 -1
- package/dist/wgcRecorder.d.ts +0 -2
- package/dist/wgcRecorder.d.ts.map +0 -1
- package/dist/wgcRecorder.js.map +0 -1
package/dist/utils/media.js
CHANGED
|
@@ -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,16 +79,11 @@ 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
85
|
export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFAULT_MAX_FRAMES, dedupe = false) {
|
|
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}`;
|
|
110
88
|
return [
|
|
111
89
|
"-y", "-i", input, "-vf", vf,
|
|
@@ -113,12 +91,7 @@ export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFA
|
|
|
113
91
|
"-frames:v", String(maxFrames), outputPattern,
|
|
114
92
|
];
|
|
115
93
|
}
|
|
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
94
|
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
95
|
export function buildSceneScanArgs(input, threshold = DEFAULT_SCENE_THRESHOLD) {
|
|
123
96
|
if (!Number.isFinite(threshold) || threshold <= 0 || threshold >= 1) {
|
|
124
97
|
throw new ScreencastError("sceneThreshold must be between 0 and 1 (exclusive).");
|
|
@@ -129,7 +102,6 @@ export function buildSceneScanArgs(input, threshold = DEFAULT_SCENE_THRESHOLD) {
|
|
|
129
102
|
"-f", "null", "-",
|
|
130
103
|
];
|
|
131
104
|
}
|
|
132
|
-
/** Parse `metadata=print` output into (time, score) pairs. Pure. */
|
|
133
105
|
export function parseSceneScan(stdout) {
|
|
134
106
|
const out = [];
|
|
135
107
|
let time = null;
|
|
@@ -147,9 +119,6 @@ export function parseSceneScan(stdout) {
|
|
|
147
119
|
}
|
|
148
120
|
return out;
|
|
149
121
|
}
|
|
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
122
|
export function pickSceneFrames(changes, maxFrames) {
|
|
154
123
|
const strongest = [...changes]
|
|
155
124
|
.filter((c) => c.timeSec > 0)
|
|
@@ -158,32 +127,24 @@ export function pickSceneFrames(changes, maxFrames) {
|
|
|
158
127
|
.map((c) => c.timeSec);
|
|
159
128
|
return [0, ...strongest].sort((a, b) => a - b);
|
|
160
129
|
}
|
|
161
|
-
/** Build one ffmpeg invocation per timestamp (accurate single-frame seek). */
|
|
162
130
|
export function buildSampleAtTimestampArgs(input, timestampSec, output) {
|
|
163
131
|
if (!Number.isFinite(timestampSec) || timestampSec < 0) {
|
|
164
132
|
throw new ScreencastError("timestamp must be a non-negative number.");
|
|
165
133
|
}
|
|
166
134
|
return ["-y", "-ss", String(timestampSec), "-i", input, "-frames:v", "1", ...stillOutput(output)];
|
|
167
135
|
}
|
|
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
136
|
export function editOutputExt(input, opts = {}) {
|
|
172
137
|
const ext = extname(input).toLowerCase();
|
|
173
138
|
if (ext === ".mp4" || ext === ".mkv" || ext === ".mov")
|
|
174
139
|
return ext;
|
|
175
|
-
// Audio tools also keep an audio-only container they can encode to.
|
|
176
140
|
if (opts.audio && AUDIO_ONLY_EXTS.has(ext))
|
|
177
141
|
return ext;
|
|
178
142
|
return ".mp4";
|
|
179
143
|
}
|
|
180
144
|
const AUDIO_ONLY_EXTS = new Set([".wav", ".mp3", ".m4a"]);
|
|
181
|
-
/** True when the output path is an audio-only container (.wav/.mp3/.m4a). */
|
|
182
145
|
export function isAudioOnlyPath(path) {
|
|
183
146
|
return AUDIO_ONLY_EXTS.has(extname(path).toLowerCase());
|
|
184
147
|
}
|
|
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
148
|
export function assertEditContainer(output) {
|
|
188
149
|
if (output === undefined)
|
|
189
150
|
return;
|
|
@@ -193,9 +154,6 @@ export function assertEditContainer(output) {
|
|
|
193
154
|
`output, then convert (format: "webm") or export_gif the result.`);
|
|
194
155
|
}
|
|
195
156
|
}
|
|
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
157
|
export function buildTrimArgs(input, output, opts) {
|
|
200
158
|
const start = opts.start;
|
|
201
159
|
if (!Number.isFinite(start) || start < 0) {
|
|
@@ -212,8 +170,6 @@ export function buildTrimArgs(input, output, opts) {
|
|
|
212
170
|
if (opts.end <= start) {
|
|
213
171
|
throw new ScreencastError("end must be greater than start.");
|
|
214
172
|
}
|
|
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
173
|
args.push("-t", String(Math.round((opts.end - start) * 1000) / 1000));
|
|
218
174
|
}
|
|
219
175
|
else {
|
|
@@ -225,7 +181,6 @@ export function buildTrimArgs(input, output, opts) {
|
|
|
225
181
|
args.push(...resolveQuality(DEFAULT_EDIT_QUALITY), "-c:a", "aac", output);
|
|
226
182
|
return args;
|
|
227
183
|
}
|
|
228
|
-
/** Build the concat-demuxer list file content for a set of inputs. */
|
|
229
184
|
export function buildConcatListContent(inputs) {
|
|
230
185
|
if (inputs.length < 2) {
|
|
231
186
|
throw new ScreencastError("concat requires at least two input files.");
|
|
@@ -237,18 +192,12 @@ export function buildConcatListContent(inputs) {
|
|
|
237
192
|
export function buildConcatArgs(listFile, output) {
|
|
238
193
|
return ["-y", "-f", "concat", "-safe", "0", "-i", listFile, "-c", "copy", output];
|
|
239
194
|
}
|
|
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
195
|
export function hasHiddenFrames(info) {
|
|
244
196
|
const { videoFrames: n, videoDurationSec: d, fps } = info;
|
|
245
197
|
if (n === null || d === null || fps === null)
|
|
246
198
|
return false;
|
|
247
199
|
return n > d * fps * 1.05 + 2;
|
|
248
200
|
}
|
|
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
201
|
export function concatCopyBlocker(paths, infos) {
|
|
253
202
|
const fields = [
|
|
254
203
|
["videoCodec", "video codec"],
|
|
@@ -261,27 +210,25 @@ export function concatCopyBlocker(paths, infos) {
|
|
|
261
210
|
["channels", "audio channels"],
|
|
262
211
|
];
|
|
263
212
|
const first = infos[0];
|
|
264
|
-
for (
|
|
265
|
-
if (hasHiddenFrames(
|
|
213
|
+
for (const [i, info] of infos.entries()) {
|
|
214
|
+
if (hasHiddenFrames(info))
|
|
266
215
|
return `${paths[i]} holds hidden frames behind an edit list`;
|
|
267
|
-
if (i === 0)
|
|
216
|
+
if (i === 0 || !first)
|
|
268
217
|
continue;
|
|
269
218
|
for (const [key, label] of fields) {
|
|
270
|
-
if (
|
|
271
|
-
return `${label} differs: ${paths[0]} has ${first[key] ?? "none"}, ${paths[i]} has ${
|
|
219
|
+
if (info[key] !== first[key]) {
|
|
220
|
+
return `${label} differs: ${paths[0]} has ${first[key] ?? "none"}, ${paths[i]} has ${info[key] ?? "none"}`;
|
|
272
221
|
}
|
|
273
222
|
}
|
|
274
223
|
}
|
|
275
224
|
return null;
|
|
276
225
|
}
|
|
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
226
|
export function buildConvertArgs(input, output, format, opts = {}) {
|
|
280
227
|
switch (format) {
|
|
281
228
|
case "gif": {
|
|
282
229
|
const fps = opts.fps ?? 12;
|
|
283
230
|
const width = opts.width ?? 720;
|
|
284
|
-
const filter = `fps=${fps},scale
|
|
231
|
+
const filter = `fps=${fps},scale='min(${width},iw)':-1:flags=lanczos,split[s0][s1];` +
|
|
285
232
|
`[s0]palettegen[p];[s1][p]paletteuse`;
|
|
286
233
|
return ["-y", "-i", input, "-vf", filter, output];
|
|
287
234
|
}
|
|
@@ -289,7 +236,7 @@ export function buildConvertArgs(input, output, format, opts = {}) {
|
|
|
289
236
|
return [
|
|
290
237
|
"-y", "-i", input,
|
|
291
238
|
"-c:v", "libvpx-vp9", "-b:v", "0", "-crf", "30",
|
|
292
|
-
"-row-mt", "1",
|
|
239
|
+
"-deadline", "good", "-cpu-used", "4", "-row-mt", "1",
|
|
293
240
|
output,
|
|
294
241
|
];
|
|
295
242
|
case "mp4":
|
|
@@ -304,11 +251,6 @@ export function buildConvertArgs(input, output, format, opts = {}) {
|
|
|
304
251
|
throw new ScreencastError(`Unsupported convert format "${format}".`);
|
|
305
252
|
}
|
|
306
253
|
}
|
|
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
254
|
function requireNonNegativeInt(value, label) {
|
|
313
255
|
if (!Number.isInteger(value) || value < 0) {
|
|
314
256
|
throw new ScreencastError(`${label} must be a non-negative integer.`);
|
|
@@ -321,7 +263,6 @@ function requirePositiveInt(value, label) {
|
|
|
321
263
|
}
|
|
322
264
|
return value;
|
|
323
265
|
}
|
|
324
|
-
/** Build a libavfilter `enable=` timeline expression, or "" for always-on. */
|
|
325
266
|
export function enableExpr(start, end) {
|
|
326
267
|
if (start !== undefined && end !== undefined) {
|
|
327
268
|
if (end <= start)
|
|
@@ -334,10 +275,6 @@ export function enableExpr(start, end) {
|
|
|
334
275
|
return `lte(t,${end})`;
|
|
335
276
|
return "";
|
|
336
277
|
}
|
|
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
278
|
export function cropFilter(rect, dims) {
|
|
342
279
|
const x = requireNonNegativeInt(rect.x, "crop x");
|
|
343
280
|
const y = requireNonNegativeInt(rect.y, "crop y");
|
|
@@ -360,8 +297,6 @@ export function buildCropArgs(input, output, rect, dims, quality = DEFAULT_EDIT_
|
|
|
360
297
|
output,
|
|
361
298
|
];
|
|
362
299
|
}
|
|
363
|
-
/** Scale to a width and/or height. A missing side uses -2 (keep aspect, even
|
|
364
|
-
* dimension as required by yuv420p). */
|
|
365
300
|
export function scaleFilter(opts) {
|
|
366
301
|
if (opts.width === undefined && opts.height === undefined) {
|
|
367
302
|
throw new ScreencastError("scale requires width or height (or both).");
|
|
@@ -374,8 +309,6 @@ export function scaleFilter(opts) {
|
|
|
374
309
|
}
|
|
375
310
|
return `scale=${opts.width ?? -2}:${opts.height ?? -2}`;
|
|
376
311
|
}
|
|
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
312
|
export function scaledSize(W, H, opts) {
|
|
380
313
|
const even = (v) => Math.max(2, Math.round(v / 2) * 2);
|
|
381
314
|
if (opts.width !== undefined && opts.height !== undefined)
|
|
@@ -393,8 +326,6 @@ export function buildScaleArgs(input, output, opts, quality = DEFAULT_EDIT_QUALI
|
|
|
393
326
|
output,
|
|
394
327
|
];
|
|
395
328
|
}
|
|
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
329
|
export function atempoChain(factor) {
|
|
399
330
|
let remaining = factor;
|
|
400
331
|
const parts = [];
|
|
@@ -406,11 +337,9 @@ export function atempoChain(factor) {
|
|
|
406
337
|
parts.push("atempo=0.5");
|
|
407
338
|
remaining /= 0.5;
|
|
408
339
|
}
|
|
409
|
-
parts.push(`atempo=${
|
|
340
|
+
parts.push(`atempo=${Number(remaining.toFixed(6))}`);
|
|
410
341
|
return parts.join(",");
|
|
411
342
|
}
|
|
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
343
|
export function buildSpeedArgs(input, output, factor, hasAudio, quality = DEFAULT_EDIT_QUALITY) {
|
|
415
344
|
if (!Number.isFinite(factor) || factor <= 0) {
|
|
416
345
|
throw new ScreencastError("speed factor must be a positive number.");
|
|
@@ -428,11 +357,6 @@ export function buildSpeedArgs(input, output, factor, hasAudio, quality = DEFAUL
|
|
|
428
357
|
args.push(output);
|
|
429
358
|
return args;
|
|
430
359
|
}
|
|
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
360
|
export function buildOverlayArgs(input, overlay, output, opts, quality = DEFAULT_EDIT_QUALITY) {
|
|
437
361
|
const x = requireNonNegativeInt(opts.x, "overlay x");
|
|
438
362
|
const y = requireNonNegativeInt(opts.y, "overlay y");
|
|
@@ -457,7 +381,6 @@ export function buildOverlayArgs(input, overlay, output, opts, quality = DEFAULT
|
|
|
457
381
|
"-map", "[v]", "-map", "0:a?",
|
|
458
382
|
...resolveQuality(quality),
|
|
459
383
|
"-c:a", "copy",
|
|
460
|
-
// A longer overlay video would otherwise run the output past the main clip.
|
|
461
384
|
...(dur != null && dur > 0 ? ["-t", String(dur)] : []),
|
|
462
385
|
output,
|
|
463
386
|
];
|
|
@@ -467,8 +390,6 @@ const COMPRESS_CRF = {
|
|
|
467
390
|
medium: 28,
|
|
468
391
|
heavy: 32,
|
|
469
392
|
};
|
|
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
393
|
export function buildCompressArgs(input, output, opts = {}) {
|
|
473
394
|
const level = opts.level ?? "medium";
|
|
474
395
|
const crf = COMPRESS_CRF[level];
|
|
@@ -477,7 +398,6 @@ export function buildCompressArgs(input, output, opts = {}) {
|
|
|
477
398
|
const args = ["-y", "-i", input];
|
|
478
399
|
if (opts.maxWidth !== undefined) {
|
|
479
400
|
requirePositiveInt(opts.maxWidth, "maxWidth");
|
|
480
|
-
// Always even and never an upscale: libx264 rejects an odd width (#239).
|
|
481
401
|
args.push("-vf", `scale='trunc(min(${opts.maxWidth},iw)/2)*2':-2`);
|
|
482
402
|
}
|
|
483
403
|
args.push("-c:v", "libx264", "-preset", "slow", "-crf", String(crf), "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart", output);
|
|
@@ -489,11 +409,6 @@ const AUDIO_CODEC = {
|
|
|
489
409
|
wav: ["-c:a", "pcm_s16le"],
|
|
490
410
|
copy: ["-c:a", "copy"],
|
|
491
411
|
};
|
|
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
412
|
export function copyAudioExtension(codec) {
|
|
498
413
|
switch (codec) {
|
|
499
414
|
case "aac":
|
|
@@ -518,9 +433,6 @@ export function buildExtractAudioArgs(input, output, format) {
|
|
|
518
433
|
throw new ScreencastError(`Unknown audio format "${format}".`);
|
|
519
434
|
return ["-y", "-i", input, "-vn", ...codec, output];
|
|
520
435
|
}
|
|
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
436
|
export function buildClipArgs(input, output, seg, quality = DEFAULT_EDIT_QUALITY) {
|
|
525
437
|
if (!Number.isFinite(seg.start) || seg.start < 0) {
|
|
526
438
|
throw new ScreencastError("clip start must be a non-negative number.");
|
|
@@ -537,9 +449,6 @@ export function buildClipArgs(input, output, seg, quality = DEFAULT_EDIT_QUALITY
|
|
|
537
449
|
output,
|
|
538
450
|
];
|
|
539
451
|
}
|
|
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
452
|
function normalizeRegions(regions, pad, dims) {
|
|
544
453
|
return regions.map((r, i) => {
|
|
545
454
|
const x0 = requireNonNegativeInt(r.x, `region[${i}] x`);
|
|
@@ -563,35 +472,21 @@ function normalizeRegions(regions, pad, dims) {
|
|
|
563
472
|
return { x, y, w: right - x, h: bottom - y, enable: enableExpr(r.start, r.end) };
|
|
564
473
|
});
|
|
565
474
|
}
|
|
566
|
-
/** Smallest blur radius in px, where the region allows it (#204). */
|
|
567
475
|
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
476
|
export const BLUR_PASSES = 3;
|
|
571
|
-
/** Smallest pixelate block in px: about two characters of UI text (#204). */
|
|
572
477
|
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
478
|
export function blurRadius(r) {
|
|
578
479
|
const m = Math.min(r.w, r.h);
|
|
579
480
|
const lr = Math.min(Math.floor(m / 2), Math.max(MIN_BLUR_RADIUS, Math.min(20, Math.floor(m / 4))));
|
|
580
481
|
const cr = Math.min(lr, Math.floor(Math.ceil(m / 2) / 2));
|
|
581
482
|
return `lr=${lr}:lp=${BLUR_PASSES}:cr=${cr}:cp=${BLUR_PASSES}`;
|
|
582
483
|
}
|
|
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
484
|
export function pixelateFilter(r) {
|
|
587
485
|
const block = Math.max(MIN_PIXEL_BLOCK, Math.ceil(Math.max(r.w, r.h) / 16));
|
|
588
486
|
const cols = Math.max(1, Math.round(r.w / block));
|
|
589
487
|
const rows = Math.max(1, Math.round(r.h / block));
|
|
590
488
|
return `scale=${cols}:${rows}:flags=area,scale=${r.w}:${r.h}:flags=neighbor`;
|
|
591
489
|
}
|
|
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
490
|
export function redactSteps(regions, opts, dims, input, tag) {
|
|
596
491
|
if (regions.length === 0) {
|
|
597
492
|
throw new ScreencastError("redact_region requires at least one region.");
|
|
@@ -612,8 +507,6 @@ export function redactSteps(regions, opts, dims, input, tag) {
|
|
|
612
507
|
.join(",");
|
|
613
508
|
return { steps: [`${input}${boxes}[${tag}out]`], out: `[${tag}out]` };
|
|
614
509
|
}
|
|
615
|
-
// blur / pixelate: split the source, soften each cropped region, then overlay
|
|
616
|
-
// the softened patches back over the base in order.
|
|
617
510
|
const n = rs.length;
|
|
618
511
|
const steps = [];
|
|
619
512
|
const splitOuts = [`${tag}base`, ...rs.map((_, i) => `${tag}s${i}`)];
|
|
@@ -634,14 +527,11 @@ export function redactSteps(regions, opts, dims, input, tag) {
|
|
|
634
527
|
});
|
|
635
528
|
return { steps, out: `[${tag}out]` };
|
|
636
529
|
}
|
|
637
|
-
/** Redact declared rectangles. `box` (default) draws an irreversible solid fill;
|
|
638
|
-
* `blur` and `pixelate` composite a softened crop back over each region. */
|
|
639
530
|
export function buildRedactArgs(input, output, regions, opts = {}, dims) {
|
|
640
531
|
const { steps, out } = redactSteps(regions, opts, dims, "[0:v]", "");
|
|
641
|
-
|
|
642
|
-
if ((opts.style ?? "box") === "box") {
|
|
643
|
-
|
|
644
|
-
const vf = steps[0].slice("[0:v]".length, -out.length);
|
|
532
|
+
const [chain] = steps;
|
|
533
|
+
if ((opts.style ?? "box") === "box" && chain !== undefined) {
|
|
534
|
+
const vf = chain.slice("[0:v]".length, -out.length);
|
|
645
535
|
return ["-y", "-i", input, "-vf", vf, ...resolveQuality("high"), "-c:a", "copy", output];
|
|
646
536
|
}
|
|
647
537
|
return [
|
|
@@ -653,4 +543,3 @@ export function buildRedactArgs(input, output, regions, opts = {}, dims) {
|
|
|
653
543
|
output,
|
|
654
544
|
];
|
|
655
545
|
}
|
|
656
|
-
//# sourceMappingURL=media.js.map
|
package/dist/utils/monitors.js
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Monitor geometry discovery.
|
|
3
|
-
*
|
|
4
|
-
* gdigrab has no native "capture monitor N" selector: you capture the whole
|
|
5
|
-
* virtual desktop and crop to a monitor's bounds with -offset_x / -offset_y /
|
|
6
|
-
* -video_size. To do that correctly on a multi-monitor setup (for example a
|
|
7
|
-
* 4480x1440 dual-monitor desktop where the second display starts at x=2560),
|
|
8
|
-
* we need each monitor's pixel bounds. On Windows those come from
|
|
9
|
-
* System.Windows.Forms.Screen.AllScreens via PowerShell. The enumeration must be
|
|
10
|
-
* per-monitor-DPI-aware, or Screen.Bounds returns LOGICAL (DPI-scaled)
|
|
11
|
-
* coordinates while gdigrab works in PHYSICAL pixels - on a scaled display that
|
|
12
|
-
* makes monitor:N capture a cropped top-left slice (e.g. 1280x800 of a 1920x1200
|
|
13
|
-
* screen at 150%). So the shim sets DPI awareness before reading bounds, exactly
|
|
14
|
-
* as the window-bounds shim in windows.ts does.
|
|
15
|
-
*
|
|
16
|
-
* `parseMonitors` is pure so the offset math is unit-tested without Windows.
|
|
17
|
-
*/
|
|
18
1
|
import { execFile } from "node:child_process";
|
|
19
2
|
import { ScreencastError } from "./errors.js";
|
|
20
|
-
/** Normalize raw PowerShell screen objects into ordered Monitor records.
|
|
21
|
-
* Primary monitor is sorted first so monitor:0 is the primary display. */
|
|
22
3
|
export function parseMonitors(raw) {
|
|
23
4
|
const arr = Array.isArray(raw) ? raw : raw ? [raw] : [];
|
|
24
5
|
const screens = arr.map((s) => ({
|
|
@@ -27,6 +8,7 @@ export function parseMonitors(raw) {
|
|
|
27
8
|
width: Number(s.Width ?? 0),
|
|
28
9
|
height: Number(s.Height ?? 0),
|
|
29
10
|
primary: Boolean(s.Primary),
|
|
11
|
+
...(Number(s.Dpi) > 0 ? { dpi: Number(s.Dpi) } : {}),
|
|
30
12
|
}));
|
|
31
13
|
screens.sort((a, b) => {
|
|
32
14
|
if (a.primary !== b.primary)
|
|
@@ -37,43 +19,30 @@ export function parseMonitors(raw) {
|
|
|
37
19
|
});
|
|
38
20
|
return screens.map((s, index) => ({ index, ...s }));
|
|
39
21
|
}
|
|
40
|
-
// Set per-monitor-DPI-awareness-v2 (-4) before reading Screen.AllScreens so the
|
|
41
|
-
// bounds are PHYSICAL pixels (matching gdigrab), not DPI-scaled logical ones.
|
|
42
|
-
// Passed base64 (EncodedCommand) so the C# shim needs no quoting through argv.
|
|
43
22
|
const PS_SCRIPT = `
|
|
44
23
|
Add-Type @"
|
|
45
24
|
using System;using System.Runtime.InteropServices;
|
|
46
|
-
public class DpiShim{ [DllImport("user32.dll")] public static extern IntPtr SetProcessDpiAwarenessContext(IntPtr v);
|
|
25
|
+
public class DpiShim{ [DllImport("user32.dll")] public static extern IntPtr SetProcessDpiAwarenessContext(IntPtr v);
|
|
26
|
+
public struct PT{public int X,Y;}
|
|
27
|
+
[DllImport("user32.dll")] public static extern IntPtr MonitorFromPoint(PT p,uint f);
|
|
28
|
+
[DllImport("shcore.dll")] public static extern int GetDpiForMonitor(IntPtr m,int t,out uint x,out uint y);
|
|
29
|
+
public static int Dpi(int x,int y){try{PT p=new PT();p.X=x;p.Y=y;uint dx,dy;if(GetDpiForMonitor(MonitorFromPoint(p,2),0,out dx,out dy)==0)return (int)dx;}catch{}return 0;} }
|
|
47
30
|
"@
|
|
48
31
|
try{[void][DpiShim]::SetProcessDpiAwarenessContext([IntPtr](-4))}catch{}
|
|
49
32
|
Add-Type -AssemblyName System.Windows.Forms
|
|
50
33
|
[System.Windows.Forms.Screen]::AllScreens | ForEach-Object {
|
|
51
|
-
[pscustomobject]@{ X=$_.Bounds.X; Y=$_.Bounds.Y; Width=$_.Bounds.Width; Height=$_.Bounds.Height; Primary=$_.Primary }
|
|
34
|
+
[pscustomobject]@{ X=$_.Bounds.X; Y=$_.Bounds.Y; Width=$_.Bounds.Width; Height=$_.Bounds.Height; Primary=$_.Primary; Dpi=[DpiShim]::Dpi($_.Bounds.X,$_.Bounds.Y) }
|
|
52
35
|
} | ConvertTo-Json -Compress
|
|
53
36
|
`;
|
|
54
|
-
/** How long a monitor layout is reused before it is queried again (#88). The
|
|
55
|
-
* layout changes only when a display is plugged in or rearranged, while an
|
|
56
|
-
* agent's screenshot loop can call this every few seconds. */
|
|
57
37
|
export const MONITOR_CACHE_MS = 5_000;
|
|
58
38
|
let cache = null;
|
|
59
|
-
/** Make PowerShell write UTF-8. By default it writes the console's OEM code
|
|
60
|
-
* page (e.g. 437), which turns "é" into a replacement character and maps
|
|
61
|
-
* symbols such as "•" and "→" to raw control bytes (0x07, 0x1A): window
|
|
62
|
-
* titles stopped matching and OCR output stopped parsing as JSON. */
|
|
63
39
|
export const PS_UTF8_PREAMBLE = "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\n";
|
|
64
|
-
/** Default limit for one enumeration script (monitors, windows) (#183). */
|
|
65
40
|
export const PS_TIMEOUT_MS = 20_000;
|
|
66
|
-
/** Overrides every PowerShell helper's limit, in ms. */
|
|
67
41
|
export const PS_TIMEOUT_ENV = "SCREENCAST_PS_TIMEOUT_MS";
|
|
68
|
-
/** The env override when it is a positive integer, else `fallback`. */
|
|
69
42
|
export function psTimeoutMs(fallback, env = process.env) {
|
|
70
43
|
const override = Number(env[PS_TIMEOUT_ENV]);
|
|
71
44
|
return Number.isInteger(override) && override > 0 ? override : fallback;
|
|
72
45
|
}
|
|
73
|
-
/** Run a base64-encoded PowerShell script without blocking the event loop and
|
|
74
|
-
* return its stdout (UTF-8). Shared by window enumeration and OCR. A script
|
|
75
|
-
* that runs past the timeout is killed, so a stuck WinRT or user32 call fails
|
|
76
|
-
* the tool instead of hanging it (#183). */
|
|
77
46
|
export function runPowerShell(script, what, opts = {}) {
|
|
78
47
|
const encoded = Buffer.from(PS_UTF8_PREAMBLE + script, "utf16le").toString("base64");
|
|
79
48
|
const timeout = opts.timeoutMs ?? psTimeoutMs(PS_TIMEOUT_MS);
|
|
@@ -102,9 +71,6 @@ async function queryMonitors() {
|
|
|
102
71
|
throw new ScreencastError(`Could not parse monitor geometry: ${err.message}`);
|
|
103
72
|
}
|
|
104
73
|
}
|
|
105
|
-
/** Query live monitor geometry on Windows, reusing a result from the last
|
|
106
|
-
* MONITOR_CACHE_MS. Concurrent callers share one query; a failure is not
|
|
107
|
-
* cached. Throws on non-Windows or failure. */
|
|
108
74
|
export function getMonitors(now = Date.now()) {
|
|
109
75
|
if (process.platform !== "win32") {
|
|
110
76
|
return Promise.reject(new ScreencastError("Monitor enumeration is implemented for Windows (gdigrab) only."));
|
|
@@ -119,8 +85,6 @@ export function getMonitors(now = Date.now()) {
|
|
|
119
85
|
});
|
|
120
86
|
return entry.monitors;
|
|
121
87
|
}
|
|
122
|
-
/** Drop the cached layout (tests, or after a capture failure). */
|
|
123
88
|
export function clearMonitorCache() {
|
|
124
89
|
cache = null;
|
|
125
90
|
}
|
|
126
|
-
//# sourceMappingURL=monitors.js.map
|