automovie 0.0.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/README.md +145 -18
- package/lib/AUTOMOVIE_CAPTURE_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_CAPTURE_OPTIONS.js +16 -0
- package/lib/AUTOMOVIE_CAPTURE_OPTIONS.js.map +1 -0
- package/lib/AUTOMOVIE_INSPECT_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_INSPECT_OPTIONS.js +14 -0
- package/lib/AUTOMOVIE_INSPECT_OPTIONS.js.map +1 -0
- package/lib/AUTOMOVIE_RENDER_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_RENDER_OPTIONS.js +15 -0
- package/lib/AUTOMOVIE_RENDER_OPTIONS.js.map +1 -0
- package/lib/AUTOMOVIE_REVIEW_OPTIONS.d.ts +6 -0
- package/lib/AUTOMOVIE_REVIEW_OPTIONS.js +14 -0
- package/lib/AUTOMOVIE_REVIEW_OPTIONS.js.map +1 -0
- package/lib/AutoMovieCaptureBackend.d.ts +9 -0
- package/lib/{IAutoMoviePackageManager.js → AutoMovieCaptureBackend.js} +1 -1
- package/lib/AutoMovieCaptureBackend.js.map +1 -0
- package/lib/AutoMovieCaptureHost.d.ts +114 -0
- package/lib/AutoMovieCaptureHost.js +219 -0
- package/lib/AutoMovieCaptureHost.js.map +1 -0
- package/lib/AutoMovieCommand.d.ts +24 -13
- package/lib/IAutoMovieChromium.d.ts +75 -0
- package/lib/IAutoMovieChromium.js +3 -0
- package/lib/IAutoMovieChromium.js.map +1 -0
- package/lib/captureAutoMovie.d.ts +23 -0
- package/lib/captureAutoMovie.js +133 -0
- package/lib/captureAutoMovie.js.map +1 -0
- package/lib/deriveAutoMovieProjectName.d.ts +1 -1
- package/lib/deriveAutoMovieProjectName.js +1 -1
- package/lib/findAutoMovieFreePort.d.ts +14 -0
- package/lib/findAutoMovieFreePort.js +61 -0
- package/lib/findAutoMovieFreePort.js.map +1 -0
- package/lib/formatAutoMovieInspectUrl.d.ts +14 -0
- package/lib/formatAutoMovieInspectUrl.js +24 -0
- package/lib/formatAutoMovieInspectUrl.js.map +1 -0
- package/lib/index.d.ts +30 -2
- package/lib/index.js +30 -2
- package/lib/index.js.map +1 -1
- package/lib/inspectAutoMovie.d.ts +19 -0
- package/lib/inspectAutoMovie.js +97 -0
- package/lib/inspectAutoMovie.js.map +1 -0
- package/lib/launchAutoMovieChromium.d.ts +28 -0
- package/lib/launchAutoMovieChromium.js +42 -0
- package/lib/launchAutoMovieChromium.js.map +1 -0
- package/lib/loadAutoMovieProductionModule.d.ts +14 -0
- package/lib/loadAutoMovieProductionModule.js +61 -0
- package/lib/loadAutoMovieProductionModule.js.map +1 -0
- package/lib/planAutoMovieChromiumLaunch.d.ts +27 -0
- package/lib/planAutoMovieChromiumLaunch.js +34 -0
- package/lib/planAutoMovieChromiumLaunch.js.map +1 -0
- package/lib/planAutoMovieModulePageViteConfig.d.ts +37 -0
- package/lib/planAutoMovieModulePageViteConfig.js +27 -0
- package/lib/planAutoMovieModulePageViteConfig.js.map +1 -0
- package/lib/readAutoMovieAddArguments.d.ts +1 -1
- package/lib/readAutoMovieAddArguments.js +1 -1
- package/lib/readAutoMovieCaptureHostOptions.d.ts +36 -0
- package/lib/readAutoMovieCaptureHostOptions.js +57 -0
- package/lib/readAutoMovieCaptureHostOptions.js.map +1 -0
- package/lib/readAutoMovieCommandArguments.d.ts +1 -1
- package/lib/readAutoMovieCommandArguments.js +10 -5
- package/lib/readAutoMovieCommandArguments.js.map +1 -1
- package/lib/readAutoMovieCreateArguments.d.ts +1 -1
- package/lib/readAutoMovieCreateArguments.js +1 -1
- package/lib/readAutoMovieInspectHostOptions.d.ts +29 -0
- package/lib/readAutoMovieInspectHostOptions.js +48 -0
- package/lib/readAutoMovieInspectHostOptions.js.map +1 -0
- package/lib/readAutoMovieRenderOptions.d.ts +33 -0
- package/lib/readAutoMovieRenderOptions.js +51 -0
- package/lib/readAutoMovieRenderOptions.js.map +1 -0
- package/lib/readAutoMovieReviewOptions.d.ts +27 -0
- package/lib/readAutoMovieReviewOptions.js +54 -0
- package/lib/readAutoMovieReviewOptions.js.map +1 -0
- package/lib/readAutoMovieRevision.d.ts +12 -0
- package/lib/readAutoMovieRevision.js +32 -0
- package/lib/readAutoMovieRevision.js.map +1 -0
- package/lib/readAutoMovieVideoProbe.d.ts +23 -0
- package/lib/readAutoMovieVideoProbe.js +39 -0
- package/lib/readAutoMovieVideoProbe.js.map +1 -0
- package/lib/recordAutoMoviePlayback.d.ts +37 -0
- package/lib/recordAutoMoviePlayback.js +122 -0
- package/lib/recordAutoMoviePlayback.js.map +1 -0
- package/lib/renderAutoMovie.d.ts +21 -0
- package/lib/renderAutoMovie.js +95 -0
- package/lib/renderAutoMovie.js.map +1 -0
- package/lib/renderAutoMovieScaffoldNextSteps.d.ts +3 -5
- package/lib/renderAutoMovieScaffoldNextSteps.js +5 -14
- package/lib/renderAutoMovieScaffoldNextSteps.js.map +1 -1
- package/lib/renderAutoMovieVideo.d.ts +35 -0
- package/lib/renderAutoMovieVideo.js +110 -0
- package/lib/renderAutoMovieVideo.js.map +1 -0
- package/lib/resolveAutoMovieFfmpeg.d.ts +19 -0
- package/lib/resolveAutoMovieFfmpeg.js +32 -0
- package/lib/resolveAutoMovieFfmpeg.js.map +1 -0
- package/lib/reviewAutoMovie.d.ts +21 -0
- package/lib/reviewAutoMovie.js +71 -0
- package/lib/reviewAutoMovie.js.map +1 -0
- package/lib/run.d.ts +14 -11
- package/lib/run.js +103 -67
- package/lib/run.js.map +1 -1
- package/lib/runAutoMovieFfmpeg.d.ts +14 -0
- package/lib/runAutoMovieFfmpeg.js +40 -0
- package/lib/runAutoMovieFfmpeg.js.map +1 -0
- package/lib/serveAutoMovieDrawPage.d.ts +28 -0
- package/lib/serveAutoMovieDrawPage.js +108 -0
- package/lib/serveAutoMovieDrawPage.js.map +1 -0
- package/lib/serveAutoMovieInspectorPage.d.ts +32 -0
- package/lib/serveAutoMovieInspectorPage.js +52 -0
- package/lib/serveAutoMovieInspectorPage.js.map +1 -0
- package/lib/writeAutoMovieModulePage.d.ts +38 -0
- package/lib/writeAutoMovieModulePage.js +75 -0
- package/lib/writeAutoMovieModulePage.js.map +1 -0
- package/package.json +27 -6
- package/src/AUTOMOVIE_CAPTURE_OPTIONS.ts +12 -0
- package/src/AUTOMOVIE_INSPECT_OPTIONS.ts +10 -0
- package/src/AUTOMOVIE_RENDER_OPTIONS.ts +11 -0
- package/src/AUTOMOVIE_REVIEW_OPTIONS.ts +10 -0
- package/src/AutoMovieCaptureBackend.ts +9 -0
- package/src/AutoMovieCaptureHost.ts +245 -0
- package/src/AutoMovieCommand.ts +28 -13
- package/src/IAutoMovieChromium.ts +78 -0
- package/src/captureAutoMovie.ts +148 -0
- package/src/deriveAutoMovieProjectName.ts +1 -1
- package/src/findAutoMovieFreePort.ts +27 -0
- package/src/formatAutoMovieInspectUrl.ts +25 -0
- package/src/index.ts +30 -2
- package/src/inspectAutoMovie.ts +81 -0
- package/src/launchAutoMovieChromium.ts +61 -0
- package/src/loadAutoMovieProductionModule.ts +30 -0
- package/src/planAutoMovieChromiumLaunch.ts +45 -0
- package/src/planAutoMovieModulePageViteConfig.ts +53 -0
- package/src/readAutoMovieAddArguments.ts +1 -1
- package/src/readAutoMovieCaptureHostOptions.ts +76 -0
- package/src/readAutoMovieCommandArguments.ts +6 -4
- package/src/readAutoMovieCreateArguments.ts +1 -1
- package/src/readAutoMovieInspectHostOptions.ts +66 -0
- package/src/readAutoMovieRenderOptions.ts +67 -0
- package/src/readAutoMovieReviewOptions.ts +70 -0
- package/src/readAutoMovieRevision.ts +29 -0
- package/src/readAutoMovieVideoProbe.ts +55 -0
- package/src/recordAutoMoviePlayback.ts +168 -0
- package/src/renderAutoMovie.ts +86 -0
- package/src/renderAutoMovieScaffoldNextSteps.ts +4 -18
- package/src/renderAutoMovieVideo.ts +127 -0
- package/src/resolveAutoMovieFfmpeg.ts +33 -0
- package/src/reviewAutoMovie.ts +65 -0
- package/src/run.ts +116 -105
- package/src/runAutoMovieFfmpeg.ts +50 -0
- package/src/serveAutoMovieDrawPage.ts +105 -0
- package/src/serveAutoMovieInspectorPage.ts +82 -0
- package/src/writeAutoMovieModulePage.ts +83 -0
- package/lib/IAutoMoviePackageManager.d.ts +0 -14
- package/lib/IAutoMoviePackageManager.js.map +0 -1
- package/lib/readAutoMovieSyncArguments.d.ts +0 -13
- package/lib/readAutoMovieSyncArguments.js +0 -49
- package/lib/readAutoMovieSyncArguments.js.map +0 -1
- package/lib/selectAutoMoviePackageManager.d.ts +0 -23
- package/lib/selectAutoMoviePackageManager.js +0 -70
- package/lib/selectAutoMoviePackageManager.js.map +0 -1
- package/src/IAutoMoviePackageManager.ts +0 -15
- package/src/readAutoMovieSyncArguments.ts +0 -48
- package/src/selectAutoMoviePackageManager.ts +0 -45
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type * as Render from "@automovie/render";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { AutoMovieCaptureHost } from "./AutoMovieCaptureHost";
|
|
6
|
+
import { loadAutoMovieProductionModule } from "./loadAutoMovieProductionModule";
|
|
7
|
+
import { readAutoMovieRenderOptions } from "./readAutoMovieRenderOptions";
|
|
8
|
+
import { renderAutoMovieVideo } from "./renderAutoMovieVideo";
|
|
9
|
+
import { resolveAutoMovieFfmpeg } from "./resolveAutoMovieFfmpeg";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Run `automovie render` in a production: draw one subject of a module's draw page frame by frame in headless Chromium and encode it into one video, resolving to the exit status.
|
|
13
|
+
*
|
|
14
|
+
* Options are read by `readAutoMovieCaptureArguments` and split by `readAutoMovieRenderOptions`; the rest is the request, of which a render takes only `subject`, read by `parseAutoMovieCapturePlanRequest` as `capture` reads it, and any other key is refused. A `--props` file is read as JSON before anything starts. FFmpeg is resolved before the page is built, so a missing encoder costs no drawing. The work is `renderAutoMovieVideo` through one `AutoMovieCaptureHost`, closed on every outcome. It prints the video, the report and the frame count, and resolves to 0; a refusal throws to `run`, which prints it.
|
|
15
|
+
*
|
|
16
|
+
* @evidence contracts/development/common.md#meaningful-documentation States how options are read, the order of the checks, what does the work, what is printed and the status.
|
|
17
|
+
* @evidence contracts/development/implementation.md#principled-implementation Every rule is the render package's or `renderAutoMovieVideo`'s; the command loads the production's packages and reports.
|
|
18
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read, resolve FFmpeg, open the host, render, report.
|
|
19
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts An unknown option and a request key a render cannot honour are refused, and FFmpeg's absence fails before any drawing.
|
|
20
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One page build, one browser and one encode.
|
|
21
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One render per command.
|
|
22
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The host is closed on every outcome.
|
|
23
|
+
*/
|
|
24
|
+
export async function renderAutoMovie(props: {
|
|
25
|
+
/** The tokens after `render`. */
|
|
26
|
+
args: readonly string[];
|
|
27
|
+
|
|
28
|
+
/** The production's root folder, the working directory. */
|
|
29
|
+
root: string;
|
|
30
|
+
|
|
31
|
+
/** The environment, read for `CHROME_PATH` and `FFMPEG_PATH`. */
|
|
32
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
33
|
+
}): Promise<number> {
|
|
34
|
+
const { root } = props;
|
|
35
|
+
const render: typeof Render = loadAutoMovieProductionModule(
|
|
36
|
+
root,
|
|
37
|
+
"@automovie/render",
|
|
38
|
+
) as typeof Render;
|
|
39
|
+
const options: ReturnType<typeof readAutoMovieRenderOptions> =
|
|
40
|
+
readAutoMovieRenderOptions(
|
|
41
|
+
render.readAutoMovieCaptureArguments(props.args),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// The request names the subject; a render draws its whole clock through its own camera, so no other key applies.
|
|
45
|
+
const request: Render.IAutoMovieCapturePlanRequest =
|
|
46
|
+
render.parseAutoMovieCapturePlanRequest(options.request);
|
|
47
|
+
for (const key of options.request.keys())
|
|
48
|
+
if (key !== "subject")
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Render draws a subject's whole clock through its own camera; the request key --${key} does not apply, only --subject`,
|
|
51
|
+
);
|
|
52
|
+
const data: unknown =
|
|
53
|
+
options.props === null
|
|
54
|
+
? null
|
|
55
|
+
: JSON.parse(
|
|
56
|
+
await fs.readFile(path.resolve(root, options.props), "utf8"),
|
|
57
|
+
);
|
|
58
|
+
const ffmpeg: string = resolveAutoMovieFfmpeg({
|
|
59
|
+
env: props.env,
|
|
60
|
+
load: (id: string): unknown => loadAutoMovieProductionModule(root, id),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const host: AutoMovieCaptureHost = await AutoMovieCaptureHost.open({
|
|
64
|
+
root,
|
|
65
|
+
module: options.module,
|
|
66
|
+
backend: options.backend,
|
|
67
|
+
env: props.env,
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
const written: Awaited<ReturnType<typeof renderAutoMovieVideo>> =
|
|
71
|
+
await renderAutoMovieVideo({
|
|
72
|
+
host,
|
|
73
|
+
root,
|
|
74
|
+
subject: request.subject,
|
|
75
|
+
props: data,
|
|
76
|
+
...(options.out === null ? {} : { out: options.out }),
|
|
77
|
+
ffmpeg,
|
|
78
|
+
});
|
|
79
|
+
process.stdout.write(
|
|
80
|
+
`render: ${written.frames} frames into ${written.video}\nbackend ${host.backend}\n${written.report}\n`,
|
|
81
|
+
);
|
|
82
|
+
return 0;
|
|
83
|
+
} finally {
|
|
84
|
+
await host.close();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import type { IAutoMoviePackageManager } from "./IAutoMoviePackageManager";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Explain the work between a freshly written installation and a runnable production.
|
|
5
3
|
*
|
|
6
|
-
* `directory` is printed as given (`run` passes the absolute target). The text starts with a blank line because `run` appends it to the written-file list. A `production` is a single production
|
|
4
|
+
* `directory` is printed as given (`run` passes the absolute target). The text starts with a blank line because `run` appends it to the written-file list. A `production` is a single production in its own pnpm repository; a `workspace` is a pnpm workspace root that still needs its first production; a `workspace-production` is a production added to such a root. The steps name the generated `README.md`, `AGENTS.md`, the `lint` and `evidence` scripts and the workspace's `add` command, so they must change with the scaffold's first-run README sections.
|
|
7
5
|
*
|
|
8
6
|
* @param directory The installed directory.
|
|
9
7
|
* @param kind Which installation was written.
|
|
10
|
-
* @param packageManager The manager a `production` installs with, from `selectAutoMoviePackageManager`; workspace kinds always use pnpm.
|
|
11
8
|
* @returns The closing text.
|
|
12
9
|
*
|
|
13
|
-
* @evidence contracts/development/implementation.md#principled-implementation The steps are fixed text derived from each layer's first-run contract: the production README's install and checks
|
|
10
|
+
* @evidence contracts/development/implementation.md#principled-implementation The steps are fixed text derived from each layer's first-run contract: the production README's pnpm install and checks, and the workspace README's pnpm install and add.
|
|
14
11
|
* @evidence contracts/development/implementation.md#clear-and-simple-structure One pure function returns the text for every installation kind and leaves writing to `run`, so the message has a single owner and no terminal effect.
|
|
15
12
|
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The text names no fixture or particular directory and is not altered by any caller; a closed union selects the variant.
|
|
16
13
|
* @evidence contracts/development/common.md#meaningful-documentation The comment states how `directory` is printed, why the text opens with a blank line, what each kind means and what must change with the scaffold.
|
|
@@ -21,7 +18,6 @@ import type { IAutoMoviePackageManager } from "./IAutoMoviePackageManager";
|
|
|
21
18
|
export function renderAutoMovieScaffoldNextSteps(
|
|
22
19
|
directory: string,
|
|
23
20
|
kind: "production" | "workspace" | "workspace-production",
|
|
24
|
-
packageManager: IAutoMoviePackageManager = { manager: "npm" },
|
|
25
21
|
): string {
|
|
26
22
|
if (kind === "workspace")
|
|
27
23
|
return (
|
|
@@ -38,21 +34,11 @@ export function renderAutoMovieScaffoldNextSteps(
|
|
|
38
34
|
` 3. Author the production in TypeScript under src with the public AutoMovie package APIs.\n` +
|
|
39
35
|
` 4. Run pnpm run lint and pnpm run evidence there.\n`
|
|
40
36
|
);
|
|
41
|
-
if (packageManager.manager === "pnpm")
|
|
42
|
-
return (
|
|
43
|
-
`\n\nNext (from ${directory}):\n` +
|
|
44
|
-
` 1. Read README.md and AGENTS.md. This is an empty harness.\n` +
|
|
45
|
-
(packageManager.workspace === undefined
|
|
46
|
-
? ` 2. Run pnpm install.\n`
|
|
47
|
-
: ` 2. Run pnpm install at the workspace root ${packageManager.workspace}; its pnpm-workspace.yaml must list this directory.\n`) +
|
|
48
|
-
` 3. Author the production in TypeScript under src with the public AutoMovie package APIs.\n` +
|
|
49
|
-
` 4. Run pnpm run lint for source and pnpm run evidence for checklist answers.\n`
|
|
50
|
-
);
|
|
51
37
|
return (
|
|
52
38
|
`\n\nNext (from ${directory}):\n` +
|
|
53
39
|
` 1. Read README.md and AGENTS.md. This is an empty harness.\n` +
|
|
54
|
-
` 2. Run
|
|
40
|
+
` 2. Run pnpm install.\n` +
|
|
55
41
|
` 3. Author the production in TypeScript under src with the public AutoMovie package APIs.\n` +
|
|
56
|
-
` 4. Run
|
|
42
|
+
` 4. Run pnpm run lint for source and pnpm run evidence for checklist answers.\n`
|
|
57
43
|
);
|
|
58
44
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type * as Render from "@automovie/render";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import type { AutoMovieCaptureHost } from "./AutoMovieCaptureHost";
|
|
6
|
+
import { readAutoMovieRevision } from "./readAutoMovieRevision";
|
|
7
|
+
import { runAutoMovieFfmpeg } from "./runAutoMovieFfmpeg";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The delivery encoding of a drawn subject: H.264 in yuv420p at CRF 18, without tone mapping, as the production's render used; the frame format is the subject's own clock and raster.
|
|
11
|
+
*/
|
|
12
|
+
const SPEC: Parameters<typeof Render.renderAutoMovieDrawnVideo>[0]["spec"] = {
|
|
13
|
+
target: "production",
|
|
14
|
+
toneMapping: "none",
|
|
15
|
+
codec: "h264",
|
|
16
|
+
pixelFormat: "yuv420p",
|
|
17
|
+
crf: 18,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Render one subject of a host's draw page into `<out>/film.mp4`, with `render-report.json` beside it.
|
|
22
|
+
*
|
|
23
|
+
* The subject is opened through the host's draw session, every frame of its clock is drawn by `renderAutoMovieDrawnVideo` into a scratch folder under `<root>/.cache/render/`, and FFmpeg encodes them into a partial file that is renamed to `film.mp4` only once it is complete, so a failed render leaves no file that looks finished. The report names the subject, the source revision, the backend, the encoder's arguments and every frame's second and pixel hash. The scratch folder is deleted and the session closed on every outcome.
|
|
24
|
+
*
|
|
25
|
+
* @evidence contracts/development/common.md#meaningful-documentation States what is written where, how a failure leaves the output, what the report holds, and what is released.
|
|
26
|
+
* @evidence contracts/development/implementation.md#principled-implementation Drawing and encoding are the render package's; this host supplies the session, files and FFmpeg, so a delivered frame is drawn by the same function as a capture's still.
|
|
27
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Open, draw and encode, rename, report, release.
|
|
28
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The output is replaced only by a complete encode; no frame is reused from an earlier render.
|
|
29
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One draw and one PNG file per frame, then one FFmpeg run.
|
|
30
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each render draws afresh.
|
|
31
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The frame files live in the scratch folder until the encode ends, then are deleted with it; the session's page is closed on every outcome.
|
|
32
|
+
*/
|
|
33
|
+
export async function renderAutoMovieVideo(props: {
|
|
34
|
+
/** The opened draw host. */
|
|
35
|
+
host: AutoMovieCaptureHost;
|
|
36
|
+
|
|
37
|
+
/** The production's root folder. */
|
|
38
|
+
root: string;
|
|
39
|
+
|
|
40
|
+
/** The subject's name, or null for the page's only subject. */
|
|
41
|
+
subject: string | null;
|
|
42
|
+
|
|
43
|
+
/** Data the subject module reads, as JSON, or null. */
|
|
44
|
+
props: unknown;
|
|
45
|
+
|
|
46
|
+
/** Output folder, relative to the root or absolute; absent, `media/automovie/<subject>/videos`. */
|
|
47
|
+
out?: string;
|
|
48
|
+
|
|
49
|
+
/** FFmpeg executable. */
|
|
50
|
+
ffmpeg: string;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
/** The video written. */
|
|
53
|
+
video: string;
|
|
54
|
+
|
|
55
|
+
/** The report written beside it. */
|
|
56
|
+
report: string;
|
|
57
|
+
|
|
58
|
+
/** Frames drawn. */
|
|
59
|
+
frames: number;
|
|
60
|
+
}> {
|
|
61
|
+
const session: Render.AutoMovieDrawSession = await props.host.session({
|
|
62
|
+
subject: props.subject,
|
|
63
|
+
props: props.props,
|
|
64
|
+
});
|
|
65
|
+
const name: string = session.subject.name;
|
|
66
|
+
const out: string = path.resolve(
|
|
67
|
+
props.root,
|
|
68
|
+
props.out ?? path.join("media", "automovie", name, "videos"),
|
|
69
|
+
);
|
|
70
|
+
const scratch: string = path.join(
|
|
71
|
+
props.root,
|
|
72
|
+
".cache",
|
|
73
|
+
"render",
|
|
74
|
+
`${name}-${process.pid}-${Date.now()}`,
|
|
75
|
+
);
|
|
76
|
+
const partial: string = path.join(out, `.film-${process.pid}.mp4`);
|
|
77
|
+
try {
|
|
78
|
+
await fs.mkdir(scratch, { recursive: true });
|
|
79
|
+
await fs.mkdir(out, { recursive: true });
|
|
80
|
+
const result: Awaited<ReturnType<typeof Render.renderAutoMovieDrawnVideo>> =
|
|
81
|
+
await props.host.render.renderAutoMovieDrawnVideo({
|
|
82
|
+
session,
|
|
83
|
+
spec: SPEC,
|
|
84
|
+
frameDir: scratch.split(path.sep).join("/"),
|
|
85
|
+
outputPath: partial,
|
|
86
|
+
audio: null,
|
|
87
|
+
write: (file: string, data: Uint8Array): Promise<void> =>
|
|
88
|
+
fs.writeFile(file, data),
|
|
89
|
+
encode: async (args: readonly string[]): Promise<void> => {
|
|
90
|
+
await runAutoMovieFfmpeg(props.ffmpeg, args);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const video: string = path.join(out, "film.mp4");
|
|
94
|
+
await fs.rename(partial, video);
|
|
95
|
+
const report: string = path.join(out, "render-report.json");
|
|
96
|
+
await fs.writeFile(
|
|
97
|
+
report,
|
|
98
|
+
JSON.stringify(
|
|
99
|
+
{
|
|
100
|
+
subject: name,
|
|
101
|
+
revision: readAutoMovieRevision(props.root),
|
|
102
|
+
backend: session.backend,
|
|
103
|
+
video: "film.mp4",
|
|
104
|
+
args: result.args,
|
|
105
|
+
frames: result.frames.map(
|
|
106
|
+
(frame: {
|
|
107
|
+
index: number;
|
|
108
|
+
seconds: number;
|
|
109
|
+
hash: string;
|
|
110
|
+
}): { index: number; seconds: number; hash: string } => ({
|
|
111
|
+
index: frame.index,
|
|
112
|
+
seconds: frame.seconds,
|
|
113
|
+
hash: frame.hash,
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
},
|
|
117
|
+
null,
|
|
118
|
+
2,
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
return { video, report, frames: result.frames.length };
|
|
122
|
+
} finally {
|
|
123
|
+
await fs.rm(partial, { force: true });
|
|
124
|
+
await fs.rm(scratch, { recursive: true, force: true });
|
|
125
|
+
await session.close();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the FFmpeg executable a capture of a video file runs: `FFMPEG_PATH` when the environment sets it to a non-blank path, else the binary of the production's `ffmpeg-static`.
|
|
3
|
+
*
|
|
4
|
+
* It throws naming both `FFMPEG_PATH` and `ffmpeg-static` when neither gives a path, so a capture that plans a video says how to supply one before it touches its folder.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the order of the two sources and the refusal.
|
|
7
|
+
* @evidence contracts/development/implementation.md#principled-implementation `ffmpeg-static` exports the path of the binary it downloaded, or null on a platform it has none for; the environment variable wins so a machine's own build can be used.
|
|
8
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read the variable, else load the package, else refuse.
|
|
9
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No `ffmpeg` on the search path is guessed, because a capture records the binary it ran.
|
|
10
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One module load at most.
|
|
11
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Resolved once per capture.
|
|
12
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources Returns a path and keeps nothing.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveAutoMovieFfmpeg(props: {
|
|
15
|
+
/** The environment, read for `FFMPEG_PATH`. */
|
|
16
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
17
|
+
|
|
18
|
+
/** Loads a package from the production, throwing when it is not installed. */
|
|
19
|
+
load: (id: string) => unknown;
|
|
20
|
+
}): string {
|
|
21
|
+
const given: string | undefined = props.env.FFMPEG_PATH?.trim();
|
|
22
|
+
if (given !== undefined && given !== "") return given;
|
|
23
|
+
let binary: unknown = null;
|
|
24
|
+
try {
|
|
25
|
+
binary = props.load("ffmpeg-static");
|
|
26
|
+
} catch {
|
|
27
|
+
binary = null;
|
|
28
|
+
}
|
|
29
|
+
if (typeof binary === "string" && binary !== "") return binary;
|
|
30
|
+
throw new Error(
|
|
31
|
+
"A video capture needs FFmpeg: set FFMPEG_PATH to an ffmpeg executable, or install ffmpeg-static in the production",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type * as Render from "@automovie/render";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { loadAutoMovieProductionModule } from "./loadAutoMovieProductionModule";
|
|
6
|
+
import { readAutoMovieReviewOptions } from "./readAutoMovieReviewOptions";
|
|
7
|
+
import { recordAutoMoviePlayback } from "./recordAutoMoviePlayback";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Run `automovie review` in a production: record real-time playback of its running inspector page for a person to watch, and resolve to the exit status.
|
|
11
|
+
*
|
|
12
|
+
* Options are read by `readAutoMovieCaptureArguments` and admitted by `readAutoMovieReviewOptions`. The recording is `recordAutoMoviePlayback` with the production's `playwright-core`; it and `playback.json`, holding the time readings and the page's script errors, go into `--out` or `media/automovie/review`. It prints the video and the number of errors, and resolves to 1 when the page reported a script error, since a playback that errors is not one to watch, and 0 otherwise.
|
|
13
|
+
*
|
|
14
|
+
* @evidence contracts/development/common.md#meaningful-documentation States how options are read, what records, what is written where, what is printed and the status with its reason.
|
|
15
|
+
* @evidence contracts/development/implementation.md#principled-implementation The recording's rules are `recordAutoMoviePlayback`'s; the command supplies the production's Playwright and writes the result.
|
|
16
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Read, record, write, report.
|
|
17
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts An unknown option is refused; a page error is reported in the status, not hidden.
|
|
18
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms One recording.
|
|
19
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work One review per command.
|
|
20
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The browser is the recording's and closed by it.
|
|
21
|
+
*/
|
|
22
|
+
export async function reviewAutoMovie(props: {
|
|
23
|
+
/** The tokens after `review`. */
|
|
24
|
+
args: readonly string[];
|
|
25
|
+
|
|
26
|
+
/** The production's root folder, the working directory. */
|
|
27
|
+
root: string;
|
|
28
|
+
|
|
29
|
+
/** The environment, read for `CHROME_PATH`. */
|
|
30
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
31
|
+
}): Promise<number> {
|
|
32
|
+
const { root } = props;
|
|
33
|
+
const render: typeof Render = loadAutoMovieProductionModule(
|
|
34
|
+
root,
|
|
35
|
+
"@automovie/render",
|
|
36
|
+
) as typeof Render;
|
|
37
|
+
const options: ReturnType<typeof readAutoMovieReviewOptions> =
|
|
38
|
+
readAutoMovieReviewOptions(
|
|
39
|
+
render.readAutoMovieCaptureArguments(props.args),
|
|
40
|
+
);
|
|
41
|
+
const out: string = path.resolve(
|
|
42
|
+
root,
|
|
43
|
+
options.out ?? path.join("media", "automovie", "review"),
|
|
44
|
+
);
|
|
45
|
+
const recorded: Awaited<ReturnType<typeof recordAutoMoviePlayback>> =
|
|
46
|
+
await recordAutoMoviePlayback({
|
|
47
|
+
chromium: (
|
|
48
|
+
loadAutoMovieProductionModule(root, "playwright-core") as {
|
|
49
|
+
chromium: unknown;
|
|
50
|
+
}
|
|
51
|
+
).chromium,
|
|
52
|
+
url: options.url,
|
|
53
|
+
seconds: options.seconds,
|
|
54
|
+
out,
|
|
55
|
+
env: props.env,
|
|
56
|
+
});
|
|
57
|
+
await fs.writeFile(
|
|
58
|
+
path.join(out, "playback.json"),
|
|
59
|
+
JSON.stringify(recorded, null, 2),
|
|
60
|
+
);
|
|
61
|
+
process.stdout.write(
|
|
62
|
+
`review: ${recorded.video}\n${recorded.errors.length} page errors\n`,
|
|
63
|
+
);
|
|
64
|
+
return recorded.errors.length === 0 ? 0 : 1;
|
|
65
|
+
}
|