imgtune 0.1.0 → 0.2.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.
- package/CHANGELOG.md +74 -0
- package/README.md +41 -0
- package/dist/animated.js +176 -0
- package/dist/backgrounds.js +13 -2
- package/dist/check-report.js +20 -3
- package/dist/check.js +8 -4
- package/dist/cli.js +66 -8
- package/dist/fetch.js +9 -4
- package/dist/ffmpeg.js +495 -0
- package/dist/gpu.js +12 -0
- package/dist/hints.js +418 -6
- package/dist/image-file.js +154 -34
- package/dist/images.js +27 -2
- package/dist/locate-join.js +86 -0
- package/dist/locate-only.js +14 -3
- package/dist/locate.js +6 -2
- package/dist/media-encode.js +1050 -0
- package/dist/media-file.js +284 -0
- package/dist/media-limits.js +31 -0
- package/dist/media-model.js +247 -0
- package/dist/media-phase.js +652 -0
- package/dist/media-prepare.js +31 -0
- package/dist/recheck.js +3 -3
- package/dist/remote.js +474 -69
- package/dist/result-cache.js +56 -3
- package/dist/run.js +8 -4
- package/dist/summary.js +23 -3
- package/dist/video-analysis.js +273 -0
- package/dist/webp-animation.js +283 -0
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Makes a media file readable by the pipeline and probes it: the shared step of `imgtune image` (media-file.ts) and the scan's
|
|
2
|
+
// media phase (media-phase.ts). Kept apart from media-file.ts, which imports the scan's remote.ts helpers, so the phase can use
|
|
3
|
+
// it without a cycle. A plain file is probed with ffprobe; an animated WebP is read frame by frame (webp-animation.ts), since
|
|
4
|
+
// ffmpeg cannot read it, and its probe is taken from the animation.
|
|
5
|
+
import { animationOf } from "./animated.js";
|
|
6
|
+
import { probeMedia } from "./ffmpeg.js";
|
|
7
|
+
import { WebpAnimation } from "./webp-animation.js";
|
|
8
|
+
import { MAX_INPUT_PIXELS_FFMPEG } from "./media-limits.js";
|
|
9
|
+
/** Longest a probe of one file may take, in ms. */
|
|
10
|
+
export const PROBE_MS = 30_000;
|
|
11
|
+
/** The frame rate of an animated WebP's constant-rate timeline. */
|
|
12
|
+
export const WEBP_FPS = 30;
|
|
13
|
+
/**
|
|
14
|
+
* Makes a file readable and probes it. An animated WebP is opened as a WebpAnimation (no frame is decoded here): its probe is its
|
|
15
|
+
* canvas size and its length. `framePixelLimit` is the per-frame pixel limit (MAX_INPUT_PIXELS_FFMPEG by default; a test lowers
|
|
16
|
+
* it). An APNG reports no length to ffprobe, so its animation length stands in. Throws with the reason when the file cannot be
|
|
17
|
+
* read, or is too large to score.
|
|
18
|
+
*/
|
|
19
|
+
export async function prepareMedia(path, buffer, _dir, framePixelLimit = MAX_INPUT_PIXELS_FFMPEG, _signal) {
|
|
20
|
+
const animation = animationOf(buffer);
|
|
21
|
+
if (animation?.format === "webp") {
|
|
22
|
+
const webp = new WebpAnimation(buffer, WEBP_FPS, framePixelLimit);
|
|
23
|
+
const probe = { durationS: webp.durationMs / 1000, width: webp.width, height: webp.height, fps: WEBP_FPS, videoCodec: "webp" };
|
|
24
|
+
return { source: webp, probe, animation };
|
|
25
|
+
}
|
|
26
|
+
const probe = await probeMedia(path, PROBE_MS);
|
|
27
|
+
if (!probe)
|
|
28
|
+
throw new Error("ffprobe could not read this file");
|
|
29
|
+
const sized = animation && !(probe.durationS > 0) ? { ...probe, durationS: animation.durationMs / 1000 } : probe;
|
|
30
|
+
return { source: path, probe: sized, animation };
|
|
31
|
+
}
|
package/dist/recheck.js
CHANGED
|
@@ -6,7 +6,7 @@ import { resolve } from "node:path";
|
|
|
6
6
|
import { launchChromium } from "./browser.js";
|
|
7
7
|
import { DEFAULT_VIEWPORTS } from "./config.js";
|
|
8
8
|
import { hasFix } from "./images.js";
|
|
9
|
-
import {
|
|
9
|
+
import { gpuSettingOf, gpuSettingOne } from "./gpu.js";
|
|
10
10
|
import { parseViewports, safeText, scanOnce, scorerNote } from "./remote.js";
|
|
11
11
|
import { settleLimit } from "./concurrency.js";
|
|
12
12
|
import { cleanRecord } from "./locate-join.js";
|
|
@@ -46,7 +46,7 @@ export function parseRecheckArgs(argv) {
|
|
|
46
46
|
if (arg === "--allow-third-party")
|
|
47
47
|
continue;
|
|
48
48
|
if (arg === "--gpu") {
|
|
49
|
-
gpu ??=
|
|
49
|
+
gpu ??= gpuSettingOne(0);
|
|
50
50
|
continue;
|
|
51
51
|
}
|
|
52
52
|
if (arg === "--no-cache") {
|
|
@@ -61,7 +61,7 @@ export function parseRecheckArgs(argv) {
|
|
|
61
61
|
if (arg === "--recheck")
|
|
62
62
|
files.push(value);
|
|
63
63
|
else if (arg === "--gpu-device")
|
|
64
|
-
gpu =
|
|
64
|
+
gpu = gpuSettingOf(value);
|
|
65
65
|
else if (arg === "--viewports")
|
|
66
66
|
viewports = parseViewports(value);
|
|
67
67
|
else if (arg === "--allow-host")
|