proofed-cli 0.2.0 → 0.2.1

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.
@@ -68,6 +68,36 @@ async function required(bin, args, timeout) {
68
68
  throw new Error(result.text);
69
69
  return result.text;
70
70
  }
71
+ // Kane can think for a minute while the device screen stands still, and the device records all of it. Each still
72
+ // stretch keeps its first second, so a six-minute run plays in about half a minute with every change in it.
73
+ // Small changes, such as a blinking text cursor, count as still. The screen the run ends on stays longer: it shows
74
+ // what the check was about before the GIF loops.
75
+ const NATIVE_FPS = 10;
76
+ const STILL_HOLD = 1;
77
+ const END_HOLD = 3;
78
+ export async function squeezeStills(input, output, length, timeout) {
79
+ const text = await required("ffmpeg", ["-hide_banner", "-nostats", "-i", input, "-vf", "scale=270:-2,freezedetect=n=-50dB:d=1.5", "-f", "null", "-"], timeout);
80
+ const cuts = [];
81
+ const cut = (from, to, hold = STILL_HOLD) => {
82
+ if (to - from > hold)
83
+ cuts.push(`between(t,${(from + hold).toFixed(2)},${to.toFixed(2)})`);
84
+ };
85
+ let start;
86
+ for (const [, edge, at] of text.matchAll(/freeze_(start|end): ([\d.]+)/g)) {
87
+ if (edge === "start")
88
+ start = Number(at);
89
+ else if (start !== undefined) {
90
+ cut(start, Number(at));
91
+ start = undefined;
92
+ }
93
+ }
94
+ // The recording can end on a still screen.
95
+ if (start !== undefined)
96
+ cut(start, length, END_HOLD);
97
+ if (cuts.length === 0)
98
+ return renameSync(input, output);
99
+ await required("ffmpeg", ["-y", "-i", input, "-vf", `select='not(${cuts.join("+")})',setpts=N/${NATIVE_FPS}/TB`, "-c:v", "libx264", "-pix_fmt", "yuv420p", "-movflags", "+faststart", output], timeout);
100
+ }
71
101
  async function nativeRecorder(target, dir, id) {
72
102
  // Transferring and encoding long recordings can take minutes on CI runners.
73
103
  const recordingTimeout = 10 * 60 * 1000;
@@ -169,24 +199,32 @@ async function nativeRecorder(target, dir, id) {
169
199
  const list = join(dir, "segments.txt");
170
200
  writeFileSync(list, segments.map((f) => `file '${f.replaceAll("\\", "/").replaceAll("'", "'\\''")}'`).join("\n"));
171
201
  const mp4 = join(dir, "clip.mp4"), jpg = join(dir, "clip.jpg"), gif = join(dir, "clip.gif");
172
- const untrimmed = join(dir, "clip-untrimmed.mp4");
202
+ const untrimmed = join(dir, "clip-untrimmed.mp4"), whole = join(dir, "clip-whole.mp4");
173
203
  try {
174
204
  // Use a constant frame rate so the thumbnail seek finds a frame even when the Android screen stops changing.
175
- await required("ffmpeg", ["-y", "-f", "concat", "-safe", "0", "-i", list, "-vf", "fps=10,scale=trunc(iw/2)*2:trunc(ih/2)*2", "-c:v", "libx264", "-bf", "0", "-pix_fmt", "yuv420p", untrimmed], recordingTimeout);
205
+ await required("ffmpeg", ["-y", "-f", "concat", "-safe", "0", "-i", list, "-vf", `fps=${NATIVE_FPS},scale=trunc(iw/2)*2:trunc(ih/2)*2`, "-c:v", "libx264", "-bf", "0", "-pix_fmt", "yuv420p", untrimmed], recordingTimeout);
176
206
  const { text } = await command("ffmpeg", ["-hide_banner", "-i", untrimmed], process.env, recordingTimeout);
177
207
  const duration = /^\s*Duration: (\d+):(\d{2}):(\d{2}\.\d+),/m.exec(text);
178
- const seconds = duration ? Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3]) : 0;
208
+ let seconds = duration ? Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3]) : 0;
179
209
  // Kane closes the app at the end, so cut away the launcher frames.
180
- if (seconds > 3)
181
- await required("ffmpeg", ["-y", "-i", untrimmed, "-t", (seconds - 1.5).toFixed(2), "-c", "copy", mp4], recordingTimeout);
210
+ if (seconds > 3) {
211
+ await required("ffmpeg", ["-y", "-i", untrimmed, "-t", (seconds - 1.5).toFixed(2), "-c", "copy", whole], recordingTimeout);
212
+ seconds -= 1.5;
213
+ }
182
214
  else
183
- renameSync(untrimmed, mp4);
215
+ renameSync(untrimmed, whole);
216
+ await squeezeStills(whole, mp4, seconds, recordingTimeout).catch((error) => {
217
+ log(`Kept the whole recording: ${error instanceof Error ? error.message : error}`);
218
+ renameSync(whole, mp4);
219
+ });
184
220
  }
185
221
  finally {
186
222
  rmSync(untrimmed, { force: true });
223
+ rmSync(whole, { force: true });
187
224
  }
188
225
  await required("ffmpeg", ["-y", "-sseof", "-0.1", "-i", mp4, "-frames:v", "1", jpg], recordingTimeout);
189
- await required("ffmpeg", ["-y", "-i", mp4, "-vf", "fps=6,scale=480:-1", gif], recordingTimeout);
226
+ // The same palette as web clips: the default one dithers gradients into noise.
227
+ await required("ffmpeg", ["-y", "-i", mp4, "-vf", `fps=${NATIVE_FPS},scale=480:-1:flags=lanczos,split[a][b];[a]palettegen=max_colors=96:stats_mode=diff[p];[b][p]paletteuse=dither=bayer:bayer_scale=4:diff_mode=rectangle`, gif], recordingTimeout);
190
228
  return { mp4, jpg, gif };
191
229
  })();
192
230
  },
package/docs/cli.md CHANGED
@@ -249,7 +249,8 @@ actual inventory; the examples do not install a runtime or choose a device for y
249
249
  Native recording uses `simctl recordVideo` or `adb shell screenrecord`. Android segments
250
250
  are limited to 175 seconds and concatenated after pulling them. ffmpeg produces MP4,
251
251
  final JPG and GIF without changing portrait orientation or adding a cursor or zoom.
252
- Segment boundaries may have a gap. A recording failure is reported separately and
252
+ Each stretch where the screen stands still keeps its first second, so a run in which Kane
253
+ thinks for minutes plays in well under a minute. Segment boundaries may have a gap. A recording failure is reported separately and
253
254
  preserves Kane's verdict. Cloud recordings are not available through this adapter.
254
255
  Only Proofed's remote recording files are removed, after a successful pull.
255
256
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proofed-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Check web, Android and Electron app scenarios with Kane CLI before you call a change done.",
5
5
  "repository": {
6
6
  "type": "git",