popost 4.6.15 → 4.6.16
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 +1 -1
- package/SKILL.md +4 -2
- package/dist/cli.js +1258 -590
- package/dist/index.js +1256 -588
- package/dist/types/feedback/bundle.d.ts +7 -0
- package/dist/types/feedback/media.d.ts +34 -0
- package/dist/types/feedback/request.d.ts +8 -0
- package/dist/types/feedback/transcript.d.ts +2 -0
- package/dist/types/feedback/upload.d.ts +7 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/video/generate/cloud.d.ts +18 -4
- package/dist/types/video/generate/failure.d.ts +61 -0
- package/dist/types/video/generate/index.d.ts +21 -4
- package/dist/types/video/generate/picture-fit.d.ts +60 -0
- package/dist/types/video/generate/voice-clips.d.ts +47 -0
- package/dist/types/video/render/record.d.ts +13 -3
- package/dist/types/video/replication/check.d.ts +10 -0
- package/dist/types/video/wallet.d.ts +6 -0
- package/package.json +1 -1
- package/references/execution-contract.md +2 -2
- package/references/providers.md +1 -1
- package/references/video-continuity.md +1 -1
- package/references/video-performers.md +2 -2
- package/references/video-product.md +4 -3
- package/references/video-replication.md +2 -2
- package/references/video-sound.md +9 -2
- package/references/video-step-1-read.md +1 -1
- package/references/video-step-7-deliver.md +3 -2
- package/references/video-tools.md +37 -13
- package/references/video.md +15 -8
package/dist/cli.js
CHANGED
|
@@ -280,7 +280,7 @@ var VERSION;
|
|
|
280
280
|
var init_version = __esm({
|
|
281
281
|
"src/version.ts"() {
|
|
282
282
|
"use strict";
|
|
283
|
-
VERSION = "4.6.
|
|
283
|
+
VERSION = "4.6.16";
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
286
|
|
|
@@ -954,6 +954,11 @@ var init_api_errors = __esm({
|
|
|
954
954
|
"The video model does not take these settings (resolution, seconds, aspect ratio or references; popost video generate --models lists what each model takes); nothing was charged",
|
|
955
955
|
"\u8BE5\u89C6\u9891\u6A21\u578B\u4E0D\u652F\u6301\u8FD9\u4E9B\u8BBE\u7F6E\uFF08\u5206\u8FA8\u7387\u3001\u65F6\u957F\u3001\u753B\u5E45\u6216\u53C2\u8003\u7D20\u6750\uFF1Bpopost video generate --models \u5217\u51FA\u5404\u6A21\u578B\u652F\u6301\u7684\u8BBE\u7F6E\uFF09\uFF0C\u672A\u6263\u8D39"
|
|
956
956
|
);
|
|
957
|
+
case "VIDEO_REQUEST_REJECTED":
|
|
958
|
+
return msg(
|
|
959
|
+
"The video model does not take this request as it is (a reference picture or frame of a shape or size it does not take, a reference sound or clip it does not take, or a setting it does not have); sent again unchanged it fails again, and nothing is charged for it",
|
|
960
|
+
"\u8BE5\u89C6\u9891\u6A21\u578B\u4E0D\u63A5\u53D7\u8FD9\u4E2A\u8BF7\u6C42\uFF08\u53C2\u8003\u56FE\u6216\u9996\u5C3E\u5E27\u7684\u6BD4\u4F8B\u6216\u5C3A\u5BF8\u3001\u53C2\u8003\u97F3\u9891\u6216\u89C6\u9891\uFF0C\u6216\u67D0\u9879\u8BBE\u7F6E\u4E0D\u88AB\u652F\u6301\uFF09\uFF1B\u539F\u6837\u91CD\u53D1\u4ECD\u4F1A\u5931\u8D25\uFF0C\u4E0D\u6263\u8D39"
|
|
961
|
+
);
|
|
957
962
|
case "GENERATION_FAILED":
|
|
958
963
|
return msg("popost.ai could not make it", "popost.ai \u672A\u80FD\u751F\u6210");
|
|
959
964
|
case "QUOTE_EXPIRED":
|
|
@@ -2810,7 +2815,7 @@ var init_install = __esm({
|
|
|
2810
2815
|
await rt.fs.writeFile(rt.path.join(target2, name), data);
|
|
2811
2816
|
return data.byteLength;
|
|
2812
2817
|
});
|
|
2813
|
-
const total2 = sizes.reduce((sum2,
|
|
2818
|
+
const total2 = sizes.reduce((sum2, size2) => sum2 + size2, 0);
|
|
2814
2819
|
if (names.length !== role.fileCount || total2 !== role.totalBytes)
|
|
2815
2820
|
throw new FontError(msg(`font role ${role.id} is incomplete: ${names.length} files, ${total2} bytes`, `\u5B57\u4F53\u89D2\u8272 ${role.id} \u4E0D\u5B8C\u6574\uFF1A${names.length} \u4E2A\u6587\u4EF6\uFF0C${total2} \u5B57\u8282`));
|
|
2816
2821
|
const license = await readFontAsset(rt, lib, `${role.id}/LICENSE`, role.license.sha256);
|
|
@@ -2910,7 +2915,7 @@ var init_project_fonts = __esm({
|
|
|
2910
2915
|
if (body) return body.index;
|
|
2911
2916
|
const root = /<html\b[^>]*>/i.exec(html2);
|
|
2912
2917
|
if (root) return root.index + root[0].length;
|
|
2913
|
-
for (const
|
|
2918
|
+
for (const tag4 of html2.matchAll(/<!--[\s\S]*?-->|<(?![!?/])/g)) if (!tag4[0].startsWith("<!--")) return tag4.index;
|
|
2914
2919
|
return 0;
|
|
2915
2920
|
};
|
|
2916
2921
|
withFontLinks = (html2, links2) => {
|
|
@@ -4808,8 +4813,8 @@ var init_device_login = __esm({
|
|
|
4808
4813
|
};
|
|
4809
4814
|
startDevice = async (rt, target2, previous) => {
|
|
4810
4815
|
if (previous && previous.expiresAt > Date.now()) return previous;
|
|
4811
|
-
const
|
|
4812
|
-
const publicKey =
|
|
4816
|
+
const pair5 = generateKeyPairSync("ed25519");
|
|
4817
|
+
const publicKey = pair5.publicKey.export({ format: "jwk" }).x;
|
|
4813
4818
|
const agent = target2.profile === "terminal" ? "CLI" : agentLabel(target2.profile);
|
|
4814
4819
|
const label2 = [agent, rt.deviceName].filter(Boolean).join(" \xB7 ").slice(0, 80);
|
|
4815
4820
|
const start = await deviceApi(rt.fetch, target2.baseUrl, "start", { label: label2, publicKey });
|
|
@@ -4818,7 +4823,7 @@ var init_device_login = __esm({
|
|
|
4818
4823
|
publicKey,
|
|
4819
4824
|
deviceCode: start.deviceCode,
|
|
4820
4825
|
userCode: start.userCode,
|
|
4821
|
-
privateKey:
|
|
4826
|
+
privateKey: pair5.privateKey.export({ format: "der", type: "pkcs8" }).toString("base64url"),
|
|
4822
4827
|
expiresAt: Date.now() + Math.min(600, start.expiresIn) * 1e3,
|
|
4823
4828
|
interval: Math.max(1, start.interval)
|
|
4824
4829
|
};
|
|
@@ -5422,8 +5427,8 @@ failure: {"ok": false, "error", ...} \u76EE\u5F55\u5199\u4E0D\u8FDB\u53BB\u65F6\
|
|
|
5422
5427
|
byDirectory = (rt, agents, homeDir2) => {
|
|
5423
5428
|
const dirs = [...new Set(agents.map((agent) => agent.skillsDir(rt, homeDir2)))];
|
|
5424
5429
|
return dirs.map((skillsDir) => {
|
|
5425
|
-
const [
|
|
5426
|
-
return { agent:
|
|
5430
|
+
const [first2, ...rest] = agents.filter((agent) => agent.skillsDir(rt, homeDir2) === skillsDir).map((agent) => agent.id);
|
|
5431
|
+
return { agent: first2, skillsDir, alsoFor: rest };
|
|
5427
5432
|
});
|
|
5428
5433
|
};
|
|
5429
5434
|
ownerOf = (rt, homeDir2, skillsDir) => {
|
|
@@ -5440,9 +5445,9 @@ failure: {"ok": false, "error", ...} \u76EE\u5F55\u5199\u4E0D\u8FDB\u53BB\u65F6\
|
|
|
5440
5445
|
const readers = AGENTS.filter((agent) => agent.skillsDir(rt, homeDir2) === skillsDir);
|
|
5441
5446
|
const here = [];
|
|
5442
5447
|
for (const agent of readers) if (await present(rt, agent, homeDir2)) here.push(agent.id);
|
|
5443
|
-
const [
|
|
5448
|
+
const [first2, ...rest] = here;
|
|
5444
5449
|
const fallback = recorded2.find((entry2) => entry2.skillsDir === skillsDir)?.agent ?? (readers.length === 1 ? readers[0].id : SHARED);
|
|
5445
|
-
targets.push({ agent:
|
|
5450
|
+
targets.push({ agent: first2 ?? fallback, skillsDir, alsoFor: rest });
|
|
5446
5451
|
}
|
|
5447
5452
|
}
|
|
5448
5453
|
for (const entry2 of recorded2)
|
|
@@ -5953,10 +5958,10 @@ ${OUTPUT2}`
|
|
|
5953
5958
|
};
|
|
5954
5959
|
busy = async (rt, paths) => othersRunning(rt, paths);
|
|
5955
5960
|
busyMessage = (others) => {
|
|
5956
|
-
const
|
|
5961
|
+
const first2 = others[0];
|
|
5957
5962
|
return msg(
|
|
5958
|
-
`another popost process of this installation is running (popost ${
|
|
5959
|
-
`\u8FD9\u4EFD\u5B89\u88C5\u8FD8\u6709\u5176\u4ED6 popost \u8FDB\u7A0B\u5728\u8FD0\u884C\uFF08popost ${
|
|
5963
|
+
`another popost process of this installation is running (popost ${first2.command}, process ${first2.pid}${others.length > 1 ? `, and ${others.length - 1} more` : ""}): an open editor or Studio, or a render, would lose the files it has not loaded yet. Close it and run popost update again, or pass --force to update anyway`,
|
|
5964
|
+
`\u8FD9\u4EFD\u5B89\u88C5\u8FD8\u6709\u5176\u4ED6 popost \u8FDB\u7A0B\u5728\u8FD0\u884C\uFF08popost ${first2.command}\uFF0C\u8FDB\u7A0B ${first2.pid}${others.length > 1 ? `\uFF0C\u53E6\u6709 ${others.length - 1} \u4E2A` : ""}\uFF09\uFF1A\u6253\u5F00\u7740\u7684\u7F16\u8F91\u5668\u3001Studio \u6216\u6E32\u67D3\u4F1A\u4E22\u5931\u5C1A\u672A\u52A0\u8F7D\u7684\u6587\u4EF6\u3002\u8BF7\u5148\u5173\u95ED\u5B83\u518D\u8FD0\u884C popost update\uFF0C\u6216\u52A0 --force \u5F3A\u5236\u66F4\u65B0`
|
|
5960
5965
|
);
|
|
5961
5966
|
};
|
|
5962
5967
|
lostLock = () => msg("another popost update took over while this one was downloading", "\u4E0B\u8F7D\u671F\u95F4\u53E6\u4E00\u4E2A popost \u66F4\u65B0\u63A5\u624B\u4E86");
|
|
@@ -6086,8 +6091,8 @@ var init_references = __esm({
|
|
|
6086
6091
|
explicitPath = async (project, given2) => {
|
|
6087
6092
|
const { rt } = project;
|
|
6088
6093
|
if (await isFile(rt, rt.path.resolve(rt.cwd, given2))) return given2;
|
|
6089
|
-
const
|
|
6090
|
-
if (
|
|
6094
|
+
const inProject5 = rt.path.isAbsolute(given2) ? null : project.abs(given2);
|
|
6095
|
+
if (inProject5 && await isFile(rt, inProject5)) return inProject5;
|
|
6091
6096
|
throw unknownReference(project, given2);
|
|
6092
6097
|
};
|
|
6093
6098
|
noRegistered = (token, role) => {
|
|
@@ -7032,11 +7037,11 @@ var init_popost_validate = __esm({
|
|
|
7032
7037
|
if (!stat2?.isFile) throw new CapabilityError(msg(`the local reference image does not exist: ${path4}`, `\u672C\u5730\u53C2\u8003\u56FE\u4E0D\u5B58\u5728: ${path4}`));
|
|
7033
7038
|
const name = rt.path.basename(path4);
|
|
7034
7039
|
if (stat2.size > MAX_REF_BYTES) {
|
|
7035
|
-
const [
|
|
7040
|
+
const [size2, limit] = [(stat2.size / 1048576).toFixed(1), MAX_REF_BYTES / 1048576];
|
|
7036
7041
|
throw new CapabilityError(
|
|
7037
7042
|
msg(
|
|
7038
|
-
`the reference image ${name} is ${
|
|
7039
|
-
`\u53C2\u8003\u56FE ${name} \u4E3A ${
|
|
7043
|
+
`the reference image ${name} is ${size2} MiB, more than the ${limit} MiB limit per image; compress it or use an https URL instead`,
|
|
7044
|
+
`\u53C2\u8003\u56FE ${name} \u4E3A ${size2} MiB\uFF0C\u8D85\u8FC7\u5355\u5F20 ${limit} MiB \u4E0A\u9650\uFF1B\u8BF7\u538B\u7F29\u6216\u6539\u7528 https URL`
|
|
7040
7045
|
)
|
|
7041
7046
|
);
|
|
7042
7047
|
}
|
|
@@ -7061,8 +7066,8 @@ var init_popost_validate = __esm({
|
|
|
7061
7066
|
total2 += await checkLocalRef(rt, ref.value);
|
|
7062
7067
|
}
|
|
7063
7068
|
if (total2 > MAX_REF_TOTAL_BYTES) {
|
|
7064
|
-
const [
|
|
7065
|
-
throw new CapabilityError(msg(`the local reference images add up to ${
|
|
7069
|
+
const [size2, limit2] = [(total2 / 1048576).toFixed(1), MAX_REF_TOTAL_BYTES / 1048576];
|
|
7070
|
+
throw new CapabilityError(msg(`the local reference images add up to ${size2} MiB, more than the ${limit2} MiB limit`, `\u672C\u5730\u53C2\u8003\u56FE\u5408\u8BA1 ${size2} MiB\uFF0C\u8D85\u8FC7 ${limit2} MiB \u4E0A\u9650`));
|
|
7066
7071
|
}
|
|
7067
7072
|
};
|
|
7068
7073
|
}
|
|
@@ -7628,8 +7633,8 @@ var init_context = __esm({
|
|
|
7628
7633
|
return { existing, add: add2, final: [...existing, ...add2] };
|
|
7629
7634
|
};
|
|
7630
7635
|
pageSize = (ctx) => {
|
|
7631
|
-
const
|
|
7632
|
-
return { width: ctx.spec.width ??
|
|
7636
|
+
const first2 = ctx.project?.manifest.pages[0];
|
|
7637
|
+
return { width: ctx.spec.width ?? first2?.width ?? 1080, height: ctx.spec.height ?? first2?.height ?? 1350 };
|
|
7633
7638
|
};
|
|
7634
7639
|
}
|
|
7635
7640
|
});
|
|
@@ -9519,11 +9524,11 @@ var init_steps = __esm({
|
|
|
9519
9524
|
const project = await Project.create(rt, ctx.dir, spec10.brief, mode, spec10.width, spec10.height);
|
|
9520
9525
|
await project.appendDesignNote(initDesignNote());
|
|
9521
9526
|
ctx.project = project;
|
|
9522
|
-
const
|
|
9527
|
+
const first2 = project.manifest.pages[0];
|
|
9523
9528
|
return done(
|
|
9524
9529
|
msg(
|
|
9525
|
-
`created the project (${mode} mode) with page p1 (${
|
|
9526
|
-
`\u5DF2\u521B\u5EFA\u9879\u76EE\uFF08${mode} \u6A21\u5F0F\uFF09\uFF0C\u542B\u9875 p1\uFF08${
|
|
9530
|
+
`created the project (${mode} mode) with page p1 (${first2.width}x${first2.height})`,
|
|
9531
|
+
`\u5DF2\u521B\u5EFA\u9879\u76EE\uFF08${mode} \u6A21\u5F0F\uFF09\uFF0C\u542B\u9875 p1\uFF08${first2.width}x${first2.height}\uFF09`
|
|
9527
9532
|
)
|
|
9528
9533
|
);
|
|
9529
9534
|
};
|
|
@@ -10865,13 +10870,13 @@ var init_push = __esm({
|
|
|
10865
10870
|
};
|
|
10866
10871
|
};
|
|
10867
10872
|
syncBody = (project, html2, pictures, ids3, options) => {
|
|
10868
|
-
const
|
|
10873
|
+
const first2 = project.manifest.pages[0];
|
|
10869
10874
|
const brief3 = Array.from(String(project.manifest.brief ?? "").replace(/\s+/g, " ").trim()).slice(0, TITLE_CHARS).join("");
|
|
10870
10875
|
return {
|
|
10871
10876
|
projectId: project.manifest.projectId,
|
|
10872
10877
|
title: brief3 || "Popost",
|
|
10873
|
-
width:
|
|
10874
|
-
height:
|
|
10878
|
+
width: first2.width,
|
|
10879
|
+
height: first2.height,
|
|
10875
10880
|
platform: typeof project.manifest.platform === "string" && project.manifest.platform ? project.manifest.platform : null,
|
|
10876
10881
|
html: html2,
|
|
10877
10882
|
assets: pictures.map((p) => ({ url: p.url, uploadId: ids3.get(p.sha) })),
|
|
@@ -11359,12 +11364,12 @@ var init_handoff = __esm({
|
|
|
11359
11364
|
await writeJson(rt, serviceState(rt, root), { url, ...pid !== void 0 ? { pid } : {}, version: EDITOR_VERSION });
|
|
11360
11365
|
};
|
|
11361
11366
|
editorInfo = (project) => {
|
|
11362
|
-
const
|
|
11367
|
+
const identity2 = sha256(project.rt.path.resolve(project.root));
|
|
11363
11368
|
return {
|
|
11364
11369
|
schema: "popost-editor-info.v1",
|
|
11365
11370
|
version: EDITOR_VERSION,
|
|
11366
|
-
projectId: project.manifest.projectId ||
|
|
11367
|
-
projectIdentity:
|
|
11371
|
+
projectId: project.manifest.projectId || identity2.slice(0, 32),
|
|
11372
|
+
projectIdentity: identity2,
|
|
11368
11373
|
capabilities: ["edit-text", "edit-layout", "save-local", "export-png", "export-formats", "compare-reference", "export-project", "cloud-save"]
|
|
11369
11374
|
};
|
|
11370
11375
|
};
|
|
@@ -12057,8 +12062,8 @@ var init_routes_post = __esm({
|
|
|
12057
12062
|
staleFonts = () => msg("The project was changed by another window or by the agent. Reload it, then choose the fonts.", "\u5DE5\u7A0B\u5DF2\u88AB\u53E6\u4E00\u7A97\u53E3\u6216 Agent \u4FEE\u6539\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u540E\u9009\u62E9\u5B57\u4F53\u3002");
|
|
12058
12063
|
failure = (ctx, error2, kind = "bad-or-server") => jsonResponse(ctx.req, isBadRequest(error2) || kind === "bad-only" ? 400 : 500, { ok: false, error: errorMessage(error2) });
|
|
12059
12064
|
canvasPreview = async (ctx) => {
|
|
12060
|
-
const
|
|
12061
|
-
if (!(
|
|
12065
|
+
const size2 = ctx.req.body.byteLength;
|
|
12066
|
+
if (!(size2 > 0 && size2 <= MAX_PREVIEW_BYTES))
|
|
12062
12067
|
return jsonResponse(ctx.req, 413, { ok: false, error: msg("preview is empty or too large", "\u9884\u89C8\u5185\u5BB9\u4E3A\u7A7A\u6216\u8FC7\u5927") });
|
|
12063
12068
|
try {
|
|
12064
12069
|
const data = parseJsonObject(ctx.req);
|
|
@@ -12208,10 +12213,10 @@ var init_server = __esm({
|
|
|
12208
12213
|
const declared = Number(req.headers["content-length"] ?? 0);
|
|
12209
12214
|
if (declared > limit) return resolve2(null);
|
|
12210
12215
|
const chunks = [];
|
|
12211
|
-
let
|
|
12216
|
+
let size2 = 0;
|
|
12212
12217
|
req.on("data", (chunk) => {
|
|
12213
|
-
|
|
12214
|
-
if (
|
|
12218
|
+
size2 += chunk.byteLength;
|
|
12219
|
+
if (size2 > limit) {
|
|
12215
12220
|
chunks.length = 0;
|
|
12216
12221
|
req.pause();
|
|
12217
12222
|
return resolve2(null);
|
|
@@ -12219,7 +12224,7 @@ var init_server = __esm({
|
|
|
12219
12224
|
chunks.push(chunk);
|
|
12220
12225
|
});
|
|
12221
12226
|
req.on("end", () => {
|
|
12222
|
-
const body = new Uint8Array(
|
|
12227
|
+
const body = new Uint8Array(size2);
|
|
12223
12228
|
let offset = 0;
|
|
12224
12229
|
for (const chunk of chunks) {
|
|
12225
12230
|
body.set(chunk, offset);
|
|
@@ -12384,13 +12389,13 @@ var init_render = __esm({
|
|
|
12384
12389
|
};
|
|
12385
12390
|
};
|
|
12386
12391
|
syncDelivered = async (rt, project) => !commandSyncs(rt) ? void 0 : deliverToCloud(new CloudService(rt, () => project.root), project.manifest.language?.toLowerCase().startsWith("zh") ? "zh" : "en");
|
|
12387
|
-
rendering = (spec10,
|
|
12392
|
+
rendering = (spec10, prepare5 = false) => ({
|
|
12388
12393
|
spec: { ...spec10, options: [DIR3, ...spec10.options ?? []] },
|
|
12389
12394
|
run: async (args2, rt) => {
|
|
12390
12395
|
const project = await Project.load(rt, args2.req("dir"));
|
|
12391
12396
|
let before = {};
|
|
12392
12397
|
try {
|
|
12393
|
-
if (
|
|
12398
|
+
if (prepare5) before = await prepareRender(project, args2);
|
|
12394
12399
|
const final = args2.flag("final");
|
|
12395
12400
|
if (final) await requireReadyToDeliver(project);
|
|
12396
12401
|
const exported = await exportPages(project, args2, rt);
|
|
@@ -12567,9 +12572,9 @@ var init_sheet_layout = __esm({
|
|
|
12567
12572
|
let bestCost = Infinity;
|
|
12568
12573
|
for (let columns = 1; columns <= Math.min(count5, widest); columns++) {
|
|
12569
12574
|
const rows3 = Math.ceil(count5 / columns);
|
|
12570
|
-
const
|
|
12575
|
+
const size2 = sheetSize(columns, rows3, cellFor(columns, aspect));
|
|
12571
12576
|
const empty = (rows3 * columns - count5) / (rows3 * columns);
|
|
12572
|
-
const cost = Math.abs(Math.log(
|
|
12577
|
+
const cost = Math.abs(Math.log(size2.width / size2.height / TARGET_ASPECT)) + EMPTY_CELL_PENALTY * empty;
|
|
12573
12578
|
if (cost < bestCost - 1e-9) {
|
|
12574
12579
|
best = columns;
|
|
12575
12580
|
bestCost = cost;
|
|
@@ -12584,7 +12589,7 @@ var init_sheet_layout = __esm({
|
|
|
12584
12589
|
const budget2 = (widthPx - fontPx * 1.2) / fontPx;
|
|
12585
12590
|
if (emSum(chars) <= budget2) return label2;
|
|
12586
12591
|
const room = Math.max(1, budget2 - 1);
|
|
12587
|
-
const
|
|
12592
|
+
const take2 = (source2, limit) => {
|
|
12588
12593
|
const taken = [];
|
|
12589
12594
|
let used = 0;
|
|
12590
12595
|
for (const char of source2) {
|
|
@@ -12594,8 +12599,8 @@ var init_sheet_layout = __esm({
|
|
|
12594
12599
|
}
|
|
12595
12600
|
return taken;
|
|
12596
12601
|
};
|
|
12597
|
-
const head =
|
|
12598
|
-
const tail4 =
|
|
12602
|
+
const head = take2(chars, room * 0.6);
|
|
12603
|
+
const tail4 = take2([...chars].reverse(), room * 0.4).reverse();
|
|
12599
12604
|
return `${head.join("")}\u2026${tail4.join("")}`;
|
|
12600
12605
|
};
|
|
12601
12606
|
layoutSheet = (bands) => {
|
|
@@ -12756,8 +12761,8 @@ var init_sheet2 = __esm({
|
|
|
12756
12761
|
const only = bands.length === 1 ? bands[0] : void 0;
|
|
12757
12762
|
if (!only || only.length <= MAX_SHEET_IMAGES) return [bands];
|
|
12758
12763
|
const count5 = Math.ceil(only.length / MAX_SHEET_IMAGES);
|
|
12759
|
-
const
|
|
12760
|
-
return Array.from({ length: count5 }, (_, k) => [only.slice(k *
|
|
12764
|
+
const size2 = Math.ceil(only.length / count5);
|
|
12765
|
+
return Array.from({ length: count5 }, (_, k) => [only.slice(k * size2, (k + 1) * size2)]);
|
|
12761
12766
|
};
|
|
12762
12767
|
partPath = (path4, k) => k === 0 ? path4 : path4.replace(/(\.jpe?g)$/i, `-${k + 1}$1`);
|
|
12763
12768
|
drawSheets = async (rt, parts, target2, shown3) => {
|
|
@@ -13085,8 +13090,8 @@ var init_image_info = __esm({
|
|
|
13085
13090
|
SVG_HEAD_BYTES = 65536;
|
|
13086
13091
|
SVG_ROOT = /^\uFEFF?\s*(?:<\?xml[^>]*\?>\s*)?(?:<!--[\s\S]*?-->\s*)*(?:<!DOCTYPE[^>[]*(?:\[[^\]]*\])?\s*>\s*)?(?:<!--[\s\S]*?-->\s*)*(<svg\b(?:[^>"']|"[^"]*"|'[^']*')*>)/i;
|
|
13087
13092
|
UNIT_PX = { "": 1, px: 1, pt: 4 / 3, pc: 16, mm: 96 / 25.4, cm: 96 / 2.54, in: 96 };
|
|
13088
|
-
attribute = (
|
|
13089
|
-
const match = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, "i").exec(
|
|
13093
|
+
attribute = (tag4, name) => {
|
|
13094
|
+
const match = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, "i").exec(tag4);
|
|
13090
13095
|
return match ? match[1] ?? match[2] : void 0;
|
|
13091
13096
|
};
|
|
13092
13097
|
lengthPx = (value) => {
|
|
@@ -13095,18 +13100,18 @@ var init_image_info = __esm({
|
|
|
13095
13100
|
const px2 = Number(match[1]) * UNIT_PX[(match[2] ?? "").toLowerCase()];
|
|
13096
13101
|
return px2 > 0 ? Math.round(px2 * 100) / 100 : void 0;
|
|
13097
13102
|
};
|
|
13098
|
-
viewBoxSize = (
|
|
13099
|
-
const numbers3 = (attribute(
|
|
13103
|
+
viewBoxSize = (tag4) => {
|
|
13104
|
+
const numbers3 = (attribute(tag4, "viewBox") ?? "").trim().split(/[\s,]+/).map(Number);
|
|
13100
13105
|
const [width, height] = [numbers3[2], numbers3[3]];
|
|
13101
13106
|
return numbers3.length === 4 && width > 0 && height > 0 ? { width, height } : void 0;
|
|
13102
13107
|
};
|
|
13103
13108
|
svgOf = (bytes) => {
|
|
13104
13109
|
const root = SVG_ROOT.exec(new TextDecoder().decode(bytes.subarray(0, SVG_HEAD_BYTES)));
|
|
13105
13110
|
if (!root) return null;
|
|
13106
|
-
const
|
|
13107
|
-
const box2 = viewBoxSize(
|
|
13108
|
-
const width = lengthPx(attribute(
|
|
13109
|
-
const height = lengthPx(attribute(
|
|
13111
|
+
const tag4 = root[1];
|
|
13112
|
+
const box2 = viewBoxSize(tag4);
|
|
13113
|
+
const width = lengthPx(attribute(tag4, "width")) ?? box2?.width;
|
|
13114
|
+
const height = lengthPx(attribute(tag4, "height")) ?? box2?.height;
|
|
13110
13115
|
return { format: "svg", ...width !== void 0 && height !== void 0 ? { width, height } : {} };
|
|
13111
13116
|
};
|
|
13112
13117
|
describePicture = (bytes, name) => {
|
|
@@ -13197,11 +13202,11 @@ var init_edit = __esm({
|
|
|
13197
13202
|
const page2 = await context.newPage();
|
|
13198
13203
|
await page2.setContent(sourceHtml(source2), { waitUntil: "load", timeout: 3e4 });
|
|
13199
13204
|
await settlePage(page2);
|
|
13200
|
-
const
|
|
13201
|
-
if (!
|
|
13202
|
-
const planned = plan4(
|
|
13205
|
+
const size2 = await callInPage(page2, SIZE_SCRIPT);
|
|
13206
|
+
if (!size2.width || !size2.height) throw new ValueError(msg("the picture could not be decoded", "\u56FE\u7247\u65E0\u6CD5\u89E3\u7801"));
|
|
13207
|
+
const planned = plan4(size2.width, size2.height);
|
|
13203
13208
|
const url = await callInPage(page2, DRAW_SCRIPT, { plan: planned, output });
|
|
13204
|
-
return { bytes: decodeDataUrl(url, output.format), plan: planned, source:
|
|
13209
|
+
return { bytes: decodeDataUrl(url, output.format), plan: planned, source: size2 };
|
|
13205
13210
|
} finally {
|
|
13206
13211
|
await context.close();
|
|
13207
13212
|
}
|
|
@@ -13426,8 +13431,8 @@ var init_info = __esm({
|
|
|
13426
13431
|
init_io();
|
|
13427
13432
|
locate = async (rt, file, dir) => {
|
|
13428
13433
|
if (dir === void 0 || rt.path.isAbsolute(file) || await isFile(rt, rt.path.resolve(rt.cwd, file))) return file;
|
|
13429
|
-
const
|
|
13430
|
-
return await isFile(rt,
|
|
13434
|
+
const inProject5 = rt.path.resolve(rt.cwd, dir, file);
|
|
13435
|
+
return await isFile(rt, inProject5) ? inProject5 : file;
|
|
13431
13436
|
};
|
|
13432
13437
|
describeFile = async (rt, file, dir) => {
|
|
13433
13438
|
try {
|
|
@@ -14004,8 +14009,8 @@ var init_inspiration_plan = __esm({
|
|
|
14004
14009
|
tagsOf = (raw) => {
|
|
14005
14010
|
const out2 = [];
|
|
14006
14011
|
for (const item2 of Array.isArray(raw) ? raw : []) {
|
|
14007
|
-
const
|
|
14008
|
-
if (
|
|
14012
|
+
const tag4 = String(item2).trim().replace(/^#+/, "").trim();
|
|
14013
|
+
if (tag4 && !out2.includes(tag4)) out2.push(tag4);
|
|
14009
14014
|
}
|
|
14010
14015
|
if (out2.length > LIMITS.tags) throw new InputError(msg(`more than ${LIMITS.tags} tags`, `tags \u8D85\u8FC7 ${LIMITS.tags} \u4E2A`));
|
|
14011
14016
|
return out2;
|
|
@@ -14278,15 +14283,15 @@ var init_link_bundle = __esm({
|
|
|
14278
14283
|
tagsOf2 = (raw) => {
|
|
14279
14284
|
const out2 = [];
|
|
14280
14285
|
for (const item2 of Array.isArray(raw) ? raw : []) {
|
|
14281
|
-
const
|
|
14282
|
-
if (
|
|
14286
|
+
const tag4 = typeof item2 === "string" ? item2.trim().replace(/^#+/, "").trim() : "";
|
|
14287
|
+
if (tag4 && !out2.includes(tag4)) out2.push(tag4);
|
|
14283
14288
|
}
|
|
14284
14289
|
return out2.slice(0, LIMITS.tags);
|
|
14285
14290
|
};
|
|
14286
14291
|
imageOf = (raw, index) => {
|
|
14287
14292
|
if (!isRecord(raw) || typeof raw.url !== "string" || !raw.url) throw badResponse(msg(`picture ${index + 1} of the parsed result has no address`, `\u89E3\u6790\u7ED3\u679C\u7684\u7B2C ${index + 1} \u5F20\u56FE\u7247\u7F3A\u5C11\u5730\u5740`));
|
|
14288
|
-
const
|
|
14289
|
-
return { url: raw.url, ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {}, ...
|
|
14293
|
+
const size2 = (key2) => isInt(raw[key2]) && raw[key2] > 0 ? { [key2]: raw[key2] } : {};
|
|
14294
|
+
return { url: raw.url, ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {}, ...size2("width"), ...size2("height"), ...text3(raw.alt) ? { alt: [...text3(raw.alt)].slice(0, 500).join("") } : {} };
|
|
14290
14295
|
};
|
|
14291
14296
|
validPublishedAt = (value) => {
|
|
14292
14297
|
try {
|
|
@@ -14384,7 +14389,7 @@ var init_link_bundle = __esm({
|
|
|
14384
14389
|
});
|
|
14385
14390
|
videoResource = (v) => ({ id: "video", kind: "video", path: v.file, mimeType: v.mimeType, sha256: v.sha256, bytes: v.bytes });
|
|
14386
14391
|
buildBundle = (rt, plan4, saved, video) => {
|
|
14387
|
-
const
|
|
14392
|
+
const first2 = saved[0];
|
|
14388
14393
|
const complete3 = saved.length > 0;
|
|
14389
14394
|
return {
|
|
14390
14395
|
schema: "postbundle.v1",
|
|
@@ -14395,7 +14400,7 @@ var init_link_bundle = __esm({
|
|
|
14395
14400
|
tags: plan4.tags,
|
|
14396
14401
|
music: { title: "", url: "" },
|
|
14397
14402
|
pageOrder: saved.map((s) => s.index),
|
|
14398
|
-
ratio:
|
|
14403
|
+
ratio: first2?.width && first2.height ? ratioOf(first2.width, first2.height) : null,
|
|
14399
14404
|
resources: [...saved.map(pictureResource), ...video ? [videoResource(video)] : []],
|
|
14400
14405
|
parseStatus: complete3 ? "ready" : "missing_resources",
|
|
14401
14406
|
auth: {
|
|
@@ -14528,17 +14533,17 @@ var init_link_resolve = __esm({
|
|
|
14528
14533
|
const code = Number.parseInt(hex3 ?? dec ?? "", hex3 ? 16 : 10);
|
|
14529
14534
|
return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole2;
|
|
14530
14535
|
});
|
|
14531
|
-
attributeOf = (
|
|
14532
|
-
const match = new RegExp(`[\\s"']${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`, "i").exec(
|
|
14536
|
+
attributeOf = (tag4, name) => {
|
|
14537
|
+
const match = new RegExp(`[\\s"']${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`, "i").exec(tag4);
|
|
14533
14538
|
const value = match?.[1] ?? match?.[2] ?? match?.[3];
|
|
14534
14539
|
return value === void 0 ? null : decodeEntities(value).trim();
|
|
14535
14540
|
};
|
|
14536
14541
|
REFRESH_CONTENT = /^\s*\d+(?:\.\d+)?\s*[;,]\s*(?:url\s*=\s*)?(["']?)(.+?)\1\s*$/i;
|
|
14537
14542
|
JS_LOCATION = /\blocation(?:\.replace\(\s*|(?:\.href)?\s*=\s*)(?:"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)')/;
|
|
14538
14543
|
metaRefreshOf = (html2) => {
|
|
14539
|
-
for (const [
|
|
14540
|
-
if (attributeOf(
|
|
14541
|
-
const target2 = REFRESH_CONTENT.exec(attributeOf(
|
|
14544
|
+
for (const [tag4] of html2.matchAll(/<meta\b[^>]*>/gi)) {
|
|
14545
|
+
if (attributeOf(tag4, "http-equiv")?.toLowerCase() !== "refresh") continue;
|
|
14546
|
+
const target2 = REFRESH_CONTENT.exec(attributeOf(tag4, "content") ?? "")?.[2];
|
|
14542
14547
|
if (target2) return target2;
|
|
14543
14548
|
}
|
|
14544
14549
|
return null;
|
|
@@ -14725,12 +14730,12 @@ var init_link_task = __esm({
|
|
|
14725
14730
|
throw new PopostApiError(msg("the GET /links/parse answer has an unexpected format (no task, or a different id)", "GET /links/parse \u54CD\u5E94\u683C\u5F0F\u4E0D\u7B26\uFF08\u7F3A\u5C11 task \u6216 id \u4E0D\u4E00\u81F4\uFF09"), { code: "BAD_RESPONSE" });
|
|
14726
14731
|
return task;
|
|
14727
14732
|
};
|
|
14728
|
-
waitForTask2 = async (rt, client2, id2,
|
|
14733
|
+
waitForTask2 = async (rt, client2, id2, first2, timeoutSec) => {
|
|
14729
14734
|
const timeoutMs = timeoutSec * 1e3;
|
|
14730
14735
|
const started = rt.now().getTime();
|
|
14731
|
-
let last =
|
|
14736
|
+
let last = first2;
|
|
14732
14737
|
let failures = 0;
|
|
14733
|
-
let pauseMs =
|
|
14738
|
+
let pauseMs = first2 !== null ? POLL_INTERVAL_MS : 0;
|
|
14734
14739
|
for (; ; ) {
|
|
14735
14740
|
if (last && isTerminal(last)) return { kind: "done", task: last };
|
|
14736
14741
|
const elapsed = rt.now().getTime() - started;
|
|
@@ -14915,9 +14920,9 @@ var init_link = __esm({
|
|
|
14915
14920
|
const post = { platform: plan4.platform, ...plan4.kind ? { kind: plan4.kind } : {}, title: plan4.title, sourceUrl: plan4.sourceUrl, imageCount: saved.length, ...plan4.inspirationId ? { inspirationId: plan4.inspirationId } : {} };
|
|
14916
14921
|
return { exit: 0, body: { ok: true, task: info, bundle: bundlePath, images, ...video.fields, post, next: `popost validate --file ${file} && popost import --file ${file}`, note: note + video.note } };
|
|
14917
14922
|
};
|
|
14918
|
-
finish2 = async (rt, client2, state2,
|
|
14923
|
+
finish2 = async (rt, client2, state2, first2, call2, fallback) => {
|
|
14919
14924
|
const id2 = state2.id;
|
|
14920
|
-
const waited = await waitForTask2(rt, client2, id2,
|
|
14925
|
+
const waited = await waitForTask2(rt, client2, id2, first2, call2.timeoutSec);
|
|
14921
14926
|
if (waited.task) state2.task = waited.task;
|
|
14922
14927
|
if (waited.kind === "timeout")
|
|
14923
14928
|
return unfinishedOutcome("WAIT_TIMEOUT", msg(`The task had not finished after ${call2.timeoutSec} seconds.`, `\u7B49\u5F85 ${call2.timeoutSec} \u79D2\u540E\u4EFB\u52A1\u4ECD\u672A\u7ED3\u675F\u3002`), id2, waited.task, call2);
|
|
@@ -15914,8 +15919,8 @@ var init_import_deck = __esm({
|
|
|
15914
15919
|
noSlide = () => msg("the document has no .slide page: nothing to import", "\u6587\u6863\u91CC\u6CA1\u6709 .slide \u9875\u9762\uFF1A\u6CA1\u6709\u53EF\u5BFC\u5165\u7684\u5185\u5BB9");
|
|
15915
15920
|
FALLBACK_SIZE = { width: 1080, height: 1350 };
|
|
15916
15921
|
defaultSizeOf = (project) => {
|
|
15917
|
-
const
|
|
15918
|
-
return
|
|
15922
|
+
const first2 = project.manifest.pages[0];
|
|
15923
|
+
return first2 ? { width: Number(first2.width), height: Number(first2.height) } : FALLBACK_SIZE;
|
|
15919
15924
|
};
|
|
15920
15925
|
validSize2 = (n) => Number.isInteger(n) && n >= 1 && n <= MAX_CANVAS;
|
|
15921
15926
|
checkSizes = (pages) => {
|
|
@@ -16417,9 +16422,9 @@ var init_camera = __esm({
|
|
|
16417
16422
|
return { scale: s, translate: [(1 - s) * (m.focus[0] - 0.5) + (shift[0] ?? 0), (1 - s) * (m.focus[1] - 0.5) + (shift[1] ?? 0)] };
|
|
16418
16423
|
};
|
|
16419
16424
|
movesAt = (moves, n) => {
|
|
16420
|
-
const
|
|
16421
|
-
if (!
|
|
16422
|
-
const current = [...moves].reverse().find((m) => n >= m.from) ??
|
|
16425
|
+
const first2 = moves[0];
|
|
16426
|
+
if (!first2) return STILL_CAMERA;
|
|
16427
|
+
const current = [...moves].reverse().find((m) => n >= m.from) ?? first2;
|
|
16423
16428
|
const t = n < current.from ? 0 : clamp01((n - current.from) / Math.max(1, current.to - current.from));
|
|
16424
16429
|
return moveState(current, ease(current.ease, t));
|
|
16425
16430
|
};
|
|
@@ -16480,9 +16485,9 @@ var init_frame = __esm({
|
|
|
16480
16485
|
const into = seg?.transition;
|
|
16481
16486
|
const next = r.segments[k + 1]?.transition;
|
|
16482
16487
|
if (!seg) return [0, 0];
|
|
16483
|
-
const
|
|
16488
|
+
const first2 = into && (into.side ?? "both") === "both" ? into.a : seg.start;
|
|
16484
16489
|
const last = next && (next.side ?? "both") === "both" ? next.a + next.frames - 1 : seg.end - 1;
|
|
16485
|
-
return [
|
|
16490
|
+
return [first2, last];
|
|
16486
16491
|
};
|
|
16487
16492
|
cameraAt = (r, k, n) => {
|
|
16488
16493
|
const base = r.segments[k]?.base;
|
|
@@ -16547,18 +16552,18 @@ var init_footage = __esm({
|
|
|
16547
16552
|
playsOf = (r) => [
|
|
16548
16553
|
...r.segments.flatMap((s, k) => {
|
|
16549
16554
|
if (s.base.kind !== "video") return [];
|
|
16550
|
-
const [
|
|
16551
|
-
return [{ play: s.base.play, first, last }];
|
|
16555
|
+
const [first2, last] = visibleRange(r, k);
|
|
16556
|
+
return [{ play: s.base.play, first: first2, last }];
|
|
16552
16557
|
}),
|
|
16553
16558
|
...r.items.flatMap((it) => it.play && it.end > it.start ? [{ play: it.play, first: it.start, last: it.end - 1 }] : [])
|
|
16554
16559
|
];
|
|
16555
16560
|
usedFrames = (r) => {
|
|
16556
16561
|
const sets = /* @__PURE__ */ new Map();
|
|
16557
|
-
for (const { play, first, last } of playsOf(r)) {
|
|
16562
|
+
for (const { play, first: first2, last } of playsOf(r)) {
|
|
16558
16563
|
const f = r.footage?.[play.material];
|
|
16559
16564
|
if (!f) continue;
|
|
16560
16565
|
const set2 = sets.get(play.material) ?? /* @__PURE__ */ new Set();
|
|
16561
|
-
for (let n = Math.max(0,
|
|
16566
|
+
for (let n = Math.max(0, first2); n <= Math.min(last, r.frames - 1); n++) set2.add(sourceFrame(play, f, r.canvas.fps, n));
|
|
16562
16567
|
sets.set(play.material, set2);
|
|
16563
16568
|
}
|
|
16564
16569
|
return new Map([...sets].map(([id2, set2]) => [id2, [...set2].sort((a, b) => a - b)]));
|
|
@@ -16797,14 +16802,14 @@ var init_project2 = __esm({
|
|
|
16797
16802
|
const frames = await sweepFrames(rt, root, { started: Infinity, drop: true, capBytes: Infinity, ...o.dryRun ? { dryRun: true } : {} });
|
|
16798
16803
|
if (frames.removed.length < all.length) kept3.push(FOOTAGE_CACHE + ": " + (all.length - frames.removed.length) + " in use by a running " + (holds.kinds.includes("preview") ? "preview" : "render"));
|
|
16799
16804
|
const busy3 = (f) => holds.kinds.length > 0 || holds.unknown || f.used > now - HOLD_TTL_MS;
|
|
16800
|
-
const
|
|
16805
|
+
const take2 = async (found, rel2) => {
|
|
16801
16806
|
const free = found.filter((f) => !busy3(f));
|
|
16802
16807
|
if (free.length < found.length) kept3.push(rel2 + ": " + (found.length - free.length) + " in use or just written");
|
|
16803
16808
|
if (!o.dryRun) for (const f of free) await rt.fs.rm(rt.path.join(root, rel2, f.name));
|
|
16804
16809
|
return free;
|
|
16805
16810
|
};
|
|
16806
|
-
const chunks = await
|
|
16807
|
-
const made = await
|
|
16811
|
+
const chunks = await take2(await chunkSets(rt, root), CHUNK_DIR);
|
|
16812
|
+
const made = await take2(await drafts(rt, root), DRAFTS);
|
|
16808
16813
|
if (!o.dryRun) {
|
|
16809
16814
|
for (const rel2 of [FOOTAGE_CACHE + "/" + HOLDS_DIR, FOOTAGE_CACHE, CHUNK_DIR, ".cache", DRAFTS]) if (await isPlainInside(rt, root, rt.path.join(root, rel2))) await removeEmpty(rt, rt.path.join(root, rel2));
|
|
16810
16815
|
}
|
|
@@ -16922,22 +16927,22 @@ var init_ffmpeg = __esm({
|
|
|
16922
16927
|
const rows3 = crc.split("\n").filter((line) => line.trim() && !line.startsWith("#"));
|
|
16923
16928
|
const tb = crc.match(/^#tb\s+0:\s*(\d+\/\d+)/m)?.[1];
|
|
16924
16929
|
const ticks = tb ? rational(tb) : 0;
|
|
16925
|
-
let
|
|
16930
|
+
let first2 = Infinity, end = -Infinity;
|
|
16926
16931
|
for (const row of rows3) {
|
|
16927
16932
|
const parts = row.split(",").map((s) => s.trim());
|
|
16928
16933
|
const pts = Number(parts[2]), duration2 = Number(parts[3]);
|
|
16929
16934
|
if (parts.length < 4 || !Number.isFinite(pts) || !Number.isFinite(duration2) || duration2 <= 0) return { frames: rows3.length };
|
|
16930
|
-
|
|
16935
|
+
first2 = Math.min(first2, pts);
|
|
16931
16936
|
end = Math.max(end, pts + duration2);
|
|
16932
16937
|
}
|
|
16933
|
-
const duration = (end -
|
|
16938
|
+
const duration = (end - first2) * ticks;
|
|
16934
16939
|
return duration > 0 && Number.isFinite(duration) ? { frames: rows3.length, duration, fps: rows3.length / duration } : { frames: rows3.length };
|
|
16935
16940
|
};
|
|
16936
16941
|
probe2 = async (rt, file) => {
|
|
16937
16942
|
const r = await runFfmpeg(rt, ["-i", file, "-map", "0:v:0", "-c", "copy", "-f", "framecrc", "-"]);
|
|
16938
16943
|
const video = r.stderr.match(/Stream #0:\d+[^\n]*: Video: [^\n]*/);
|
|
16939
16944
|
if (!video) throw new FfmpegError("No video stream found in " + file, r.stderr);
|
|
16940
|
-
const
|
|
16945
|
+
const size2 = video[0].match(/, (\d{2,5})x(\d{2,5})[ ,[]/);
|
|
16941
16946
|
const fpsText = video[0].match(/, ([\d.]+) fps/)?.[1] ?? video[0].match(/, ([\d.]+) tbr/)?.[1];
|
|
16942
16947
|
const reportedAverage = video[0].match(/, ([\d.]+) fps/)?.[1];
|
|
16943
16948
|
const rate = r.stderr.match(/r_frame_rate=(\d+\/\d+)/)?.[1];
|
|
@@ -16945,11 +16950,11 @@ var init_ffmpeg = __esm({
|
|
|
16945
16950
|
const frames = clock4.frames;
|
|
16946
16951
|
const d = r.stderr.match(/Duration: (\d+):(\d+):([\d.]+)/);
|
|
16947
16952
|
const duration = d ? Number(d[1]) * 3600 + Number(d[2]) * 60 + Number(d[3]) : 0;
|
|
16948
|
-
if (!
|
|
16953
|
+
if (!size2 || !fpsText) throw new FfmpegError("Could not read the size or frame rate of " + file, r.stderr);
|
|
16949
16954
|
const precision = reportedAverage ? Math.min(5e-3, 0.5 / 10 ** (reportedAverage.split(".")[1]?.length ?? 0)) : Infinity;
|
|
16950
16955
|
const edited = clock4.fps !== void 0 && reportedAverage !== void 0 && Math.abs(clock4.fps - Number(reportedAverage)) > precision + 1e-9;
|
|
16951
16956
|
const fps = edited ? Number(reportedAverage) : clock4.fps ?? (rate ? rational(rate) : Number(fpsText));
|
|
16952
|
-
return { width: Number(
|
|
16957
|
+
return { width: Number(size2[1]), height: Number(size2[2]), fps, frames, duration: frames && fps ? frames / fps : duration, hasAudio: /Stream #0:\d+[^\n]*: Audio:/.test(r.stderr) };
|
|
16953
16958
|
};
|
|
16954
16959
|
}
|
|
16955
16960
|
});
|
|
@@ -17180,9 +17185,9 @@ var init_words = __esm({
|
|
|
17180
17185
|
for (let k = 0; k + units2.length <= tokens3.length; k++) if (units2.every((u, q) => tokens3[k + q]?.key === u)) out2.push(k);
|
|
17181
17186
|
return out2;
|
|
17182
17187
|
};
|
|
17183
|
-
placeAt = (tokens3,
|
|
17184
|
-
const part = tokens3.slice(
|
|
17185
|
-
return { first, last:
|
|
17188
|
+
placeAt = (tokens3, first2, count5) => {
|
|
17189
|
+
const part = tokens3.slice(first2, first2 + count5);
|
|
17190
|
+
return { first: first2, last: first2 + count5 - 1, start: part[0]?.start ?? 0, end: part[part.length - 1]?.end ?? 0, confidence: Math.min(...part.map((t) => t.confidence)) };
|
|
17186
17191
|
};
|
|
17187
17192
|
phraseFrames = (tl, place4, span2) => framesOf(tl, place4.start - (span2.lead ?? 0), place4.end + (span2.hold ?? 0));
|
|
17188
17193
|
findPhrase = (tokens3, span2) => {
|
|
@@ -17907,12 +17912,12 @@ var init_check3 = __esm({
|
|
|
17907
17912
|
init_check_words();
|
|
17908
17913
|
init_lint();
|
|
17909
17914
|
duplicates = (list7, name, what) => {
|
|
17910
|
-
const
|
|
17915
|
+
const first2 = /* @__PURE__ */ new Map();
|
|
17911
17916
|
list7.forEach((x2, i) => {
|
|
17912
|
-
if (!
|
|
17917
|
+
if (!first2.has(x2.id)) first2.set(x2.id, i);
|
|
17913
17918
|
});
|
|
17914
17919
|
return list7.flatMap((x2, i) => {
|
|
17915
|
-
const j =
|
|
17920
|
+
const j = first2.get(x2.id) ?? i;
|
|
17916
17921
|
return j === i ? [] : [error(name + "[" + i + "].id", what + ' id "' + x2.id + '" is already used by ' + name + "[" + j + "].", 'Give it its own id, for example "' + x2.id + "-" + (i + 1) + '".')];
|
|
17917
17922
|
});
|
|
17918
17923
|
};
|
|
@@ -18738,7 +18743,7 @@ var init_decode = __esm({
|
|
|
18738
18743
|
const h = Math.max(2, Math.round(srcH * w / srcW / 2) * 2);
|
|
18739
18744
|
return { width: w, height: h };
|
|
18740
18745
|
};
|
|
18741
|
-
filterChain2 = (o,
|
|
18746
|
+
filterChain2 = (o, size2) => {
|
|
18742
18747
|
const parts = [];
|
|
18743
18748
|
const start = o.startFrame ?? 0;
|
|
18744
18749
|
if (start > 0 || o.frameCount !== void 0) {
|
|
@@ -18747,7 +18752,7 @@ var init_decode = __esm({
|
|
|
18747
18752
|
if (o.every !== void 0 && o.every > 1) parts.push("select='not(mod(n," + o.every + "))'");
|
|
18748
18753
|
if (o.fps !== void 0) parts.push("fps=" + o.fps);
|
|
18749
18754
|
const colour2 = o.colour ? ":in_color_matrix=" + o.colour.matrix + ":in_range=" + o.colour.range : "";
|
|
18750
|
-
parts.push("scale=" +
|
|
18755
|
+
parts.push("scale=" + size2.width + ":" + size2.height + colour2 + ":flags=area+accurate_rnd", "format=" + (o.gray ? "gray" : "rgb24"));
|
|
18751
18756
|
return parts.join(",");
|
|
18752
18757
|
};
|
|
18753
18758
|
readColour = async (rt, file, p) => colourOf((await runFfmpeg(rt, ["-i", file])).stderr, p.width, p.height);
|
|
@@ -18784,18 +18789,18 @@ var init_decode = __esm({
|
|
|
18784
18789
|
if (!(opts.width >= 2)) throw new Error("decodeFrames: width must be at least 2 pixels (got " + opts.width + "). Pass a thumbnail width such as 96.");
|
|
18785
18790
|
const p = opts.probe ?? await probe2(rt, file);
|
|
18786
18791
|
const colour2 = opts.colour ?? await readColour(rt, file, p);
|
|
18787
|
-
const
|
|
18788
|
-
const frameBytes =
|
|
18792
|
+
const size2 = thumbSize(p.width, p.height, opts.width);
|
|
18793
|
+
const frameBytes = size2.width * size2.height * (opts.gray ? 1 : 3);
|
|
18789
18794
|
const expected2 = expectedFrames(opts, p);
|
|
18790
18795
|
const limit = opts.maxBytes ?? MAX_DECODE_BYTES;
|
|
18791
18796
|
if (expected2 * frameBytes > limit) {
|
|
18792
18797
|
const mb = Math.round(expected2 * frameBytes / 1048576);
|
|
18793
|
-
throw new Error("decodeFrames(" + file + "): " + expected2 + " frames of " +
|
|
18798
|
+
throw new Error("decodeFrames(" + file + "): " + expected2 + " frames of " + size2.width + "x" + size2.height + " would take about " + mb + " MB, more than the limit of " + Math.round(limit / 1048576) + " MB. Lower width, set gray: true, or decode a part with frameCount (or a lower fps / a larger every).");
|
|
18794
18799
|
}
|
|
18795
|
-
const args2 = ["-i", file, "-map", "0:v:0", "-an", "-sn", "-vf", filterChain2({ ...opts, colour: colour2 },
|
|
18800
|
+
const args2 = ["-i", file, "-map", "0:v:0", "-an", "-sn", "-vf", filterChain2({ ...opts, colour: colour2 }, size2), "-fps_mode", "passthrough", "-f", "rawvideo", "pipe:1"];
|
|
18796
18801
|
const frames = await readFrames(rt, args2, frameBytes, Math.max(expected2 * 2, 1));
|
|
18797
18802
|
const fps = opts.fps ?? p.fps / Math.max(1, opts.every ?? 1);
|
|
18798
|
-
return { width:
|
|
18803
|
+
return { width: size2.width, height: size2.height, fps, frames };
|
|
18799
18804
|
};
|
|
18800
18805
|
extractFrame = async (rt, file, frame2, out2, width) => {
|
|
18801
18806
|
const ext = out2.toLowerCase().split(".").pop() ?? "";
|
|
@@ -19704,45 +19709,45 @@ var init_fits = __esm({
|
|
|
19704
19709
|
orient = (img, dir) => {
|
|
19705
19710
|
const { w, h, data } = img;
|
|
19706
19711
|
const horizontal = dir === "left" || dir === "right";
|
|
19707
|
-
const
|
|
19708
|
-
const out2 = new Float32Array(
|
|
19712
|
+
const size2 = horizontal ? w : h, across = horizontal ? h : w;
|
|
19713
|
+
const out2 = new Float32Array(size2 * across * 3);
|
|
19709
19714
|
for (let v = 0; v < across; v++) {
|
|
19710
|
-
for (let u = 0; u <
|
|
19715
|
+
for (let u = 0; u < size2; u++) {
|
|
19711
19716
|
const x2 = dir === "left" ? u : dir === "right" ? w - 1 - u : v;
|
|
19712
19717
|
const y = dir === "up" ? u : dir === "down" ? h - 1 - u : v;
|
|
19713
|
-
for (let c = 0; c < 3; c++) out2[(v *
|
|
19718
|
+
for (let c = 0; c < 3; c++) out2[(v * size2 + u) * 3 + c] = data[(y * w + x2) * 3 + c];
|
|
19714
19719
|
}
|
|
19715
19720
|
}
|
|
19716
|
-
return { size, across, data: out2 };
|
|
19721
|
+
return { size: size2, across, data: out2 };
|
|
19717
19722
|
};
|
|
19718
19723
|
compose = (mode, A, B, k) => {
|
|
19719
|
-
const { size, across } = A;
|
|
19720
|
-
const cut3 =
|
|
19724
|
+
const { size: size2, across } = A;
|
|
19725
|
+
const cut3 = size2 - k;
|
|
19721
19726
|
const oldShift = mode === "push" || mode === "reveal" ? k : 0;
|
|
19722
19727
|
const newShift = mode === "push" || mode === "cover" ? -cut3 : 0;
|
|
19723
19728
|
const out2 = new Float32Array(A.data.length);
|
|
19724
19729
|
for (let v = 0; v < across; v++) {
|
|
19725
|
-
for (let u = 0; u <
|
|
19726
|
-
const src = u < cut3 ? (v *
|
|
19730
|
+
for (let u = 0; u < size2; u++) {
|
|
19731
|
+
const src = u < cut3 ? (v * size2 + u + oldShift) * 3 : (v * size2 + u + newShift) * 3;
|
|
19727
19732
|
const pic = u < cut3 ? A.data : B.data;
|
|
19728
|
-
for (let c = 0; c < 3; c++) out2[(v *
|
|
19733
|
+
for (let c = 0; c < 3; c++) out2[(v * size2 + u) * 3 + c] = pic[src + c];
|
|
19729
19734
|
}
|
|
19730
19735
|
}
|
|
19731
19736
|
return out2;
|
|
19732
19737
|
};
|
|
19733
|
-
smearAlong = (P,
|
|
19738
|
+
smearAlong = (P, size2, across, r) => {
|
|
19734
19739
|
let cur = P;
|
|
19735
19740
|
for (let pass = 0; pass < 2; pass++) {
|
|
19736
19741
|
const out2 = new Float32Array(cur.length);
|
|
19737
19742
|
for (let v = 0; v < across; v++) {
|
|
19738
|
-
for (let u = 0; u <
|
|
19743
|
+
for (let u = 0; u < size2; u++) {
|
|
19739
19744
|
for (let c = 0; c < 3; c++) {
|
|
19740
19745
|
let s = 0, n = 0;
|
|
19741
|
-
for (let q = Math.max(0, u - r); q <= Math.min(
|
|
19742
|
-
s += cur[(v *
|
|
19746
|
+
for (let q = Math.max(0, u - r); q <= Math.min(size2 - 1, u + r); q++) {
|
|
19747
|
+
s += cur[(v * size2 + q) * 3 + c];
|
|
19743
19748
|
n++;
|
|
19744
19749
|
}
|
|
19745
|
-
out2[(v *
|
|
19750
|
+
out2[(v * size2 + u) * 3 + c] = s / n;
|
|
19746
19751
|
}
|
|
19747
19752
|
}
|
|
19748
19753
|
}
|
|
@@ -19762,22 +19767,22 @@ var init_fits = __esm({
|
|
|
19762
19767
|
return quantile(ratios, 0.25);
|
|
19763
19768
|
};
|
|
19764
19769
|
edgeError = (mode, A, B, M, k) => {
|
|
19765
|
-
const { size, across } = A;
|
|
19766
|
-
const cut3 =
|
|
19770
|
+
const { size: size2, across } = A;
|
|
19771
|
+
const cut3 = size2 - k;
|
|
19767
19772
|
const oldShift = mode === "push" || mode === "reveal" ? k : 0;
|
|
19768
19773
|
const newShift = mode === "push" || mode === "cover" ? -cut3 : 0;
|
|
19769
19774
|
const a = A.data, b = B.data, m = M.data;
|
|
19770
19775
|
let err3 = 0;
|
|
19771
19776
|
for (let v = 0; v < across; v++) {
|
|
19772
|
-
const row = v *
|
|
19773
|
-
for (let u = 0; u <
|
|
19777
|
+
const row = v * size2;
|
|
19778
|
+
for (let u = 0; u < size2; u++) {
|
|
19774
19779
|
const src = u < cut3 ? (row + u + oldShift) * 3 : (row + u + newShift) * 3;
|
|
19775
19780
|
const pic = u < cut3 ? a : b;
|
|
19776
19781
|
const at7 = (row + u) * 3;
|
|
19777
19782
|
err3 += Math.abs(m[at7] - pic[src]) + Math.abs(m[at7 + 1] - pic[src + 1]) + Math.abs(m[at7 + 2] - pic[src + 2]);
|
|
19778
19783
|
}
|
|
19779
19784
|
}
|
|
19780
|
-
return err3 / (
|
|
19785
|
+
return err3 / (size2 * across * 3);
|
|
19781
19786
|
};
|
|
19782
19787
|
DIRS = ["left", "right", "up", "down"];
|
|
19783
19788
|
MODES2 = ["wipe", "push", "cover", "reveal"];
|
|
@@ -20013,9 +20018,9 @@ var init_robust = __esm({
|
|
|
20013
20018
|
}
|
|
20014
20019
|
let left = KEEP * a.length, s = 0;
|
|
20015
20020
|
for (let k = 0; k < 256 && left > 0; k++) {
|
|
20016
|
-
const
|
|
20017
|
-
if (
|
|
20018
|
-
left -=
|
|
20021
|
+
const take2 = Math.min(left, hist[k]);
|
|
20022
|
+
if (take2 > 0) s += sums[k] / hist[k] * take2;
|
|
20023
|
+
left -= take2;
|
|
20019
20024
|
}
|
|
20020
20025
|
return [all / Math.max(1, a.length), s / Math.max(1, KEEP * a.length)];
|
|
20021
20026
|
};
|
|
@@ -20679,10 +20684,10 @@ var init_boundaries = __esm({
|
|
|
20679
20684
|
return chains;
|
|
20680
20685
|
};
|
|
20681
20686
|
widen = (sg, chains, ramps2) => chains.map((chain, i) => {
|
|
20682
|
-
const
|
|
20683
|
-
const lo = Math.max(i > 0 ? chains[i - 1].at(-1).frame : 0, ...ramps2.filter((r) => r.e <
|
|
20687
|
+
const first2 = chain[0].frame, last = chain[chain.length - 1].frame;
|
|
20688
|
+
const lo = Math.max(i > 0 ? chains[i - 1].at(-1).frame : 0, ...ramps2.filter((r) => r.e < first2 - 1).map((r) => r.e));
|
|
20684
20689
|
const hi = Math.min(i + 1 < chains.length ? chains[i + 1][0].frame - 1 : sg.n - 1, ...ramps2.filter((r) => r.s > last).map((r) => r.s));
|
|
20685
|
-
return { s: activeSpan(sg,
|
|
20690
|
+
return { s: activeSpan(sg, first2, lo, hi).start, e: activeSpan(sg, last, lo, hi).end, cuts: chain, ramp: false };
|
|
20686
20691
|
});
|
|
20687
20692
|
mergeAll = (sg, cands) => {
|
|
20688
20693
|
const sorted = [...cands].sort((a, b) => a.s - b.s || a.e - b.e);
|
|
@@ -20756,11 +20761,11 @@ var init_bars = __esm({
|
|
|
20756
20761
|
MIN_LIVE = 0.1;
|
|
20757
20762
|
SAMPLES = 120;
|
|
20758
20763
|
rangeOf = (t) => {
|
|
20759
|
-
const n = t.gray.length, k = Math.min(SAMPLES, n),
|
|
20760
|
-
const lo = new Uint8Array(
|
|
20764
|
+
const n = t.gray.length, k = Math.min(SAMPLES, n), size2 = t.width * t.height;
|
|
20765
|
+
const lo = new Uint8Array(size2).fill(255), hi = new Uint8Array(size2);
|
|
20761
20766
|
for (let s = 0; s < k; s++) {
|
|
20762
20767
|
const g = t.gray[Math.floor(s * (n - 1) / Math.max(1, k - 1))];
|
|
20763
|
-
for (let p = 0; p <
|
|
20768
|
+
for (let p = 0; p < size2; p++) {
|
|
20764
20769
|
const v = g[p];
|
|
20765
20770
|
if (v < lo[p]) lo[p] = v;
|
|
20766
20771
|
if (v > hi[p]) hi[p] = v;
|
|
@@ -20867,8 +20872,8 @@ var init_moves = __esm({
|
|
|
20867
20872
|
return n ? s / n : void 0;
|
|
20868
20873
|
};
|
|
20869
20874
|
fitAt = (fr, L, s, e, bound = Infinity) => {
|
|
20870
|
-
const
|
|
20871
|
-
const base = meanIn(fr, L,
|
|
20875
|
+
const first2 = fr[0], last = fr[fr.length - 1];
|
|
20876
|
+
const base = meanIn(fr, L, first2, s) ?? L[0];
|
|
20872
20877
|
const top2 = meanIn(fr, L, e, last) ?? L[L.length - 1];
|
|
20873
20878
|
const ratio3 = Math.exp(top2 - base);
|
|
20874
20879
|
const holdTerm = (i, x2) => (L[i] - (base + Math.log(1 + (ratio3 - 1) * (x2 <= 0 ? 0 : 1)))) ** 2;
|
|
@@ -20898,11 +20903,11 @@ var init_moves = __esm({
|
|
|
20898
20903
|
return best;
|
|
20899
20904
|
};
|
|
20900
20905
|
fitMove = (fr, L, minFrames) => {
|
|
20901
|
-
const
|
|
20906
|
+
const first2 = fr[0], last = fr[fr.length - 1], gap = Math.max(1, Math.round((last - first2) / Math.max(1, fr.length - 1)));
|
|
20902
20907
|
const minLen = Math.max(2, minFrames);
|
|
20903
20908
|
let best;
|
|
20904
20909
|
const consider = (s, e) => {
|
|
20905
|
-
if (s <
|
|
20910
|
+
if (s < first2 || e > last || e - s < minLen) return;
|
|
20906
20911
|
const f = fitAt(fr, L, s, e, best ? best.err - 1e-12 : Infinity);
|
|
20907
20912
|
if (f && (!best || f.err < best.err - 1e-12)) best = f;
|
|
20908
20913
|
};
|
|
@@ -20996,10 +21001,10 @@ var init_camera2 = __esm({
|
|
|
20996
21001
|
STILL_PAN = 5e-3;
|
|
20997
21002
|
MIN_TEXTURE = 1.5;
|
|
20998
21003
|
UNKNOWN = { kind: "unknown", zoomPerS: 0, panPerS: [0, 0], confidence: 0 };
|
|
20999
|
-
fitStep = (c, i, j, init4,
|
|
21004
|
+
fitStep = (c, i, j, init4, first2) => {
|
|
21000
21005
|
const a = c.gray[i], b = c.gray[j];
|
|
21001
21006
|
const near3 = align(a, b, c.width, c.height, { init: init4 });
|
|
21002
|
-
if (!
|
|
21007
|
+
if (!first2) return near3;
|
|
21003
21008
|
const searched = align(a, b, c.width, c.height, { init: init4, search: true });
|
|
21004
21009
|
return searched.residual < near3.residual ? searched : near3;
|
|
21005
21010
|
};
|
|
@@ -21229,10 +21234,10 @@ var init_profile2 = __esm({
|
|
|
21229
21234
|
}
|
|
21230
21235
|
return { outline: on ? os / on : 0, ground: gn ? gs / gn : 0 };
|
|
21231
21236
|
};
|
|
21232
|
-
kindOf2 = (
|
|
21237
|
+
kindOf2 = (first2, last, w, h, thr) => {
|
|
21233
21238
|
const changed2 = new Uint8Array(w * h);
|
|
21234
|
-
for (let p = 0; p < w * h; p++) changed2[p] = pixDiff(
|
|
21235
|
-
const c0 = contrasts(
|
|
21239
|
+
for (let p = 0; p < w * h; p++) changed2[p] = pixDiff(first2, last, p * 3) > thr ? 1 : 0;
|
|
21240
|
+
const c0 = contrasts(first2, changed2, w, h), c1 = contrasts(last, changed2, w, h);
|
|
21236
21241
|
const e0 = Math.max(0, c0.outline - c0.ground), e1 = Math.max(0, c1.outline - c1.ground);
|
|
21237
21242
|
if (e1 > 1.5 * e0 + 5) return "appear";
|
|
21238
21243
|
if (e0 > 1.5 * e1 + 5) return "disappear";
|
|
@@ -21263,8 +21268,8 @@ var init_profile2 = __esm({
|
|
|
21263
21268
|
const dx = F.cx - f.cx, dy = F.cy - f.cy;
|
|
21264
21269
|
const horizontal = Math.abs(dx) / fw >= Math.abs(dy) / fh;
|
|
21265
21270
|
const travel2 = horizontal ? Math.abs(dx) : Math.abs(dy);
|
|
21266
|
-
const
|
|
21267
|
-
if (travel2 < Math.max(1.5, 0.12 * (horizontal ? fw : fh)) ||
|
|
21271
|
+
const size2 = horizontal ? (f.x1 - f.x0 + 1) / fw : (f.y1 - f.y0 + 1) / fh;
|
|
21272
|
+
if (travel2 < Math.max(1.5, 0.12 * (horizontal ? fw : fh)) || size2 < 0.6) return void 0;
|
|
21268
21273
|
const direction2 = horizontal ? dx > 0 ? "right" : "left" : dy > 0 ? "down" : "up";
|
|
21269
21274
|
return { how: "slide", direction: direction2, q: vis.map((s) => clamp2(1 - Math.hypot(F.cx - s.cx, F.cy - s.cy) / Math.hypot(dx, dy), 0, 1)) };
|
|
21270
21275
|
};
|
|
@@ -21281,10 +21286,10 @@ var init_profile2 = __esm({
|
|
|
21281
21286
|
profileCrop = (c) => {
|
|
21282
21287
|
const n = c.frames.length;
|
|
21283
21288
|
if (n < 2) return void 0;
|
|
21284
|
-
const
|
|
21285
|
-
const total2 = meanDiff(
|
|
21289
|
+
const first2 = c.frames[0], last = c.frames[n - 1];
|
|
21290
|
+
const total2 = meanDiff(first2, last);
|
|
21286
21291
|
if (total2 < 0.5) return void 0;
|
|
21287
|
-
const kind = kindOf2(
|
|
21292
|
+
const kind = kindOf2(first2, last, c.w, c.h, 12);
|
|
21288
21293
|
const seq = kind === "disappear" ? [...c.frames].reverse() : [...c.frames];
|
|
21289
21294
|
const ref = seq[0], target2 = seq[n - 1];
|
|
21290
21295
|
const tol = Math.max(0.7, 0.02 * total2);
|
|
@@ -21988,14 +21993,14 @@ var init_tracks = __esm({
|
|
|
21988
21993
|
later = m.mask;
|
|
21989
21994
|
live.unshift(m);
|
|
21990
21995
|
}
|
|
21991
|
-
const
|
|
21996
|
+
const first2 = live[0];
|
|
21992
21997
|
const covers = live.map((m) => m.fresh / m.total);
|
|
21993
21998
|
const fallen = covers.reduce((s, c, i) => s + (i > 0 ? Math.max(0, covers[i - 1] - c) : 0), 0);
|
|
21994
21999
|
if ((covers[covers.length - 1] ?? 0) < REACHES || fallen > FALLS) return void 0;
|
|
21995
22000
|
const middle = live.filter((m) => m.fresh / m.total >= 0.2 && m.fresh / m.total <= 0.8);
|
|
21996
|
-
if (!
|
|
22001
|
+
if (!first2 || live.length < 3 || median2(live.map((m) => m.foreign / m.total)) > MOST_FOREIGN || median2((middle.length ? middle : live).map((m) => m.mixed)) > MOST_MIXED) return void 0;
|
|
21997
22002
|
let ox = 0, oy = 0, on = 0;
|
|
21998
|
-
|
|
22003
|
+
first2.mask.forEach((v, p) => {
|
|
21999
22004
|
if (v === NEW) {
|
|
22000
22005
|
ox += p % w;
|
|
22001
22006
|
oy += Math.floor(p / w);
|
|
@@ -22040,7 +22045,7 @@ var init_tracks = __esm({
|
|
|
22040
22045
|
samples,
|
|
22041
22046
|
path: pathOf2(samples, w, h, t.fps),
|
|
22042
22047
|
size: medianSize(samples),
|
|
22043
|
-
reveal: { start:
|
|
22048
|
+
reveal: { start: first2.frame, end: done2.frame, edge },
|
|
22044
22049
|
confidence: round2(clamp2(calm * (edge.shape === "irregular" ? 0.6 : edge.fit) * (0.5 + 0.5 * edge.share), 0, 1), 2)
|
|
22045
22050
|
};
|
|
22046
22051
|
};
|
|
@@ -22147,8 +22152,8 @@ var init_signature = __esm({
|
|
|
22147
22152
|
};
|
|
22148
22153
|
signatureFrames = (s) => {
|
|
22149
22154
|
const all = new Uint8Array(Buffer.from(s.data, "base64"));
|
|
22150
|
-
const
|
|
22151
|
-
return Array.from({ length: s.count }, (_, k) => all.subarray(k *
|
|
22155
|
+
const size2 = s.width * s.height;
|
|
22156
|
+
return Array.from({ length: s.count }, (_, k) => all.subarray(k * size2, (k + 1) * size2));
|
|
22152
22157
|
};
|
|
22153
22158
|
}
|
|
22154
22159
|
});
|
|
@@ -22453,6 +22458,14 @@ var init_wallet = __esm({
|
|
|
22453
22458
|
settle(reserved, charged) {
|
|
22454
22459
|
this.spent += Math.max(0, charged) - Math.max(0, reserved);
|
|
22455
22460
|
}
|
|
22461
|
+
/**
|
|
22462
|
+
* Credits this command paid and the platform gave back (a clip paid when it was sent, then failed and was refunded):
|
|
22463
|
+
* the command may spend them again. What it spends net never passes max: the caller gives back only what it paid
|
|
22464
|
+
* itself and the platform refunded.
|
|
22465
|
+
*/
|
|
22466
|
+
refund(credits2) {
|
|
22467
|
+
this.spent = Math.max(0, this.spent - Math.max(0, credits2));
|
|
22468
|
+
}
|
|
22456
22469
|
};
|
|
22457
22470
|
NOTHING = () => new Wallet(0);
|
|
22458
22471
|
}
|
|
@@ -22772,8 +22785,8 @@ var init_hosted = __esm({
|
|
|
22772
22785
|
};
|
|
22773
22786
|
downloadVoiceAudio = async (rt, url, out2, again = "Run the same command again.") => {
|
|
22774
22787
|
const bytes = await downloadPaid(rt, url, { what: "the voice audio", again, maxBytes: 50 * 1024 * 1024 });
|
|
22775
|
-
const
|
|
22776
|
-
if (
|
|
22788
|
+
const tag4 = (a, b) => String.fromCharCode(...bytes.subarray(a, b));
|
|
22789
|
+
if (tag4(0, 4) !== "RIFF" || tag4(8, 12) !== "WAVE" || bytes.length <= 44) throw new Error("The speech service did not return a WAV recording.");
|
|
22777
22790
|
await rt.fs.writeFile(out2, bytes);
|
|
22778
22791
|
};
|
|
22779
22792
|
hostedOperationKey = (voiceId, text13, speed, out2) => operationKeyOf({ voiceId, text: text13, speed, out: out2 });
|
|
@@ -22917,9 +22930,9 @@ var init_voice = __esm({
|
|
|
22917
22930
|
const raw = await rt.fs.readText(file).then((t) => JSON.parse(t), () => void 0);
|
|
22918
22931
|
await rt.fs.rm(file);
|
|
22919
22932
|
const list7 = Array.isArray(raw?.words) ? raw.words.filter((w) => typeof w.text === "string" && typeof w.start === "number" && typeof w.end === "number") : [];
|
|
22920
|
-
const
|
|
22921
|
-
if (!
|
|
22922
|
-
return list7.map((w) => ({ text: w.text, start: Math.max(0, w.start -
|
|
22933
|
+
const first2 = list7[0];
|
|
22934
|
+
if (!first2) return void 0;
|
|
22935
|
+
return list7.map((w) => ({ text: w.text, start: Math.max(0, w.start - first2.start), end: Math.max(0, w.end - first2.start) }));
|
|
22923
22936
|
};
|
|
22924
22937
|
TRIM = "silenceremove=start_periods=1:start_threshold=-45dB:detection=peak,areverse,silenceremove=start_periods=1:start_threshold=-45dB:detection=peak,areverse";
|
|
22925
22938
|
speakLines = async (rt, o) => {
|
|
@@ -23042,11 +23055,11 @@ var init_dialogue = __esm({
|
|
|
23042
23055
|
TAG = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
23043
23056
|
WIDE_LANGUAGES = ["zh", "yue", "ja", "ko"];
|
|
23044
23057
|
WIDE = /[\u{3040}-\u{30ff}\u{3400}-\u{9fff}\u{ac00}-\u{d7af}]/u;
|
|
23045
|
-
languageName = (
|
|
23046
|
-
const t =
|
|
23047
|
-
return NAMES2[t] ?? NAMES2[t.split("-")[0] ?? ""] ??
|
|
23058
|
+
languageName = (tag4) => {
|
|
23059
|
+
const t = tag4.trim().toLowerCase();
|
|
23060
|
+
return NAMES2[t] ?? NAMES2[t.split("-")[0] ?? ""] ?? tag4.trim();
|
|
23048
23061
|
};
|
|
23049
|
-
wideLanguage = (
|
|
23062
|
+
wideLanguage = (tag4) => WIDE_LANGUAGES.includes(tag4.trim().toLowerCase().split("-")[0] ?? "");
|
|
23050
23063
|
wideText = (text13) => {
|
|
23051
23064
|
const chars = spokenChars(text13);
|
|
23052
23065
|
return chars.filter((c) => WIDE.test(c)).length * 2 >= chars.length;
|
|
@@ -23277,7 +23290,7 @@ var init_revision = __esm({
|
|
|
23277
23290
|
});
|
|
23278
23291
|
|
|
23279
23292
|
// src/video/replication/check.ts
|
|
23280
|
-
var problem, BIND, sameHash, validSource, hasMedia, mediaEvidence, VISUAL, AUDIBLE, DYNAMIC, checkReplicationSource, checkReplicationReadiness, checkReplicationAudio, frameKeys, assessReplication;
|
|
23293
|
+
var problem, BIND, sameHash, validSource, hasMedia, mediaEvidence, VISUAL, AUDIBLE, DYNAMIC, checkReplicationSource, checkReplicationReadiness, checkReplicationAudio, LENGTH_SLACK, frameKeys, assessReplication;
|
|
23281
23294
|
var init_check4 = __esm({
|
|
23282
23295
|
"src/video/replication/check.ts"() {
|
|
23283
23296
|
"use strict";
|
|
@@ -23367,6 +23380,7 @@ var init_check4 = __esm({
|
|
|
23367
23380
|
});
|
|
23368
23381
|
return out2;
|
|
23369
23382
|
};
|
|
23383
|
+
LENGTH_SLACK = { near: 0.03, far: 0.1 };
|
|
23370
23384
|
frameKeys = (evidence3) => new Set(evidence3.flatMap((e) => {
|
|
23371
23385
|
if (!hasMedia(e, VISUAL)) return [];
|
|
23372
23386
|
if (e.media === "frame") return [e.sha256.toLowerCase()];
|
|
@@ -23405,8 +23419,18 @@ var init_check4 = __esm({
|
|
|
23405
23419
|
const span2 = c.scope?.span ?? [0, c.source.frames];
|
|
23406
23420
|
const expected2 = (span2[1] - span2[0]) / c.source.fps;
|
|
23407
23421
|
const duration = actualArtifact.frames / actualArtifact.fps;
|
|
23408
|
-
const
|
|
23409
|
-
|
|
23422
|
+
const frame2 = Math.max(1 / c.source.fps, 1 / actualArtifact.fps) + 1e-6;
|
|
23423
|
+
const off2 = Math.abs(duration - expected2), share2 = Math.round(off2 / expected2 * 1e3) / 10;
|
|
23424
|
+
const lengths = duration.toFixed(2) + " s against the retained reference interval's " + expected2.toFixed(2) + " s (" + share2 + "%)";
|
|
23425
|
+
if (off2 > Math.max(frame2, LENGTH_SLACK.far * expected2))
|
|
23426
|
+
fail2("review.target", "Final duration is " + lengths + ", more than " + LENGTH_SLACK.far * 100 + "% off; equal frame counts are not enough.");
|
|
23427
|
+
else if (off2 > Math.max(frame2, LENGTH_SLACK.near * expected2))
|
|
23428
|
+
out2.push(problem(
|
|
23429
|
+
"review.target",
|
|
23430
|
+
"Final duration is " + lengths + ": accepted, as within " + LENGTH_SLACK.far * 100 + "%; say it in the delivery notes.",
|
|
23431
|
+
"warning",
|
|
23432
|
+
"Say the length difference in the delivery notes; re-time only when the user asks for the exact length."
|
|
23433
|
+
));
|
|
23410
23434
|
}
|
|
23411
23435
|
const inspect = (name, f, media) => {
|
|
23412
23436
|
if (f?.status === "failed") {
|
|
@@ -23547,12 +23571,12 @@ var init_footage3 = __esm({
|
|
|
23547
23571
|
}
|
|
23548
23572
|
return dir;
|
|
23549
23573
|
};
|
|
23550
|
-
keyOf3 = async (rt, projectDir, src,
|
|
23574
|
+
keyOf3 = async (rt, projectDir, src, size2) => {
|
|
23551
23575
|
const file = rt.path.resolve(rt.cwd, projectDir, src);
|
|
23552
23576
|
const info = await rt.fs.stat(file);
|
|
23553
23577
|
if (!info) throw new Error("The video material " + src + " disappeared while the page was built. Build it again.");
|
|
23554
23578
|
return {
|
|
23555
|
-
key: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs,
|
|
23579
|
+
key: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs, size2.width, size2.height])).slice(0, 16),
|
|
23556
23580
|
source: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs])).slice(0, 16)
|
|
23557
23581
|
};
|
|
23558
23582
|
};
|
|
@@ -23565,8 +23589,8 @@ var init_footage3 = __esm({
|
|
|
23565
23589
|
const facts = probed.info[id2];
|
|
23566
23590
|
const colour2 = probed.colour[id2];
|
|
23567
23591
|
if (!facts || "error" in facts || !colour2) throw new Error('extractFootage: video material "' + id2 + '" was not probed. Pass the result of probeFootage for this project.');
|
|
23568
|
-
const
|
|
23569
|
-
return { id: id2, f, size, colour: colour2, ...await keyOf3(rt, projectDir, f.src,
|
|
23592
|
+
const size2 = extractSize(r, id2, facts, opts.scale);
|
|
23593
|
+
return { id: id2, f, size: size2, colour: colour2, ...await keyOf3(rt, projectDir, f.src, size2) };
|
|
23570
23594
|
}));
|
|
23571
23595
|
const dirs = /* @__PURE__ */ new Map();
|
|
23572
23596
|
for (const j of jobs2) dirs.set(j.key, await cacheDir(rt, projectDir, FOOTAGE_CACHE + "/" + j.key));
|
|
@@ -24630,19 +24654,19 @@ var init_measure2 = __esm({
|
|
|
24630
24654
|
return rms > 0 ? Math.max(FLOOR_DB, 20 * Math.log10(rms)) : FLOOR_DB;
|
|
24631
24655
|
};
|
|
24632
24656
|
levelCurve = (pcm, rate, step2 = 0.5) => {
|
|
24633
|
-
const
|
|
24634
|
-
return Array.from({ length: Math.ceil(pcm.length /
|
|
24657
|
+
const size2 = Math.max(1, Math.round(step2 * rate));
|
|
24658
|
+
return Array.from({ length: Math.ceil(pcm.length / size2) }, (_, i) => r1(rmsDb(pcm, i * size2, (i + 1) * size2)));
|
|
24635
24659
|
};
|
|
24636
24660
|
silencesOf = (pcm, rate, db = SILENCE_DB, least = SILENCE_SECONDS) => {
|
|
24637
|
-
const
|
|
24661
|
+
const size2 = Math.max(1, Math.round(0.05 * rate));
|
|
24638
24662
|
const out2 = [];
|
|
24639
24663
|
let start = -1;
|
|
24640
|
-
const n = Math.ceil(pcm.length /
|
|
24664
|
+
const n = Math.ceil(pcm.length / size2);
|
|
24641
24665
|
for (let i = 0; i <= n; i++) {
|
|
24642
|
-
const quiet = i < n && rmsDb(pcm, i *
|
|
24666
|
+
const quiet = i < n && rmsDb(pcm, i * size2, (i + 1) * size2) < db;
|
|
24643
24667
|
if (quiet && start < 0) start = i;
|
|
24644
24668
|
if (!quiet && start >= 0) {
|
|
24645
|
-
const a = start *
|
|
24669
|
+
const a = start * size2 / rate, b = Math.min(pcm.length, i * size2) / rate;
|
|
24646
24670
|
if (b - a >= least) out2.push([r22(a), r22(b)]);
|
|
24647
24671
|
start = -1;
|
|
24648
24672
|
}
|
|
@@ -24670,9 +24694,9 @@ var init_measure2 = __esm({
|
|
|
24670
24694
|
re[reverse[i]] = (pcm[at7 + i] ?? 0) * hann[i];
|
|
24671
24695
|
im[i] = 0;
|
|
24672
24696
|
}
|
|
24673
|
-
for (let
|
|
24674
|
-
const half2 =
|
|
24675
|
-
for (let i = 0; i < n; i +=
|
|
24697
|
+
for (let size2 = 2; size2 <= n; size2 *= 2) {
|
|
24698
|
+
const half2 = size2 / 2, step2 = n / size2;
|
|
24699
|
+
for (let i = 0; i < n; i += size2) {
|
|
24676
24700
|
for (let j = 0; j < half2; j++) {
|
|
24677
24701
|
const c = cos[j * step2], s = sin[j * step2];
|
|
24678
24702
|
const a = i + j, b = a + half2;
|
|
@@ -24780,12 +24804,12 @@ var init_measure2 = __esm({
|
|
|
24780
24804
|
phase = p;
|
|
24781
24805
|
}
|
|
24782
24806
|
}
|
|
24783
|
-
const
|
|
24807
|
+
const first2 = (phase * HOP + ONSET_AT * FRAME) / rate;
|
|
24784
24808
|
return {
|
|
24785
24809
|
bpm: r1(60 / period),
|
|
24786
24810
|
confidence: r22(Math.max(0, Math.min(1, best.value))),
|
|
24787
24811
|
period: r3(period),
|
|
24788
|
-
first: r3(
|
|
24812
|
+
first: r3(first2 % period),
|
|
24789
24813
|
others: peaks.slice(1, 3).map((p) => ({ bpm: r1(60 * fps / p.lag), confidence: r22(Math.max(0, Math.min(1, p.value))) }))
|
|
24790
24814
|
};
|
|
24791
24815
|
};
|
|
@@ -24887,11 +24911,11 @@ var init_sample = __esm({
|
|
|
24887
24911
|
const length2 = Math.min(want, best[1] - best[0]);
|
|
24888
24912
|
return { at: Math.round(best[0] * 100) / 100, seconds: Math.round(length2 * 100) / 100 };
|
|
24889
24913
|
};
|
|
24890
|
-
VOICE_NAMED = (speakers,
|
|
24891
|
-
VOICE_NAMED_EN(speakers,
|
|
24892
|
-
" " + speakers.map((s, i) => s + "\u7684\u58F0\u97F3\u662F @audio" + (
|
|
24914
|
+
VOICE_NAMED = (speakers, first2) => pl(
|
|
24915
|
+
VOICE_NAMED_EN(speakers, first2),
|
|
24916
|
+
" " + speakers.map((s, i) => s + "\u7684\u58F0\u97F3\u662F @audio" + (first2 + i)).join("\uFF1B") + "\uFF1A" + (speakers.length === 1 ? "\u5B83" : "\u6BCF\u4E00\u6BB5") + "\u53EA\u786E\u5B9A\u58F0\u97F3\u7684\u8EAB\u4EFD\u548C\u97F3\u8272\u3002\u53F0\u8BCD\u7528" + (speakers.length === 1 ? "\u8FD9\u4E2A\u58F0\u97F3" : "\u8FD9\u4E9B\u58F0\u97F3") + "\u8BF4\u51FA\uFF0C\u7EDD\u4E0D\u8BF4\u53C2\u8003\u5F55\u97F3\u91CC\u7684\u8BDD\uFF0C\u5E76\u4E14\u8FD9\u4E2A\u58F0\u97F3\u5728\u6BCF\u4E2A\u7247\u6BB5\u91CC\u4FDD\u6301\u4E00\u81F4\u3002"
|
|
24893
24917
|
);
|
|
24894
|
-
VOICE_NAMED_EN = (speakers,
|
|
24918
|
+
VOICE_NAMED_EN = (speakers, first2) => " " + speakers.map((s, i) => "The voice of " + s + " is @audio" + (first2 + i)).join("; ") + ": " + (speakers.length === 1 ? "it defines" : "each defines") + " the voice's identity and timbre only. The lines are spoken with " + (speakers.length === 1 ? "that voice" : "those voices") + ", never with the words of the reference recording, and the voice stays the same through every clip.";
|
|
24895
24919
|
readRecord = (rt, file) => rt.fs.readText(file + ".json").then((t) => JSON.parse(t), () => void 0);
|
|
24896
24920
|
cutSample = async (rt, dir, profile2, o) => {
|
|
24897
24921
|
const out2 = rt.path.join(dir, sampleFile(profile2.id));
|
|
@@ -24973,6 +24997,60 @@ var init_clip_sound = __esm({
|
|
|
24973
24997
|
}
|
|
24974
24998
|
});
|
|
24975
24999
|
|
|
25000
|
+
// src/video/generate/voice-clips.ts
|
|
25001
|
+
var nativeSpeakers, planVoiceClips, clipVoices, voiceClipsAwaited, adoptClipVoice;
|
|
25002
|
+
var init_voice_clips = __esm({
|
|
25003
|
+
"src/video/generate/voice-clips.ts"() {
|
|
25004
|
+
"use strict";
|
|
25005
|
+
init_profile3();
|
|
25006
|
+
init_sample();
|
|
25007
|
+
init_speech();
|
|
25008
|
+
nativeSpeakers = (r) => r.speech?.mode === "native" ? speakersOf(r.speech) : [];
|
|
25009
|
+
planVoiceClips = (order, registered, canCarry) => {
|
|
25010
|
+
const clipOf = /* @__PURE__ */ new Map(), waits = /* @__PURE__ */ new Map();
|
|
25011
|
+
const speakers = [...new Set(order.flatMap(nativeSpeakers))].filter((s) => !registered.has(s));
|
|
25012
|
+
for (const speaker of speakers) {
|
|
25013
|
+
const at7 = order.findIndex((r) => {
|
|
25014
|
+
const who = nativeSpeakers(r);
|
|
25015
|
+
return who.length === 1 && who[0] === speaker;
|
|
25016
|
+
});
|
|
25017
|
+
if (at7 < 0) continue;
|
|
25018
|
+
const later = order.slice(at7 + 1).filter((r) => nativeSpeakers(r).includes(speaker) && canCarry(r));
|
|
25019
|
+
if (!later.length) continue;
|
|
25020
|
+
clipOf.set(speaker, order[at7].file);
|
|
25021
|
+
for (const r of later) waits.set(r.file, [...waits.get(r.file) ?? [], speaker]);
|
|
25022
|
+
}
|
|
25023
|
+
return { clipOf, waits };
|
|
25024
|
+
};
|
|
25025
|
+
clipVoices = async (rt, dir, r, fromFrames, notes2) => {
|
|
25026
|
+
const refs = [];
|
|
25027
|
+
for (const id2 of nativeSpeakers(r)) {
|
|
25028
|
+
const profile2 = await voiceProfile(rt, dir, id2).catch(() => void 0);
|
|
25029
|
+
if (profile2) refs.push({ id: id2, profile: profile2 });
|
|
25030
|
+
}
|
|
25031
|
+
if (!refs.length || !fromFrames) return refs;
|
|
25032
|
+
notes2.push(r.file + ": " + refs.map((v) => v.id).join(", ") + " speak" + (refs.length === 1 ? "s" : "") + " with the video model's own voice; the voice registered for the project is not passed as a reference (this clip starts from a frame, and a clip made from frames takes no references). Listen to the clip beside the others.");
|
|
25033
|
+
return [];
|
|
25034
|
+
};
|
|
25035
|
+
voiceClipsAwaited = (plan4, file, settled2) => [...new Set((plan4.waits.get(file) ?? []).filter((s) => !settled2.has(s)).map((s) => plan4.clipOf.get(s)))];
|
|
25036
|
+
adoptClipVoice = async (rt, dir, plan4, file, notes2) => {
|
|
25037
|
+
const registered = new Set((await readVoices(rt, dir)).speakers.map((v) => v.id));
|
|
25038
|
+
const speakers = [...plan4.clipOf].filter(([s, f]) => f === file && !registered.has(s)).map(([s]) => s);
|
|
25039
|
+
for (const speaker of speakers) {
|
|
25040
|
+
const clip11 = rt.path.resolve(dir, file);
|
|
25041
|
+
try {
|
|
25042
|
+
const profile2 = await registerVoice(rt, dir, speaker, clip11, "native-reference");
|
|
25043
|
+
await cutSample(rt, dir, profile2, { file: clip11, from: "clip" });
|
|
25044
|
+
notes2.push(file + ": the voice " + speaker + " speaks with here is now theirs: a sample of it (assets/voices/" + speaker + ".sample.wav) goes to their later clips as the reference sound, so they keep one voice.");
|
|
25045
|
+
} catch (e) {
|
|
25046
|
+
notes2.push(file + ": no voice sample could be cut from it for " + speaker + " (" + (e instanceof Error ? e.message : String(e)) + "); their later clips speak with the video model's own voice. To keep one voice, cut a sample from a clip in which they speak clearly: popost video voice sample <project> --speaker " + speaker + " --from <that clip>, after registering it from the same clip (popost video voice add <project> --speaker " + speaker + " --file <that clip> --mode native-reference).");
|
|
25047
|
+
}
|
|
25048
|
+
}
|
|
25049
|
+
return speakers;
|
|
25050
|
+
};
|
|
25051
|
+
}
|
|
25052
|
+
});
|
|
25053
|
+
|
|
24976
25054
|
// src/video/product/sheet.ts
|
|
24977
25055
|
var PRODUCT_FILE, PRODUCT_DIR, FACT_SOURCES, REQUIRED_FACTS, OPTIONAL_FACTS, FACTS, FACT_HELP, NO_LABEL, PICTURE_EXT, ID, tidy, clause, inferredFacts, inferredHash, confirmationOf, confirmLine, productBody, imageNames, productBlock, isFact, FIX_FACT, factProblems, lines, fileProblems, FACE_FIX, pictureProblems, productProblems, crossProblems, readProductSheet, blank2, skeleton;
|
|
24978
25056
|
var init_sheet3 = __esm({
|
|
@@ -25185,7 +25263,7 @@ var init_sheet3 = __esm({
|
|
|
25185
25263
|
});
|
|
25186
25264
|
|
|
25187
25265
|
// src/video/product/requests.ts
|
|
25188
|
-
var VIDEO, usesFrames, escape, mentions, shownProducts, picturesOf2, receiptFile, withProducts, DECLARE, INSTEAD, SEVERAL, LONG_PRODUCT_CLIP, shownProblems, PRODUCT_WORDS, PRODUCT_FILES, unsheeted, productRequestProblems, castPictureCount;
|
|
25266
|
+
var VIDEO, usesFrames, escape, mentions, shownProducts, picturesOf2, receiptFile, withProducts, DECLARE, INSTEAD, ASK_MODEL, SEVERAL, LONG_PRODUCT_CLIP, shownProblems, PRODUCT_WORDS, PRODUCT_FILES, unsheeted, productRequestProblems, castPictureCount;
|
|
25189
25267
|
var init_requests = __esm({
|
|
25190
25268
|
"src/video/product/requests.ts"() {
|
|
25191
25269
|
"use strict";
|
|
@@ -25217,6 +25295,7 @@ var init_requests = __esm({
|
|
|
25217
25295
|
};
|
|
25218
25296
|
DECLARE = 'Add "products": ["<id>"] with the id(s) from ' + PRODUCT_FILE + ` to every request that shows the product (the user's pictures and the product block then go with it), and "products": [] to a request that shows none.`;
|
|
25219
25297
|
INSTEAD = `make the shot from the real picture instead: a scene that moves the user's picture (a packshot, a close-up, a label shot), or a clip whose "firstFrame" is the user's picture or a still composed from it and listed under "stills" in ` + PRODUCT_FILE;
|
|
25298
|
+
ASK_MODEL = "set POPOST_VIDEO_MODEL only to a model the user names";
|
|
25220
25299
|
SEVERAL = /\bthen\b|\bafter that\b|hard cuts?|然后|接着|随后/gi;
|
|
25221
25300
|
LONG_PRODUCT_CLIP = 10;
|
|
25222
25301
|
shownProblems = async (rt, dir, r, at7, products, policy) => {
|
|
@@ -25231,7 +25310,7 @@ var init_requests = __esm({
|
|
|
25231
25310
|
if (r.continues !== void 0)
|
|
25232
25311
|
out2.push(warning(at7 + ".continues", "This clip shows the product (" + ids3 + ") and starts from the last frame of " + JSON.stringify(r.continues) + ", a generated frame: the product's pictures cannot go with it, and whatever that frame got wrong is carried on.", "Run the product check on " + JSON.stringify(r.continues) + " first and continue it only when its last frame shows the product as in the user's picture; otherwise make this part as its own clip with the pictures as references."));
|
|
25233
25312
|
if (policy.limits?.frames === false)
|
|
25234
|
-
out2.push(error(at7 + ".firstFrame", "The video model in use" + (policy.limits.model ? " (" + policy.limits.model + ")" : "") + " takes no first frame, and a clip from frames is the only way this request shows the product.", `Remove the frames so that the product's pictures go as references, or
|
|
25313
|
+
out2.push(error(at7 + ".firstFrame", "The video model in use" + (policy.limits.model ? " (" + policy.limits.model + ")" : "") + " takes no first frame, and a clip from frames is the only way this request shows the product.", `Remove the frames so that the product's pictures go as references, or ask the user whether to use a model that popost video generate --models lists with "frames": true (` + ASK_MODEL + ")."));
|
|
25235
25314
|
} else if (clip11 && policy.limits?.maxReferenceImages !== void 0) {
|
|
25236
25315
|
const max = policy.limits.maxReferenceImages;
|
|
25237
25316
|
const model = "The video model in use" + (policy.limits.model ? " (" + policy.limits.model + ")" : "");
|
|
@@ -25239,11 +25318,11 @@ var init_requests = __esm({
|
|
|
25239
25318
|
const cast = (r.cast ?? []).reduce((n, id2) => n + (policy.castPictures?.(id2) ?? 0), 0);
|
|
25240
25319
|
const all = picturesOf2(r, products).length + cast;
|
|
25241
25320
|
if (max === 0)
|
|
25242
|
-
out2.push(error(at7 + ".products", model + " takes no reference pictures, so it cannot be shown the product (" + ids3 + "): it would draw one from words.", '
|
|
25321
|
+
out2.push(error(at7 + ".products", model + " takes no reference pictures, so it cannot be shown the product (" + ids3 + "): it would draw one from words.", INSTEAD.charAt(0).toUpperCase() + INSTEAD.slice(1) + ', or ask the user whether to use a model that takes reference pictures (popost video generate --models lists "maxReferenceImages"; ' + ASK_MODEL + ")."));
|
|
25243
25322
|
else if (mine > max)
|
|
25244
|
-
out2.push(error(at7 + ".products", model + " takes " + max + " reference picture" + (max === 1 ? "" : "s") + ", and the user gave " + mine + " of the product (" + ids3 + "): every one of them goes with every clip that shows it.", "
|
|
25323
|
+
out2.push(error(at7 + ".products", model + " takes " + max + " reference picture" + (max === 1 ? "" : "s") + ", and the user gave " + mine + " of the product (" + ids3 + "): every one of them goes with every clip that shows it.", "Ask the user: which pictures to leave out (remove those from " + PRODUCT_FILE + " with their words; never choose for them), or a model that takes at least " + mine + " (popost video generate --models; " + ASK_MODEL + ")."));
|
|
25245
25324
|
else if (all > max)
|
|
25246
|
-
out2.push(error(at7 + ".images", model + " takes " + max + " reference picture" + (max === 1 ? "" : "s") + "; this request has " + all + ": " + mine + " of the product, " + cast + " of the cast and " + (all - mine - cast) + " of its own. The product's pictures always go.", 'Make room below them, in this order: remove pictures from "images" (' + (all - mine - cast) + "), then show fewer people with identity pictures in this clip, or split it so the product and the person are in separate clips; or
|
|
25325
|
+
out2.push(error(at7 + ".images", model + " takes " + max + " reference picture" + (max === 1 ? "" : "s") + "; this request has " + all + ": " + mine + " of the product, " + cast + " of the cast and " + (all - mine - cast) + " of its own. The product's pictures always go.", 'Make room below them, in this order: remove pictures from "images" (' + (all - mine - cast) + "), then show fewer people with identity pictures in this clip, or split it so the product and the person are in separate clips; or ask the user whether to use a model that takes " + all + " (popost video generate --models; " + ASK_MODEL + ")."));
|
|
25247
25326
|
}
|
|
25248
25327
|
const text13 = (r.prompt ?? "").match(SEVERAL)?.length ?? 0;
|
|
25249
25328
|
if (clip11 && (r.seconds ?? 0) >= LONG_PRODUCT_CLIP && text13 >= 1)
|
|
@@ -25306,8 +25385,219 @@ var init_requests = __esm({
|
|
|
25306
25385
|
}
|
|
25307
25386
|
});
|
|
25308
25387
|
|
|
25388
|
+
// src/video/generate/failure.ts
|
|
25389
|
+
var GenerationFailed, REASON_CHARS, failureOf6, REFUSED_REQUEST, SOUND_WORDS, OTHER_WORDS, refusedSound, withSound, failureKind, KEEP_MODEL, NEXT, nextAfter, WHAT, failureLine, KNOWN_FAILURE, failedProblem;
|
|
25390
|
+
var init_failure = __esm({
|
|
25391
|
+
"src/video/generate/failure.ts"() {
|
|
25392
|
+
"use strict";
|
|
25393
|
+
GenerationFailed = class extends Error {
|
|
25394
|
+
constructor(failure4, message2) {
|
|
25395
|
+
super(message2);
|
|
25396
|
+
this.failure = failure4;
|
|
25397
|
+
}
|
|
25398
|
+
failure;
|
|
25399
|
+
name = "GenerationFailed";
|
|
25400
|
+
};
|
|
25401
|
+
REASON_CHARS = 400;
|
|
25402
|
+
failureOf6 = (value) => {
|
|
25403
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
25404
|
+
const v = value;
|
|
25405
|
+
if (typeof v.code !== "string" || !v.code.trim()) return void 0;
|
|
25406
|
+
const refunded = typeof v.refundedCredits === "number" && v.refundedCredits > 0 ? v.refundedCredits : void 0;
|
|
25407
|
+
const reason2 = typeof v.reason === "string" && v.reason.trim() ? v.reason.trim().slice(0, REASON_CHARS) : void 0;
|
|
25408
|
+
return {
|
|
25409
|
+
code: v.code.trim(),
|
|
25410
|
+
...typeof v.retryable === "boolean" ? { retryable: v.retryable } : {},
|
|
25411
|
+
...reason2 ? { reason: reason2 } : {},
|
|
25412
|
+
...refunded !== void 0 ? { refundedCredits: refunded } : {},
|
|
25413
|
+
...v.sound === true ? { sound: true } : {}
|
|
25414
|
+
};
|
|
25415
|
+
};
|
|
25416
|
+
REFUSED_REQUEST = /* @__PURE__ */ new Set(["VIDEO_REQUEST_REJECTED", "VIDEO_OPTION_UNSUPPORTED"]);
|
|
25417
|
+
SOUND_WORDS = /\b(?:audio|sound|voice|speech)s?\b|audio_url|音频|声音|语音|音色|配音/i;
|
|
25418
|
+
OTHER_WORDS = /\b(?:image|picture|photo|frame|prompt|text)s?\b|image_url|video_url|图片|图像|画面|提示词|文本|文字/i;
|
|
25419
|
+
refusedSound = (f, hadSound) => f.code === "CONTENT_REJECTED" && (!!f.reason && SOUND_WORDS.test(f.reason) || hadSound && !(f.reason && OTHER_WORDS.test(f.reason)));
|
|
25420
|
+
withSound = (f, hadSound) => refusedSound(f, hadSound) ? { ...f, sound: true } : f;
|
|
25421
|
+
failureKind = (f) => {
|
|
25422
|
+
if (REFUSED_REQUEST.has(f.code)) return "request";
|
|
25423
|
+
if (f.code === "CONTENT_REJECTED") return f.sound ? "sound" : "content";
|
|
25424
|
+
if (f.code === "UPSTREAM_ERROR" || f.retryable === true) return "later";
|
|
25425
|
+
return f.retryable === false ? "request" : "other";
|
|
25426
|
+
};
|
|
25427
|
+
KEEP_MODEL = "Keep the model: another one is used only when the user names it.";
|
|
25428
|
+
NEXT = {
|
|
25429
|
+
request: "Running it again unchanged fails again. First change what the reason names: a reference picture or frame of a shape or size the model does not take, a reference sound or clip it does not take, or a setting it does not have (seconds, aspect ratio, resolution; popost video generate --models lists what the model takes). " + KEEP_MODEL,
|
|
25430
|
+
sound: "The model's content check refused the reference sound: the voice sample that keeps the speaker's voice the same in every clip. That changes how the video sounds, so stop and ask the user which they want: another voice sample (popost video voice sample with another stretch, or another recording of theirs) or another model (one they name). Do not leave the voice reference out or change the voice on your own: the clips would speak with different voices.",
|
|
25431
|
+
content: "The same request would be refused again. Change the wording of the prompt (for example, leave out the names of brands, characters and well-known works); ask the user before changing or leaving out a picture of theirs.",
|
|
25432
|
+
later: "It was a failure of the service, not of the request: the same request may pass when it is run again later (a new attempt, priced again).",
|
|
25433
|
+
other: "Read the reason; running the command again makes a new attempt, priced again."
|
|
25434
|
+
};
|
|
25435
|
+
nextAfter = (f) => NEXT[failureKind(f)];
|
|
25436
|
+
WHAT = {
|
|
25437
|
+
VIDEO_REQUEST_REJECTED: "the video model does not take this request as it is",
|
|
25438
|
+
VIDEO_OPTION_UNSUPPORTED: "the video model does not take this request as it is",
|
|
25439
|
+
CONTENT_REJECTED: "the model's content check refused it",
|
|
25440
|
+
UPSTREAM_ERROR: "the generation service failed for now"
|
|
25441
|
+
};
|
|
25442
|
+
failureLine = (f, o) => {
|
|
25443
|
+
const why = f.reason ?? (o.message?.trim().slice(0, REASON_CHARS) || void 0);
|
|
25444
|
+
const what = WHAT[f.code] ? WHAT[f.code] + (why ? " (" + why + ")" : "") + " [" + f.code + "]" : o.other;
|
|
25445
|
+
const money = o.charged === "refunded" ? "Its credits were refunded, so nothing was charged." : "Nothing was charged.";
|
|
25446
|
+
return "The clip could not be made: " + what + ". " + money + " " + nextAfter(f);
|
|
25447
|
+
};
|
|
25448
|
+
KNOWN_FAILURE = /\[(CONTENT_REJECTED|VIDEO_REQUEST_REJECTED|VIDEO_OPTION_UNSUPPORTED|UPSTREAM_ERROR)\]/;
|
|
25449
|
+
failedProblem = (m, hadSound) => {
|
|
25450
|
+
const named = m.error?.match(KNOWN_FAILURE)?.[1];
|
|
25451
|
+
const f = m.failure ?? (named ? withSound({ code: named }, hadSound) : void 0);
|
|
25452
|
+
const money = m.failure?.refundedCredits ? " Its " + m.failure.refundedCredits + " credits were refunded." : "";
|
|
25453
|
+
const message2 = m.failure?.reason ? "It could not be made [" + m.failure.code + "]: " + m.failure.reason + "." + money : "It could not be made: " + m.error;
|
|
25454
|
+
return { message: message2, fix: f ? nextAfter(f) : "Read the message; a request that was refused cost nothing. Run the command again to make only what is missing." };
|
|
25455
|
+
};
|
|
25456
|
+
}
|
|
25457
|
+
});
|
|
25458
|
+
|
|
25459
|
+
// src/video/generate/picture-fit.ts
|
|
25460
|
+
var DEFAULT_PICTURE_LIMITS, positive2, isBag, first, pair2, HOLDERS, MIN_RATIO2, MAX_RATIO, MIN_SIDE, MAX_SIDE2, statedIn, pictureLimitsOf, fitPlan, jpegOrientation, tiffOrientation, shownSize, size, ratioText, rangeText, fitText, fittedList, fitKey, BLUR_SHARE, FILL_BRIGHTNESS, fitArgs, decodedSize, fitPicture;
|
|
25461
|
+
var init_picture_fit = __esm({
|
|
25462
|
+
"src/video/generate/picture-fit.ts"() {
|
|
25463
|
+
"use strict";
|
|
25464
|
+
init_image();
|
|
25465
|
+
init_util();
|
|
25466
|
+
init_host();
|
|
25467
|
+
init_ffmpeg();
|
|
25468
|
+
DEFAULT_PICTURE_LIMITS = { minRatio: 0.4, maxRatio: 2.5, minSide: 300, maxSide: 6e3 };
|
|
25469
|
+
positive2 = (v) => {
|
|
25470
|
+
if (typeof v === "number" && Number.isFinite(v) && v > 0) return v;
|
|
25471
|
+
const m = typeof v === "string" ? /^\s*(\d+(?:\.\d+)?)\s*(?:[:/]\s*(\d+(?:\.\d+)?))?\s*$/.exec(v) : null;
|
|
25472
|
+
if (!m) return void 0;
|
|
25473
|
+
const value = m[2] === void 0 ? Number(m[1]) : Number(m[1]) / Number(m[2]);
|
|
25474
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
25475
|
+
};
|
|
25476
|
+
isBag = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
25477
|
+
first = (bag, names) => names.map((n) => positive2(bag[n])).find((v) => v !== void 0);
|
|
25478
|
+
pair2 = (v) => Array.isArray(v) && v.length === 2 ? [positive2(v[0]), positive2(v[1])] : isBag(v) ? [positive2(v.min), positive2(v.max)] : [void 0, void 0];
|
|
25479
|
+
HOLDERS = ["imageSize", "pictureLimits", "imageLimits", "referenceImageLimits", "pictures", "images"];
|
|
25480
|
+
MIN_RATIO2 = ["minRatio", "minAspectRatio", "minPictureRatio", "minImageRatio"];
|
|
25481
|
+
MAX_RATIO = ["maxRatio", "maxAspectRatio", "maxPictureRatio", "maxImageRatio"];
|
|
25482
|
+
MIN_SIDE = ["minSide", "minEdge", "minDimension", "minPictureSide", "minImageSide"];
|
|
25483
|
+
MAX_SIDE2 = ["maxSide", "maxEdge", "maxDimension", "maxPictureSide", "maxImageSide"];
|
|
25484
|
+
statedIn = (bag) => {
|
|
25485
|
+
const [ratioLow, ratioHigh] = pair2(bag.ratio ?? bag.aspectRatio ?? bag.ratioRange ?? bag.aspectRatioRange);
|
|
25486
|
+
const [sideLow, sideHigh] = pair2(bag.side ?? bag.sides ?? bag.sideRange);
|
|
25487
|
+
const minSide = first(bag, MIN_SIDE) ?? sideLow ?? (positive2(bag.minWidth) && positive2(bag.minHeight) ? Math.max(positive2(bag.minWidth) ?? 0, positive2(bag.minHeight) ?? 0) : void 0);
|
|
25488
|
+
const maxSide = first(bag, MAX_SIDE2) ?? sideHigh ?? (positive2(bag.maxWidth) && positive2(bag.maxHeight) ? Math.min(positive2(bag.maxWidth) ?? Infinity, positive2(bag.maxHeight) ?? Infinity) : void 0);
|
|
25489
|
+
const found = { minRatio: first(bag, MIN_RATIO2) ?? ratioLow, maxRatio: first(bag, MAX_RATIO) ?? ratioHigh, minSide, maxSide };
|
|
25490
|
+
return Object.fromEntries(Object.entries(found).filter(([, v]) => v !== void 0));
|
|
25491
|
+
};
|
|
25492
|
+
pictureLimitsOf = (model) => {
|
|
25493
|
+
if (!isBag(model)) return DEFAULT_PICTURE_LIMITS;
|
|
25494
|
+
const stated = [model, ...HOLDERS.map((h) => model[h]).filter(isBag)].reduce((acc, bag) => ({ ...statedIn(bag), ...acc }), {});
|
|
25495
|
+
const limits = { ...DEFAULT_PICTURE_LIMITS, ...stated };
|
|
25496
|
+
return limits.minRatio <= limits.maxRatio && limits.minSide <= limits.maxSide ? limits : DEFAULT_PICTURE_LIMITS;
|
|
25497
|
+
};
|
|
25498
|
+
fitPlan = (width, height, limits) => {
|
|
25499
|
+
const ratio3 = width / height;
|
|
25500
|
+
const wide = ratio3 < limits.minRatio ? height * limits.minRatio : width;
|
|
25501
|
+
const tall = ratio3 > limits.maxRatio ? width / limits.maxRatio : height;
|
|
25502
|
+
const [short3, long] = [Math.min(wide, tall), Math.max(wide, tall)];
|
|
25503
|
+
const scale = long > limits.maxSide ? limits.maxSide / long : short3 < limits.minSide ? limits.minSide / short3 : 1;
|
|
25504
|
+
if (scale === 1 && wide === width && tall === height) return void 0;
|
|
25505
|
+
const pw = Math.max(1, Math.round(width * scale));
|
|
25506
|
+
const ph = Math.max(1, Math.round(height * scale));
|
|
25507
|
+
let cw = pw / ph < limits.minRatio ? Math.ceil(ph * limits.minRatio - 1e-9) : pw;
|
|
25508
|
+
let ch = pw / ph > limits.maxRatio ? Math.ceil(pw / limits.maxRatio - 1e-9) : ph;
|
|
25509
|
+
if (cw < limits.minSide && cw >= limits.minSide - 1) cw = limits.minSide;
|
|
25510
|
+
if (ch < limits.minSide && ch >= limits.minSide - 1) ch = limits.minSide;
|
|
25511
|
+
return { from: [width, height], picture: [pw, ph], canvas: [cw, ch] };
|
|
25512
|
+
};
|
|
25513
|
+
jpegOrientation = (b) => {
|
|
25514
|
+
if (b[0] !== 255 || b[1] !== 216) return 1;
|
|
25515
|
+
for (let o = 2; o + 4 < b.length && b[o] === 255; ) {
|
|
25516
|
+
const marker = b[o + 1] ?? 0;
|
|
25517
|
+
const length2 = (b[o + 2] ?? 0) << 8 | (b[o + 3] ?? 0);
|
|
25518
|
+
if (marker === 218 || marker === 217) return 1;
|
|
25519
|
+
if (marker === 225 && String.fromCharCode(...b.subarray(o + 4, o + 10)) === "Exif\0\0") return tiffOrientation(b.subarray(o + 10, o + 2 + length2));
|
|
25520
|
+
o += 2 + length2;
|
|
25521
|
+
}
|
|
25522
|
+
return 1;
|
|
25523
|
+
};
|
|
25524
|
+
tiffOrientation = (t) => {
|
|
25525
|
+
const little = t[0] === 73;
|
|
25526
|
+
const u16 = (o) => little ? (t[o] ?? 0) | (t[o + 1] ?? 0) << 8 : (t[o] ?? 0) << 8 | (t[o + 1] ?? 0);
|
|
25527
|
+
const u322 = (o) => little ? u16(o) + u16(o + 2) * 65536 : u16(o) * 65536 + u16(o + 2);
|
|
25528
|
+
const ifd = u322(4);
|
|
25529
|
+
for (let i = 0, n = u16(ifd); i < n && ifd + 2 + i * 12 + 12 <= t.length; i++) {
|
|
25530
|
+
const entry2 = ifd + 2 + i * 12;
|
|
25531
|
+
if (u16(entry2) === 274) {
|
|
25532
|
+
const value = u16(entry2 + 8);
|
|
25533
|
+
return value >= 1 && value <= 8 ? value : 1;
|
|
25534
|
+
}
|
|
25535
|
+
}
|
|
25536
|
+
return 1;
|
|
25537
|
+
};
|
|
25538
|
+
shownSize = (bytes) => {
|
|
25539
|
+
try {
|
|
25540
|
+
const info = sniffImage(bytes);
|
|
25541
|
+
return info.format === "jpeg" && jpegOrientation(bytes) >= 5 ? [info.height, info.width] : [info.width, info.height];
|
|
25542
|
+
} catch (e) {
|
|
25543
|
+
if (e instanceof ImageError) return void 0;
|
|
25544
|
+
throw e;
|
|
25545
|
+
}
|
|
25546
|
+
};
|
|
25547
|
+
size = (s) => s[0] + "x" + s[1];
|
|
25548
|
+
ratioText = (s) => String(Math.round(s[0] / s[1] * 1e3) / 1e3);
|
|
25549
|
+
rangeText = (limits) => "the video model takes width/height from " + limits.minRatio + " to " + limits.maxRatio + " and sides of " + limits.minSide + " to " + limits.maxSide + " px";
|
|
25550
|
+
fitText = (plan4, limits) => {
|
|
25551
|
+
const [from, picture3, canvas] = [plan4.from, plan4.picture, plan4.canvas];
|
|
25552
|
+
const scaled2 = picture3[0] === from[0] && picture3[1] === from[1] ? "" : (picture3[0] > from[0] ? "scaled up" : "scaled down") + " to " + size(picture3);
|
|
25553
|
+
const padded = canvas[0] === picture3[0] && canvas[1] === picture3[1] ? "" : "padded " + (canvas[0] > picture3[0] ? "left and right" : "above and below") + " to " + size(canvas) + " (width/height " + ratioText(canvas) + "; it was " + ratioText(from) + ") with a blurred, darkened copy of the picture";
|
|
25554
|
+
return [scaled2, padded].filter(Boolean).join(", then ") + "; nothing of the picture was cut (" + rangeText(limits) + ")";
|
|
25555
|
+
};
|
|
25556
|
+
fittedList = (value) => {
|
|
25557
|
+
if (!Array.isArray(value)) return void 0;
|
|
25558
|
+
const text13 = (v) => typeof v === "string" ? v.slice(0, 600) : void 0;
|
|
25559
|
+
const list7 = value.flatMap((v) => {
|
|
25560
|
+
if (!isBag(v)) return [];
|
|
25561
|
+
const [file, was, now, how] = [text13(v.file), text13(v.was), text13(v.now), text13(v.how)];
|
|
25562
|
+
return file && was && now && how ? [{ file, was, now, how }] : [];
|
|
25563
|
+
});
|
|
25564
|
+
return list7.length ? list7 : void 0;
|
|
25565
|
+
};
|
|
25566
|
+
fitKey = (plan4) => "fit1:" + size(plan4.picture) + "@" + size(plan4.canvas);
|
|
25567
|
+
BLUR_SHARE = 1 / 24;
|
|
25568
|
+
FILL_BRIGHTNESS = 0.5;
|
|
25569
|
+
fitArgs = (src, out2, plan4) => {
|
|
25570
|
+
const [[w, h], [pw, ph], [cw, ch]] = [plan4.from, plan4.picture, plan4.canvas];
|
|
25571
|
+
const quality = out2.endsWith(".png") ? [] : ["-q:v", "2"];
|
|
25572
|
+
if (cw === pw && ch === ph) return ["-y", "-loglevel", "error", "-i", src, "-vf", "scale=" + pw + ":" + ph + ":flags=lanczos", "-frames:v", "1", ...quality, out2];
|
|
25573
|
+
const cover = Math.max(cw / w, ch / h);
|
|
25574
|
+
const [bw, bh] = [Math.max(cw, Math.ceil(w * cover)), Math.max(ch, Math.ceil(h * cover))];
|
|
25575
|
+
const sigma = Math.min(1024, Math.max(4, Math.round(Math.max(cw, ch) * BLUR_SHARE)));
|
|
25576
|
+
const dim = "colorchannelmixer=rr=" + FILL_BRIGHTNESS + ":gg=" + FILL_BRIGHTNESS + ":bb=" + FILL_BRIGHTNESS;
|
|
25577
|
+
const graph = "[0:v]split=2[a][b];[a]format=rgb24,scale=" + bw + ":" + bh + ":flags=bilinear,crop=" + cw + ":" + ch + ",gblur=sigma=" + sigma + "," + dim + "[bg];[b]scale=" + pw + ":" + ph + ":flags=lanczos[fg];[bg][fg]overlay=" + Math.floor((cw - pw) / 2) + ":" + Math.floor((ch - ph) / 2) + ":format=rgb,format=rgb24[out]";
|
|
25578
|
+
return ["-y", "-loglevel", "error", "-i", src, "-filter_complex", graph, "-map", "[out]", "-frames:v", "1", ...quality, out2];
|
|
25579
|
+
};
|
|
25580
|
+
decodedSize = async (rt, src) => {
|
|
25581
|
+
const r = await runFfmpegOk(rt, ["-i", src, "-vf", "showinfo", "-frames:v", "1", "-f", "null", "-"]);
|
|
25582
|
+
const m = /\bs:(\d+)x(\d+)\b/.exec(r.stderr);
|
|
25583
|
+
return m ? [Number(m[1]), Number(m[2])] : void 0;
|
|
25584
|
+
};
|
|
25585
|
+
fitPicture = async (rt, src, mimeType2, plan4, limits) => {
|
|
25586
|
+
const decoded = await decodedSize(rt, src);
|
|
25587
|
+
const used = decoded && (decoded[0] !== plan4.from[0] || decoded[1] !== plan4.from[1]) ? fitPlan(decoded[0], decoded[1], limits) ?? plan4 : plan4;
|
|
25588
|
+
const png2 = mimeType2 === "image/png";
|
|
25589
|
+
return withTempDir(rt, "popost-fit-", async (dir) => {
|
|
25590
|
+
const out2 = rt.path.join(dir, png2 ? "fitted.png" : "fitted.jpg");
|
|
25591
|
+
await runFfmpegOk(rt, fitArgs(src, out2, used));
|
|
25592
|
+
const bytes = await rt.fs.readFile(out2);
|
|
25593
|
+
return { bytes, mimeType: png2 ? "image/png" : "image/jpeg", sha256: sha256(bytes) };
|
|
25594
|
+
});
|
|
25595
|
+
};
|
|
25596
|
+
}
|
|
25597
|
+
});
|
|
25598
|
+
|
|
25309
25599
|
// src/video/generate/index.ts
|
|
25310
|
-
var ConfirmNeeded, CONFIRM_EXIT2, StillMaking, PENDING_EXIT2, run3, lastObject, isPrice, isPending, commandGenerator, VIDEOS, PICTURES, NOTES, REFERENCES, LISTS, ASPECT5, extOf, inputKey, kindOf3, FRAME_FIX, frameProblems, SHORT_CLIP, MANY_SHORT, groupingAdvice, checkRequests, beatsSaid, saidBefore, ANCHOR_FILE, CLOSE, usesFrames2, takesAnchor, anchorIndex, grabAnchor, NOTHING_ADDED, anchorSentence, anchored, readNotes, inOrder, lastFrameFile, lastFrameOf,
|
|
25600
|
+
var ConfirmNeeded, CONFIRM_EXIT2, StillMaking, PENDING_EXIT2, run3, lastObject, isPrice, isPending, withFitted, commandGenerator, VIDEOS, PICTURES, NOTES, REFERENCES, LISTS, ASPECT5, extOf, inputKey, kindOf3, FRAME_FIX, frameProblems, SHORT_CLIP, MANY_SHORT, groupingAdvice, checkRequests, beatsSaid, saidBefore, ANCHOR_FILE, CLOSE, usesFrames2, takesAnchor, anchorIndex, grabAnchor, NOTHING_ADDED, anchorSentence, anchored, readNotes, inOrder, inProject2, lastFrameFile, lastFrameOf, makeMaterials, makeMaterialsIn;
|
|
25311
25601
|
var init_generate = __esm({
|
|
25312
25602
|
"src/video/generate/index.ts"() {
|
|
25313
25603
|
"use strict";
|
|
@@ -25332,8 +25622,11 @@ var init_generate = __esm({
|
|
|
25332
25622
|
init_modes();
|
|
25333
25623
|
init_sample();
|
|
25334
25624
|
init_clip_sound();
|
|
25625
|
+
init_voice_clips();
|
|
25335
25626
|
init_requests();
|
|
25336
25627
|
init_sheet3();
|
|
25628
|
+
init_failure();
|
|
25629
|
+
init_picture_fit();
|
|
25337
25630
|
ConfirmNeeded = class extends Error {
|
|
25338
25631
|
constructor(confirm4, message2) {
|
|
25339
25632
|
super(message2);
|
|
@@ -25368,6 +25661,10 @@ var init_generate = __esm({
|
|
|
25368
25661
|
};
|
|
25369
25662
|
isPrice = (value) => value !== null && typeof value === "object" && typeof value.credits === "number";
|
|
25370
25663
|
isPending = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
25664
|
+
withFitted = ({ fitted: listed3, ...rest }) => {
|
|
25665
|
+
const fitted = fittedList(listed3);
|
|
25666
|
+
return { ...rest, ...fitted ? { fitted } : {} };
|
|
25667
|
+
};
|
|
25371
25668
|
commandGenerator = (rt) => {
|
|
25372
25669
|
const words = toolCommand(rt, "POPOST_GEN_CMD");
|
|
25373
25670
|
if (!words) return void 0;
|
|
@@ -25379,11 +25676,13 @@ var init_generate = __esm({
|
|
|
25379
25676
|
const said = lastObject(r.stdout);
|
|
25380
25677
|
const why = r.stderr.trim().split("\n").slice(-2).join(" | ");
|
|
25381
25678
|
if (r.code === CONFIRM_EXIT2 && isPrice(said.confirm)) throw new ConfirmNeeded(said.confirm, why || "It costs " + said.confirm.credits + " credits and needs the user's agreement first; nothing was charged.");
|
|
25382
|
-
if (r.code === PENDING_EXIT2 && isPending(said.pending)) throw new StillMaking(said.pending, why || "It is still being made.");
|
|
25679
|
+
if (r.code === PENDING_EXIT2 && isPending(said.pending)) throw new StillMaking(withFitted(said.pending), why || "It is still being made.");
|
|
25680
|
+
const failure4 = r.code !== 0 ? failureOf6(said.error) : void 0;
|
|
25681
|
+
if (failure4) throw new GenerationFailed(failure4, why || "The generator exited with " + r.code + " [" + failure4.code + "].");
|
|
25383
25682
|
if (r.code !== 0) throw new Error(why || "The generator exited with " + r.code + ".");
|
|
25384
25683
|
const count5 = (v) => typeof v === "number" ? v : void 0;
|
|
25385
|
-
const [credits2, chargedCredits] = [count5(said.credits), count5(said.chargedCredits)];
|
|
25386
|
-
return { ...credits2 !== void 0 ? { credits: credits2 } : {}, ...chargedCredits !== void 0 ? { chargedCredits } : {}, ...typeof said.key === "string" ? { key: said.key } : {}, ...typeof said.task === "string" ? { task: said.task } : {} };
|
|
25684
|
+
const [credits2, chargedCredits, fitted] = [count5(said.credits), count5(said.chargedCredits), fittedList(said.fitted)];
|
|
25685
|
+
return { ...credits2 !== void 0 ? { credits: credits2 } : {}, ...chargedCredits !== void 0 ? { chargedCredits } : {}, ...typeof said.key === "string" ? { key: said.key } : {}, ...typeof said.task === "string" ? { task: said.task } : {}, ...fitted ? { fitted } : {} };
|
|
25387
25686
|
})
|
|
25388
25687
|
};
|
|
25389
25688
|
};
|
|
@@ -25564,11 +25863,11 @@ var init_generate = __esm({
|
|
|
25564
25863
|
return { ...r, images, prompt: r.prompt.trim() + " " + anchorSentence(images.length, source2, person) + (product ? pl(" The product follows its own pictures named above, not @image" + images.length + ".", "\u5546\u54C1\u4EE5\u4E0A\u9762\u6307\u660E\u7684\u5546\u54C1\u56FE\u7247\u4E3A\u51C6\uFF0C\u4E0D\u4EE5 @image" + images.length + " \u4E3A\u51C6\u3002") : "") };
|
|
25565
25864
|
};
|
|
25566
25865
|
readNotes = (rt, dir) => rt.fs.readText(rt.path.join(dir, NOTES)).then((t) => JSON.parse(t), () => ({}));
|
|
25567
|
-
inOrder = (requests,
|
|
25568
|
-
const out2 =
|
|
25866
|
+
inOrder = (requests, first2) => {
|
|
25867
|
+
const out2 = first2 >= 0 ? [requests[first2]] : [];
|
|
25569
25868
|
const listed3 = new Set(requests.map((r) => r.file));
|
|
25570
25869
|
const placed2 = new Set(out2.map((r) => r.file));
|
|
25571
|
-
let left = requests.filter((_r, i) => i !==
|
|
25870
|
+
let left = requests.filter((_r, i) => i !== first2);
|
|
25572
25871
|
while (left.length) {
|
|
25573
25872
|
const ready = left.filter((r) => !r.continues || placed2.has(r.continues) || !listed3.has(r.continues));
|
|
25574
25873
|
for (const r of ready.length ? ready : left) {
|
|
@@ -25579,6 +25878,10 @@ var init_generate = __esm({
|
|
|
25579
25878
|
}
|
|
25580
25879
|
return out2;
|
|
25581
25880
|
};
|
|
25881
|
+
inProject2 = (rt, dir, fitted) => fitted.map((f) => {
|
|
25882
|
+
const inside6 = rt.path.relative(dir, f.file);
|
|
25883
|
+
return inside6 && !inside6.startsWith("..") && !rt.path.isAbsolute(inside6) ? { ...f, file: inside6.split(rt.path.sep).join("/") } : f;
|
|
25884
|
+
});
|
|
25582
25885
|
lastFrameFile = (clip11) => clip11.slice(0, clip11.length - extOf(clip11).length) + ".last.png";
|
|
25583
25886
|
lastFrameOf = async (rt, dir, clip11, frame2) => {
|
|
25584
25887
|
const from = rt.path.resolve(dir, clip11);
|
|
@@ -25589,7 +25892,6 @@ var init_generate = __esm({
|
|
|
25589
25892
|
await extractFrame(rt, from, index, to);
|
|
25590
25893
|
return to;
|
|
25591
25894
|
};
|
|
25592
|
-
afterFailure = (message2) => message2.includes("[CONTENT_REJECTED]") ? "Its content was refused, and the same request would be refused again (it cost nothing). Change the prompt or the reference pictures of this request (for example, leave out the names of brands, characters and well-known works, and pictures of them), then run the command again." : "Read the message; a request that was refused cost nothing. Run the command again to make only what is missing.";
|
|
25593
25895
|
makeMaterials = async (rt, o) => withPromptLang(o.lang ?? await readProjectLang(rt, o.dir), o.policy ?? "user", () => makeMaterialsIn(rt, o));
|
|
25594
25896
|
makeMaterialsIn = async (rt, o) => {
|
|
25595
25897
|
const replication = await materialReplicationProblems(rt, o.dir, o.requests);
|
|
@@ -25607,7 +25909,6 @@ var init_generate = __esm({
|
|
|
25607
25909
|
said.push(...sound2.notes);
|
|
25608
25910
|
const locked = /* @__PURE__ */ new Map();
|
|
25609
25911
|
const voices = /* @__PURE__ */ new Map();
|
|
25610
|
-
const spoken = /* @__PURE__ */ new Map();
|
|
25611
25912
|
const uses = /* @__PURE__ */ new Map();
|
|
25612
25913
|
for (const r of o.requests) for (const id2 of r.cast ?? []) uses.set(id2, (uses.get(id2) ?? 0) + 1);
|
|
25613
25914
|
for (const r of o.requests) if (r.cast?.length) {
|
|
@@ -25624,23 +25925,8 @@ var init_generate = __esm({
|
|
|
25624
25925
|
problems2.push(error(r.file + ".cast", String(e), "Complete every identity image before generating any clip."));
|
|
25625
25926
|
}
|
|
25626
25927
|
}
|
|
25627
|
-
for (const r of o.requests) if (r.speech) {
|
|
25928
|
+
for (const r of o.requests) if (r.speech && r.speech.mode !== "native") {
|
|
25628
25929
|
const speaker = speakersOf(r.speech)[0] ?? "";
|
|
25629
|
-
if (r.speech.mode === "native") {
|
|
25630
|
-
const refs = [];
|
|
25631
|
-
for (const id2 of speakersOf(r.speech)) {
|
|
25632
|
-
const profile2 = await voiceProfile(rt, o.dir, id2).catch(() => void 0);
|
|
25633
|
-
if (profile2) refs.push({ id: id2, profile: profile2 });
|
|
25634
|
-
}
|
|
25635
|
-
if (!refs.length) continue;
|
|
25636
|
-
if (!usesFrames2(r)) {
|
|
25637
|
-
spoken.set(r.file, refs);
|
|
25638
|
-
if (refs[0]?.id === speaker) voices.set(r.file, refs[0].profile);
|
|
25639
|
-
continue;
|
|
25640
|
-
}
|
|
25641
|
-
said.push(r.file + ": " + refs.map((v) => v.id).join(", ") + " speak" + (refs.length === 1 ? "s" : "") + " with the video model's own voice; the voice registered for the project is not passed as a reference (this clip starts from a frame, and a clip made from frames takes no references). Listen to the clip beside the voice-over.");
|
|
25642
|
-
continue;
|
|
25643
|
-
}
|
|
25644
25930
|
try {
|
|
25645
25931
|
const profile2 = await voiceProfile(rt, o.dir, speaker);
|
|
25646
25932
|
if (!profile2) continue;
|
|
@@ -25665,19 +25951,21 @@ var init_generate = __esm({
|
|
|
25665
25951
|
const materials2 = [];
|
|
25666
25952
|
const takers = o.requests.filter(takesAnchor).length;
|
|
25667
25953
|
const fromClip = !o.picture && o.anchor !== false && takers >= (o.anchor ? 1 : 2);
|
|
25668
|
-
const
|
|
25669
|
-
const order = inOrder(o.requests,
|
|
25670
|
-
const anchorFile =
|
|
25954
|
+
const first2 = fromClip ? anchorIndex(o.requests) : -1;
|
|
25955
|
+
const order = inOrder(o.requests, first2);
|
|
25956
|
+
const anchorFile = first2 >= 0 ? o.requests[first2].file : void 0;
|
|
25957
|
+
const voicePlan = planVoiceClips(order, new Set((await readVoices(rt, o.dir).catch(() => ({ speakers: [] }))).speakers.map((v) => v.id)), (r) => kindOf3(r.file) === "video" && !usesFrames2(r));
|
|
25958
|
+
const settled2 = /* @__PURE__ */ new Set(), voiceClipFiles = new Set(voicePlan.clipOf.values());
|
|
25671
25959
|
const source2 = o.picture ? o.picture.person ? "character" : "image" : fromClip ? "clip" : void 0;
|
|
25672
25960
|
let picture3 = o.picture?.file;
|
|
25673
25961
|
const absent2 = /* @__PURE__ */ new Map();
|
|
25674
25962
|
for (const [i, original] of order.entries()) {
|
|
25675
25963
|
const cast = locked.get(original.file);
|
|
25676
|
-
const
|
|
25964
|
+
const refs = original.speech?.mode === "native" ? await clipVoices(rt, o.dir, original, usesFrames2(original), said) : [];
|
|
25965
|
+
const voice2 = voices.get(original.file) ?? (original.speech && refs[0]?.id === speakersOf(original.speech)[0] ? refs[0]?.profile : void 0);
|
|
25677
25966
|
const shown3 = withProducts(original, sheet4.sheet);
|
|
25678
25967
|
const base = shown3?.request ?? original;
|
|
25679
25968
|
const withCast = cast ? { ...base, ...!usesFrames2(base) ? { images: [...base.images ?? [], ...cast.images] } : {}, prompt: base.prompt + " " + cast.instruction } : base;
|
|
25680
|
-
const refs = original.speech?.mode === "native" ? spoken.get(original.file) ?? [] : [];
|
|
25681
25969
|
const { ids: ids3, samples } = await speakerSamples(rt, o.dir, original.file, refs, said);
|
|
25682
25970
|
const asked3 = ids3.length ? { ...withCast, audios: [...withCast.audios ?? [], ...samples], prompt: withCast.prompt + VOICE_NAMED(ids3, (withCast.audios?.length ?? 0) + 1) } : withCast;
|
|
25683
25971
|
const sent = isDialogue(original.speech) ? timedDialogue(original.speech, o.times) : original.speech;
|
|
@@ -25690,20 +25978,20 @@ var init_generate = __esm({
|
|
|
25690
25978
|
cast?.legacyInstructions?.map((instruction) => ({ ...signed(asked3), prompt: original.prompt + " " + instruction + (ids3.length ? VOICE_NAMED(ids3, (withCast.audios?.length ?? 0) + 1) : "") })) ?? []
|
|
25691
25979
|
);
|
|
25692
25980
|
if (refs.length) {
|
|
25693
|
-
const
|
|
25694
|
-
const before2 = { ...withCast, audios: [...withCast.audios ?? [],
|
|
25981
|
+
const first3 = refs[0].profile;
|
|
25982
|
+
const before2 = { ...withCast, audios: [...withCast.audios ?? [], first3.reference], prompt: withCast.prompt + " @audio" + ((withCast.audios?.length ?? 0) + 1) + " defines the voice identity and timbre only. Speak the exact new dialogue with that voice, never the reference recording\u2019s words. Keep the speaker\u2019s voice stable across all shots." };
|
|
25695
25983
|
signatures.push(
|
|
25696
25984
|
...materialSignatures(
|
|
25697
|
-
{ request: signed(before2), voiceHash:
|
|
25985
|
+
{ request: signed(before2), voiceHash: first3.sha256, dependencies: await dependenciesOf(before2), ...rest },
|
|
25698
25986
|
cast?.legacyInstructions?.map((instruction) => ({ ...signed(before2), prompt: original.prompt + " " + instruction + before2.prompt.slice(withCast.prompt.length) })) ?? []
|
|
25699
25987
|
),
|
|
25700
25988
|
...materialSignatures({ request: signed(withCast), dependencies: await dependenciesOf(withCast), ...rest }, cast?.legacyInstructions?.map((instruction) => ({ ...signed(withCast), prompt: original.prompt + " " + instruction })) ?? [])
|
|
25701
25989
|
);
|
|
25702
25990
|
}
|
|
25703
25991
|
const signature2 = signatures[0];
|
|
25704
|
-
const isAnchor =
|
|
25992
|
+
const isAnchor = first2 >= 0 && i === 0;
|
|
25705
25993
|
const takes = source2 !== void 0 && takesAnchor(asked3) && !isAnchor;
|
|
25706
|
-
const needs = [...takes && anchorFile ? [anchorFile] : [], ...asked3.continues ? [asked3.continues] : []];
|
|
25994
|
+
const needs = [...takes && anchorFile ? [anchorFile] : [], ...asked3.continues ? [asked3.continues] : [], ...voiceClipsAwaited(voicePlan, asked3.file, settled2)];
|
|
25707
25995
|
const kind = kindOf3(asked3.file);
|
|
25708
25996
|
const mode = sound2.modeOf(original);
|
|
25709
25997
|
const basis = mode ? sound2.basisOf(original) : void 0;
|
|
@@ -25778,6 +26066,7 @@ var init_generate = __esm({
|
|
|
25778
26066
|
entry2 = { ...entry2, receipt };
|
|
25779
26067
|
}
|
|
25780
26068
|
if (made.task) entry2 = { ...entry2, task: made.task };
|
|
26069
|
+
if (made.fitted) entry2 = { ...entry2, fitted: inProject2(rt, o.dir, made.fitted) };
|
|
25781
26070
|
if (mode) await writeModeReceipt(rt, target2, { sound: mode, ...basis ? { clipMusic: basis } : {}, ...stripped ? { stripped: true } : {} });
|
|
25782
26071
|
if (asked3.speech) {
|
|
25783
26072
|
for (const ext of [".speech.wav", ".speech.json"]) if (await exists4(partial + ext)) await rt.fs.rename(partial + ext, target2 + ext);
|
|
@@ -25791,11 +26080,11 @@ var init_generate = __esm({
|
|
|
25791
26080
|
if (e instanceof StillMaking) {
|
|
25792
26081
|
absent2.set(asked3.file, "pending");
|
|
25793
26082
|
const charged = e.pending.chargedCredits;
|
|
25794
|
-
materials2.push({ ...entry2, pending: true, ...e.pending.task ? { task: e.pending.task } : {}, ...charged !== void 0 ? { chargedCredits: charged } : {} });
|
|
26083
|
+
materials2.push({ ...entry2, pending: true, ...e.pending.task ? { task: e.pending.task } : {}, ...charged !== void 0 ? { chargedCredits: charged } : {}, ...e.pending.fitted ? { fitted: inProject2(rt, o.dir, e.pending.fitted) } : {} });
|
|
25795
26084
|
continue;
|
|
25796
26085
|
}
|
|
25797
26086
|
absent2.set(asked3.file, e instanceof ConfirmNeeded ? "priced" : "failed");
|
|
25798
|
-
materials2.push({ ...entry2, error: e instanceof Error ? e.message : String(e), ...e instanceof ConfirmNeeded ? { confirm: e.confirm } : {}, ...priceOnly ? { waiting: true, waitsFor: priced } : {} });
|
|
26087
|
+
materials2.push({ ...entry2, error: e instanceof Error ? e.message : String(e), ...e instanceof ConfirmNeeded ? { confirm: e.confirm } : {}, ...e instanceof GenerationFailed ? { failure: withSound(e.failure, (asked3.audios?.length ?? 0) > 0) } : {}, ...priceOnly ? { waiting: true, waitsFor: priced } : {} });
|
|
25799
26088
|
continue;
|
|
25800
26089
|
}
|
|
25801
26090
|
}
|
|
@@ -25814,18 +26103,24 @@ var init_generate = __esm({
|
|
|
25814
26103
|
else absent2.set(asked3.file, "failed");
|
|
25815
26104
|
entry2 = { ...entry2, anchor: true };
|
|
25816
26105
|
}
|
|
26106
|
+
if (voiceClipFiles.has(asked3.file)) for (const s of await adoptClipVoice(rt, o.dir, voicePlan, asked3.file, said)) settled2.add(s);
|
|
25817
26107
|
notes2[asked3.file] = asked3.note ?? asked3.prompt;
|
|
25818
26108
|
await rt.fs.writeFile(rt.path.join(o.dir, NOTES), JSON.stringify(notes2, null, 1) + "\n");
|
|
25819
26109
|
materials2.push(entry2);
|
|
25820
26110
|
}
|
|
25821
|
-
const
|
|
26111
|
+
const failedError = (m) => {
|
|
26112
|
+
const request = o.requests.find((r) => r.file === m.file);
|
|
26113
|
+
const { message: message2, fix: fix2 } = failedProblem(m, (request?.audios?.length ?? 0) > 0);
|
|
26114
|
+
return error(m.file, message2, fix2 + (source2 && m.file !== anchorFile && request && takesAnchor(request) ? " It was sent with the anchor picture as a reference picture: a generator that takes none needs --no-anchor." : ""));
|
|
26115
|
+
};
|
|
26116
|
+
const why = (m) => m.waitsFor === anchorFile && !o.requests.some((r) => r.file === m.file && r.continues === m.waitsFor) ? "a frame of it goes to this clip as a reference picture, so that the clips show the same person, product and place" : voiceClipFiles.has(m.waitsFor ?? "") ? "the voice its speaker has there goes to this clip as the reference sound, so that the speaker keeps one voice" : "this clip starts from its last frame";
|
|
25822
26117
|
const failed4 = materials2.filter((m) => m.error).map(
|
|
25823
|
-
(m) => m.confirm ? m.confirm.reason === "unplanned" ? error(m.file, "It was not made: it is outside the recorded clip plan and costs " + m.confirm.credits + " credits. Nothing was charged for it.", unplannedNext(m.confirm.clip?.key)) : error(m.file, "It was not made: it costs " + m.confirm.credits + " credits, and the user has not agreed to that price. Nothing was charged.", "Show the user the price with what it buys (confirm has the total and each clip's model, resolution, seconds and aspect ratio). Only after they agree, or when it fits what is left of the agreed budget, run again with --confirm --max-credits N.") :
|
|
26118
|
+
(m) => m.confirm ? m.confirm.reason === "unplanned" ? error(m.file, "It was not made: it is outside the recorded clip plan and costs " + m.confirm.credits + " credits. Nothing was charged for it.", unplannedNext(m.confirm.clip?.key)) : error(m.file, "It was not made: it costs " + m.confirm.credits + " credits, and the user has not agreed to that price. Nothing was charged.", "Show the user the price with what it buys (confirm has the total and each clip's model, resolution, seconds and aspect ratio). Only after they agree, or when it fits what is left of the agreed budget, run again with --confirm --max-credits N.") : failedError(m)
|
|
25824
26119
|
);
|
|
25825
26120
|
const held = materials2.filter((m) => m.waiting && !m.confirm && !m.queued).map((m) => error(
|
|
25826
26121
|
m.file,
|
|
25827
26122
|
"It was not sent: it waits for " + m.waitsFor + " (" + why(m) + "), and that clip is not there" + (materials2.some((x2) => x2.file === m.waitsFor && !x2.error && !x2.waiting) ? " as a file a frame can be read from" : "") + ". Nothing was charged for it.",
|
|
25828
|
-
"Get " + m.waitsFor + " made first (its own problem says how; a file no frame can be read from is deleted and made again), then run the command again." + (m.waitsFor === anchorFile ? " --no-anchor makes the clips now, without a shared picture." : "")
|
|
26123
|
+
"Get " + m.waitsFor + " made first (its own problem says how; a file no frame can be read from is deleted and made again), then run the command again." + (m.waitsFor === anchorFile ? " --no-anchor makes the clips now, without a shared picture." : "") + (voiceClipFiles.has(m.waitsFor ?? "") ? " Or give the speaker a voice first (popost video voice add <project> --speaker <id> --file <a recording or a clip of theirs> --mode native-reference)." : "")
|
|
25829
26124
|
));
|
|
25830
26125
|
const loose = materials2.filter((m) => m.unanchored).map((m) => warning(m.file, "It was made without " + (o.requests.some((r) => r.file === m.file && r.continues) ? "the frame it should start from" : "the anchor picture") + ': the generator was asked for its price only ("priceOnly": true in the request) while ' + m.waitsFor + " waited for the user's agreement, and made the clip.", "Look at it beside the other clips; when it does not match them, delete the file and run the command again once " + m.waitsFor + " exists."));
|
|
25831
26126
|
const asked2 = materials2.filter((m) => m.confirm);
|
|
@@ -25942,8 +26237,8 @@ var init_record2 = __esm({
|
|
|
25942
26237
|
block;
|
|
25943
26238
|
name = "InputsPending";
|
|
25944
26239
|
};
|
|
25945
|
-
holdVoice = async (rt, dir, project,
|
|
25946
|
-
if (!
|
|
26240
|
+
holdVoice = async (rt, dir, project, paying2, o) => {
|
|
26241
|
+
if (!paying2) return;
|
|
25947
26242
|
const held = await voicePending(rt, dir, o);
|
|
25948
26243
|
if (!held) return;
|
|
25949
26244
|
const block = confirmBlock(rt, dir, await readInputs(rt, dir), held.pending, project);
|
|
@@ -26023,8 +26318,8 @@ var init_shared = __esm({
|
|
|
26023
26318
|
const file = args2.string(option);
|
|
26024
26319
|
const data = file ? JSON.parse(await rt.fs.readText(userPath(rt, file))) : void 0;
|
|
26025
26320
|
const captions = data !== null && typeof data === "object" ? data.captions : void 0;
|
|
26026
|
-
const
|
|
26027
|
-
return typeof
|
|
26321
|
+
const first2 = Array.isArray(captions) ? captions.find((c) => typeof c === "string" && c.trim()) : void 0;
|
|
26322
|
+
return typeof first2 === "string" ? firstWords(first2.replace(/\*/g, "")) : void 0;
|
|
26028
26323
|
};
|
|
26029
26324
|
userPath = (rt, p) => rt.path.resolve(rt.cwd, p);
|
|
26030
26325
|
}
|
|
@@ -26811,10 +27106,10 @@ var init_carry = __esm({
|
|
|
26811
27106
|
const whole2 = numbered2.shots[j];
|
|
26812
27107
|
const r = e.shots.find((s) => s.shot === j + 1);
|
|
26813
27108
|
if (!x2 || !whole2 || !r) return shot;
|
|
26814
|
-
const
|
|
26815
|
-
const effect =
|
|
27109
|
+
const first2 = x2.start === whole2.start;
|
|
27110
|
+
const effect = first2 ? shotEffect(e, numbered2, j, ratio3, picture3) : void 0;
|
|
26816
27111
|
const { in: _measured, ...rest } = shot;
|
|
26817
|
-
const read2 =
|
|
27112
|
+
const read2 = first2 ? r.transitionIn : void 0;
|
|
26818
27113
|
const corrected = read2 && read2.kind !== "custom" ? read2.kind === "cut" ? rest : {
|
|
26819
27114
|
...rest,
|
|
26820
27115
|
in: {
|
|
@@ -26900,15 +27195,15 @@ var init_wav = __esm({
|
|
|
26900
27195
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
26901
27196
|
let fmt;
|
|
26902
27197
|
for (let at7 = 12; at7 + 8 <= bytes.length; ) {
|
|
26903
|
-
const id2 = tag2(bytes, at7),
|
|
26904
|
-
if (id2 === "fmt " &&
|
|
27198
|
+
const id2 = tag2(bytes, at7), size2 = view.getUint32(at7 + 4, true), body = at7 + 8;
|
|
27199
|
+
if (id2 === "fmt " && size2 >= 16 && body + 16 <= bytes.length)
|
|
26905
27200
|
fmt = { format: view.getUint16(body, true), channels: view.getUint16(body + 2, true), sampleRate: view.getUint32(body + 4, true), byteRate: view.getUint32(body + 8, true), bitsPerSample: view.getUint16(body + 14, true) };
|
|
26906
27201
|
if (id2 === "data") {
|
|
26907
27202
|
if (!fmt || !fmt.byteRate) break;
|
|
26908
|
-
const data = bytes.subarray(body, Math.min(bytes.length, body +
|
|
27203
|
+
const data = bytes.subarray(body, Math.min(bytes.length, body + size2));
|
|
26909
27204
|
return { ...fmt, data, seconds: data.length / fmt.byteRate };
|
|
26910
27205
|
}
|
|
26911
|
-
at7 = body +
|
|
27206
|
+
at7 = body + size2 + size2 % 2;
|
|
26912
27207
|
}
|
|
26913
27208
|
throw new Error("The WAV file has no format or no sound.");
|
|
26914
27209
|
};
|
|
@@ -27190,10 +27485,10 @@ var init_speech2 = __esm({
|
|
|
27190
27485
|
const out2 = [];
|
|
27191
27486
|
for (const r of runs4) {
|
|
27192
27487
|
const prev = out2[out2.length - 1];
|
|
27193
|
-
const last = prev?.words[prev.words.length - 1],
|
|
27194
|
-
const crosses = boundaries.some((f) => f > mid(last) && f <= mid(
|
|
27488
|
+
const last = prev?.words[prev.words.length - 1], first2 = r.words[0], start = prev?.words[0], end = r.words[r.words.length - 1];
|
|
27489
|
+
const crosses = boundaries.some((f) => f > mid(last) && f <= mid(first2));
|
|
27195
27490
|
const together2 = (end?.end ?? 0) - (start?.start ?? 0);
|
|
27196
|
-
const paused = (
|
|
27491
|
+
const paused = (first2?.start ?? 0) - (last?.end ?? 0) >= pauseFrames;
|
|
27197
27492
|
if (prev && (span(prev) < min || span(r) < min) && !crosses && !paused && together2 <= max) out2[out2.length - 1] = { words: [...prev.words, ...r.words], pauses: [...prev.pauses, ...r.pauses] };
|
|
27198
27493
|
else out2.push(r);
|
|
27199
27494
|
}
|
|
@@ -27778,7 +28073,7 @@ var init_issues = __esm({
|
|
|
27778
28073
|
|
|
27779
28074
|
// src/video/project/schema.ts
|
|
27780
28075
|
import { z as z6 } from "zod";
|
|
27781
|
-
var NAMED_COLORS, COLOR_RE, isColor, color, id, fraction, ease2, direction,
|
|
28076
|
+
var NAMED_COLORS, COLOR_RE, isColor, color, id, fraction, ease2, direction, pair3, GradientSchema, fill, shadowSchema, CanvasSchema, MaterialSchema, TransitionSchema, CameraMoveSchema, CameraObjectSchema, CameraSchema, footage, BaseObjectSchema, FOOTAGE_KEYS2, BaseSchema, SegmentSchema, MotionSchema, SHIFT, SpanObjectSchema, SpanSchema, StrokeSchema, BackgroundSchema, TextShadowSchema, TextSpanSchema, textSpans, SpokenPastSchema, SpokenSchema, TextStyleSchema, BorderSchema, ItemShadowSchema, LoopSchema, box, itemCommon, textStyle2, mask, TextTrackSchema, ImageTrackSchema, ShapeTrackSchema, VideoTrackSchema, AudioTrackSchema, CueSchema, CaptionTrackSchema, TrackSchema, ProjectSchema, keys, KEY_TABLE, asProject, parseProject;
|
|
27782
28077
|
var init_schema = __esm({
|
|
27783
28078
|
"src/video/project/schema.ts"() {
|
|
27784
28079
|
"use strict";
|
|
@@ -27796,7 +28091,7 @@ var init_schema = __esm({
|
|
|
27796
28091
|
fraction = z6.number().min(0).max(1);
|
|
27797
28092
|
ease2 = z6.enum(["linear", "in", "out", "in-out"]);
|
|
27798
28093
|
direction = z6.enum(["left", "right", "up", "down"]);
|
|
27799
|
-
|
|
28094
|
+
pair3 = z6.tuple([z6.number().min(-1).max(1), z6.number().min(-1).max(1)]);
|
|
27800
28095
|
GradientSchema = z6.object({
|
|
27801
28096
|
type: z6.enum(["linear", "radial"]),
|
|
27802
28097
|
angle: z6.number().min(-360).max(360).optional(),
|
|
@@ -27838,12 +28133,12 @@ var init_schema = __esm({
|
|
|
27838
28133
|
to: z6.number().int().min(1),
|
|
27839
28134
|
scale: z6.tuple([z6.number().gt(0).max(20), z6.number().gt(0).max(20)]),
|
|
27840
28135
|
focus: z6.tuple([fraction, fraction]).optional(),
|
|
27841
|
-
shift: z6.tuple([
|
|
28136
|
+
shift: z6.tuple([pair3, pair3]).optional(),
|
|
27842
28137
|
ease: ease2.optional()
|
|
27843
28138
|
});
|
|
27844
28139
|
CameraObjectSchema = z6.object({
|
|
27845
28140
|
zoom: z6.number().min(-1).max(1).optional(),
|
|
27846
|
-
pan:
|
|
28141
|
+
pan: pair3.optional(),
|
|
27847
28142
|
moves: z6.array(CameraMoveSchema).min(1).max(64).optional()
|
|
27848
28143
|
});
|
|
27849
28144
|
CameraSchema = CameraObjectSchema.refine((c) => c.moves === void 0 || c.zoom === void 0 && c.pan === void 0, {
|
|
@@ -28124,8 +28419,8 @@ var init_words2 = __esm({
|
|
|
28124
28419
|
const voice2 = parsed.success ? void 0 : VoiceWordsSchema.safeParse(json4);
|
|
28125
28420
|
if (voice2?.success) return parseWordsFile({ fps: VOICE_FPS, tokens: voiceTokens(voice2.data.words) }, name);
|
|
28126
28421
|
if (!parsed.success) {
|
|
28127
|
-
const
|
|
28128
|
-
return { error: 'The words file "' + name + '" is not a words file: ' + (
|
|
28422
|
+
const first2 = issueProblems(parsed.error.issues)[0];
|
|
28423
|
+
return { error: 'The words file "' + name + '" is not a words file: ' + (first2?.message ?? "wrong shape"), fix: (first2?.fix ? first2.fix + " " : "") + "The format is " + FORMAT3 + ' (as src/align writes it), or the { "words": [{ "text", "start", "end" }] } in seconds a voice writes beside its WAV.' };
|
|
28129
28424
|
}
|
|
28130
28425
|
const file = parsed.data;
|
|
28131
28426
|
for (let k = 0; k < file.tokens.length; k++) {
|
|
@@ -28200,15 +28495,15 @@ var init_speech_lock = __esm({
|
|
|
28200
28495
|
continue;
|
|
28201
28496
|
}
|
|
28202
28497
|
for (const use2 of playsOf(r).filter((p) => p.play.material === id2)) {
|
|
28203
|
-
const
|
|
28204
|
-
if (last <
|
|
28498
|
+
const first2 = Math.max(0, use2.first, use2.play.start), last = Math.min(r.frames - 1, use2.last);
|
|
28499
|
+
if (last < first2) continue;
|
|
28205
28500
|
const matched = r.audio.some((a) => {
|
|
28206
|
-
if (a.src !== f.src || a.start >
|
|
28207
|
-
const audioTime = (a.from ? a.from.frame / a.from.fps : 0) + (
|
|
28208
|
-
const videoTime = sourceFrame(use2.play, f, r.canvas.fps,
|
|
28501
|
+
if (a.src !== f.src || a.start > first2 || (a.end ?? r.frames) <= last || Math.abs((a.speed ?? 1) - use2.play.speed) > 1e-6) return false;
|
|
28502
|
+
const audioTime = (a.from ? a.from.frame / a.from.fps : 0) + (first2 - a.start) / r.canvas.fps * (a.speed ?? 1);
|
|
28503
|
+
const videoTime = sourceFrame(use2.play, f, r.canvas.fps, first2) / f.fps;
|
|
28209
28504
|
return Math.abs(audioTime - videoTime) <= 1 / f.fps;
|
|
28210
28505
|
});
|
|
28211
|
-
if (!matched) out2.push(error("materials." + id2, "Visible mouth motion has no matching locked audio at timeline frame " +
|
|
28506
|
+
if (!matched) out2.push(error("materials." + id2, "Visible mouth motion has no matching locked audio at timeline frame " + first2 + ".", fix2));
|
|
28212
28507
|
}
|
|
28213
28508
|
}
|
|
28214
28509
|
return out2;
|
|
@@ -29092,8 +29387,8 @@ var init_capacity = __esm({
|
|
|
29092
29387
|
return Array.from(long).slice(0, n).join("").trimEnd();
|
|
29093
29388
|
};
|
|
29094
29389
|
linesOf = (b) => {
|
|
29095
|
-
const
|
|
29096
|
-
return Math.max(0, Math.floor((b.box[3] + 1e-9) / (
|
|
29390
|
+
const size2 = b.style.size ?? 0.045;
|
|
29391
|
+
return Math.max(0, Math.floor((b.box[3] + 1e-9) / (size2 * (b.style.lineHeight ?? DEFAULT_LINE_HEIGHT))));
|
|
29097
29392
|
};
|
|
29098
29393
|
LATIN_ADVANCE = 0.55;
|
|
29099
29394
|
WRAP_LOSS = 0.9;
|
|
@@ -29449,14 +29744,14 @@ var init_cues = __esm({
|
|
|
29449
29744
|
return [...done2, ...open];
|
|
29450
29745
|
};
|
|
29451
29746
|
toCue = (run7, step2, total2) => {
|
|
29452
|
-
const
|
|
29747
|
+
const first2 = run7.frames[0] ?? 0, last = run7.frames[run7.frames.length - 1] ?? 0;
|
|
29453
29748
|
const exact = run7.lines.filter((l) => !l.partial);
|
|
29454
29749
|
const placed2 = exact.length ? exact : run7.lines;
|
|
29455
29750
|
const box2 = union2(placed2.map((l) => l.box));
|
|
29456
29751
|
const heights = placed2.map((l) => l.box[3]).sort((a, b) => a - b);
|
|
29457
29752
|
return {
|
|
29458
29753
|
text: bestText(run7.lines),
|
|
29459
|
-
start: Math.max(0,
|
|
29754
|
+
start: Math.max(0, first2 - Math.floor(step2 / 2)),
|
|
29460
29755
|
end: Math.min(total2, last + Math.ceil(step2 / 2)),
|
|
29461
29756
|
box: box2,
|
|
29462
29757
|
size: Math.round((heights[Math.floor(heights.length / 2)] ?? 0) * 1e4) / 1e4,
|
|
@@ -29693,8 +29988,8 @@ var init_speech3 = __esm({
|
|
|
29693
29988
|
const around3 = (b) => [b - 1, b, b + 1].reduce((n, k) => n + (texts.get(k)?.size ?? 0), 0);
|
|
29694
29989
|
const top2 = [...texts.keys()].sort((a, b) => around3(b) - around3(a) || a - b)[0];
|
|
29695
29990
|
if (top2 === void 0) return () => false;
|
|
29696
|
-
const
|
|
29697
|
-
return (c) => Math.abs(bandOf(c) - top2) <= 1 && c.size <= SIZE_RATIO *
|
|
29991
|
+
const size2 = median6(said.filter((c) => Math.abs(bandOf(c) - top2) <= 1).map((c) => c.size));
|
|
29992
|
+
return (c) => Math.abs(bandOf(c) - top2) <= 1 && c.size <= SIZE_RATIO * size2 && c.size * SIZE_RATIO >= size2;
|
|
29698
29993
|
};
|
|
29699
29994
|
notCaption = (s) => {
|
|
29700
29995
|
if (s.said === void 0) return "shown while nothing is said, outside the band of the said captions";
|
|
@@ -29752,8 +30047,8 @@ var init_beats = __esm({
|
|
|
29752
30047
|
const groups2 = [];
|
|
29753
30048
|
for (const c of captions) {
|
|
29754
30049
|
const g = groups2[groups2.length - 1];
|
|
29755
|
-
const
|
|
29756
|
-
if (g &&
|
|
30050
|
+
const first2 = g?.[0];
|
|
30051
|
+
if (g && first2 && c.start - first2.start <= step2 && c.start < Math.max(...g.map((x2) => x2.end))) g.push(c);
|
|
29757
30052
|
else groups2.push([c]);
|
|
29758
30053
|
}
|
|
29759
30054
|
return groups2;
|
|
@@ -29793,10 +30088,10 @@ var init_beats = __esm({
|
|
|
29793
30088
|
return runs4;
|
|
29794
30089
|
};
|
|
29795
30090
|
isStray = (run7, shown3, fps) => {
|
|
29796
|
-
const
|
|
29797
|
-
if (!
|
|
30091
|
+
const first2 = run7[0], last = run7[run7.length - 1];
|
|
30092
|
+
if (!first2 || !last || run7.reduce((n, w) => n + syllablesOf(w.text), 0) > STRAY_SYLLABLES) return false;
|
|
29798
30093
|
const near3 = STRAY_SECONDS * fps;
|
|
29799
|
-
return shown3.some((b) => Math.abs(
|
|
30094
|
+
return shown3.some((b) => Math.abs(first2.start - b.end) <= near3 || Math.abs(b.start - last.end) <= near3);
|
|
29800
30095
|
};
|
|
29801
30096
|
ordered = (beats2) => {
|
|
29802
30097
|
const sorted = [...beats2].sort((a, b) => a.start - b.start || Number(b.shown) - Number(a.shown)).map((b) => ({ ...b }));
|
|
@@ -29922,11 +30217,11 @@ var init_inset = __esm({
|
|
|
29922
30217
|
return { width: d.width, height: d.height, frames: d.frames.map((rgb, i) => ({ frame: i * every, rgb })) };
|
|
29923
30218
|
};
|
|
29924
30219
|
medianOf = (pictures) => {
|
|
29925
|
-
const
|
|
29926
|
-
if (pictures.length === 1) return
|
|
29927
|
-
const out2 = new Uint8Array(
|
|
30220
|
+
const first2 = pictures[0];
|
|
30221
|
+
if (pictures.length === 1) return first2;
|
|
30222
|
+
const out2 = new Uint8Array(first2.length);
|
|
29928
30223
|
const values = new Array(pictures.length);
|
|
29929
|
-
for (let i = 0; i <
|
|
30224
|
+
for (let i = 0; i < first2.length; i++) {
|
|
29930
30225
|
for (let k = 0; k < pictures.length; k++) values[k] = pictures[k][i];
|
|
29931
30226
|
values.sort((a, b) => a - b);
|
|
29932
30227
|
out2[i] = values[pictures.length - 1 >> 1];
|
|
@@ -30263,11 +30558,11 @@ var init_move = __esm({
|
|
|
30263
30558
|
round4 = (v, d = 3) => Math.round(v * 10 ** d) / 10 ** d;
|
|
30264
30559
|
INK_THRESHOLD = 24;
|
|
30265
30560
|
groundOf = (f, roi) => {
|
|
30266
|
-
const
|
|
30561
|
+
const first2 = f.frames[0];
|
|
30267
30562
|
const border = [[], [], []];
|
|
30268
30563
|
for (let y = roi.y; y < roi.y + roi.h; y++) for (let x2 = roi.x; x2 < roi.x + roi.w; x2++) {
|
|
30269
30564
|
if (x2 - roi.x >= 2 && y - roi.y >= 2 && x2 < roi.x + roi.w - 2 && y < roi.y + roi.h - 2) continue;
|
|
30270
|
-
for (let c = 0; c < 3; c++) border[c].push(
|
|
30565
|
+
for (let c = 0; c < 3; c++) border[c].push(first2[(y * f.width + x2) * 3 + c] ?? 0);
|
|
30271
30566
|
}
|
|
30272
30567
|
const flat = border.map(median7);
|
|
30273
30568
|
const off2 = border[0].filter((_v, i) => Math.max(...[0, 1, 2].map((c) => Math.abs((border[c][i] ?? 0) - flat[c]))) > INK_THRESHOLD / 2).length;
|
|
@@ -30387,19 +30682,19 @@ var init_move = __esm({
|
|
|
30387
30682
|
const frac = (r) => [round4((r.x ?? 0) / f.width), round4((r.y ?? 0) / f.height)];
|
|
30388
30683
|
const shift = { ...sc, startFrame: sc.startFrame + (seen[0] ?? 0) };
|
|
30389
30684
|
if (seen.length >= 4) {
|
|
30390
|
-
const
|
|
30391
|
-
const dx = (last.x ?? 0) - (
|
|
30685
|
+
const first2 = at7(0), last = at7(seen.length - 1);
|
|
30686
|
+
const dx = (last.x ?? 0) - (first2.x ?? 0), dy = (last.y ?? 0) - (first2.y ?? 0), len = Math.hypot(dx, dy);
|
|
30392
30687
|
const xs = seen.map((_s, i) => at7(i).x ?? 0), ys = seen.map((_s, i) => at7(i).y ?? 0);
|
|
30393
30688
|
const rangeX = Math.max(...xs) - Math.min(...xs), rangeY = Math.max(...ys) - Math.min(...ys);
|
|
30394
|
-
const along2 = len >= minPx ? seen.map((_s, i) => (((at7(i).x ?? 0) - (
|
|
30689
|
+
const along2 = len >= minPx ? seen.map((_s, i) => (((at7(i).x ?? 0) - (first2.x ?? 0)) * dx + ((at7(i).y ?? 0) - (first2.y ?? 0)) * dy) / len) : rangeY >= rangeX ? ys : xs;
|
|
30395
30690
|
const prop = len >= minPx ? "path" : rangeY >= rangeX ? "y" : "x";
|
|
30396
30691
|
for (const s of stretchesOf(along2, f.fps, minPx, 0.5)) {
|
|
30397
30692
|
if (s.pulse) pulses.push({ prop, pulse: true, start: round4((shift.startFrame + s.a) / f.fps), duration: round4((s.b - s.a) / f.fps), frames: s.b - s.a, peak: round4(Math.abs(s.peak - along2[s.a]) / f.width) });
|
|
30398
30693
|
else moves.push(describeMove(prop, along2, s, seen.map((i) => rows3[i]), shift, (i) => frac(at7(i)), Math.abs(along2[s.b] - along2[s.a])));
|
|
30399
30694
|
}
|
|
30400
|
-
for (const
|
|
30401
|
-
const v = seen.map((_s, i) => at7(i)[
|
|
30402
|
-
for (const s of stretchesOf(v, f.fps, minPx, 1)) if (!s.pulse) moves.push(describeMove(
|
|
30695
|
+
for (const size2 of ["w", "h"]) {
|
|
30696
|
+
const v = seen.map((_s, i) => at7(i)[size2]);
|
|
30697
|
+
for (const s of stretchesOf(v, f.fps, minPx, 1)) if (!s.pulse) moves.push(describeMove(size2, v, s, [], shift, (i) => [round4(v[i] / (size2 === "w" ? f.width : f.height))]));
|
|
30403
30698
|
}
|
|
30404
30699
|
}
|
|
30405
30700
|
if (!moves.length) {
|
|
@@ -30770,8 +31065,8 @@ var init_describe = __esm({
|
|
|
30770
31065
|
const captions = text13.cues.filter((c) => c.role === "caption");
|
|
30771
31066
|
if (captions.length) {
|
|
30772
31067
|
const y = captions.map((c) => c.box[1] + c.box[3] / 2).sort((a, b) => a - b)[Math.floor(captions.length / 2)] ?? 0;
|
|
30773
|
-
const
|
|
30774
|
-
L.push("- Captions: " + captions.length + " lines in a band at " + pct6(y) + " of the height, line height " + pct6(
|
|
31068
|
+
const size2 = captions.map((c) => c.size).sort((a, b) => a - b)[Math.floor(captions.length / 2)] ?? 0;
|
|
31069
|
+
L.push("- Captions: " + captions.length + " lines in a band at " + pct6(y) + " of the height, line height " + pct6(size2) + ", " + (captions.reduce((n, c) => n + c.end - c.start, 0) / captions.length / fps).toFixed(1) + " s each on average" + (text13.captionLook ? "; " + lookText(text13.captionLook) : ""));
|
|
30775
31070
|
} else L.push("- Captions: none found");
|
|
30776
31071
|
const marks = [...new Set(text13.cues.filter((c) => c.role === "watermark").map((c) => c.text))];
|
|
30777
31072
|
if (marks.length) L.push("- Watermark text (not to be re-created): " + marks.slice(0, 4).map(quote6).join(", "));
|
|
@@ -30939,8 +31234,8 @@ var init_caption_look = __esm({
|
|
|
30939
31234
|
stroke: { color: color2, width: 0.16 },
|
|
30940
31235
|
shadow: cast?.blur !== void 0 ? { color: cast.color ?? color2, blur: cast.blur, x: cast.x ?? 0, y: cast.y ?? 0 } : { color: color2, blur: 0.3, x: 0, y: 0.05 }
|
|
30941
31236
|
});
|
|
30942
|
-
captionStyle = (look2, plan4,
|
|
30943
|
-
const base = { size, weight: look2?.weight === "regular" ? 500 : 800, color: plan4.captionColor ?? look2?.color ?? "#ffffff", align: "center" };
|
|
31237
|
+
captionStyle = (look2, plan4, size2) => {
|
|
31238
|
+
const base = { size: size2, weight: look2?.weight === "regular" ? 500 : 800, color: plan4.captionColor ?? look2?.color ?? "#ffffff", align: "center" };
|
|
30944
31239
|
const plate = look2?.kind === "plate" && look2.plate ? { background: plateStyle(look2.plate) } : {};
|
|
30945
31240
|
if (plan4.captionOutline) return { ...base, ...outlined(plan4.captionOutline, look2?.shadow), ...plate };
|
|
30946
31241
|
if (!look2 || look2.kind === "plain" && !look2.color) return { ...base, ...outlined("#111111") };
|
|
@@ -31088,20 +31383,20 @@ var init_titles = __esm({
|
|
|
31088
31383
|
};
|
|
31089
31384
|
wordBox = (p) => {
|
|
31090
31385
|
const [x2, y, w, h] = p.box;
|
|
31091
|
-
const
|
|
31092
|
-
const height = Math.min(1, up4(Math.max(h,
|
|
31386
|
+
const size2 = r4(p.size * FONT_OF_BOX), cx = x2 + w / 2;
|
|
31387
|
+
const height = Math.min(1, up4(Math.max(h, size2 * DEFAULT_LINE_HEIGHT)));
|
|
31093
31388
|
const top2 = r4(Math.min(1 - height, Math.max(0, y + h / 2 - height / 2)));
|
|
31094
31389
|
const align2 = Math.abs(cx - 0.5) <= 0.1 ? "center" : cx < 0.5 ? "left" : "right";
|
|
31095
31390
|
if (align2 === "center") {
|
|
31096
31391
|
const half2 = Math.max(w / 2, Math.min(cx - MARGIN, 1 - MARGIN - cx));
|
|
31097
|
-
return { box: [r4(cx - half2), top2, r4(2 * half2), height], align: align2, size };
|
|
31392
|
+
return { box: [r4(cx - half2), top2, r4(2 * half2), height], align: align2, size: size2 };
|
|
31098
31393
|
}
|
|
31099
|
-
if (align2 === "left") return { box: [r4(x2), top2, r4(Math.max(w, 1 - MARGIN - x2)), height], align: align2, size };
|
|
31100
|
-
return { box: [MARGIN, top2, r4(Math.max(w, x2 + w - MARGIN)), height], align: align2, size };
|
|
31394
|
+
if (align2 === "left") return { box: [r4(x2), top2, r4(Math.max(w, 1 - MARGIN - x2)), height], align: align2, size: size2 };
|
|
31395
|
+
return { box: [MARGIN, top2, r4(Math.max(w, x2 + w - MARGIN)), height], align: align2, size: size2 };
|
|
31101
31396
|
};
|
|
31102
31397
|
wordStyle = (p) => {
|
|
31103
|
-
const { align: align2, size } = wordBox(p);
|
|
31104
|
-
return { ...captionStyle(void 0, {},
|
|
31398
|
+
const { align: align2, size: size2 } = wordBox(p);
|
|
31399
|
+
return { ...captionStyle(void 0, {}, size2), align: align2 };
|
|
31105
31400
|
};
|
|
31106
31401
|
wordTracks = (segment2, words, places, time, length2) => words.flatMap((raw, j) => {
|
|
31107
31402
|
const p = places[j], line = unmark(raw);
|
|
@@ -31143,18 +31438,18 @@ var init_titles = __esm({
|
|
|
31143
31438
|
const prev = places[j - 1]?.box, next = places[j + 1]?.box;
|
|
31144
31439
|
const right = next ? (x2 + w + next[0]) / 2 : void 0, left = prev ? (prev[0] + prev[2] + x2) / 2 : void 0;
|
|
31145
31440
|
const lo = Math.max(MARGIN, left ?? x2 - ((right ?? x2 + w) - (x2 + w))), hi = Math.min(1 - MARGIN, right ?? x2 + w + (x2 - (left ?? x2)));
|
|
31146
|
-
const
|
|
31147
|
-
const height = Math.min(1, up4(Math.max(h,
|
|
31148
|
-
return { box: [r4(Math.min(lo, x2)), r4(Math.min(1 - height, Math.max(0, y + h / 2 - height / 2))), r4(Math.max(w, hi - Math.min(lo, x2))), height], size };
|
|
31441
|
+
const size2 = r4(p.size * FONT_OF_BOX);
|
|
31442
|
+
const height = Math.min(1, up4(Math.max(h, size2 * DEFAULT_LINE_HEIGHT)));
|
|
31443
|
+
return { box: [r4(Math.min(lo, x2)), r4(Math.min(1 - height, Math.max(0, y + h / 2 - height / 2))), r4(Math.max(w, hi - Math.min(lo, x2))), height], size: size2 };
|
|
31149
31444
|
};
|
|
31150
31445
|
MARKED_STYLE = { weight: 800, color: "#111111", align: "center", background: { color: "#ffd84a", padding: 0.25, radius: 0.3 } };
|
|
31151
31446
|
barTracks = (bar, words, segments2, total2) => words.flatMap((raw, j) => {
|
|
31152
31447
|
const text13 = raw.trim();
|
|
31153
31448
|
if (!text13 || !bar.places[j]) return [];
|
|
31154
|
-
const { box: box2, size } = barBox(bar.places, j);
|
|
31155
|
-
const
|
|
31156
|
-
const plain2 = { id: "bar-" + (j + 1), type: "text", text: text13, box: box2, style: { ...captionStyle(void 0, {},
|
|
31157
|
-
const lit = segments2.flatMap((s, k) => bar.marked[k] === j ? [{ id: "bar-" + (j + 1) + "-" + s.id, type: "text", text: text13, box: box2, style: { size, ...MARKED_STYLE }, during: { segment: s.id } }] : []);
|
|
31449
|
+
const { box: box2, size: size2 } = barBox(bar.places, j);
|
|
31450
|
+
const first2 = segments2[0]?.id ?? "shot-01";
|
|
31451
|
+
const plain2 = { id: "bar-" + (j + 1), type: "text", text: text13, box: box2, style: { ...captionStyle(void 0, {}, size2), align: "center" }, during: { segment: first2, from: 0, to: total2 } };
|
|
31452
|
+
const lit = segments2.flatMap((s, k) => bar.marked[k] === j ? [{ id: "bar-" + (j + 1) + "-" + s.id, type: "text", text: text13, box: box2, style: { size: size2, ...MARKED_STYLE }, during: { segment: s.id } }] : []);
|
|
31158
31453
|
return [plain2, ...lit];
|
|
31159
31454
|
});
|
|
31160
31455
|
barProblems = (bar, places) => {
|
|
@@ -31279,10 +31574,10 @@ var init_retarget = __esm({
|
|
|
31279
31574
|
return [{ level: "warning", at: "captions", message: has2 + " The last " + (n - lines2) + " beats stay without a caption.", fix: "Add lines, or leave it if the ending should be silent." }];
|
|
31280
31575
|
};
|
|
31281
31576
|
captionLayout = (cues) => {
|
|
31282
|
-
const
|
|
31577
|
+
const size2 = median8(cues.map((c) => c.size));
|
|
31283
31578
|
const centre2 = median8(cues.map((c) => c.box[1] + c.box[3] / 2));
|
|
31284
|
-
const half2 = Math.max(
|
|
31285
|
-
return { box: [0.08, r42(centre2 - half2), 0.84, r42(2 * half2)], size: r42(
|
|
31579
|
+
const half2 = Math.max(size2 * 0.6, Math.min(size2 * 1.4, centre2 - 0.01, 0.99 - centre2));
|
|
31580
|
+
return { box: [0.08, r42(centre2 - half2), 0.84, r42(2 * half2)], size: r42(size2 * 0.92) };
|
|
31286
31581
|
};
|
|
31287
31582
|
spokenForm = (line, say) => (say ?? []).reduce((s, x2) => s.split(x2.text).join(x2.as), line);
|
|
31288
31583
|
LINE_TAIL = 4;
|
|
@@ -31410,7 +31705,7 @@ var init_retarget = __esm({
|
|
|
31410
31705
|
const lines2 = plan4.captions ?? [];
|
|
31411
31706
|
if (captionCues.length && lines2.some((l, i) => l.trim() && beats2[i]?.shown)) {
|
|
31412
31707
|
const layout = captionLayout(captionCues);
|
|
31413
|
-
const
|
|
31708
|
+
const first2 = segments2[0]?.id ?? "shot-01";
|
|
31414
31709
|
const look2 = captionStyle(read2.text?.captionLook, plan4, layout.size);
|
|
31415
31710
|
const lit = highlightColour(read2.text?.captionLook, look2.color);
|
|
31416
31711
|
const cues = beats2.flatMap((b, i) => {
|
|
@@ -31423,7 +31718,7 @@ var init_retarget = __esm({
|
|
|
31423
31718
|
const next = flow ? flow.starts[i + 1] ?? total2 : shift ? beats2[i + 1]?.start ?? total2 : total2;
|
|
31424
31719
|
const to = Math.min(end, next, total2);
|
|
31425
31720
|
const marks2 = marked2[i]?.marks ?? [];
|
|
31426
|
-
return to > from ? [{ text: text13, during: { segment:
|
|
31721
|
+
return to > from ? [{ text: text13, during: { segment: first2, from, to }, ...marks2.length ? { spans: markSpans(marks2, lit) } : {} }] : [];
|
|
31427
31722
|
});
|
|
31428
31723
|
const follows = Boolean(input.wordsFile && plan4.sound);
|
|
31429
31724
|
const measured2 = read2.text?.captionLook?.reveal;
|
|
@@ -31444,8 +31739,8 @@ var init_retarget = __esm({
|
|
|
31444
31739
|
}
|
|
31445
31740
|
(plan4.beds ?? []).forEach((bed, i) => {
|
|
31446
31741
|
const [a, b] = bed.shots;
|
|
31447
|
-
const
|
|
31448
|
-
const from = bed.in ?? (
|
|
31742
|
+
const first2 = plan4.shots[a - 1];
|
|
31743
|
+
const from = bed.in ?? (first2 && "footage" in first2 && first2.footage === bed.footage ? first2.in ?? 0 : 0);
|
|
31449
31744
|
const frames = lengths.slice(a - 1, b).reduce((n, x2) => n + x2, 0);
|
|
31450
31745
|
tracks.push({ id: "bed-" + (i + 1), type: "audio", material: use2(bed.footage, "video"), bed: true, ...from ? { in: from } : {}, ...bed.audio !== void 0 ? { gain: bed.audio } : {}, during: { segment: "shot-" + two8(a), from: 0, to: frames } });
|
|
31451
31746
|
});
|
|
@@ -31879,7 +32174,7 @@ var init_card = __esm({
|
|
|
31879
32174
|
const s = tpl.speech;
|
|
31880
32175
|
if (!s) return [];
|
|
31881
32176
|
const dialogue = (tpl.captions?.beats ?? []).flatMap((b, i) => b.speech === "on-camera" ? [i] : []);
|
|
31882
|
-
const voice2 = s.kinds.includes("narration") ? 'the narration is re-made as a voice-over ("voice")' : 'no narration, so no "voice" and no --speak unless the user asks for one (--voice-asked "<their words>")';
|
|
32177
|
+
const voice2 = s.kinds.includes("narration") ? 'the narration is re-made as a voice-over ("voice"); in a video whose clips are generated and speak, those clips say it instead, as offscreen lines on its beats in the voice of the host (no "voice", no --speak: video-performers.md)' : 'no narration, so no "voice" and no --speak unless the user asks for one (--voice-asked "<their words>")';
|
|
31883
32178
|
return [
|
|
31884
32179
|
"- Speech of the source: " + s.kinds.join(", ") + ": " + voice2 + "." + (dialogue.length ? " Beats " + runsText(dialogue) + " are said on camera: the person of a generated clip says each line (its request's speech.lines names the beat); the voice-over never reads them." : "")
|
|
31885
32180
|
];
|
|
@@ -32069,8 +32364,8 @@ var init_slots = __esm({
|
|
|
32069
32364
|
};
|
|
32070
32365
|
});
|
|
32071
32366
|
wordSlots = (tpl, s, k, texts = []) => (s.words ?? []).map((p, j) => {
|
|
32072
|
-
const { box: box2, size } = wordBox(p);
|
|
32073
|
-
const cap2 = estimateCapacity({ canvas: tpl.canvas, box: box2, style: { size } });
|
|
32367
|
+
const { box: box2, size: size2 } = wordBox(p);
|
|
32368
|
+
const cap2 = estimateCapacity({ canvas: tpl.canvas, box: box2, style: { size: size2 } });
|
|
32074
32369
|
const was = texts[j]?.trim();
|
|
32075
32370
|
return { at: "shots[" + k + "].words[" + j + "]", seconds: r28((p.to - p.from) / tpl.canvas.fps), max: { cjk: cap2.cjk, latin: cap2.latin }, ...was ? { example: { text: was, chars: charsOf(was).length } } : {} };
|
|
32076
32371
|
});
|
|
@@ -32078,8 +32373,8 @@ var init_slots = __esm({
|
|
|
32078
32373
|
const bar = tpl.bar;
|
|
32079
32374
|
if (!bar) return void 0;
|
|
32080
32375
|
const words = bar.places.map((_p, j) => {
|
|
32081
|
-
const { box: box2, size } = barBox(bar.places, j);
|
|
32082
|
-
const cap2 = estimateCapacity({ canvas: tpl.canvas, box: box2, style: { size } });
|
|
32376
|
+
const { box: box2, size: size2 } = barBox(bar.places, j);
|
|
32377
|
+
const cap2 = estimateCapacity({ canvas: tpl.canvas, box: box2, style: { size: size2 } });
|
|
32083
32378
|
const was = texts[j]?.trim();
|
|
32084
32379
|
return { max: { cjk: cap2.cjk, latin: cap2.latin }, ...was ? { example: { text: was, chars: charsOf(was).length } } : {} };
|
|
32085
32380
|
});
|
|
@@ -32286,21 +32581,21 @@ var init_clips = __esm({
|
|
|
32286
32581
|
let fill4;
|
|
32287
32582
|
if (onto !== void 0) {
|
|
32288
32583
|
const pkg = await loadTemplate(rt, userPath(rt, onto));
|
|
32289
|
-
const
|
|
32584
|
+
const first2 = (args2.number("first") ?? 1) - 1;
|
|
32290
32585
|
const lengths = fillLengths(pkg.template);
|
|
32291
|
-
if (
|
|
32292
|
-
throw new VideoCommandError("The clip has " + m.shots.length + " shots and the template " + pkg.template.shots.length + ": from shot " + (
|
|
32586
|
+
if (first2 < 0 || first2 + m.shots.length > pkg.template.shots.length)
|
|
32587
|
+
throw new VideoCommandError("The clip has " + m.shots.length + " shots and the template " + pkg.template.shots.length + ": from shot " + (first2 + 1) + " they do not fit. Open the pictures (--out): a cut the clip does not have, or one too many, changes which shot goes where; give --first, or fill those shots by hand.");
|
|
32293
32588
|
const footage2 = fillPath(typed);
|
|
32294
32589
|
const notes2 = [];
|
|
32295
32590
|
const entries3 = m.shots.map((s, i) => {
|
|
32296
|
-
const k =
|
|
32591
|
+
const k = first2 + i;
|
|
32297
32592
|
const need2 = footageNeed(pkg.template, k, lengths) / pkg.template.canvas.fps;
|
|
32298
32593
|
const have = Math.max(1, s.end - s.start - 2 * GUARD) / fps;
|
|
32299
32594
|
const speed = Math.min(4, Math.max(0.25, r29(have / need2)));
|
|
32300
32595
|
if (speed < SLOWED) notes2.push("shots[" + k + "]: the clip's shot " + (i + 1) + " is " + r29(have) + " s and the template's shot needs " + r29(need2) + " s, so it would play at " + speed + " of its speed. Ask for that shot longer when the group is made again, or fill it otherwise; do not slow it down.");
|
|
32301
32596
|
return { shot: k + 1, fill: { footage: footage2, in: s.start + GUARD, ...speed !== 1 ? { speed } : {} } };
|
|
32302
32597
|
});
|
|
32303
|
-
fill4 = { shots: entries3, bed: { footage: footage2, shots: [
|
|
32598
|
+
fill4 = { shots: entries3, bed: { footage: footage2, shots: [first2 + 1, first2 + m.shots.length], in: (m.shots[0]?.start ?? 0) + GUARD }, ...notes2.length ? { notes: notes2 } : {} };
|
|
32304
32599
|
}
|
|
32305
32600
|
printJson(rt, {
|
|
32306
32601
|
ok: true,
|
|
@@ -32385,7 +32680,7 @@ var init_cast2 = __esm({
|
|
|
32385
32680
|
});
|
|
32386
32681
|
|
|
32387
32682
|
// src/video/generate/cloud.ts
|
|
32388
|
-
var GenerateError, MINUTE_MS, POLL_MS2, DEFAULT_WAIT_MIN, DEFAULT_SECONDS, CREATE_TRIES, CREATE_TIMEOUT_SEC, UPLOAD_TIMEOUT_MS, DOWNLOAD_TIMEOUT_SEC2, MAX_CLIP_BYTES, RETRY_HINT, setting, numberSetting, keysOf, cloudSettings, agreeToPrice, requestKey, LISTS2, has, mediaType, readReference3, readReferences, recordFile2, readRecord2, save2, keyOf4, stillValid, text6, putBytes, upload2, ensureUploads2, specOf, ensureQuote, taskOf3, createTask2, submit, getTask, findTask, ENDED, PASSING2, waitFor,
|
|
32683
|
+
var GenerateError, MINUTE_MS, POLL_MS2, DEFAULT_WAIT_MIN, DEFAULT_SECONDS, CREATE_TRIES, CREATE_TIMEOUT_SEC, UPLOAD_TIMEOUT_MS, DOWNLOAD_TIMEOUT_SEC2, MAX_CLIP_BYTES, RETRY_HINT, setting, numberSetting, keysOf, cloudSettings, agreeToPrice, requestKey, LISTS2, has, mediaType, readReference3, identity, planFits, fittedOf, fitReferences, readReferences, recordFile2, readRecord2, save2, keyOf4, stillValid, text6, putBytes, upload2, ensureUploads2, specOf, ensureQuote, taskOf3, createTask2, submit, getTask, findTask, ENDED, PASSING2, waitFor, ended, unsupported2, fetchClip, gateOf, ASK_MODEL2, modelFacts, wavSeconds, checkReferenceSounds, prepare4, makeClip, priceClip, listModels;
|
|
32389
32684
|
var init_cloud2 = __esm({
|
|
32390
32685
|
"src/video/generate/cloud.ts"() {
|
|
32391
32686
|
"use strict";
|
|
@@ -32401,12 +32696,16 @@ var init_cloud2 = __esm({
|
|
|
32401
32696
|
init_submit_retry();
|
|
32402
32697
|
init_approved();
|
|
32403
32698
|
init_generate();
|
|
32699
|
+
init_failure();
|
|
32700
|
+
init_picture_fit();
|
|
32404
32701
|
GenerateError = class extends Error {
|
|
32405
|
-
constructor(message2, exitCode = 1) {
|
|
32702
|
+
constructor(message2, exitCode = 1, failure4) {
|
|
32406
32703
|
super(message2);
|
|
32407
32704
|
this.exitCode = exitCode;
|
|
32705
|
+
this.failure = failure4;
|
|
32408
32706
|
}
|
|
32409
32707
|
exitCode;
|
|
32708
|
+
failure;
|
|
32410
32709
|
name = "GenerateError";
|
|
32411
32710
|
};
|
|
32412
32711
|
MINUTE_MS = 6e4;
|
|
@@ -32479,7 +32778,30 @@ var init_cloud2 = __esm({
|
|
|
32479
32778
|
});
|
|
32480
32779
|
const mimeType2 = mediaType(kind, bytes.subarray(0, 16));
|
|
32481
32780
|
if (!mimeType2) throw new GenerateError(name + ' in "' + where3 + '" is not ' + what + "; nothing was sent.", 2);
|
|
32482
|
-
|
|
32781
|
+
const hash5 = sha256(bytes);
|
|
32782
|
+
return { kind, path: path4, name, bytes, sha256: hash5, mimeType: mimeType2, source: hash5 };
|
|
32783
|
+
};
|
|
32784
|
+
identity = (r) => r.fit ? r.source + ":" + fitKey(r.fit) : r.source;
|
|
32785
|
+
planFits = (refs, limits) => refs.map((r) => {
|
|
32786
|
+
const shown3 = r.kind === "image" ? shownSize(r.bytes) : void 0;
|
|
32787
|
+
const fit = shown3 ? fitPlan(shown3[0], shown3[1], limits) : void 0;
|
|
32788
|
+
return fit ? { ...r, fit } : r;
|
|
32789
|
+
});
|
|
32790
|
+
fittedOf = (refs, limits) => refs.flatMap((r) => r.fit ? [{ file: r.path, was: r.fit.from.join("x"), now: r.fit.canvas.join("x"), how: fitText(r.fit, limits) }] : []);
|
|
32791
|
+
fitReferences = async (rt, refs, limits) => {
|
|
32792
|
+
const out2 = [];
|
|
32793
|
+
for (const r of refs) {
|
|
32794
|
+
if (!r.fit) {
|
|
32795
|
+
out2.push(r);
|
|
32796
|
+
continue;
|
|
32797
|
+
}
|
|
32798
|
+
const fitted = await fitPicture(rt, r.path, r.mimeType, r.fit, limits).catch((e) => {
|
|
32799
|
+
const why = e instanceof Error ? e.message : String(e);
|
|
32800
|
+
throw new GenerateError(r.name + " is " + r.fit?.from.join("x") + " and " + rangeText(limits) + ": it is fitted before it is sent (padded, never cut), which needs ffmpeg. " + why + " Nothing was sent.", 2);
|
|
32801
|
+
});
|
|
32802
|
+
out2.push({ ...r, ...fitted });
|
|
32803
|
+
}
|
|
32804
|
+
return out2;
|
|
32483
32805
|
};
|
|
32484
32806
|
readReferences = async (rt, request) => {
|
|
32485
32807
|
const out2 = [];
|
|
@@ -32545,13 +32867,13 @@ var init_cloud2 = __esm({
|
|
|
32545
32867
|
const idOf = (r) => sent.uploads[r?.sha256 ?? ""]?.uploadId ?? "";
|
|
32546
32868
|
const ids3 = (kind) => refs.filter((r) => r.kind === kind && !r.frame).map(idOf);
|
|
32547
32869
|
const references = Object.fromEntries(LISTS2.map(([kind, list7]) => [list7, ids3(kind)]).filter(([, list7]) => list7.length));
|
|
32548
|
-
const [
|
|
32870
|
+
const [first2, last] = [refs.find((r) => r.frame === "first"), refs.find((r) => r.frame === "last")];
|
|
32549
32871
|
return {
|
|
32550
32872
|
...s.videoModel ? { model: s.videoModel } : {},
|
|
32551
32873
|
...s.resolution ? { resolution: s.resolution } : {},
|
|
32552
32874
|
seconds: seconds8,
|
|
32553
32875
|
...request.aspect ? { aspectRatio: request.aspect } : {},
|
|
32554
|
-
...
|
|
32876
|
+
...first2 ? { frames: { first: idOf(first2), ...last ? { last: idOf(last) } : {} } } : {},
|
|
32555
32877
|
...Object.keys(references).length ? { references } : {},
|
|
32556
32878
|
// Only for a model that can make a clip without a sound track; the quote and the generation say the same.
|
|
32557
32879
|
...silent ? { generateAudio: false } : {}
|
|
@@ -32561,9 +32883,10 @@ var init_cloud2 = __esm({
|
|
|
32561
32883
|
const json4 = JSON.stringify(body);
|
|
32562
32884
|
if (sent.quote?.body === json4 && stillValid(rt, sent.quote.expiresAt, MINUTE_MS)) return sent;
|
|
32563
32885
|
const data = await client2.request("POST", "/videos/quote", { body }).catch((error2) => {
|
|
32564
|
-
if (
|
|
32565
|
-
|
|
32566
|
-
|
|
32886
|
+
if (!(error2 instanceof PopostApiError) || error2.code !== "VIDEO_OPTION_UNSUPPORTED") throw error2;
|
|
32887
|
+
if (body.frames && error2.details.field === "frames")
|
|
32888
|
+
throw new GenerateError('This video model does not take a first or last frame (popost video generate --models lists "frames" for each model): give the picture as a reference in "images" instead, or ask the user whether to use a model that takes frames (' + ASK_MODEL2 + "). Nothing was charged.", 1, { code: "VIDEO_OPTION_UNSUPPORTED", retryable: false, reason: "frames" });
|
|
32889
|
+
throw unsupported2(error2);
|
|
32567
32890
|
});
|
|
32568
32891
|
if (!isRecord(data) || typeof data.quoteId !== "string" || typeof data.credits !== "number")
|
|
32569
32892
|
throw new GenerateError("popost.ai answered the quote without a quote id or a price; nothing was charged. Try again later.");
|
|
@@ -32585,17 +32908,19 @@ var init_cloud2 = __esm({
|
|
|
32585
32908
|
}, { tries: CREATE_TRIES, pauseMs: POLL_MS2 });
|
|
32586
32909
|
submit = async (rt, client2, s, job, start) => {
|
|
32587
32910
|
let sent = start;
|
|
32911
|
+
const refs = await fitReferences(rt, job.refs, job.limits);
|
|
32588
32912
|
for (let round6 = 1; ; round6++) {
|
|
32589
|
-
sent = await ensureUploads2(rt, client2,
|
|
32590
|
-
const body = specOf(s, job.request, job.seconds,
|
|
32913
|
+
sent = await ensureUploads2(rt, client2, refs, sent, job.file);
|
|
32914
|
+
const body = specOf(s, job.request, job.seconds, refs, sent, job.silent);
|
|
32591
32915
|
sent = await ensureQuote(rt, client2, body, sent, job.file);
|
|
32592
32916
|
const quote16 = sent.quote;
|
|
32593
32917
|
if (job.request.priceOnly) throw new ConfirmNeeded(quote16.price, "This costs " + quote16.price.credits + " credits. Only its price was asked for: nothing was made or charged.");
|
|
32594
32918
|
agreeToPrice(s, quote16.price, job.unplanned);
|
|
32595
32919
|
try {
|
|
32596
32920
|
const task = await createTask2(rt, client2, { ...body, prompt: job.request.prompt, quoteId: quote16.quoteId, idempotencyKey: keyOf4(sent) });
|
|
32597
|
-
|
|
32598
|
-
await
|
|
32921
|
+
const paid = typeof task.credits === "number" ? task.credits : quote16.price.credits;
|
|
32922
|
+
await save2(rt, job.file, { ...sent, taskId: task.id, paid });
|
|
32923
|
+
await job.onPaid(paid);
|
|
32599
32924
|
return task;
|
|
32600
32925
|
} catch (error2) {
|
|
32601
32926
|
if (round6 > 1 || !(error2 instanceof PopostApiError) || error2.code !== "QUOTE_EXPIRED") throw error2;
|
|
@@ -32615,9 +32940,9 @@ var init_cloud2 = __esm({
|
|
|
32615
32940
|
});
|
|
32616
32941
|
ENDED = ["succeeded", "failed", "expired"];
|
|
32617
32942
|
PASSING2 = /* @__PURE__ */ new Set(["NETWORK", "BAD_RESPONSE", "RATE_LIMITED", "SERVICE_UNAVAILABLE", "INTERNAL_ERROR", "TIMEOUT", "UPSTREAM_ERROR"]);
|
|
32618
|
-
waitFor = async (rt, client2,
|
|
32943
|
+
waitFor = async (rt, client2, first2, minutes) => {
|
|
32619
32944
|
const deadline2 = rt.now().getTime() + minutes * MINUTE_MS;
|
|
32620
|
-
let task =
|
|
32945
|
+
let task = first2;
|
|
32621
32946
|
while (!ENDED.includes(task.status)) {
|
|
32622
32947
|
if (rt.now().getTime() >= deadline2)
|
|
32623
32948
|
throw new GenerateError("The clip is still being made on popost.ai after " + minutes + " minutes (task " + task.id + ", " + task.status + "). Run the same command again later to pick it up: it is not paid twice. POPOST_GEN_WAIT_MIN waits longer.");
|
|
@@ -32630,15 +32955,23 @@ var init_cloud2 = __esm({
|
|
|
32630
32955
|
}
|
|
32631
32956
|
return task;
|
|
32632
32957
|
};
|
|
32633
|
-
|
|
32634
|
-
CONTENT_REJECTED: "the same request would be refused again, so change its prompt or its reference pictures before asking for the clip again: for example, leave out the names of brands, characters and well-known works, and pictures of them."
|
|
32635
|
-
};
|
|
32636
|
-
ended = (task) => {
|
|
32958
|
+
ended = (task, sent, hadSound) => {
|
|
32637
32959
|
if (task.status === "expired")
|
|
32638
32960
|
return new GenerateError("The clip of task " + task.id + " was kept 7 days on popost.ai and has been deleted. Run the command again to make it again (it is priced again).");
|
|
32639
32961
|
const code = text6(task.error?.code) ?? "GENERATION_FAILED";
|
|
32640
|
-
const
|
|
32641
|
-
|
|
32962
|
+
const reason2 = text6(task.error?.reason)?.trim().slice(0, 400);
|
|
32963
|
+
const retryable = typeof task.error?.retryable === "boolean" ? task.error.retryable : void 0;
|
|
32964
|
+
const refunded = sent.taskId === task.id ? sent.paid ?? sent.quote?.price.credits : void 0;
|
|
32965
|
+
const failure4 = withSound({ code, ...retryable !== void 0 ? { retryable } : {}, ...reason2 ? { reason: reason2 } : {}, ...refunded !== void 0 && refunded > 0 ? { refundedCredits: refunded } : {} }, hadSound);
|
|
32966
|
+
const message2 = text6(task.error?.message);
|
|
32967
|
+
return new GenerateError(failureLine(failure4, { other: describeError(code, message2), ...message2 ? { message: message2 } : {}, charged: "refunded" }), 1, failure4);
|
|
32968
|
+
};
|
|
32969
|
+
unsupported2 = (error2) => {
|
|
32970
|
+
const field = text6(error2.details.field);
|
|
32971
|
+
const allowed = error2.details.allowed;
|
|
32972
|
+
const reason2 = [field, allowed === void 0 ? void 0 : "allowed: " + JSON.stringify(allowed).slice(0, 200)].filter(Boolean).join(", ");
|
|
32973
|
+
const failure4 = { code: "VIDEO_OPTION_UNSUPPORTED", retryable: false, ...reason2 ? { reason: reason2 } : {} };
|
|
32974
|
+
return new GenerateError(failureLine(failure4, { other: describeError(error2.code, error2.message), message: error2.message, charged: "nothing" }), 1, failure4);
|
|
32642
32975
|
};
|
|
32643
32976
|
fetchClip = async (rt, client2, done2, out2) => {
|
|
32644
32977
|
const labels = { what: "the clip", retry: "run the same command again: it downloads the clip without paying again" };
|
|
@@ -32667,6 +33000,7 @@ var init_cloud2 = __esm({
|
|
|
32667
33000
|
const file = s.gate.file ?? (inside6.startsWith("..") ? void 0 : inside6.split(rt.path.sep).join("/"));
|
|
32668
33001
|
return { ...s.gate, project, ...file ? { file } : {} };
|
|
32669
33002
|
};
|
|
33003
|
+
ASK_MODEL2 = "set POPOST_VIDEO_MODEL only to a model the user names";
|
|
32670
33004
|
modelFacts = async (client2, id2) => {
|
|
32671
33005
|
const data = await client2.request("GET", "/videos/models").catch(() => void 0);
|
|
32672
33006
|
if (!isRecord(data) || !Array.isArray(data.models)) return void 0;
|
|
@@ -32675,7 +33009,7 @@ var init_cloud2 = __esm({
|
|
|
32675
33009
|
if (!model) return void 0;
|
|
32676
33010
|
const count5 = (v) => typeof v === "number" && v >= 0 ? v : void 0;
|
|
32677
33011
|
const [sounds, seconds8] = [count5(model.maxReferenceAudios), count5(model.maxReferenceAudioSeconds)];
|
|
32678
|
-
return { audioOptional: model.audioOptional === true, ...sounds !== void 0 ? { maxReferenceAudios: sounds } : {}, ...seconds8 !== void 0 ? { maxReferenceAudioSeconds: seconds8 } : {} };
|
|
33012
|
+
return { audioOptional: model.audioOptional === true, ...sounds !== void 0 ? { maxReferenceAudios: sounds } : {}, ...seconds8 !== void 0 ? { maxReferenceAudioSeconds: seconds8 } : {}, pictures: pictureLimitsOf(model) };
|
|
32679
33013
|
};
|
|
32680
33014
|
wavSeconds = (bytes) => {
|
|
32681
33015
|
try {
|
|
@@ -32688,26 +33022,32 @@ var init_cloud2 = __esm({
|
|
|
32688
33022
|
const sounds = refs.filter((r) => r.kind === "audio");
|
|
32689
33023
|
if (!sounds.length || !facts) return;
|
|
32690
33024
|
if (facts.maxReferenceAudios !== void 0 && sounds.length > facts.maxReferenceAudios)
|
|
32691
|
-
throw new GenerateError(facts.maxReferenceAudios === 0 ? "This video model takes no reference sounds, and the request has " + sounds.length + ' in "audios" (a voice sample goes with every speaking clip of a registered voice).
|
|
33025
|
+
throw new GenerateError(facts.maxReferenceAudios === 0 ? "This video model takes no reference sounds, and the request has " + sounds.length + ' in "audios" (a voice sample goes with every speaking clip of a registered voice, so that it speaks with the same voice in every clip). Ask the user whether to use a model that takes them (popost video generate --models lists "maxReferenceAudios"; ' + ASK_MODEL2 + ") or to go on without the voice sample; do not leave it out on your own. Nothing was sent." : "This video model takes at most " + facts.maxReferenceAudios + " reference sound" + (facts.maxReferenceAudios === 1 ? "" : "s") + ", and the request has " + sounds.length + ". Nothing was sent.", 2);
|
|
32692
33026
|
const total2 = sounds.reduce((n, r) => n + (wavSeconds(r.bytes) ?? 0), 0);
|
|
32693
33027
|
if (facts.maxReferenceAudioSeconds !== void 0 && facts.maxReferenceAudioSeconds > 0 && total2 > facts.maxReferenceAudioSeconds + 0.05)
|
|
32694
|
-
throw new GenerateError("The reference sounds of this request are " + total2.toFixed(1) + " s together; this video model takes " + facts.maxReferenceAudioSeconds + " s in all. Cut each speaker's sample shorter (popost video voice sample <project> --speaker <id> --start S --end E), or
|
|
33028
|
+
throw new GenerateError("The reference sounds of this request are " + total2.toFixed(1) + " s together; this video model takes " + facts.maxReferenceAudioSeconds + " s in all. Cut each speaker's sample shorter (popost video voice sample <project> --speaker <id> --start S --end E), or ask the user whether to use a model that takes more (popost video generate --models; " + ASK_MODEL2 + "). Nothing was sent.", 2);
|
|
33029
|
+
};
|
|
33030
|
+
prepare4 = async (rt, client2, s, request) => {
|
|
33031
|
+
const read2 = await readReferences(rt, request);
|
|
33032
|
+
const facts = request.audio === false || read2.some((r) => r.kind === "audio" || r.kind === "image") ? await modelFacts(client2, s.videoModel) : void 0;
|
|
33033
|
+
checkReferenceSounds(read2, facts);
|
|
33034
|
+
const limits = facts?.pictures ?? DEFAULT_PICTURE_LIMITS;
|
|
33035
|
+
const refs = planFits(read2, limits);
|
|
33036
|
+
const silent = request.audio === false && facts?.audioOptional === true;
|
|
33037
|
+
return { refs, limits, silent, seconds: request.seconds ?? DEFAULT_SECONDS, fitted: fittedOf(refs, limits) };
|
|
32695
33038
|
};
|
|
32696
33039
|
makeClip = async (rt, client2, s, request, out2) => {
|
|
32697
|
-
const seconds8 =
|
|
32698
|
-
const
|
|
32699
|
-
const
|
|
32700
|
-
|
|
32701
|
-
const silent = request.audio === false && facts?.audioOptional === true;
|
|
32702
|
-
const byContent = Object.fromEntries(LISTS2.map(([kind, list7]) => [list7, refs.filter((r) => r.kind === kind && !r.frame).map((r) => r.sha256)]));
|
|
32703
|
-
const frames = Object.fromEntries(refs.flatMap((r) => r.frame ? [[r.frame + "Frame", r.sha256]] : []));
|
|
33040
|
+
const { refs, limits, silent, seconds: seconds8, fitted } = await prepare4(rt, client2, s, request);
|
|
33041
|
+
const told = fitted.length ? { fitted } : {};
|
|
33042
|
+
const byContent = Object.fromEntries(LISTS2.map(([kind, list7]) => [list7, refs.filter((r) => r.kind === kind && !r.frame).map(identity)]));
|
|
33043
|
+
const frames = Object.fromEntries(refs.flatMap((r) => r.frame ? [[r.frame + "Frame", identity(r)]] : []));
|
|
32704
33044
|
const key2 = requestKey("video", { model: s.videoModel ?? null, resolution: s.resolution ?? null, prompt: request.prompt, seconds: seconds8, aspect: request.aspect ?? null, ...byContent, ...frames, ...silent ? { generateAudio: false } : {} });
|
|
32705
33045
|
const file = recordFile2(rt, key2);
|
|
32706
33046
|
let sent = await readRecord2(rt, file, key2);
|
|
32707
33047
|
let task = sent.taskId ? await findTask(client2, sent.taskId) : void 0;
|
|
32708
33048
|
if (task && sent.taskId && sent.told !== sent.taskId && (task.status === "failed" || task.status === "expired")) {
|
|
32709
33049
|
await save2(rt, file, { ...sent, told: sent.taskId });
|
|
32710
|
-
throw ended(task);
|
|
33050
|
+
throw ended(task, sent, refs.some((r) => r.kind === "audio"));
|
|
32711
33051
|
}
|
|
32712
33052
|
if (sent.taskId && (!task || task.status === "failed" || task.status === "expired")) {
|
|
32713
33053
|
sent = { key: key2, attempt: sent.attempt + 1, uploads: sent.uploads };
|
|
@@ -32723,26 +33063,24 @@ var init_cloud2 = __esm({
|
|
|
32723
33063
|
charged = credits2;
|
|
32724
33064
|
if (gate && (standing2 === "plan" || standing2 === "user")) await recordClip(rt, gate, { key: key2, ...gate.file ? { file: gate.file } : {}, what, seconds: seconds8, credits: credits2, by: standing2 });
|
|
32725
33065
|
};
|
|
32726
|
-
task = await submit(rt, client2, s, { request, seconds: seconds8, refs, file, silent, onPaid, ...unplanned ? { unplanned } : {} }, sent);
|
|
33066
|
+
task = await submit(rt, client2, s, { request, seconds: seconds8, refs, limits, file, silent, onPaid, ...unplanned ? { unplanned } : {} }, sent);
|
|
32727
33067
|
}
|
|
32728
33068
|
if (s.noWait && !ENDED.includes(task.status))
|
|
32729
|
-
throw new StillMaking({ task: task.id, state: task.status, chargedCredits: charged }, "The clip is being made on popost.ai (task " + task.id + ", " + task.status + "); it takes a few minutes. Run the same command again later to pick it up: it is not paid twice.");
|
|
33069
|
+
throw new StillMaking({ task: task.id, state: task.status, chargedCredits: charged, ...told }, "The clip is being made on popost.ai (task " + task.id + ", " + task.status + "); it takes a few minutes. Run the same command again later to pick it up: it is not paid twice.");
|
|
32730
33070
|
const done2 = await waitFor(rt, client2, task, s.waitMinutes);
|
|
32731
33071
|
if (done2.status !== "succeeded") {
|
|
32732
|
-
|
|
32733
|
-
|
|
33072
|
+
const record2 = await readRecord2(rt, file, key2);
|
|
33073
|
+
await save2(rt, file, { ...record2, told: done2.id });
|
|
33074
|
+
throw ended(done2, record2, refs.some((r) => r.kind === "audio"));
|
|
32734
33075
|
}
|
|
32735
33076
|
await fetchClip(rt, client2, done2, out2);
|
|
32736
|
-
return { ...typeof done2.credits === "number" ? { credits: done2.credits } : {}, chargedCredits: charged, key: key2, task: done2.id };
|
|
33077
|
+
return { ...typeof done2.credits === "number" ? { credits: done2.credits } : {}, chargedCredits: charged, key: key2, task: done2.id, ...told };
|
|
32737
33078
|
};
|
|
32738
33079
|
priceClip = async (rt, client2, s, request) => {
|
|
32739
|
-
const seconds8 =
|
|
32740
|
-
const
|
|
32741
|
-
const facts = request.audio === false || refs.some((r) => r.kind === "audio") ? await modelFacts(client2, s.videoModel) : void 0;
|
|
32742
|
-
checkReferenceSounds(refs, facts);
|
|
32743
|
-
const silent = request.audio === false && facts?.audioOptional === true;
|
|
32744
|
-
const key2 = "price-" + sha256(JSON.stringify([s.videoModel ?? null, s.resolution ?? null, seconds8, request.aspect ?? null, silent, refs.map((r) => [r.kind, r.frame ?? "", r.sha256])]));
|
|
33080
|
+
const { refs: planned, limits, silent, seconds: seconds8 } = await prepare4(rt, client2, s, request);
|
|
33081
|
+
const key2 = "price-" + sha256(JSON.stringify([s.videoModel ?? null, s.resolution ?? null, seconds8, request.aspect ?? null, silent, planned.map((r) => [r.kind, r.frame ?? "", identity(r)])]));
|
|
32745
33082
|
const file = recordFile2(rt, key2);
|
|
33083
|
+
const refs = await fitReferences(rt, planned, limits);
|
|
32746
33084
|
const uploaded = await ensureUploads2(rt, client2, refs, await readRecord2(rt, file, key2), file);
|
|
32747
33085
|
const sent = await ensureQuote(rt, client2, specOf(s, request, seconds8, refs, uploaded, silent), uploaded, file);
|
|
32748
33086
|
return sent.quote.price;
|
|
@@ -32750,10 +33088,12 @@ var init_cloud2 = __esm({
|
|
|
32750
33088
|
listModels = async (client2) => {
|
|
32751
33089
|
const data = await client2.request("GET", "/videos/models");
|
|
32752
33090
|
if (!isRecord(data) || !Array.isArray(data.models)) throw new GenerateError("popost.ai answered without a list of video models. Try again later.");
|
|
33091
|
+
const marked2 = data.models.find((m) => isRecord(m) && m.default === true && typeof m.id === "string");
|
|
33092
|
+
const byDefault = typeof data.default === "string" ? data.default : marked2 ? marked2.id : null;
|
|
32753
33093
|
return {
|
|
32754
|
-
models: data.models,
|
|
32755
|
-
default:
|
|
32756
|
-
note: `POPOST_VIDEO_MODEL takes an id, POPOST_VIDEO_RESOLUTION one of its resolutions. "frames": true is a model that takes "firstFrame" and "lastFrame". "audioOptional": true is a model that makes a clip without a sound track for a request whose "sound" is "silent" (any other model's track is taken out of the file). "maxReferenceAudios" and "maxReferenceAudioSeconds" are the reference sounds it takes (the voice sample of a speaking clip). Every clip costs credits, and popost.ai keeps it 7 days.`
|
|
33094
|
+
models: data.models.map((m) => isRecord(m) && byDefault !== null && m.id === byDefault ? { ...m, default: true } : m),
|
|
33095
|
+
default: byDefault,
|
|
33096
|
+
note: `The model marked "default": true is the platform's default: clips are made with it while POPOST_VIDEO_MODEL is unset, and it stays unset unless the user names another model (say in the plan which model is used). POPOST_VIDEO_MODEL takes an id, POPOST_VIDEO_RESOLUTION one of its resolutions. "frames": true is a model that takes "firstFrame" and "lastFrame". "audioOptional": true is a model that makes a clip without a sound track for a request whose "sound" is "silent" (any other model's track is taken out of the file). "maxReferenceAudios" and "maxReferenceAudioSeconds" are the reference sounds it takes (the voice sample of a speaking clip). A picture (a frame or a reference) outside what the model takes (its picture limits where it lists them, else width/height from ` + DEFAULT_PICTURE_LIMITS.minRatio + " to " + DEFAULT_PICTURE_LIMITS.maxRatio + " and sides of " + DEFAULT_PICTURE_LIMITS.minSide + " to " + DEFAULT_PICTURE_LIMITS.maxSide + ` px) is padded, never cut, before it is sent; the clip's result says so ("fitted"). Every clip costs credits, and popost.ai keeps it 7 days.`
|
|
32757
33097
|
};
|
|
32758
33098
|
};
|
|
32759
33099
|
}
|
|
@@ -32896,14 +33236,14 @@ var init_cloud_image = __esm({
|
|
|
32896
33236
|
place = async (rt, provider, taskId, out2, wanted) => {
|
|
32897
33237
|
const dir = out2 + ".parts";
|
|
32898
33238
|
try {
|
|
32899
|
-
const [
|
|
32900
|
-
const from = typeof
|
|
33239
|
+
const [first2] = await provider.materialize(taskId, dir);
|
|
33240
|
+
const from = typeof first2?.localPath === "string" ? first2.localPath : void 0;
|
|
32901
33241
|
if (!from) throw new GenerateError("popost.ai made the picture (task " + taskId + ") but gave no file of it. Try again later.");
|
|
32902
|
-
if (
|
|
33242
|
+
if (first2?.mimeType === wanted) return await rt.fs.rename(from, out2);
|
|
32903
33243
|
const converted = rt.programs ? await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", from, "-frames:v", "1", ...wanted === "image/jpeg" ? ["-q:v", "2"] : [], out2]).then(() => true, () => false) : false;
|
|
32904
33244
|
if (converted) return;
|
|
32905
33245
|
await rt.fs.rename(from, out2);
|
|
32906
|
-
rt.stderr("note: popost.ai made a " + String(
|
|
33246
|
+
rt.stderr("note: popost.ai made a " + String(first2?.mimeType) + " picture and it could not be converted here; " + rt.path.basename(out2) + " holds it as it was made.\n");
|
|
32907
33247
|
} finally {
|
|
32908
33248
|
await rt.fs.rm(dir);
|
|
32909
33249
|
}
|
|
@@ -32997,7 +33337,7 @@ var init_cloud_image = __esm({
|
|
|
32997
33337
|
});
|
|
32998
33338
|
|
|
32999
33339
|
// src/video/commands/credits.ts
|
|
33000
|
-
var CREDIT_OPTIONS,
|
|
33340
|
+
var CREDIT_OPTIONS, NEXT2, OVER, ceilingOf, walletFor;
|
|
33001
33341
|
var init_credits = __esm({
|
|
33002
33342
|
"src/video/commands/credits.ts"() {
|
|
33003
33343
|
"use strict";
|
|
@@ -33008,7 +33348,7 @@ var init_credits = __esm({
|
|
|
33008
33348
|
{ flag: "--confirm", kind: "flag", help: "the user agreed to the price this command printed without it (exit code 3), or it fits what is left of the budget they agreed to for this video: popost.ai may charge, within --max-credits" },
|
|
33009
33349
|
{ flag: "--max-credits", kind: "int", metavar: "N", help: "with --confirm: the most this whole command may spend, in credits (what is left of the budget of the video)" }
|
|
33010
33350
|
];
|
|
33011
|
-
|
|
33351
|
+
NEXT2 = "Nothing was charged. When these credits fit what is left of the budget the user agreed to for this video, run the same command again with --confirm --max-credits <what is left>; otherwise show the user the credits (and the balance) and run it so once they agree.";
|
|
33012
33352
|
OVER = "This costs more than --max-credits, what is left of the agreed budget; nothing was charged. Show the user the credits (and the balance), and run the same command again with --confirm --max-credits N (N at least the credits) only once they agree to more.";
|
|
33013
33353
|
ceilingOf = (args2) => {
|
|
33014
33354
|
const confirmed = args2.flag("confirm");
|
|
@@ -33025,7 +33365,7 @@ var init_credits = __esm({
|
|
|
33025
33365
|
if (balance !== void 0 && balance < credits2)
|
|
33026
33366
|
throw new VideoCommandError("Not enough credits: this needs " + credits2 + " credits and the balance is " + balance + ". Nothing was charged; popost account shows the balance and where to buy more. [INSUFFICIENT_CREDITS]");
|
|
33027
33367
|
const price = { credits: credits2, ...balance !== void 0 ? { balance } : {}, items: [...items] };
|
|
33028
|
-
if (max === void 0) throw new PriceNotAgreed(price,
|
|
33368
|
+
if (max === void 0) throw new PriceNotAgreed(price, NEXT2);
|
|
33029
33369
|
if (credits2 > max) throw new PriceNotAgreed({ ...price, maxCredits: max }, OVER);
|
|
33030
33370
|
return new Wallet(max);
|
|
33031
33371
|
};
|
|
@@ -33129,6 +33469,8 @@ var init_generate2 = __esm({
|
|
|
33129
33469
|
rt.stderr(oneLine(error2.message) + "\n");
|
|
33130
33470
|
return PENDING_EXIT2;
|
|
33131
33471
|
}
|
|
33472
|
+
const failure4 = error2 instanceof GenerateError ? error2.failure : void 0;
|
|
33473
|
+
if (failure4) printJson(rt, { error: { ...failure4, ...failure4.reason ? { reason: scrub(failure4.reason, secrets) } : {} } });
|
|
33132
33474
|
rt.stderr(oneLine(scrub(errorText(error2), secrets)) + "\n");
|
|
33133
33475
|
return exitOf(error2);
|
|
33134
33476
|
}
|
|
@@ -33142,7 +33484,7 @@ var init_generate2 = __esm({
|
|
|
33142
33484
|
{ name: "out", required: false, help: "the file to write: .mp4 for a clip, .png, .jpg or .webp for a picture" }
|
|
33143
33485
|
],
|
|
33144
33486
|
options: [
|
|
33145
|
-
{ flag: "--models", kind: "flag", help:
|
|
33487
|
+
{ flag: "--models", kind: "flag", help: `list the video models (id, resolutions, seconds, aspect ratios, reference limits, credits; the platform's default marked "default": true) and make nothing` },
|
|
33146
33488
|
{ flag: "--yes", kind: "flag", help: "the user agreed to the price this call was shown; a budget set in POPOST_GEN_MAX_CREDITS still holds" },
|
|
33147
33489
|
{ flag: "--no-wait", kind: "flag", help: 'send the clip or picture and return; while it is being made, prints {"pending": {...}} with exit code 4, and the same command later downloads it without paying again (POPOST_GEN_NO_WAIT=1 does the same). Without it the command waits for the file' },
|
|
33148
33490
|
...CREDIT_OPTIONS,
|
|
@@ -33298,9 +33640,9 @@ var init_product = __esm({
|
|
|
33298
33640
|
const [bx, by2, width, height] = m.slice(1).map(Number);
|
|
33299
33641
|
const original = x2.original ?? { file: x2.file, sha256: x2.sha256 };
|
|
33300
33642
|
const from = rt.path.resolve(dir, original.file);
|
|
33301
|
-
const
|
|
33302
|
-
if (width < MIN_CROP || height < MIN_CROP || bx + width >
|
|
33303
|
-
throw new VideoCommandError("The box " + box2 + " does not fit: the picture is " +
|
|
33643
|
+
const size2 = await sizeOf2(rt, from);
|
|
33644
|
+
if (width < MIN_CROP || height < MIN_CROP || bx + width > size2.width || by2 + height > size2.height)
|
|
33645
|
+
throw new VideoCommandError("The box " + box2 + " does not fit: the picture is " + size2.width + "x" + size2.height + ", and a crop is at least " + MIN_CROP + " pixels on each side and lies inside it. Choose a box that holds the whole product.");
|
|
33304
33646
|
const file = PRODUCT_DIR + "/" + p.id + "-" + String(i + 1).padStart(2, "0") + ".crop.png";
|
|
33305
33647
|
await rt.fs.mkdir(rt.path.join(dir, PRODUCT_DIR));
|
|
33306
33648
|
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", from, "-vf", "crop=" + width + ":" + height + ":" + bx + ":" + by2 + ":exact=1", "-frames:v", "1", rt.path.join(dir, file)]);
|
|
@@ -34172,8 +34514,8 @@ var init_collect = __esm({
|
|
|
34172
34514
|
const problems2 = (report4?.problems ?? []).filter((p) => !(p.level === "error" && /^It was not made: it costs/.test(p.message)));
|
|
34173
34515
|
const sheet4 = (await readProductSheet(rt, dir)).sheet;
|
|
34174
34516
|
const cast = await readCast(rt, dir).catch(() => void 0);
|
|
34175
|
-
const
|
|
34176
|
-
const
|
|
34517
|
+
const productPictures2 = new Map((sheet4?.products ?? []).flatMap((p) => p.pictures.map((x2) => [x2.file, p.id])));
|
|
34518
|
+
const castPictures2 = new Map((cast?.roles ?? []).flatMap((r) => r.image ? [[r.image, r.id]] : []));
|
|
34177
34519
|
const clips = [];
|
|
34178
34520
|
const kept3 = [];
|
|
34179
34521
|
for (const r of o.requests) {
|
|
@@ -34187,8 +34529,8 @@ var init_collect = __esm({
|
|
|
34187
34529
|
const anchor = o.picture?.file;
|
|
34188
34530
|
const pictures = (q.images ?? []).map((f, i) => {
|
|
34189
34531
|
const file = rel(rt, dir, f);
|
|
34190
|
-
const role =
|
|
34191
|
-
return { file, role, name: "@image" + (i + 1) + (role === "product" ? " " +
|
|
34532
|
+
const role = productPictures2.has(file) ? "product" : castPictures2.has(file) ? "cast" : file === anchor ? "anchor" : "reference";
|
|
34533
|
+
return { file, role, name: "@image" + (i + 1) + (role === "product" ? " " + productPictures2.get(file) : role === "cast" ? " " + castPictures2.get(file) : "") };
|
|
34192
34534
|
});
|
|
34193
34535
|
for (const [k, role] of [["firstFrame", "first frame"], ["lastFrame", "last frame"]]) if (r[k]) pictures.push({ file: r[k], role, name: role });
|
|
34194
34536
|
const notes2 = [
|
|
@@ -34256,7 +34598,7 @@ var init_sheet4 = __esm({
|
|
|
34256
34598
|
FONTS2 = '"Helvetica Neue", Arial, "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif';
|
|
34257
34599
|
CSS3 = "*{margin:0;padding:0;box-sizing:border-box}body{width:" + WIDTH2 + "px;background:#f4f4f2;color:#16181b;font-family:" + FONTS2 + ";font-size:20px;line-height:1.35;padding:28px}h1{font-size:30px;margin-bottom:6px}h2{font-size:22px;margin:22px 0 10px;border-bottom:2px solid #16181b;padding-bottom:4px}.sum{font-size:20px;color:#3b4046}.row{display:flex;gap:14px;flex-wrap:wrap;align-items:flex-start}.tile{width:236px}.tile .box{width:236px;height:236px;background:#fff;border:3px solid #9aa0a8;display:flex;align-items:center;justify-content:center}.tile img{max-width:100%;max-height:100%;display:block}.tile.product .box{border-color:#e8a020;border-width:5px}.tile.cast .box{border-color:#2f6fd0;border-width:5px}.tile .cap{font-size:16px;margin-top:4px;overflow-wrap:anywhere}.tile .role{font-weight:700}.card{background:#fff;border:1px solid #c9cdd3;padding:12px 14px;margin-bottom:12px}.card .head{font-weight:700;font-size:21px}.card .spec{color:#3b4046;margin:2px 0 6px}.card .what{margin-bottom:8px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}.note{font-size:16px;color:#6a4b00}.none{font-size:16px;color:#6b7079}";
|
|
34258
34600
|
short = (text13, n) => text13.length > n ? text13.slice(0, n - 1).trimEnd() + "\u2026" : text13;
|
|
34259
|
-
sheetHtml2 = (s, rows3,
|
|
34601
|
+
sheetHtml2 = (s, rows3, first2, page2, data) => {
|
|
34260
34602
|
const img = (file) => {
|
|
34261
34603
|
const bytes = data.get(file);
|
|
34262
34604
|
const mime = bytes ? sniffImageMime(bytes.subarray(0, 16)) : void 0;
|
|
@@ -34268,18 +34610,18 @@ var init_sheet4 = __esm({
|
|
|
34268
34610
|
"<h1>" + escapeHtml(msg("Inputs to confirm", "\u5F85\u786E\u8BA4\u7684\u8F93\u5165\u5185\u5BB9")) + " " + escapeHtml(page2) + "</h1>",
|
|
34269
34611
|
'<div class="sum">' + escapeHtml(t.clips + msg(" clip(s), ", " \u4E2A\u89C6\u9891\u7247\u6BB5\uFF0C") + t.seconds + msg(" s", " \u79D2") + " \xB7 " + t.pictures + msg(" picture(s)", " \u5F20\u56FE\u7247") + " \xB7 " + s.voices.length + msg(" voice(s)", " \u4E2A\u914D\u97F3") + " \xB7 " + msg("total ", "\u5408\u8BA1 ") + t.credits + msg(" credits", " \u79EF\u5206") + (t.unpriced ? msg(" + " + t.unpriced + " unpriced", " + " + t.unpriced + " \u9879\u672A\u5B9A\u4EF7") : "") + (t.balance !== void 0 ? " \xB7 " + msg("balance ", "\u4F59\u989D ") + t.balance : "")) + "</div>"
|
|
34270
34612
|
];
|
|
34271
|
-
if (
|
|
34613
|
+
if (first2 && s.products.length) {
|
|
34272
34614
|
out2.push("<h2>" + escapeHtml(msg("Product: the picture exactly as it is sent", "\u5546\u54C1\uFF1A\u5B9E\u9645\u53D1\u9001\u7684\u56FE\u7247")) + '</h2><div class="row">');
|
|
34273
34615
|
for (const p of s.products) for (const x2 of p.pictures) out2.push(tile("product", x2.file, p.id, x2.original ? msg("crop of ", "\u88C1\u526A\u81EA ") + x2.original : msg("the user's picture, whole", "\u7528\u6237\u539F\u56FE\uFF0C\u672A\u88C1\u526A")));
|
|
34274
34616
|
out2.push("</div>");
|
|
34275
34617
|
}
|
|
34276
|
-
if (
|
|
34618
|
+
if (first2 && (s.cast.length || s.anchor)) {
|
|
34277
34619
|
out2.push("<h2>" + escapeHtml(msg("People", "\u51FA\u955C\u4EBA\u7269")) + '</h2><div class="row">');
|
|
34278
34620
|
for (const c of s.cast) out2.push(c.picture ? tile("cast", c.picture, c.id, short(c.description, 90)) : '<div class="tile cast"><div class="box"><span class="none">' + escapeHtml(msg("described in the prompt, no picture", "\u4EC5\u5728\u63D0\u793A\u8BCD\u4E2D\u63CF\u8FF0\uFF0C\u65E0\u56FE\u7247")) + '</span></div><div class="cap"><span class="role">' + escapeHtml(c.id) + "</span> " + escapeHtml(short(c.description, 90)) + "</div></div>");
|
|
34279
34621
|
if (s.anchor) out2.push(tile("cast", s.anchor.file, msg("anchor", "\u951A\u5B9A\u56FE"), s.anchor.note));
|
|
34280
34622
|
out2.push("</div>");
|
|
34281
34623
|
}
|
|
34282
|
-
if (
|
|
34624
|
+
if (first2 && s.voices.length) {
|
|
34283
34625
|
out2.push("<h2>" + escapeHtml(msg("Voice", "\u914D\u97F3")) + "</h2>");
|
|
34284
34626
|
for (const v of s.voices) out2.push('<div class="card"><div class="head">' + escapeHtml(v.speaker + ": " + (v.name ?? v.voice)) + '</div><div class="spec">' + escapeHtml([v.language, msg("speed ", "\u8BED\u901F ") + v.speed, v.lines.length + msg(" line(s)", " \u53E5\u53F0\u8BCD"), v.credits === null ? "" : v.credits + msg(" credits", " \u79EF\u5206")].filter(Boolean).join(" \xB7 ")) + '</div><div class="what">' + escapeHtml(short(v.script.display ?? v.lines.join(" / "), 260)) + '</div><div class="note">' + escapeHtml(v.sample ? msg("listen: ", "\u8BD5\u542C\uFF1A") + v.sample.file : msg("no free sample", "\u6CA1\u6709\u514D\u8D39\u8BD5\u542C")) + "</div></div>");
|
|
34285
34627
|
}
|
|
@@ -34538,8 +34880,8 @@ var init_takes = __esm({
|
|
|
34538
34880
|
const spans = lines2.map((line) => {
|
|
34539
34881
|
const part = a.tokens.slice(k, k + tokenize(line).length);
|
|
34540
34882
|
k += part.length;
|
|
34541
|
-
const
|
|
34542
|
-
const span2 =
|
|
34883
|
+
const first2 = part[0], end = part[part.length - 1];
|
|
34884
|
+
const span2 = first2 && end ? { start: first2.start / 1e3, end: end.end / 1e3 } : { start: last, end: last };
|
|
34543
34885
|
last = span2.end;
|
|
34544
34886
|
return span2;
|
|
34545
34887
|
});
|
|
@@ -34550,11 +34892,11 @@ var init_takes = __esm({
|
|
|
34550
34892
|
const each = seconds8 / Math.max(1, units2.length);
|
|
34551
34893
|
return units2.map((text13, k) => ({ text: text13, start: k * each, end: (k + 1) * each }));
|
|
34552
34894
|
};
|
|
34553
|
-
piecesOf = (
|
|
34895
|
+
piecesOf = (take2, spans, ref, fps, hold, keepPauses = false) => {
|
|
34554
34896
|
const pieces = [];
|
|
34555
|
-
let lines2 = [
|
|
34556
|
-
for (let j = 1; j <
|
|
34557
|
-
const a =
|
|
34897
|
+
let lines2 = [take2.lines[0]], from = 0;
|
|
34898
|
+
for (let j = 1; j < take2.lines.length; j++) {
|
|
34899
|
+
const a = take2.lines[j - 1], b = take2.lines[j];
|
|
34558
34900
|
const sa = spans[j - 1], sb = spans[j];
|
|
34559
34901
|
const gap = (ref.starts[b] ?? 0) - ((ref.starts[a] ?? 0) + (ref.slots[a] ?? 0));
|
|
34560
34902
|
const held = (ref.starts[b] ?? 0) - (ref.starts[a] ?? 0) > (sb.start - sa.start) * fps;
|
|
@@ -34777,14 +35119,14 @@ var init_speak = __esm({
|
|
|
34777
35119
|
const clips = await speakLines(rt, { lines: takes.map((t) => t.text), dir: rt.path.join(o.outDir, "assets", "voice"), speaker: o.speaker, fps, name: "take", ...plan4.voice ? { voice: plan4.voice } : {}, ...plan4.speed ? { speed: plan4.speed } : {} });
|
|
34778
35120
|
const said = [];
|
|
34779
35121
|
let own3 = true;
|
|
34780
|
-
for (const [k,
|
|
34781
|
-
const clip11 = clips[k], lines3 =
|
|
35122
|
+
for (const [k, take2] of takes.entries()) {
|
|
35123
|
+
const clip11 = clips[k], lines3 = take2.lines.map((i) => spoken[i] ?? "");
|
|
34782
35124
|
const got = await takeWords(rt, o, clip11, lines3, fps, notes2);
|
|
34783
35125
|
const words2 = got.words;
|
|
34784
35126
|
own3 = own3 && got.own;
|
|
34785
35127
|
const { spans, matched } = lineSpans(lines3, words2);
|
|
34786
|
-
if (matched < 0.6) notes2.push("Only " + Math.round(matched * 100) + "% of the words of the take of captions[" +
|
|
34787
|
-
said.push({ take, clip: clip11, words: words2, spans, pieces: piecesOf(
|
|
35128
|
+
if (matched < 0.6) notes2.push("Only " + Math.round(matched * 100) + "% of the words of the take of captions[" + take2.lines[0] + ".." + take2.lines[take2.lines.length - 1] + "] were said as written: its lines are placed by the words around them.");
|
|
35129
|
+
said.push({ take: take2, clip: clip11, words: words2, spans, pieces: piecesOf(take2, spans, ref, fps, o.hold === true, o.keepPauses === true) });
|
|
34788
35130
|
}
|
|
34789
35131
|
const lengthNotes = [];
|
|
34790
35132
|
const fitted = await fitLength(rt, said, ref, fps, o, lengthNotes);
|
|
@@ -34819,10 +35161,10 @@ var init_speak = __esm({
|
|
|
34819
35161
|
...plan4.speed ? { speed: plan4.speed } : {}
|
|
34820
35162
|
});
|
|
34821
35163
|
const flow = (ls) => retarget({ ...o.input, plan: { ...plan4, sound: VOICE_FILE }, ...plan4.sound ? { music: plan4.sound } : {}, spoken: { frames: ls.map((l) => l.frames), ...o.hold ? { hold: true } : {} }, wordsFile: WORDS_FILE });
|
|
34822
|
-
const
|
|
34823
|
-
const fit = o.fitTempo &&
|
|
35164
|
+
const first2 = flow(said);
|
|
35165
|
+
const fit = o.fitTempo && first2.timing ? await fitTempo(rt, { lines: said, captions, slots: first2.timing.slots, max: o.fitTempo, fps }) : void 0;
|
|
34824
35166
|
const lines2 = fit?.lines ?? said;
|
|
34825
|
-
const result = fit?.tempos.some((t2) => t2 > 1) ? flow(lines2) :
|
|
35167
|
+
const result = fit?.tempos.some((t2) => t2 > 1) ? flow(lines2) : first2;
|
|
34826
35168
|
if (!result.project || !result.timing) return { result, lines: lines2, notes: notes2 };
|
|
34827
35169
|
notes2.push(...fit?.notes ?? []);
|
|
34828
35170
|
const t = result.timing;
|
|
@@ -35116,7 +35458,7 @@ var init_character = __esm({
|
|
|
35116
35458
|
});
|
|
35117
35459
|
|
|
35118
35460
|
// src/video/commands/materials.ts
|
|
35119
|
-
var errorsIn, PICTURE_EXT2, givenAnchor, characterOf, budgeted,
|
|
35461
|
+
var errorsIn, PICTURE_EXT2, givenAnchor, characterOf, budgeted, newSpend, paying, LOOK_AGAIN_MS, waitLimitMs, pendingNext3, beingMade2, allRuns, PRICE_NEXT, specOf2, toAgree, materials;
|
|
35120
35462
|
var init_materials = __esm({
|
|
35121
35463
|
"src/video/commands/materials.ts"() {
|
|
35122
35464
|
"use strict";
|
|
@@ -35130,6 +35472,7 @@ var init_materials = __esm({
|
|
|
35130
35472
|
init_character();
|
|
35131
35473
|
init_approved();
|
|
35132
35474
|
init_generate();
|
|
35475
|
+
init_failure();
|
|
35133
35476
|
init_time();
|
|
35134
35477
|
init_wallet();
|
|
35135
35478
|
init_credits();
|
|
@@ -35176,11 +35519,30 @@ var init_materials = __esm({
|
|
|
35176
35519
|
return made;
|
|
35177
35520
|
}
|
|
35178
35521
|
});
|
|
35179
|
-
|
|
35180
|
-
|
|
35181
|
-
|
|
35182
|
-
|
|
35183
|
-
|
|
35522
|
+
newSpend = () => ({ paid: /* @__PURE__ */ new Map(), refunded: 0, failed: /* @__PURE__ */ new Map() });
|
|
35523
|
+
paying = (generator, wallet, spend) => ({
|
|
35524
|
+
make: async (kind, request, out2, env2) => {
|
|
35525
|
+
const failed4 = spend.failed.get(out2);
|
|
35526
|
+
if (failed4) throw failed4;
|
|
35527
|
+
try {
|
|
35528
|
+
return await generator.make(kind, request, out2, env2);
|
|
35529
|
+
} catch (e) {
|
|
35530
|
+
if (e instanceof StillMaking) {
|
|
35531
|
+
const charged = Math.max(0, e.pending.chargedCredits ?? 0);
|
|
35532
|
+
wallet?.pay(charged);
|
|
35533
|
+
spend.paid.set(out2, (spend.paid.get(out2) ?? 0) + charged);
|
|
35534
|
+
}
|
|
35535
|
+
if (e instanceof GenerationFailed) {
|
|
35536
|
+
const paid = spend.paid.get(out2) ?? 0;
|
|
35537
|
+
const back = Math.min(paid, e.failure.refundedCredits ?? 0);
|
|
35538
|
+
wallet?.refund(back);
|
|
35539
|
+
spend.paid.set(out2, paid - back);
|
|
35540
|
+
spend.refunded += back;
|
|
35541
|
+
spend.failed.set(out2, e);
|
|
35542
|
+
}
|
|
35543
|
+
throw e;
|
|
35544
|
+
}
|
|
35545
|
+
}
|
|
35184
35546
|
});
|
|
35185
35547
|
LOOK_AGAIN_MS = 15e3;
|
|
35186
35548
|
waitLimitMs = (rt) => (Number(rt.env.POPOST_GEN_WAIT_MIN) > 0 ? Number(rt.env.POPOST_GEN_WAIT_MIN) : 30) * 6e4;
|
|
@@ -35192,7 +35554,7 @@ var init_materials = __esm({
|
|
|
35192
35554
|
};
|
|
35193
35555
|
return [...count5("video", "clip"), ...count5("image", "picture")].join(" and ");
|
|
35194
35556
|
};
|
|
35195
|
-
allRuns = async (rt, once5, noWait) => {
|
|
35557
|
+
allRuns = async (rt, once5, noWait, spend) => {
|
|
35196
35558
|
let r = await once5();
|
|
35197
35559
|
const made = new Set(r.materials.filter((m) => m.made).map((m) => m.file));
|
|
35198
35560
|
let charged = r.chargedCredits;
|
|
@@ -35205,7 +35567,8 @@ var init_materials = __esm({
|
|
|
35205
35567
|
for (const m of r.materials) if (m.made) made.add(m.file);
|
|
35206
35568
|
charged += r.chargedCredits;
|
|
35207
35569
|
}
|
|
35208
|
-
|
|
35570
|
+
const refunded = spend.refunded > 0 ? { refundedCredits: spend.refunded } : {};
|
|
35571
|
+
return { ...r, chargedCredits: charged - spend.refunded, ...refunded, materials: r.materials.map((m) => made.has(m.file) && !m.made && !m.error ? { ...m, made: true } : m) };
|
|
35209
35572
|
};
|
|
35210
35573
|
PRICE_NEXT = "Nothing was charged for these files. When the credits fit what is left of the budget the user agreed to for this video, run the same command again with --confirm --max-credits <what is left>; otherwise show the user the model, resolution, seconds, aspect ratio and credits of every item (and the balance) and run it so once they agree.";
|
|
35211
35574
|
specOf2 = (c) => ({
|
|
@@ -35300,10 +35663,12 @@ var init_materials = __esm({
|
|
|
35300
35663
|
const lang = await readProjectLang(rt, dir);
|
|
35301
35664
|
const policy = isChinese(lang) ? (await promptPolicy(rt)).policy : "user";
|
|
35302
35665
|
const musicTrack = await hasMusicTrack(rt, dir);
|
|
35666
|
+
const spend = newSpend();
|
|
35667
|
+
const paid = paying(budgeted(generator, wallet, args2.list("approve-unplanned")), wallet, spend);
|
|
35303
35668
|
const r = await allRuns(rt, () => makeMaterials(rt, {
|
|
35304
35669
|
requests,
|
|
35305
35670
|
dir,
|
|
35306
|
-
generator:
|
|
35671
|
+
generator: paid,
|
|
35307
35672
|
plan: wallet !== void 0,
|
|
35308
35673
|
submitOnly: true,
|
|
35309
35674
|
product: { ...limits, paying: !pricedOnly },
|
|
@@ -35318,7 +35683,7 @@ var init_materials = __esm({
|
|
|
35318
35683
|
...picture3 ? { picture: picture3 } : {},
|
|
35319
35684
|
// A clip takes minutes: a person watching sees which one, on stderr; stdout keeps the one JSON document.
|
|
35320
35685
|
onStep: (file, done2, total2) => rt.stderr(file + " (" + (done2 + 1) + "/" + total2 + ")\n")
|
|
35321
|
-
}), noWait);
|
|
35686
|
+
}), noWait, spend);
|
|
35322
35687
|
const agree = toAgree(r.materials, r.clipMusic);
|
|
35323
35688
|
printJson(rt, {
|
|
35324
35689
|
ok: errorsIn(r.problems) === 0,
|
|
@@ -35335,6 +35700,7 @@ var init_materials = __esm({
|
|
|
35335
35700
|
} : {},
|
|
35336
35701
|
credits: r.credits,
|
|
35337
35702
|
chargedCredits: r.chargedCredits,
|
|
35703
|
+
...r.refundedCredits ? { refundedCredits: r.refundedCredits } : {},
|
|
35338
35704
|
...r.anchor ? { anchor: r.anchor } : {},
|
|
35339
35705
|
...r.toConfirm ? { toConfirm: r.toConfirm } : {},
|
|
35340
35706
|
...agree ?? {},
|
|
@@ -35850,8 +36216,8 @@ var init_readback = __esm({
|
|
|
35850
36216
|
const unitsExpected = units(form), unitsHeard = units(heard);
|
|
35851
36217
|
line.heard = heard;
|
|
35852
36218
|
line.heardScore = Math.round(Math.max(closeness(form, heard), unitsExpected ? Math.min(1, unitsHeard / unitsExpected) * 0.6 : 0) * 100) / 100;
|
|
35853
|
-
const
|
|
35854
|
-
if (
|
|
36219
|
+
const first2 = words.find((w) => w.start < item2.end + 6 && w.end > item2.start - 6);
|
|
36220
|
+
if (first2) line.lag = item2.start - first2.start;
|
|
35855
36221
|
}
|
|
35856
36222
|
return line;
|
|
35857
36223
|
});
|
|
@@ -36176,8 +36542,8 @@ var init_rings = __esm({
|
|
|
36176
36542
|
const i = px2[j] ?? 0, x0 = i % f.w, y0 = Math.floor(i / f.w);
|
|
36177
36543
|
for (const [dx, dy] of DIRS2) {
|
|
36178
36544
|
if (!inside3(f, x0 + dx, y0 + dy)) continue;
|
|
36179
|
-
const
|
|
36180
|
-
if (dot2(sub2(
|
|
36545
|
+
const first2 = labOf(f, (y0 + dy) * f.w + x0 + dx);
|
|
36546
|
+
if (dot2(sub2(first2, lab), sub2(first2, lab)) <= NEAR * NEAR) continue;
|
|
36181
36547
|
ends++;
|
|
36182
36548
|
for (let k = 1; k <= reach && inside3(f, x0 + dx * k, y0 + dy * k); k++) {
|
|
36183
36549
|
const a = along(lab, partner, labOf(f, (y0 + dy * k) * f.w + x0 + dx * k));
|
|
@@ -36419,18 +36785,18 @@ var init_letters = __esm({
|
|
|
36419
36785
|
return lines2.length >= Math.max(2, 0.2 * n) ? [{ ...aggregate(s.group, s.px, s.perLine, lines2), ground: false, told: lines2 }] : [];
|
|
36420
36786
|
});
|
|
36421
36787
|
HUG_TIE = 0.1;
|
|
36422
|
-
fillAmong = (frames, boxes2,
|
|
36423
|
-
const mutual = (s) => along(
|
|
36424
|
-
const within = (s) => s.enclosed >= ENCLOSED && (dEdge(s.around,
|
|
36425
|
-
const a = along(s.group.lab,
|
|
36788
|
+
fillAmong = (frames, boxes2, first2, own3, weight) => {
|
|
36789
|
+
const mutual = (s) => along(first2.group.lab, first2.around, s.group.lab).t >= 0.5 && along(s.group.lab, s.around, first2.group.lab).t >= 0.5;
|
|
36790
|
+
const within = (s) => s.enclosed >= ENCLOSED && (dEdge(s.around, first2.around) <= 15 || (() => {
|
|
36791
|
+
const a = along(s.group.lab, first2.around, s.around);
|
|
36426
36792
|
return a.t >= 0.5 && a.off <= 15;
|
|
36427
36793
|
})());
|
|
36428
|
-
const rivals = own3.filter((s) => s ===
|
|
36429
|
-
if (rivals.length < 2) return
|
|
36794
|
+
const rivals = own3.filter((s) => s === first2 || within(s) || mutual(s));
|
|
36795
|
+
if (rivals.length < 2) return first2;
|
|
36430
36796
|
const told = rivals.flatMap((s) => s.told ? [s.told] : []);
|
|
36431
36797
|
const hugs = rivals.map((s) => ({ s, hug: hugOf(frames, boxes2, s.px, s.group.at.map((l, k) => told.every((t) => t.includes(k)) ? l : void 0), s.around) }));
|
|
36432
36798
|
const most = Math.max(...hugs.map((h) => h.hug));
|
|
36433
|
-
return hugs.filter((h) => h.hug >= most - HUG_TIE).sort((a, b) => weight(b.s) - weight(a.s))[0]?.s ??
|
|
36799
|
+
return hugs.filter((h) => h.hug >= most - HUG_TIE).sort((a, b) => weight(b.s) - weight(a.s))[0]?.s ?? first2;
|
|
36434
36800
|
};
|
|
36435
36801
|
lettersOf = (frames, boxes2, all, around3) => {
|
|
36436
36802
|
const n = frames.length;
|
|
@@ -36677,20 +37043,20 @@ var init_reveal2 = __esm({
|
|
|
36677
37043
|
return frames.map((f) => {
|
|
36678
37044
|
const has2 = columns.map((ink) => ink.filter((i) => near2(f, i, colours)).length >= 0.5 * ink.length);
|
|
36679
37045
|
const count5 = has2.filter(Boolean).length;
|
|
36680
|
-
const last = has2.lastIndexOf(true),
|
|
36681
|
-
const ordered3 = count5 > 0 && (count5 >= 0.85 * (last + 1) || count5 >= 0.85 * (has2.length -
|
|
37046
|
+
const last = has2.lastIndexOf(true), first2 = has2.indexOf(true);
|
|
37047
|
+
const ordered3 = count5 > 0 && (count5 >= 0.85 * (last + 1) || count5 >= 0.85 * (has2.length - first2));
|
|
36682
37048
|
return { share: count5 / columns.length, ordered: ordered3 };
|
|
36683
37049
|
});
|
|
36684
37050
|
};
|
|
36685
37051
|
lineReveal = (cover, chars, fps) => {
|
|
36686
|
-
const
|
|
36687
|
-
if (
|
|
36688
|
-
if (cover.slice(0,
|
|
36689
|
-
const full = cover.findIndex((c, k) => k >=
|
|
37052
|
+
const first2 = cover.findIndex((c) => c.share >= 0.08);
|
|
37053
|
+
if (first2 <= 0) return void 0;
|
|
37054
|
+
if (cover.slice(0, first2).some((c) => c.share >= 0.08)) return void 0;
|
|
37055
|
+
const full = cover.findIndex((c, k) => k >= first2 && c.share >= 0.9);
|
|
36690
37056
|
const wholeFrames = Math.max(2, Math.ceil(WHOLE_SECONDS * fps));
|
|
36691
|
-
if (full >= 0 && full -
|
|
37057
|
+
if (full >= 0 && full - first2 <= wholeFrames) return { kind: "whole" };
|
|
36692
37058
|
const end = full >= 0 ? full : cover.length - 1;
|
|
36693
|
-
const span2 = cover.slice(
|
|
37059
|
+
const span2 = cover.slice(first2, end + 1);
|
|
36694
37060
|
if (full < 0 && span2.length < wholeFrames + 2) return void 0;
|
|
36695
37061
|
if (span2.filter((c) => c.ordered).length < 0.7 * span2.length) return { kind: "whole" };
|
|
36696
37062
|
let steps2 = 1, at7 = span2[0]?.share ?? 0;
|
|
@@ -36700,7 +37066,7 @@ var init_reveal2 = __esm({
|
|
|
36700
37066
|
}
|
|
36701
37067
|
const reached = Math.max(0.08, span2[span2.length - 1]?.share ?? 1);
|
|
36702
37068
|
const perStep = chars * reached / steps2;
|
|
36703
|
-
return { kind: perStep >= 1.6 ? "words" : "chars", ...full >= 0 ? { frames: full -
|
|
37069
|
+
return { kind: perStep >= 1.6 ? "words" : "chars", ...full >= 0 ? { frames: full - first2 } : {} };
|
|
36704
37070
|
};
|
|
36705
37071
|
revealOf = (lines2, fps) => {
|
|
36706
37072
|
const seen = lines2.flatMap((l) => l ? [l] : []);
|
|
@@ -36723,8 +37089,8 @@ var init_reveal2 = __esm({
|
|
|
36723
37089
|
const wanted = [...new Set(spans.flatMap((s) => [...Array.from({ length: s.to - s.from + 1 }, (_v, k) => s.from + k), s.mid]))].sort((a, b) => a - b);
|
|
36724
37090
|
const scale = Math.min(1, MAX_WIDTH / info.width);
|
|
36725
37091
|
const W = Math.round(info.width * scale / 2) * 2, H = Math.round(info.height * scale / 2) * 2;
|
|
36726
|
-
const
|
|
36727
|
-
const top2 = Math.max(0, Math.floor(Math.min(...cues.map((c) => c.box[1])) * H -
|
|
37092
|
+
const size2 = median10(cues.map((c) => c.box[3])) * H;
|
|
37093
|
+
const top2 = Math.max(0, Math.floor(Math.min(...cues.map((c) => c.box[1])) * H - size2)), bottom = Math.min(H, Math.ceil(Math.max(...cues.map((c) => c.box[1] + c.box[3])) * H + size2));
|
|
36728
37094
|
const h = bottom - top2;
|
|
36729
37095
|
if (h <= 0) return void 0;
|
|
36730
37096
|
const colour2 = await readColour(rt, video, info);
|
|
@@ -37019,9 +37385,9 @@ var init_look = __esm({
|
|
|
37019
37385
|
if (picked2.length < MIN_SAMPLES) return { frames: [], boxes: [], texts: [] };
|
|
37020
37386
|
const info = await probe2(rt, video);
|
|
37021
37387
|
const W = info.width, H = info.height;
|
|
37022
|
-
const
|
|
37023
|
-
const top2 = Math.max(0, Math.floor(Math.min(...picked2.map((p) => p.cue.box[1])) * H - 2.5 *
|
|
37024
|
-
const bottom = Math.min(H, Math.ceil(Math.max(...picked2.map((p) => p.cue.box[1] + p.cue.box[3])) * H + 2.5 *
|
|
37388
|
+
const size2 = median10(picked2.map((p) => p.cue.box[3])) * H;
|
|
37389
|
+
const top2 = Math.max(0, Math.floor(Math.min(...picked2.map((p) => p.cue.box[1])) * H - 2.5 * size2));
|
|
37390
|
+
const bottom = Math.min(H, Math.ceil(Math.max(...picked2.map((p) => p.cue.box[1] + p.cue.box[3])) * H + 2.5 * size2));
|
|
37025
37391
|
const h = bottom - top2;
|
|
37026
37392
|
const frames = [...new Set(picked2.map((p) => p.frame))].sort((a, b) => a - b);
|
|
37027
37393
|
const colour2 = await readColour(rt, video, info);
|
|
@@ -37107,9 +37473,9 @@ var init_text = __esm({
|
|
|
37107
37473
|
captionBandOf = (track) => {
|
|
37108
37474
|
const captions = track.cues.filter((c) => c.role === "caption");
|
|
37109
37475
|
if (captions.length < 3) return void 0;
|
|
37110
|
-
const
|
|
37111
|
-
const top2 = Math.min(...captions.map((c) => c.box[1])) - 0.7 *
|
|
37112
|
-
const bottom = Math.max(...captions.map((c) => c.box[1] + c.box[3])) + 0.7 *
|
|
37476
|
+
const size2 = captions.map((c) => c.size).sort((a, b) => a - b)[Math.floor(captions.length / 2)] ?? 0;
|
|
37477
|
+
const top2 = Math.min(...captions.map((c) => c.box[1])) - 0.7 * size2;
|
|
37478
|
+
const bottom = Math.max(...captions.map((c) => c.box[1] + c.box[3])) + 0.7 * size2;
|
|
37113
37479
|
return { top: Math.max(0, Math.round(top2 * 1e3) / 1e3), bottom: Math.min(1, Math.round(bottom * 1e3) / 1e3) };
|
|
37114
37480
|
};
|
|
37115
37481
|
inBand = (l, band) => {
|
|
@@ -37146,11 +37512,11 @@ var init_text = __esm({
|
|
|
37146
37512
|
const maxSide = opts.maxSide ?? 1280;
|
|
37147
37513
|
const scale = Math.min(1, maxSide / Math.max(info.width, info.height));
|
|
37148
37514
|
const width = Math.round(info.width * scale / 2) * 2;
|
|
37149
|
-
const
|
|
37515
|
+
const size2 = scale < 1 ? ",scale=" + width + ":-2" : "";
|
|
37150
37516
|
return withTempDir(rt, "popost-video-frames-", async (root) => {
|
|
37151
37517
|
const wholeFrames = Array.from({ length: Math.ceil(info.frames / coarse) }, (_, k) => k * coarse);
|
|
37152
37518
|
opts.onStage?.("taking " + wholeFrames.length + " frames out");
|
|
37153
|
-
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", "select=not(mod(n\\," + coarse + "))" +
|
|
37519
|
+
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", "select=not(mod(n\\," + coarse + "))" + size2, "-fps_mode", "passthrough", "-q:v", "2", rt.path.join(root, "w%06d.jpg")]);
|
|
37154
37520
|
const listed3 = await numbered(rt, root, "w", wholeFrames);
|
|
37155
37521
|
opts.onStage?.("the reader is reading " + listed3.length + " frames");
|
|
37156
37522
|
const whole2 = (await reader.read(listed3)).sort((a, b) => a.frame - b.frame);
|
|
@@ -37159,7 +37525,7 @@ var init_text = __esm({
|
|
|
37159
37525
|
if (!band) return { samples: whole2, step: coarse, total: info.frames, fps: info.fps, whole: whole2.length, strips: 0 };
|
|
37160
37526
|
const stripFrames = Array.from({ length: Math.ceil(info.frames / step2) }, (_, k) => k * step2).filter((n) => n % coarse !== 0);
|
|
37161
37527
|
const crop2 = ",crop=iw:trunc(ih*" + (band.bottom - band.top).toFixed(4) + "/2)*2:0:trunc(ih*" + band.top.toFixed(4) + ")";
|
|
37162
|
-
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", "select=not(mod(n\\," + step2 + "))*gt(mod(n\\," + coarse + ")\\,0)" +
|
|
37528
|
+
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", "select=not(mod(n\\," + step2 + "))*gt(mod(n\\," + coarse + ")\\,0)" + size2 + crop2, "-fps_mode", "passthrough", "-q:v", "2", rt.path.join(root, "s%06d.jpg")]);
|
|
37163
37529
|
const stripped = await numbered(rt, root, "s", stripFrames);
|
|
37164
37530
|
opts.onStage?.("the reader is reading " + stripped.length + " caption strips");
|
|
37165
37531
|
const strips = await reader.read(stripped);
|
|
@@ -37228,13 +37594,13 @@ var init_readback_frames = __esm({
|
|
|
37228
37594
|
readFrames2 = async (rt, video, reader, frames, o) => {
|
|
37229
37595
|
const info = await probe2(rt, video);
|
|
37230
37596
|
const scale = Math.min(1, 1280 / Math.max(info.width, info.height));
|
|
37231
|
-
const
|
|
37597
|
+
const size2 = scale < 1 ? ",scale=" + Math.round(info.width * scale / 2) * 2 + ":-2" : "";
|
|
37232
37598
|
const wanted = [...new Set(frames.filter((f) => Number.isInteger(f) && f >= 0 && f < info.frames))].sort((a, b) => a - b);
|
|
37233
37599
|
if (!wanted.length) return { samples: [], step: o.step, total: info.frames, fps: info.fps, whole: 0, strips: 0 };
|
|
37234
37600
|
return withTempDir(rt, "popost-video-frames-", async (root) => {
|
|
37235
37601
|
o.onStage?.("taking " + wanted.length + " frames out");
|
|
37236
37602
|
const select2 = "select='" + pickExpression(wanted) + "'";
|
|
37237
|
-
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", select2 +
|
|
37603
|
+
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", select2 + size2, "-fps_mode", "passthrough", "-q:v", "2", rt.path.join(root, "r%06d.jpg")]);
|
|
37238
37604
|
const files = (await rt.fs.readdir(root)).filter((f) => f.startsWith("r") && f.endsWith(".jpg")).sort();
|
|
37239
37605
|
if (files.length !== wanted.length)
|
|
37240
37606
|
throw new ToolError("readback: extracted " + files.length + " of " + wanted.length + " requested frames. Check the video decoder and frame count; an incomplete reading cannot verify the captions.");
|
|
@@ -37349,10 +37715,10 @@ var init_readback_run = __esm({
|
|
|
37349
37715
|
if (looked || frames.length < 3 * FIRST_LOOK) return reader.read(frames);
|
|
37350
37716
|
looked = true;
|
|
37351
37717
|
const picked2 = new Set(Array.from({ length: FIRST_LOOK }, (_, k) => Math.floor((2 * k + 1) * frames.length / (2 * FIRST_LOOK))));
|
|
37352
|
-
const
|
|
37353
|
-
onFirst(
|
|
37718
|
+
const first2 = await reader.read(frames.filter((_, i) => picked2.has(i)));
|
|
37719
|
+
onFirst(first2.reduce((n, s) => n + s.lines.length, 0) / FIRST_LOOK);
|
|
37354
37720
|
const rest = await reader.read(frames.filter((_, i) => !picked2.has(i)));
|
|
37355
|
-
return [...
|
|
37721
|
+
return [...first2, ...rest].sort((a, b) => a.frame - b.frame);
|
|
37356
37722
|
}
|
|
37357
37723
|
};
|
|
37358
37724
|
};
|
|
@@ -37494,12 +37860,12 @@ var init_sheets = __esm({
|
|
|
37494
37860
|
blit = (c, tile, tw, th, x2, y) => {
|
|
37495
37861
|
for (let r = 0; r < th; r++) c.data.set(tile.subarray(r * tw * 3, (r + 1) * tw * 3), ((y + r) * c.width + x2) * 3);
|
|
37496
37862
|
};
|
|
37497
|
-
decodePicked = async (rt, video, frames,
|
|
37498
|
-
const bytes =
|
|
37863
|
+
decodePicked = async (rt, video, frames, size2, colour2, onFrame) => {
|
|
37864
|
+
const bytes = size2.width * size2.height * 3;
|
|
37499
37865
|
for (const part of frameChunks(frames)) {
|
|
37500
37866
|
let k = 0, filled2 = 0;
|
|
37501
37867
|
let current = new Uint8Array(bytes);
|
|
37502
|
-
const vf = "select='" + pickExpression(part) + "',scale=" +
|
|
37868
|
+
const vf = "select='" + pickExpression(part) + "',scale=" + size2.width + ":" + size2.height + ":in_color_matrix=" + colour2.matrix + ":in_range=" + colour2.range + ":flags=area+accurate_rnd,format=rgb24";
|
|
37503
37869
|
const r = await runFfmpeg(rt, ["-loglevel", "error", "-i", video, "-map", "0:v:0", "-an", "-sn", "-vf", vf, "-fps_mode", "passthrough", "-f", "rawvideo", "pipe:1"], void 0, (chunk) => {
|
|
37504
37870
|
let off2 = 0;
|
|
37505
37871
|
while (off2 < chunk.length) {
|
|
@@ -37544,14 +37910,14 @@ var init_sheets = __esm({
|
|
|
37544
37910
|
writeSheets2 = async (rt, video, specs2, o) => {
|
|
37545
37911
|
const p = o.probe ?? await probe2(rt, video);
|
|
37546
37912
|
const colour2 = o.colour ?? await readColour(rt, video, p);
|
|
37547
|
-
const
|
|
37913
|
+
const size2 = thumbSize(p.width, p.height, Math.min(o.width, p.width));
|
|
37548
37914
|
const fps = p.fps > 0 ? p.fps : 30;
|
|
37549
37915
|
const secondsOf4 = o.secondsOf ?? ((f) => f / fps);
|
|
37550
37916
|
const last = Math.max(0, sourceFrames(p) - 1);
|
|
37551
37917
|
const drawings = specs2.map((spec10) => {
|
|
37552
37918
|
const frames2 = spec10.frames.filter((f) => f >= 0 && f <= last);
|
|
37553
|
-
const grid = gridOf(Math.max(1, frames2.length),
|
|
37554
|
-
const drawn = { width: GAP2 + grid.columns * (
|
|
37919
|
+
const grid = gridOf(Math.max(1, frames2.length), size2.width);
|
|
37920
|
+
const drawn = { width: GAP2 + grid.columns * (size2.width + GAP2), height: GAP2 + grid.rows * (size2.height + BAND + GAP2) };
|
|
37555
37921
|
const result = { file: rt.path.join(o.outDir, spec10.file), frames: frames2, seconds: frames2.map((f) => Math.round(secondsOf4(f) * 1e3) / 1e3), ...grid, ...lookSize(drawn.width, drawn.height) };
|
|
37556
37922
|
return { spec: { ...spec10, frames: frames2 }, grid, drawn, left: frames2.length, result };
|
|
37557
37923
|
});
|
|
@@ -37573,24 +37939,24 @@ var init_sheets = __esm({
|
|
|
37573
37939
|
});
|
|
37574
37940
|
};
|
|
37575
37941
|
const frames = [.../* @__PURE__ */ new Set([...wanted.keys(), ...keep3])].sort((a, b) => a - b);
|
|
37576
|
-
await decodePicked(rt, video, frames,
|
|
37942
|
+
await decodePicked(rt, video, frames, size2, colour2, (frame2, rgb) => {
|
|
37577
37943
|
if (keep3.has(frame2)) kept3.set(frame2, rgb);
|
|
37578
37944
|
for (const { d, slot } of wanted.get(frame2) ?? []) {
|
|
37579
37945
|
const marked2 = (d.spec.marked ?? []).some(([a, b]) => frame2 >= a && frame2 <= b);
|
|
37580
|
-
place2(d, slot, rgb,
|
|
37946
|
+
place2(d, slot, rgb, size2.width, size2.height, timeLabel(secondsOf4(frame2)), marked2);
|
|
37581
37947
|
if (--d.left === 0) finish3(d);
|
|
37582
37948
|
}
|
|
37583
37949
|
});
|
|
37584
37950
|
for (const d of drawings) if (d.left > 0 && d.canvas) finish3(d);
|
|
37585
37951
|
await written2;
|
|
37586
37952
|
if (failed4) throw failed4.error;
|
|
37587
|
-
return { sheets: drawings.filter((d) => d.written).map((d) => d.result), kept: kept3, size };
|
|
37953
|
+
return { sheets: drawings.filter((d) => d.written).map((d) => d.result), kept: kept3, size: size2 };
|
|
37588
37954
|
};
|
|
37589
37955
|
}
|
|
37590
37956
|
});
|
|
37591
37957
|
|
|
37592
37958
|
// src/video/look/index.ts
|
|
37593
|
-
var two11, r36, clamp4, shotMoments, secondMoments, GLYPHS2, labelFilter, JPEG,
|
|
37959
|
+
var two11, r36, clamp4, shotMoments, secondMoments, GLYPHS2, labelFilter, JPEG, pair4, sheet3, lookAt3;
|
|
37594
37960
|
var init_look2 = __esm({
|
|
37595
37961
|
"src/video/look/index.ts"() {
|
|
37596
37962
|
"use strict";
|
|
@@ -37618,7 +37984,7 @@ var init_look2 = __esm({
|
|
|
37618
37984
|
return [box2(s, s, 7 * s, 9 * s, "black@0.6"), ...cells].join(",");
|
|
37619
37985
|
};
|
|
37620
37986
|
JPEG = LOOK_JPEG;
|
|
37621
|
-
|
|
37987
|
+
pair4 = async (rt, a, b, height, out2) => {
|
|
37622
37988
|
const side = (i, letter) => "[" + i + ":v]scale=-2:" + height + "," + labelFilter(letter, height) + "[" + letter + "]";
|
|
37623
37989
|
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", a, "-i", b, "-filter_complex", side(0, "A") + ";" + side(1, "B") + ";[A][B]hstack=inputs=2", "-frames:v", "1", ...JPEG, out2]);
|
|
37624
37990
|
};
|
|
@@ -37648,7 +38014,7 @@ var init_look2 = __esm({
|
|
|
37648
38014
|
continue;
|
|
37649
38015
|
}
|
|
37650
38016
|
const other = others[i];
|
|
37651
|
-
await
|
|
38017
|
+
await pair4(rt, left.get(m.frame), right?.get(other), height, file);
|
|
37652
38018
|
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3, against: { frame: other, second: r36(other / b.fps) } });
|
|
37653
38019
|
}
|
|
37654
38020
|
});
|
|
@@ -38981,8 +39347,8 @@ var init_build2 = __esm({
|
|
|
38981
39347
|
init_ffmpeg();
|
|
38982
39348
|
even5 = (n) => Math.max(2, Math.round(n / 2) * 2);
|
|
38983
39349
|
UNTAGGED = ",format=rgb24,setparams=color_primaries=unknown:color_trc=unknown:colorspace=unknown";
|
|
38984
|
-
grab2 = async (rt, video, frame2, out2,
|
|
38985
|
-
const crop2 = box2 ? ",crop=" + [even5(box2[2] *
|
|
39350
|
+
grab2 = async (rt, video, frame2, out2, size2, box2) => {
|
|
39351
|
+
const crop2 = box2 ? ",crop=" + [even5(box2[2] * size2.width), even5(box2[3] * size2.height), Math.round(box2[0] * size2.width), Math.round(box2[1] * size2.height)].join(":") : "";
|
|
38986
39352
|
await runFfmpegOk(rt, ["-y", "-i", video, "-vf", "select=eq(n\\," + Math.max(0, frame2) + ")" + crop2 + UNTAGGED, "-frames:v", "1", "-fps_mode", "passthrough", out2]);
|
|
38987
39353
|
};
|
|
38988
39354
|
transitionSpec2 = (b, toFrames2) => {
|
|
@@ -39019,12 +39385,12 @@ var init_build2 = __esm({
|
|
|
39019
39385
|
return w <= 0 || h <= 0 ? 0 : w * h / Math.min(a[2] * a[3], b[2] * b[3]);
|
|
39020
39386
|
};
|
|
39021
39387
|
cleanFrame = (shot, into, out2) => {
|
|
39022
|
-
const
|
|
39388
|
+
const first2 = into ? Math.max(shot.start, into.end) : shot.start;
|
|
39023
39389
|
const last = out2 ? Math.min(shot.end - 1, out2.start) : shot.end - 1;
|
|
39024
39390
|
const firstAppear = shot.events.filter((e) => e.kind === "appear").map((e) => e.start).sort((a, b) => a - b)[0];
|
|
39025
39391
|
const limit = firstAppear === void 0 ? last : Math.min(last, firstAppear - 1);
|
|
39026
|
-
if (shot.camera.kind === "move" && shot.camera.zoomPerS < 0) return Math.max(
|
|
39027
|
-
return Math.min(Math.max(
|
|
39392
|
+
if (shot.camera.kind === "move" && shot.camera.zoomPerS < 0) return Math.max(first2, limit);
|
|
39393
|
+
return Math.min(Math.max(first2, shot.start), Math.max(first2, limit));
|
|
39028
39394
|
};
|
|
39029
39395
|
buildFootageDraft = async (rt, o) => {
|
|
39030
39396
|
const m = o.measure;
|
|
@@ -39061,7 +39427,7 @@ var init_build2 = __esm({
|
|
|
39061
39427
|
const fps = Math.max(1, Math.round(m.source.fps));
|
|
39062
39428
|
const ratio3 = fps / m.source.fps;
|
|
39063
39429
|
const toFrames2 = (n) => Math.round(n * ratio3);
|
|
39064
|
-
const
|
|
39430
|
+
const size2 = { width: m.source.width, height: m.source.height };
|
|
39065
39431
|
const notes2 = [];
|
|
39066
39432
|
if (Math.abs(ratio3 - 1) > 1e-6) notes2.push({ at: "canvas.fps", kind: "approximate", message: "The source runs at " + m.source.fps.toFixed(3) + " fps; the project uses " + fps + "." });
|
|
39067
39433
|
await rt.fs.mkdir(rt.path.join(o.outDir, "assets"));
|
|
@@ -39077,7 +39443,7 @@ var init_build2 = __esm({
|
|
|
39077
39443
|
const frames = Math.max(1, toFrames2(shot.end) - start);
|
|
39078
39444
|
const file = "assets/" + id2 + ".png";
|
|
39079
39445
|
materials2.push({ id: "pic-" + id2, kind: "image", file, note: "placeholder: a frame of the reference" });
|
|
39080
|
-
jobs2.push(() => grab2(rt, o.video, cleanFrame(shot, into, out2), rt.path.join(o.outDir, file),
|
|
39446
|
+
jobs2.push(() => grab2(rt, o.video, cleanFrame(shot, into, out2), rt.path.join(o.outDir, file), size2));
|
|
39081
39447
|
const cam = shot.camera;
|
|
39082
39448
|
const moving = cam.kind === "move" && cam.confidence >= minConfidence;
|
|
39083
39449
|
const camera3 = moving ? { ...Math.abs(cam.zoomPerS) >= 5e-3 ? { zoom: Number(cam.zoomPerS.toFixed(3)) } : {}, ...Math.hypot(...cam.panPerS) >= 5e-3 ? { pan: [Number(cam.panPerS[0].toFixed(3)), Number(cam.panPerS[1].toFixed(3))] } : {} } : void 0;
|
|
@@ -39099,7 +39465,7 @@ var init_build2 = __esm({
|
|
|
39099
39465
|
const settled2 = Math.min((gone ? gone.start : shot.end) - 1, ev.end + 2);
|
|
39100
39466
|
const pic = "assets/" + itemId + ".png";
|
|
39101
39467
|
materials2.push({ id: "pic-" + itemId, kind: "image", file: pic, note: "placeholder: an element cut out of the reference" });
|
|
39102
|
-
jobs2.push(() => grab2(rt, o.video, settled2, rt.path.join(o.outDir, pic),
|
|
39468
|
+
jobs2.push(() => grab2(rt, o.video, settled2, rt.path.join(o.outDir, pic), size2, ev.box));
|
|
39103
39469
|
const from = Math.max(0, toFrames2(ev.start) - start);
|
|
39104
39470
|
const to = gone ? Math.max(from + 1, toFrames2(gone.end) - start) : frames;
|
|
39105
39471
|
const room = Math.max(1, Math.floor((to - from) / 2));
|
|
@@ -39135,7 +39501,7 @@ var init_build2 = __esm({
|
|
|
39135
39501
|
else segment2.in.frames = room;
|
|
39136
39502
|
notes2.push({ at: "segments[" + k + "].in", kind: "approximate", message: "The measured " + (segment2.in?.transition ?? "transition") + " spans " + asked2 + " frames, longer than a neighbouring shot (" + room + " frames); " + (room < 2 ? "it became a hard cut." : "it was shortened to " + room + ".") });
|
|
39137
39503
|
});
|
|
39138
|
-
const project = { version: 1, canvas: { width: even5(
|
|
39504
|
+
const project = { version: 1, canvas: { width: even5(size2.width), height: even5(size2.height), fps }, materials: materials2, segments: segments2, tracks, note: "draft built from a measurement, no model involved" };
|
|
39139
39505
|
await rt.fs.writeFile(rt.path.join(o.outDir, "video.json"), JSON.stringify(project, null, 2) + "\n");
|
|
39140
39506
|
await rt.fs.writeFile(rt.path.join(o.outDir, "draft-notes.json"), JSON.stringify(notes2, null, 2) + "\n");
|
|
39141
39507
|
return { project, notes: notes2 };
|
|
@@ -39379,8 +39745,8 @@ var init_chunked = __esm({
|
|
|
39379
39745
|
shotsIn = (r, ranges) => r.segments.filter((s) => ranges.some(([from, to]) => s.start < to && s.end > from)).map((s) => s.id);
|
|
39380
39746
|
renderInChunks = async (rt, job) => {
|
|
39381
39747
|
const started = Date.now();
|
|
39382
|
-
const
|
|
39383
|
-
const c = job.keep ? await keyContext(rt, job.root,
|
|
39748
|
+
const first2 = job.sessions[0], r = first2.resolved;
|
|
39749
|
+
const c = job.keep ? await keyContext(rt, job.root, first2, { image: job.image, quality: job.quality, crf: job.crf }) : void 0;
|
|
39384
39750
|
const dir = c ? chunkDir(rt, c) : job.out + ".chunks";
|
|
39385
39751
|
await rt.fs.mkdir(dir);
|
|
39386
39752
|
try {
|
|
@@ -39434,9 +39800,9 @@ var init_layout = __esm({
|
|
|
39434
39800
|
const fitLines = lineH > 0 ? Math.floor((h + 1e-9) / lineH) : 0;
|
|
39435
39801
|
const tall = needH > h;
|
|
39436
39802
|
const how = tall ? "it needs " + fact.lines + " line" + (fact.lines === 1 ? "" : "s") + ", " + r37(needH) + " of the canvas height (" + Math.round(needH * canvas.height) + " px), but its box is " + r37(h) + " high (" + Math.round(h * canvas.height) + " px): " + Math.round((needH / h - 1) * 100) + "% too tall" : "its widest line is " + r37(needW) + " of the canvas width (" + Math.round(needW * canvas.width) + " px), but its box is " + r37(w) + " wide";
|
|
39437
|
-
const
|
|
39803
|
+
const size2 = r37(Math.max(w, needW) * MARGIN2) + " x " + r37(Math.max(h, needH) * MARGIN2);
|
|
39438
39804
|
const shorten = tall && fitLines >= 1 && fact.lines > fitLines ? Math.max(1, Math.floor(chars * fitLines / fact.lines)) : 0;
|
|
39439
|
-
const box2 = "enlarge the box (" + at7.box + ") to " +
|
|
39805
|
+
const box2 = "enlarge the box (" + at7.box + ") to " + size2 + " (width x height, fractions of the canvas)";
|
|
39440
39806
|
const fix2 = shorten > 0 ? "Shorten the text (" + at7.text + ") to about " + shorten + " characters (it has " + chars + "), or " + box2 + "." : box2.charAt(0).toUpperCase() + box2.slice(1) + ', or use a smaller "size".';
|
|
39441
39807
|
return { level: "error", at: shorten > 0 ? at7.text : at7.box, message: describe(item2) + " does not fit its box: " + how + ".", fix: fix2 };
|
|
39442
39808
|
};
|
|
@@ -40512,11 +40878,11 @@ var init_truth = __esm({
|
|
|
40512
40878
|
const base = segment2.base;
|
|
40513
40879
|
if (base.kind === "color" || base.kind === "scene") return { kind: "static", zoomPerS: 0, panPerS: [0, 0], confidence: 1 };
|
|
40514
40880
|
if (base.moves?.length) {
|
|
40515
|
-
const
|
|
40881
|
+
const first2 = base.moves[0]?.scale[0] ?? 1, last = base.moves[base.moves.length - 1]?.scale[1] ?? 1;
|
|
40516
40882
|
const seconds8 = (segment2.end - segment2.start) / fps;
|
|
40517
40883
|
return {
|
|
40518
40884
|
kind: "move",
|
|
40519
|
-
zoomPerS: Math.round((last /
|
|
40885
|
+
zoomPerS: Math.round((last / first2 - 1) / seconds8 * 1e4) / 1e4,
|
|
40520
40886
|
panPerS: [0, 0],
|
|
40521
40887
|
confidence: 1,
|
|
40522
40888
|
moves: base.moves.map((mv) => ({ start: mv.from, end: mv.to, scale: mv.scale, focus: mv.focus }))
|
|
@@ -40571,20 +40937,20 @@ var init_write = __esm({
|
|
|
40571
40937
|
return Array.from({ length: n }, (_, i) => "c" + i + "=0x" + [0, 0, 0].map(() => r.int(0, 255).toString(16).padStart(2, "0")).join("")).join(":");
|
|
40572
40938
|
};
|
|
40573
40939
|
lavfi = (recipe, width, height) => {
|
|
40574
|
-
const
|
|
40940
|
+
const size2 = "size=" + width + "x" + height;
|
|
40575
40941
|
switch (recipe.source) {
|
|
40576
40942
|
case "mandelbrot":
|
|
40577
|
-
return { input: "mandelbrot=" +
|
|
40943
|
+
return { input: "mandelbrot=" + size2 + ":rate=10:start_scale=" + (1.5 + recipe.seed % 10 / 10).toFixed(1), seek: 1 + recipe.seed % 30 / 10 };
|
|
40578
40944
|
case "testsrc2":
|
|
40579
|
-
return { input: "testsrc2=" +
|
|
40945
|
+
return { input: "testsrc2=" + size2 + ":rate=10", seek: recipe.seed % 50 / 10 };
|
|
40580
40946
|
case "cellauto":
|
|
40581
|
-
return { input: "cellauto=" +
|
|
40947
|
+
return { input: "cellauto=" + size2 + ":rate=10:rule=" + [18, 30, 110, 150][recipe.seed % 4] + ":seed=" + recipe.seed, seek: 2 };
|
|
40582
40948
|
case "gradients":
|
|
40583
|
-
return { input: "gradients=" +
|
|
40949
|
+
return { input: "gradients=" + size2 + ":rate=10:seed=" + recipe.seed + ":nb_colors=" + (3 + recipe.seed % 4) + ":" + gradientColours(recipe.seed, 3 + recipe.seed % 4), seek: recipe.seed % 40 / 10 };
|
|
40584
40950
|
case "smptebars":
|
|
40585
|
-
return { input: "smptebars=" +
|
|
40951
|
+
return { input: "smptebars=" + size2 + ":rate=10", seek: 0 };
|
|
40586
40952
|
case "life":
|
|
40587
|
-
return { input: "life=" +
|
|
40953
|
+
return { input: "life=" + size2 + ":rate=10:seed=" + recipe.seed + ":ratio=0.3:mold=12:life_color=#40e0d0:death_color=#402010", seek: 1.5 };
|
|
40588
40954
|
}
|
|
40589
40955
|
};
|
|
40590
40956
|
makePicture2 = async (rt, recipe, out2, width, height) => {
|
|
@@ -40982,8 +41348,8 @@ var init_stage = __esm({
|
|
|
40982
41348
|
const svg = document.createElementNS(NS, "svg");
|
|
40983
41349
|
svg.setAttribute("style", "position:absolute;left:0;top:0;width:100%;height:100%;overflow:visible");
|
|
40984
41350
|
root.appendChild(svg);
|
|
40985
|
-
const shape = (
|
|
40986
|
-
const el = document.createElementNS(NS,
|
|
41351
|
+
const shape = (tag4, attrs) => {
|
|
41352
|
+
const el = document.createElementNS(NS, tag4);
|
|
40987
41353
|
for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
|
|
40988
41354
|
el.setAttribute("display", "none");
|
|
40989
41355
|
svg.appendChild(el);
|
|
@@ -41047,11 +41413,11 @@ var init_stage = __esm({
|
|
|
41047
41413
|
const selectorOf = (el) => {
|
|
41048
41414
|
const own3 = anchor(el);
|
|
41049
41415
|
if (own3 && own3 !== "body") return own3;
|
|
41050
|
-
const
|
|
41416
|
+
const tag4 = el.tagName.toLowerCase();
|
|
41051
41417
|
for (const attr2 of ["data-testid", "data-test", "aria-label", "name", "placeholder", "href"]) {
|
|
41052
41418
|
const v = el.getAttribute(attr2);
|
|
41053
41419
|
if (!v || v.length > 60 || /[",\\\n\]]/.test(v)) continue;
|
|
41054
|
-
const sel =
|
|
41420
|
+
const sel = tag4 + "[" + attr2 + '="' + v + '"]';
|
|
41055
41421
|
if (unique3(sel)) return sel;
|
|
41056
41422
|
}
|
|
41057
41423
|
if (unique3(part(el))) return part(el);
|
|
@@ -41133,8 +41499,8 @@ var init_stage = __esm({
|
|
|
41133
41499
|
range2.selectNodeContents(n);
|
|
41134
41500
|
const inView = Array.from(range2.getClientRects()).some((r) => r.width >= 2 && r.height >= 2 && r.right > cam.x && r.left < cam.x + cam.w && r.bottom > cam.y && r.top < cam.y + cam.h);
|
|
41135
41501
|
if (!inView || !visible(el)) continue;
|
|
41136
|
-
const
|
|
41137
|
-
if (
|
|
41502
|
+
const size2 = Math.round(parseFloat(getComputedStyle(el).fontSize) * 4) / 4;
|
|
41503
|
+
if (size2 > 0) counts.set(size2, (counts.get(size2) ?? 0) + chars);
|
|
41138
41504
|
}
|
|
41139
41505
|
return Array.from(counts.entries());
|
|
41140
41506
|
};
|
|
@@ -41142,9 +41508,9 @@ var init_stage = __esm({
|
|
|
41142
41508
|
const el = document.activeElement;
|
|
41143
41509
|
if (!el || el === document.body) return null;
|
|
41144
41510
|
const cs = getComputedStyle(el);
|
|
41145
|
-
const
|
|
41146
|
-
const h =
|
|
41147
|
-
const w = Math.max(1,
|
|
41511
|
+
const size2 = parseFloat(cs.fontSize) || 16;
|
|
41512
|
+
const h = size2 * 1.15;
|
|
41513
|
+
const w = Math.max(1, size2 / 14);
|
|
41148
41514
|
const textual = el instanceof HTMLTextAreaElement || el instanceof HTMLInputElement && /^(text|search|email|url|tel|password|number|)$/.test(el.type);
|
|
41149
41515
|
if (textual) {
|
|
41150
41516
|
const input = el;
|
|
@@ -41491,12 +41857,12 @@ var init_steps2 = __esm({
|
|
|
41491
41857
|
textSizes = (counts) => {
|
|
41492
41858
|
const sizes = [...counts.entries()].filter(([, n]) => n > 0).sort((a, b) => a[0] - b[0]);
|
|
41493
41859
|
const total2 = sizes.reduce((n, [, c]) => n + c, 0);
|
|
41494
|
-
const
|
|
41495
|
-
if (!
|
|
41860
|
+
const first2 = sizes[0];
|
|
41861
|
+
if (!first2 || !total2) return null;
|
|
41496
41862
|
let seen = 0;
|
|
41497
41863
|
for (const [px2, n] of sizes) {
|
|
41498
41864
|
seen += n;
|
|
41499
|
-
if (seen >= total2 / 2) return { smallestPx: Math.round(
|
|
41865
|
+
if (seen >= total2 / 2) return { smallestPx: Math.round(first2[0] * 10) / 10, medianPx: Math.round(px2 * 10) / 10 };
|
|
41500
41866
|
}
|
|
41501
41867
|
return null;
|
|
41502
41868
|
};
|
|
@@ -41586,7 +41952,7 @@ var init_director = __esm({
|
|
|
41586
41952
|
const cdp = await createScreenshotSession(page2, o.view, o.pixels);
|
|
41587
41953
|
await page2.evaluate(installStage, o.css);
|
|
41588
41954
|
const { view } = o;
|
|
41589
|
-
const
|
|
41955
|
+
const size2 = pointerSize(view);
|
|
41590
41956
|
const line = lineWidth(view);
|
|
41591
41957
|
let camera3 = WHOLE;
|
|
41592
41958
|
let pointer;
|
|
@@ -41646,7 +42012,7 @@ var init_director = __esm({
|
|
|
41646
42012
|
camera: camera3,
|
|
41647
42013
|
sample: sampleNext || frames % SAMPLE_EVERY === 0,
|
|
41648
42014
|
...highlight ? { highlight: { ...highlight, line } } : {},
|
|
41649
|
-
...pointer ? { pointer: { ...pointer, dip, size } } : {},
|
|
42015
|
+
...pointer ? { pointer: { ...pointer, dip, size: size2 } } : {},
|
|
41650
42016
|
...ring2 ? { ring: { ...ring2, line: Math.max(1.5, line * 0.75) } } : {}
|
|
41651
42017
|
};
|
|
41652
42018
|
sampleNext = false;
|
|
@@ -41824,7 +42190,7 @@ var init_director = __esm({
|
|
|
41824
42190
|
for (let f = 0; f < DEFAULTS.pressFrames; f++) {
|
|
41825
42191
|
const p = pressAt(f);
|
|
41826
42192
|
dip = p.dip;
|
|
41827
|
-
ring2 = { x: to.x, y: to.y, radius: p.ring *
|
|
42193
|
+
ring2 = { x: to.x, y: to.y, radius: p.ring * size2, opacity: p.opacity };
|
|
41828
42194
|
yield await frame2();
|
|
41829
42195
|
if (f === 1) await settleAfter(() => page2.mouse.click(to.x, to.y));
|
|
41830
42196
|
}
|
|
@@ -42185,17 +42551,17 @@ var init_files = __esm({
|
|
|
42185
42551
|
return file;
|
|
42186
42552
|
}
|
|
42187
42553
|
};
|
|
42188
|
-
parseRange = (header2,
|
|
42554
|
+
parseRange = (header2, size2) => {
|
|
42189
42555
|
const m = header2?.trim().match(/^bytes=(\d*)-(\d*)$/);
|
|
42190
42556
|
if (!m || m[1] === "" && m[2] === "") return void 0;
|
|
42191
|
-
const [
|
|
42192
|
-
if (
|
|
42557
|
+
const [first2, last] = [m[1] ?? "", m[2] ?? ""];
|
|
42558
|
+
if (first2 === "") {
|
|
42193
42559
|
const suffix = Number(last);
|
|
42194
|
-
return suffix > 0 &&
|
|
42560
|
+
return suffix > 0 && size2 > 0 ? { start: Math.max(0, size2 - suffix), end: size2 - 1 } : "unsatisfiable";
|
|
42195
42561
|
}
|
|
42196
|
-
const start = Number(
|
|
42197
|
-
const end = last === "" ?
|
|
42198
|
-
return start <
|
|
42562
|
+
const start = Number(first2);
|
|
42563
|
+
const end = last === "" ? size2 - 1 : Math.min(Number(last), size2 - 1);
|
|
42564
|
+
return start < size2 && start <= end ? { start, end } : "unsatisfiable";
|
|
42199
42565
|
};
|
|
42200
42566
|
NO_STORE = { "cache-control": "no-store" };
|
|
42201
42567
|
sendFile = async (rt, req, res, file) => {
|
|
@@ -42204,18 +42570,18 @@ var init_files = __esm({
|
|
|
42204
42570
|
res.writeHead(404, { "content-type": "text/plain; charset=utf-8", ...NO_STORE }).end("Not found: " + rt.path.basename(file));
|
|
42205
42571
|
return;
|
|
42206
42572
|
}
|
|
42207
|
-
const
|
|
42208
|
-
const range2 = parseRange(req.headers.range,
|
|
42573
|
+
const size2 = info.size;
|
|
42574
|
+
const range2 = parseRange(req.headers.range, size2);
|
|
42209
42575
|
const type = contentType(file);
|
|
42210
42576
|
const headers = { "content-type": type, "accept-ranges": "bytes", ...NO_STORE, ...type.startsWith("text/html") ? { "content-security-policy": SCENE_POLICY2 } : {} };
|
|
42211
42577
|
if (range2 === "unsatisfiable") {
|
|
42212
|
-
res.writeHead(416, { ...headers, "content-range": "bytes */" +
|
|
42578
|
+
res.writeHead(416, { ...headers, "content-range": "bytes */" + size2 }).end();
|
|
42213
42579
|
return;
|
|
42214
42580
|
}
|
|
42215
|
-
const { start, end } = range2 ?? { start: 0, end:
|
|
42581
|
+
const { start, end } = range2 ?? { start: 0, end: size2 - 1 };
|
|
42216
42582
|
const status2 = range2 ? 206 : 200;
|
|
42217
|
-
res.writeHead(status2, { ...headers, "content-length": String(Math.max(0, end - start + 1)), ...range2 ? { "content-range": "bytes " + start + "-" + end + "/" +
|
|
42218
|
-
if (req.method === "HEAD" ||
|
|
42583
|
+
res.writeHead(status2, { ...headers, "content-length": String(Math.max(0, end - start + 1)), ...range2 ? { "content-range": "bytes " + start + "-" + end + "/" + size2 } : {} });
|
|
42584
|
+
if (req.method === "HEAD" || size2 === 0) {
|
|
42219
42585
|
res.end();
|
|
42220
42586
|
return;
|
|
42221
42587
|
}
|
|
@@ -42336,8 +42702,8 @@ var init_extract = __esm({
|
|
|
42336
42702
|
break;
|
|
42337
42703
|
}
|
|
42338
42704
|
}
|
|
42339
|
-
const
|
|
42340
|
-
const start = Math.max(0, (
|
|
42705
|
+
const first2 = lv.slice(at7(t - EARLY), at7(t) + 1).findIndex((v) => v >= bed + MIN_CONTRAST_DB / 2);
|
|
42706
|
+
const start = Math.max(0, (first2 >= 0 ? at7(t - EARLY) + first2 : at7(t)) * HOP2 - PRE);
|
|
42341
42707
|
if (end - start < MIN_LEN) {
|
|
42342
42708
|
passed.push({ at: r311(t), why: "short" });
|
|
42343
42709
|
continue;
|
|
@@ -43516,11 +43882,11 @@ var init_routes = __esm({
|
|
|
43516
43882
|
readBody2 = (req, limit = MAX_BODY) => new Promise((resolve2, reject) => {
|
|
43517
43883
|
const declared = Number(req.headers["content-length"] ?? 0);
|
|
43518
43884
|
const chunks = [];
|
|
43519
|
-
let
|
|
43885
|
+
let size2 = 0;
|
|
43520
43886
|
let over = declared > limit;
|
|
43521
43887
|
req.on("data", (c) => {
|
|
43522
|
-
|
|
43523
|
-
if (
|
|
43888
|
+
size2 += c.length;
|
|
43889
|
+
if (size2 > limit) over = true;
|
|
43524
43890
|
if (!over) chunks.push(c);
|
|
43525
43891
|
});
|
|
43526
43892
|
req.on("end", () => resolve2(over ? "too-large" : Buffer.concat(chunks).toString("utf8")));
|
|
@@ -44659,7 +45025,7 @@ var init_preview = __esm({
|
|
|
44659
45025
|
});
|
|
44660
45026
|
|
|
44661
45027
|
// src/video/render/record.ts
|
|
44662
|
-
var KEEP2, SIMILAR, HASH, ROUNDS2, SOUND2, SOUND_KINDS, PICTURE_DIRS, isString, isRender, isCompare, readRecord4, writeRecord, real, recordFile4, fileHash2, namedPictureFiles, pictureHash, shown, clock2, compareCommand, reviewRender, findRender, projectOf3, roundsOf, LOOK, roundNext, reviewCompare;
|
|
45028
|
+
var KEEP2, SIMILAR, HASH, ROUNDS2, roundsWord, SOUND2, SOUND_KINDS, PICTURE_DIRS, isString, isRender, isCompare, readRecord4, writeRecord, real, recordName, recordFile4, recordedRenders, fileHash2, namedPictureFiles, pictureHash, shown, clock2, compareCommand, reviewRender, findRender, projectOf3, roundsOf, LOOK, roundNext, reviewCompare;
|
|
44663
45029
|
var init_record3 = __esm({
|
|
44664
45030
|
"src/video/render/record.ts"() {
|
|
44665
45031
|
"use strict";
|
|
@@ -44668,7 +45034,8 @@ var init_record3 = __esm({
|
|
|
44668
45034
|
KEEP2 = 40;
|
|
44669
45035
|
SIMILAR = 0.05;
|
|
44670
45036
|
HASH = 16;
|
|
44671
|
-
ROUNDS2 = { least:
|
|
45037
|
+
ROUNDS2 = { least: 1, most: 3 };
|
|
45038
|
+
roundsWord = (n) => n + (n === 1 ? " round" : " rounds");
|
|
44672
45039
|
SOUND2 = /\.(m4a|mp3|wav|aac|ogg|oga|opus|flac)$/i;
|
|
44673
45040
|
SOUND_KINDS = /* @__PURE__ */ new Set(["audio", "voice", "speech"]);
|
|
44674
45041
|
PICTURE_DIRS = ["assets", "scenes", "lib"];
|
|
@@ -44695,7 +45062,13 @@ var init_record3 = __esm({
|
|
|
44695
45062
|
const abs = rt.path.resolve(rt.cwd, p);
|
|
44696
45063
|
return rt.fs.realpath ? rt.fs.realpath(abs).catch(() => abs) : abs;
|
|
44697
45064
|
};
|
|
44698
|
-
|
|
45065
|
+
recordName = (rt, project) => (rt.path.basename(project).replace(/[^\w.-]+/g, "-").slice(0, 40) || "project") + "-" + sha256(project).slice(0, 12) + ".json";
|
|
45066
|
+
recordFile4 = (rt, project) => rt.path.join(reviewsDir(rt), recordName(rt, project));
|
|
45067
|
+
recordedRenders = async (rt, work, projectDir) => {
|
|
45068
|
+
const project = await real(rt, projectDir);
|
|
45069
|
+
const found = await readRecord4(rt, rt.path.join(work, "reviews", recordName(rt, project)));
|
|
45070
|
+
return found?.project === project ? found.renders : [];
|
|
45071
|
+
};
|
|
44699
45072
|
fileHash2 = async (rt, file) => sha256(await rt.fs.readFile(file)).slice(0, HASH);
|
|
44700
45073
|
namedPictureFiles = async (rt, root) => {
|
|
44701
45074
|
try {
|
|
@@ -44778,7 +45151,7 @@ var init_record3 = __esm({
|
|
|
44778
45151
|
LOOK = "look at each worst shot at full size (its look command: popost video look \u2026 --at \u2026), fix it or write it down with its reason in the delivery notes";
|
|
44779
45152
|
roundNext = (r) => {
|
|
44780
45153
|
if (!r) {
|
|
44781
|
-
return LOOK.charAt(0).toUpperCase() + LOOK.slice(1) + ", render again and compare again: at least " + ROUNDS2.least + "
|
|
45154
|
+
return LOOK.charAt(0).toUpperCase() + LOOK.slice(1) + ", render again and compare again: at least " + roundsWord(ROUNDS2.least) + ". Rounds are counted only for a video popost video render wrote from this working directory (or with the same POPOST_VIDEO_WORK), and this one is not in its record.";
|
|
44782
45155
|
}
|
|
44783
45156
|
const again = r.again ? "Still round " + r.round + ": this render shows the project as it was when it was compared in round " + r.round + " (no file that changes the picture changed). " : "";
|
|
44784
45157
|
const rounds = [...new Set(r.stillWorst.map((s) => s.since))];
|
|
@@ -44871,17 +45244,17 @@ var init_fill2 = __esm({
|
|
|
44871
45244
|
}
|
|
44872
45245
|
};
|
|
44873
45246
|
cellsFrom = (width, height, channels, rowAt) => {
|
|
44874
|
-
const
|
|
44875
|
-
const w = Math.ceil(width /
|
|
45247
|
+
const size2 = Math.max(1, Math.round(Math.max(width, height) / CELLS));
|
|
45248
|
+
const w = Math.ceil(width / size2), h = Math.ceil(height / size2);
|
|
44876
45249
|
const sum2 = new Float64Array(w * h * 3), count5 = new Float64Array(w * h);
|
|
44877
|
-
const column = Int32Array.from({ length: width }, (_x, x2) => Math.floor(x2 /
|
|
45250
|
+
const column = Int32Array.from({ length: width }, (_x, x2) => Math.floor(x2 / size2));
|
|
44878
45251
|
const offsets = channels < 3 ? [0, 0, 0] : [0, 1, 2];
|
|
44879
|
-
const every =
|
|
45252
|
+
const every = size2 >= 4 ? 2 : 1;
|
|
44880
45253
|
for (let y = 0; y < height; y++) {
|
|
44881
45254
|
const pixels = rowAt(y);
|
|
44882
45255
|
if (!pixels) return void 0;
|
|
44883
45256
|
if (y % every !== 0) continue;
|
|
44884
|
-
const row = Math.floor(y /
|
|
45257
|
+
const row = Math.floor(y / size2) * w;
|
|
44885
45258
|
for (let x2 = 0; x2 < width; x2 += every) {
|
|
44886
45259
|
const cell = row + (column[x2] ?? 0), p = x2 * channels;
|
|
44887
45260
|
sum2[cell * 3] = (sum2[cell * 3] ?? 0) + (pixels[p + (offsets[0] ?? 0)] ?? 0);
|
|
@@ -44902,7 +45275,7 @@ var init_fill2 = __esm({
|
|
|
44902
45275
|
}
|
|
44903
45276
|
c.set([r / n, g / n, b / n], (y * w + x2) * 3);
|
|
44904
45277
|
}
|
|
44905
|
-
return { w, h, c, size, width, height };
|
|
45278
|
+
return { w, h, c, size: size2, width, height };
|
|
44906
45279
|
};
|
|
44907
45280
|
cellsOfPng = (png2) => {
|
|
44908
45281
|
const open = openPng(png2);
|
|
@@ -44934,11 +45307,11 @@ var init_fill2 = __esm({
|
|
|
44934
45307
|
const mean5 = [0, 1, 2].map((k) => common2.reduce((s, cell) => s + (c[cell * 3 + k] ?? 0), 0) / Math.max(1, common2.length));
|
|
44935
45308
|
return edge.filter((cell) => [0, 1, 2].every((k) => Math.abs((c[cell * 3 + k] ?? 0) - (mean5[k] ?? 0)) <= SEED));
|
|
44936
45309
|
};
|
|
44937
|
-
regionCells = ({ w, h, size, width, height }, regions) => {
|
|
45310
|
+
regionCells = ({ w, h, size: size2, width, height }, regions) => {
|
|
44938
45311
|
const marked2 = new Uint8Array(w * h);
|
|
44939
45312
|
if (!regions.length) return marked2;
|
|
44940
45313
|
for (let y = 0; y < h; y++) for (let x2 = 0; x2 < w; x2++) {
|
|
44941
|
-
const px2 = Math.min(width, (x2 + 0.5) *
|
|
45314
|
+
const px2 = Math.min(width, (x2 + 0.5) * size2), py = Math.min(height, (y + 0.5) * size2);
|
|
44942
45315
|
if (regions.some((r) => inRegion(r, px2, py, width, height))) marked2[y * w + x2] = 1;
|
|
44943
45316
|
}
|
|
44944
45317
|
return marked2;
|
|
@@ -45496,7 +45869,7 @@ var init_check8 = __esm({
|
|
|
45496
45869
|
);
|
|
45497
45870
|
};
|
|
45498
45871
|
scriptFiles = (html2) => [...html2.matchAll(/<script\b[^>]*\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi)].map((m) => (m[1] ?? m[2] ?? m[3] ?? "").trim()).filter((s) => s !== "" && !/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(s));
|
|
45499
|
-
styleFiles = (html2) => [...html2.matchAll(/<link\b[^>]*>/gi)].filter(([
|
|
45872
|
+
styleFiles = (html2) => [...html2.matchAll(/<link\b[^>]*>/gi)].filter(([tag4]) => /\brel\s*=\s*["']?stylesheet/i.test(tag4)).map(([tag4]) => /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(tag4)).map((m) => (m?.[1] ?? m?.[2] ?? m?.[3] ?? "").trim()).filter((s) => s !== "" && !/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(s));
|
|
45500
45873
|
missingStylesheets = async (rt, projectDir, scenes) => {
|
|
45501
45874
|
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
45502
45875
|
const roles = await libraryRoles(rt);
|
|
@@ -46376,22 +46749,22 @@ var init_examples = __esm({
|
|
|
46376
46749
|
if (typed.trim() !== String(p.default) && !COLOUR2.test(typed.trim())) return { problem: error(at7, '"' + p.name + '" is a colour such as #ffffff, or "' + p.default + '": ' + p.what + '. Got "' + typed + '".', "Write for example --set " + p.name + "=#ffffff.") };
|
|
46377
46750
|
return { value: typed.trim() };
|
|
46378
46751
|
};
|
|
46379
|
-
setExample = (ex, set2,
|
|
46752
|
+
setExample = (ex, set2, size2 = [1280, 720]) => {
|
|
46380
46753
|
const problems2 = [];
|
|
46381
46754
|
const given2 = {};
|
|
46382
|
-
for (const
|
|
46383
|
-
const eq =
|
|
46755
|
+
for (const pair5 of set2) {
|
|
46756
|
+
const eq = pair5.indexOf("="), name = eq < 0 ? pair5 : pair5.slice(0, eq);
|
|
46384
46757
|
const p = ex.params.find((x2) => x2.name === name);
|
|
46385
46758
|
if (eq < 0 || !p) {
|
|
46386
|
-
problems2.push(error("set." + name, eq < 0 ? '--set takes name=value; got "' +
|
|
46759
|
+
problems2.push(error("set." + name, eq < 0 ? '--set takes name=value; got "' + pair5 + '".' : 'The example "' + ex.name + '" has no parameter "' + name + '".', "Use one of its parameters, for example --set " + (ex.params[0]?.name ?? "name") + "=" + (ex.params[0]?.default ?? "value") + ".", ex.params.map((x2) => x2.name)));
|
|
46387
46760
|
continue;
|
|
46388
46761
|
}
|
|
46389
|
-
const v = valueOf(p,
|
|
46762
|
+
const v = valueOf(p, pair5.slice(eq + 1));
|
|
46390
46763
|
if ("problem" in v) problems2.push(v.problem);
|
|
46391
46764
|
else given2[name] = v.value;
|
|
46392
46765
|
}
|
|
46393
46766
|
const values = Object.fromEntries(ex.params.map((p) => [p.name, given2[p.name] ?? p.default]));
|
|
46394
|
-
const html2 = ex.html.replace(VALUES, () => '"values": ' + JSON.stringify(given2)).replace(SIZE, "width: " +
|
|
46767
|
+
const html2 = ex.html.replace(VALUES, () => '"values": ' + JSON.stringify(given2)).replace(SIZE, "width: " + size2[0] + "px; height: " + size2[1] + "px;");
|
|
46395
46768
|
return { html: html2, values, problems: problems2 };
|
|
46396
46769
|
};
|
|
46397
46770
|
PREVIEW_FPS = 30;
|
|
@@ -46491,8 +46864,8 @@ var init_example = __esm({
|
|
|
46491
46864
|
return 0;
|
|
46492
46865
|
}
|
|
46493
46866
|
const ex = await readExample(rt, name);
|
|
46494
|
-
const
|
|
46495
|
-
const set2 = setExample(ex, args2.list("set"),
|
|
46867
|
+
const size2 = sizeOf3(args2.req("size"));
|
|
46868
|
+
const set2 = setExample(ex, args2.list("set"), size2);
|
|
46496
46869
|
if (set2.problems.length) {
|
|
46497
46870
|
printJson(rt, { ok: false, example: name, errors: set2.problems.length, problems: set2.problems, params: ex.params });
|
|
46498
46871
|
return 2;
|
|
@@ -46502,7 +46875,7 @@ var init_example = __esm({
|
|
|
46502
46875
|
const entry2 = (await readCatalogue(rt)).entries.find((e) => e.name === name);
|
|
46503
46876
|
const length2 = entry2 ? entry2.seconds : (Number(set2.values.delay) || 0) + (Number(set2.values.duration) || 1) + 0.5;
|
|
46504
46877
|
const libraries = librariesOf(set2.html), fonts = fontRolesOf(set2.html);
|
|
46505
|
-
const drawn = sheet4 ? await previewScene(rt, { html: set2.html, out: userPath(rt, sheet4), seconds: args2.number("seconds") ?? length2, frames: args2.number("frames") ?? 12, size }) : void 0;
|
|
46878
|
+
const drawn = sheet4 ? await previewScene(rt, { html: set2.html, out: userPath(rt, sheet4), seconds: args2.number("seconds") ?? length2, frames: args2.number("frames") ?? 12, size: size2 }) : void 0;
|
|
46506
46879
|
printJson(rt, {
|
|
46507
46880
|
ok: true,
|
|
46508
46881
|
example: name,
|
|
@@ -46952,17 +47325,17 @@ var init_see = __esm({
|
|
|
46952
47325
|
init_pictures();
|
|
46953
47326
|
init_ask();
|
|
46954
47327
|
init_pictures();
|
|
46955
|
-
ASK = (
|
|
47328
|
+
ASK = (first2, count5) => [
|
|
46956
47329
|
"These are frames of " + count5 + " shot" + (count5 === 1 ? "" : "s") + ' of one video, in order. Each shot is introduced by a line "Shot N".',
|
|
46957
47330
|
"For every shot say in one English sentence what it shows: who or what, doing what, where, and how the camera moves if it does.",
|
|
46958
47331
|
"Describe the same person or place with the same words in every shot (hair, clothes, setting), so that a reader knows it is the same one. Do not copy text that is written on the picture.",
|
|
46959
|
-
'Answer with one JSON object and nothing else: {"shots": ["...", "..."]} with exactly ' + count5 + " strings, for shots " +
|
|
47332
|
+
'Answer with one JSON object and nothing else: {"shots": ["...", "..."]} with exactly ' + count5 + " strings, for shots " + first2 + " to " + (first2 + count5 - 1) + " in order."
|
|
46960
47333
|
].join("\n");
|
|
46961
|
-
askBatch = async (rt, o,
|
|
47334
|
+
askBatch = async (rt, o, first2, shots2) => {
|
|
46962
47335
|
const per = o.framesPerShot ?? 3, side = o.maxSide ?? 384;
|
|
46963
|
-
const content = [{ type: "text", text: ASK(
|
|
47336
|
+
const content = [{ type: "text", text: ASK(first2, shots2.length) }];
|
|
46964
47337
|
for (const [k, s] of shots2.entries()) {
|
|
46965
|
-
content.push({ type: "text", text: "Shot " + (
|
|
47338
|
+
content.push({ type: "text", text: "Shot " + (first2 + k) + " (" + (s.end - s.start).toFixed(1) + " s):" });
|
|
46966
47339
|
for (const t of lookTimes(s.start, s.end, per)) content.push({ type: "image_url", image_url: { url: await pictureUrl(rt, o.video, side, t) } });
|
|
46967
47340
|
}
|
|
46968
47341
|
const usage2 = { input: 0, output: 0 };
|
|
@@ -46979,21 +47352,21 @@ var init_see = __esm({
|
|
|
46979
47352
|
return { usage: usage2, requests: 2, why };
|
|
46980
47353
|
};
|
|
46981
47354
|
seeShots = async (rt, o) => {
|
|
46982
|
-
const
|
|
47355
|
+
const size2 = Math.max(1, o.batch ?? 6);
|
|
46983
47356
|
const notes2 = [];
|
|
46984
47357
|
const problems2 = [];
|
|
46985
47358
|
const usage2 = { input: 0, output: 0 };
|
|
46986
47359
|
let requests = 0;
|
|
46987
|
-
for (let
|
|
46988
|
-
const part = o.shots.slice(
|
|
46989
|
-
const r = await askBatch(rt, o,
|
|
47360
|
+
for (let first2 = 0; first2 < o.shots.length; first2 += size2) {
|
|
47361
|
+
const part = o.shots.slice(first2, first2 + size2);
|
|
47362
|
+
const r = await askBatch(rt, o, first2, part);
|
|
46990
47363
|
usage2.input += r.usage.input;
|
|
46991
47364
|
usage2.output += r.usage.output;
|
|
46992
47365
|
requests += r.requests;
|
|
46993
47366
|
if (r.notes) notes2.push(...r.notes);
|
|
46994
47367
|
else {
|
|
46995
47368
|
notes2.push(...part.map(() => ""));
|
|
46996
|
-
problems2.push(error("shots[" +
|
|
47369
|
+
problems2.push(error("shots[" + first2 + "-" + (first2 + part.length - 1) + "]", "What these shots show could not be read: " + r.why + ".", "Run it again, or write their lines in the notes file by hand."));
|
|
46997
47370
|
}
|
|
46998
47371
|
}
|
|
46999
47372
|
return { notes: notes2, problems: problems2, usage: usage2, requests };
|
|
@@ -47849,7 +48222,7 @@ var init_loop2 = __esm({
|
|
|
47849
48222
|
const model = planModel(rt);
|
|
47850
48223
|
const out2 = userPath(rt, args2.string("out") ?? "fill.json");
|
|
47851
48224
|
const stem = out2.replace(/\.json$/, "");
|
|
47852
|
-
const
|
|
48225
|
+
const productPictures2 = generate2?.images && assetsDir ? await Promise.all(generate2.images.map((p) => pictureUrl(rt, rt.path.join(assetsDir, p), 512))) : void 0;
|
|
47853
48226
|
const r = await askFill(rt, {
|
|
47854
48227
|
pkg,
|
|
47855
48228
|
card: card2,
|
|
@@ -47862,7 +48235,7 @@ var init_loop2 = __esm({
|
|
|
47862
48235
|
...generate2 ? { generate: generate2 } : {},
|
|
47863
48236
|
...shotNotes ? { shotNotes } : {},
|
|
47864
48237
|
...budgets ? { budgets } : {},
|
|
47865
|
-
...
|
|
48238
|
+
...productPictures2 ? { productPictures: productPictures2 } : {}
|
|
47866
48239
|
});
|
|
47867
48240
|
const attemptsFile = stem + ".attempts.json";
|
|
47868
48241
|
await rt.fs.writeFile(attemptsFile, jsonText({ model: r.model, first: r.first, passed: r.fill !== void 0, attempts: r.attempts }));
|
|
@@ -47926,15 +48299,15 @@ var init_loop2 = __esm({
|
|
|
47926
48299
|
const kinds = kindRanges(speech2);
|
|
47927
48300
|
const dialogue = kinds ? sourceBeats(measure3, text13, transcript2, kinds).beats.flatMap((b, i) => b.speech === "on-camera" ? [i] : []) : [];
|
|
47928
48301
|
const reference2 = { measure: measure3, ...args2.number("fps") !== void 0 ? { fps: args2.number("fps") } : {}, ...text13 ? { text: text13 } : {}, ...transcript2 ? { transcript: transcript2 } : {}, ...kinds ? { kinds } : {}, ...dialogue.length ? { dialogue } : {} };
|
|
47929
|
-
const
|
|
48302
|
+
const first2 = retarget({ ...reference2, plan: given2 });
|
|
47930
48303
|
const askedVoice = await voiceAskedOf(rt, args2.string("voice-asked"), outDir2);
|
|
47931
|
-
const
|
|
48304
|
+
const refusedSound2 = [
|
|
47932
48305
|
...voiceProblems(speech2 ? factsOfSpeech(speech2) : void 0, voiceWanted(given2, { speak: args2.flag("speak") }), askedVoice),
|
|
47933
48306
|
...typeof given2.sound === "string" ? await soundProblems2(rt, outDir2, given2.sound, "sound") : []
|
|
47934
48307
|
];
|
|
47935
|
-
if (!
|
|
47936
|
-
const problems2 = [...
|
|
47937
|
-
printJson(rt, { ok: false, error: "The plan has " + errorsIn4(problems2) + " error(s); nothing was written.", problems: problems2, notes:
|
|
48308
|
+
if (!first2.project || refusedSound2.length) {
|
|
48309
|
+
const problems2 = [...first2.problems, ...refusedSound2];
|
|
48310
|
+
printJson(rt, { ok: false, error: "The plan has " + errorsIn4(problems2) + " error(s); nothing was written.", problems: problems2, notes: first2.notes });
|
|
47938
48311
|
return 2;
|
|
47939
48312
|
}
|
|
47940
48313
|
if (args2.flag("speak") && speaksHosted(rt, given2.voice)) await holdVoice(rt, outDir2, args2.req("out"), args2.flag("confirm"), { ...given2.voice ? { voice: given2.voice } : {}, lines: spokenLinesOf(given2, dialogue) });
|
|
@@ -47946,7 +48319,7 @@ var init_loop2 = __esm({
|
|
|
47946
48319
|
const transcriber = commandTranscriber(rt, wallet);
|
|
47947
48320
|
const language = args2.string("language");
|
|
47948
48321
|
const spoken = speaker ? await speakRetarget(rt, { input: { ...reference2, plan: given2 }, outDir: outDir2, speaker, ...transcriber ? { transcriber } : {}, ...language ? { language } : {}, ...args2.flag("keep-length") ? { hold: true } : {}, ...args2.flag("keep-pauses") ? { keepPauses: true } : {}, ...fitTempo2 ? { fitTempo: fitTempo2 } : {} }) : void 0;
|
|
47949
|
-
const r = spoken ? spoken.result :
|
|
48322
|
+
const r = spoken ? spoken.result : first2;
|
|
47950
48323
|
if (!r.project || spoken && !r.timing) {
|
|
47951
48324
|
printJson(rt, { ok: false, error: "The re-flowed project could not be built.", problems: r.problems, notes: r.notes });
|
|
47952
48325
|
return 2;
|
|
@@ -48960,8 +49333,8 @@ var init_place = __esm({
|
|
|
48960
49333
|
skipped2.push({ ...c, why: "quiet" });
|
|
48961
49334
|
continue;
|
|
48962
49335
|
}
|
|
48963
|
-
const takes = takesOf2(o.catalogue, c.cue, c.gain, o.seed, c.seconds, o.preferred),
|
|
48964
|
-
if (!
|
|
49336
|
+
const takes = takesOf2(o.catalogue, c.cue, c.gain, o.seed, c.seconds, o.preferred), first2 = takes[0];
|
|
49337
|
+
if (!first2) {
|
|
48965
49338
|
skipped2.push({ ...c, why: "no-sound", note: 'no sound of the catalogue serves "' + c.cue + '"' });
|
|
48966
49339
|
continue;
|
|
48967
49340
|
}
|
|
@@ -48970,12 +49343,12 @@ var init_place = __esm({
|
|
|
48970
49343
|
skipped2.push({ ...c, why: "gap", note: "within " + (Math.abs(near3.frame - c.frame) / o.fps).toFixed(2) + " s of the " + near3.cue + " at " + (near3.frame / o.fps).toFixed(2) + " s" });
|
|
48971
49344
|
continue;
|
|
48972
49345
|
}
|
|
48973
|
-
const at7 = startOf(c.frame,
|
|
49346
|
+
const at7 = startOf(c.frame, first2, o.fps);
|
|
48974
49347
|
if (at7 >= o.total) {
|
|
48975
49348
|
skipped2.push({ ...c, why: "late" });
|
|
48976
49349
|
continue;
|
|
48977
49350
|
}
|
|
48978
|
-
const longest = takes.reduce((a, b) => b.seconds > a.seconds ? b : a,
|
|
49351
|
+
const longest = takes.reduce((a, b) => b.seconds > a.seconds ? b : a, first2);
|
|
48979
49352
|
if (c.cue !== "impact" && overlaps2(at7, spanOf3(at7, longest, o.fps), o.speech)) {
|
|
48980
49353
|
skipped2.push({ ...c, why: "speech" });
|
|
48981
49354
|
continue;
|
|
@@ -49706,9 +50079,9 @@ var init_project_windows = __esm({
|
|
|
49706
50079
|
if (!(fps > 0) || !project.segments?.length || project.segments.some((s) => !(Number.isInteger(s.frames) && s.frames > 0))) return void 0;
|
|
49707
50080
|
const tl = timelineOf(project);
|
|
49708
50081
|
if (Math.abs(tl.total / fps - videoSeconds2) > RENDER_SLACK_S) return void 0;
|
|
49709
|
-
const
|
|
49710
|
-
if (!
|
|
49711
|
-
return
|
|
50082
|
+
const first2 = firstSegments(project, shots2);
|
|
50083
|
+
if (!first2) return void 0;
|
|
50084
|
+
return first2.map((k) => {
|
|
49712
50085
|
if (k === void 0 || k === 0) return void 0;
|
|
49713
50086
|
const t = resolveTransition(project.segments[k]?.in, tl.starts[k], fps);
|
|
49714
50087
|
const spec10 = project.segments[k]?.in;
|
|
@@ -50338,7 +50711,7 @@ var init_source2 = __esm({
|
|
|
50338
50711
|
});
|
|
50339
50712
|
|
|
50340
50713
|
// src/video/replication/pairs.ts
|
|
50341
|
-
var PAIRS_FILE, object4, text11, hash4,
|
|
50714
|
+
var PAIRS_FILE, object4, text11, hash4, positive3, relativeFile, sameHash2, sameFps, seconds7, issue3, validTrim, validSide, validatePairs, checkPairs;
|
|
50342
50715
|
var init_pairs = __esm({
|
|
50343
50716
|
"src/video/replication/pairs.ts"() {
|
|
50344
50717
|
"use strict";
|
|
@@ -50348,7 +50721,7 @@ var init_pairs = __esm({
|
|
|
50348
50721
|
object4 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
50349
50722
|
text11 = (v) => typeof v === "string" && v.trim() !== "";
|
|
50350
50723
|
hash4 = (v) => typeof v === "string" && /^[a-f\d]{64}$/i.test(v);
|
|
50351
|
-
|
|
50724
|
+
positive3 = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
50352
50725
|
relativeFile = (v) => text11(v) && !/^(?:\/|[a-z]:|[a-z][\w+.-]*:)/i.test(v.replace(/\\/g, "/")) && !v.replace(/\\/g, "/").split("/").includes("..");
|
|
50353
50726
|
sameHash2 = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
50354
50727
|
sameFps = (a, b) => Math.abs(a - b) < 0.01;
|
|
@@ -50380,7 +50753,7 @@ var init_pairs = __esm({
|
|
|
50380
50753
|
if (!text11(value.source)) {
|
|
50381
50754
|
issue3(ps, at7 + ".source", "The original URL, attachment or captured-file provenance is unknown.", true);
|
|
50382
50755
|
}
|
|
50383
|
-
if (!
|
|
50756
|
+
if (!positive3(value.sourceFps)) {
|
|
50384
50757
|
issue3(ps, at7 + ".sourceFps", "Record this file's actual source FPS, not the project FPS.");
|
|
50385
50758
|
valid = false;
|
|
50386
50759
|
}
|
|
@@ -50434,7 +50807,7 @@ var init_pairs = __esm({
|
|
|
50434
50807
|
issue3(ps, here + ".file", "The actual bytes and source clock have not yet been checked.", true);
|
|
50435
50808
|
continue;
|
|
50436
50809
|
}
|
|
50437
|
-
if (!hash4(f.sha256) || !
|
|
50810
|
+
if (!hash4(f.sha256) || !positive3(f.fps) || !Number.isInteger(f.frames) || f.frames <= 0) {
|
|
50438
50811
|
issue3(ps, here + ".file", "Actual file facts need a SHA256, source FPS and positive whole frame count.");
|
|
50439
50812
|
continue;
|
|
50440
50813
|
}
|
|
@@ -50460,7 +50833,7 @@ var init_pairs = __esm({
|
|
|
50460
50833
|
}
|
|
50461
50834
|
const s = p[use2.side];
|
|
50462
50835
|
if (use2.file !== s.file) issue3(ps, at7 + ".file", "This file is not the declared " + use2.side + ' of pair "' + p.id + '".');
|
|
50463
|
-
if (!
|
|
50836
|
+
if (!positive3(use2.sourceFps) || !sameFps(use2.sourceFps, s.sourceFps)) {
|
|
50464
50837
|
issue3(ps, at7 + ".sourceFps", "This use changes the declared source FPS; convert project frames explicitly before selecting source frames.");
|
|
50465
50838
|
continue;
|
|
50466
50839
|
}
|
|
@@ -50534,9 +50907,9 @@ var init_review3 = __esm({
|
|
|
50534
50907
|
};
|
|
50535
50908
|
spreadFrames3 = (total2, n) => [...new Set(Array.from({ length: Math.min(n, total2) }, (_, k) => Math.floor((2 * k + 1) * total2 / (2 * Math.min(n, total2)))))];
|
|
50536
50909
|
spanFrames2 = (span2, total2) => {
|
|
50537
|
-
const last = Math.max(0, Math.min(span2[1], total2) - 1),
|
|
50538
|
-
const picked2 = [.../* @__PURE__ */ new Set([
|
|
50539
|
-
if (picked2.length < 2 && total2 > 1) picked2.push(
|
|
50910
|
+
const last = Math.max(0, Math.min(span2[1], total2) - 1), first2 = Math.min(span2[0], last);
|
|
50911
|
+
const picked2 = [.../* @__PURE__ */ new Set([first2, Math.floor((first2 + last) / 2), last])];
|
|
50912
|
+
if (picked2.length < 2 && total2 > 1) picked2.push(first2 > 0 ? first2 - 1 : first2 + 1);
|
|
50540
50913
|
return picked2.sort((a, b) => a - b);
|
|
50541
50914
|
};
|
|
50542
50915
|
same4 = (a, b) => !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
@@ -51440,11 +51813,11 @@ var init_replication = __esm({
|
|
|
51440
51813
|
if (c.events.some((e) => e.kind === "comparison")) {
|
|
51441
51814
|
try {
|
|
51442
51815
|
const value = JSON.parse(await rt.fs.readText(rt.path.join(dir, PAIRS_FILE)));
|
|
51443
|
-
const
|
|
51816
|
+
const first2 = await checkPairs(rt, dir, value), uses = pairUses(built.resolved, first2.pairs);
|
|
51444
51817
|
const pairs = await checkPairs(rt, dir, value, { uses });
|
|
51445
51818
|
problems2.push(...pairs.problems);
|
|
51446
|
-
for (const
|
|
51447
|
-
problems2.push(error(PAIRS_FILE, "A declared comparison is missing one of its actual timeline sides: " +
|
|
51819
|
+
for (const pair5 of pairs.pairs) if (!uses.some((u) => u.pairId === pair5.id && u.side === "reference") || !uses.some((u) => u.pairId === pair5.id && u.side === "remake"))
|
|
51820
|
+
problems2.push(error(PAIRS_FILE, "A declared comparison is missing one of its actual timeline sides: " + pair5.id, "Place the verified sides at matching stages using their own source FPS."));
|
|
51448
51821
|
if (pairs.status !== "verified") problems2.push(error(PAIRS_FILE, "The actual comparison pairing is not verified.", "Resolve source identity, relationship, trim and source-clock evidence."));
|
|
51449
51822
|
} catch (e) {
|
|
51450
51823
|
problems2.push(error(PAIRS_FILE, String(e), "Keep a verified actual source-pair manifest with comparison scenes."));
|
|
@@ -51482,7 +51855,7 @@ var init_replication = __esm({
|
|
|
51482
51855
|
});
|
|
51483
51856
|
|
|
51484
51857
|
// src/video/commands/speech-check.ts
|
|
51485
|
-
var
|
|
51858
|
+
var inProject3, entry, speechCheck;
|
|
51486
51859
|
var init_speech_check2 = __esm({
|
|
51487
51860
|
"src/video/commands/speech-check.ts"() {
|
|
51488
51861
|
"use strict";
|
|
@@ -51493,7 +51866,7 @@ var init_speech_check2 = __esm({
|
|
|
51493
51866
|
init_speech_check();
|
|
51494
51867
|
init_credits();
|
|
51495
51868
|
init_shared();
|
|
51496
|
-
|
|
51869
|
+
inProject3 = (rt, dir, given2) => {
|
|
51497
51870
|
const rel2 = rt.path.relative(dir, userPath(rt, given2)).split(rt.path.sep).join("/");
|
|
51498
51871
|
if (!rel2 || rel2.startsWith("..") || rt.path.isAbsolute(rel2)) throw new VideoCommandError("--clip names a clip of the project; " + given2 + " is not in " + dir + ".");
|
|
51499
51872
|
return rel2;
|
|
@@ -51522,7 +51895,7 @@ var init_speech_check2 = __esm({
|
|
|
51522
51895
|
},
|
|
51523
51896
|
async (args2, rt) => {
|
|
51524
51897
|
const dir = userPath(rt, args2.req("project"));
|
|
51525
|
-
const listed3 = args2.list("clip").map((c) =>
|
|
51898
|
+
const listed3 = args2.list("clip").map((c) => inProject3(rt, dir, c));
|
|
51526
51899
|
const files = listed3.length ? listed3 : await speakingClips(rt, dir);
|
|
51527
51900
|
if (!files.length) {
|
|
51528
51901
|
printJson(rt, { ok: true, project: dir, clips: [], chargedCredits: 0, note: 'No clip of the project has a script to say (a speech receipt beside it, written when materials makes a clip with "speech").' });
|
|
@@ -51750,6 +52123,146 @@ var init_clean2 = __esm({
|
|
|
51750
52123
|
}
|
|
51751
52124
|
});
|
|
51752
52125
|
|
|
52126
|
+
// src/feedback/media.ts
|
|
52127
|
+
var MAX_PICTURES2, MAX_PICTURE_BYTES3, MAX_VIDEO_BYTES2, PARENTS_SEARCHED, EDITOR_UPLOAD, readJsonAt, asArray, str2, inProject4, tag3, productPictures, castPictures, assetsNamed, imageProjectPictures, inputCandidates, workDirs, lastRecordedRender, studioRenders, resultCandidate, sniffVideoMime2, PICTURE_TYPES2, nameOf2, take, isTaken, collectMedia;
|
|
52128
|
+
var init_media2 = __esm({
|
|
52129
|
+
"src/feedback/media.ts"() {
|
|
52130
|
+
"use strict";
|
|
52131
|
+
init_project();
|
|
52132
|
+
init_util();
|
|
52133
|
+
init_api();
|
|
52134
|
+
init_base();
|
|
52135
|
+
init_cast();
|
|
52136
|
+
init_sheet3();
|
|
52137
|
+
init_record3();
|
|
52138
|
+
MAX_PICTURES2 = 8;
|
|
52139
|
+
MAX_PICTURE_BYTES3 = 10 * 1024 * 1024;
|
|
52140
|
+
MAX_VIDEO_BYTES2 = 100 * 1024 * 1024;
|
|
52141
|
+
PARENTS_SEARCHED = 3;
|
|
52142
|
+
EDITOR_UPLOAD = /^assets\/import(\d{3}|-[0-9a-f]{32})\.(png|jpe?g|webp)$/i;
|
|
52143
|
+
readJsonAt = async (rt, file) => rt.fs.readText(file).then((text13) => JSON.parse(text13), () => void 0);
|
|
52144
|
+
asArray = (value) => Array.isArray(value) ? value : [];
|
|
52145
|
+
str2 = (value) => typeof value === "string" && value.trim() ? value : void 0;
|
|
52146
|
+
inProject4 = (rt, root, rel2) => rel2 && !rt.path.isAbsolute(rel2) && isInside(rt, root, rel2) ? rt.path.join(root, ...rel2.split("/")) : void 0;
|
|
52147
|
+
tag3 = (from, files) => files.filter((file) => file !== void 0).map((file) => ({ role: "input", from, file }));
|
|
52148
|
+
productPictures = async (rt, root) => {
|
|
52149
|
+
const sheet4 = await readJsonAt(rt, rt.path.join(root, ...PRODUCT_FILE.split("/")));
|
|
52150
|
+
if (!isRecord(sheet4)) return [];
|
|
52151
|
+
const pictures = asArray(sheet4.products).flatMap((product) => isRecord(product) ? asArray(product.pictures) : []);
|
|
52152
|
+
return pictures.map((p) => isRecord(p) ? inProject4(rt, root, str2(isRecord(p.original) ? p.original.file : void 0) ?? str2(p.file)) : void 0);
|
|
52153
|
+
};
|
|
52154
|
+
castPictures = async (rt, root) => {
|
|
52155
|
+
const cast = await readJsonAt(rt, rt.path.join(root, CAST_FILE));
|
|
52156
|
+
if (!isRecord(cast)) return [];
|
|
52157
|
+
return asArray(cast.roles).map((role) => isRecord(role) && role.identity === "user" ? inProject4(rt, root, str2(role.image)) : void 0);
|
|
52158
|
+
};
|
|
52159
|
+
assetsNamed = async (rt, root, pattern) => {
|
|
52160
|
+
const names = await rt.fs.readdir(rt.path.join(root, "assets")).catch(() => []);
|
|
52161
|
+
return names.filter((name) => pattern.test(name)).map((name) => rt.path.join(root, "assets", name));
|
|
52162
|
+
};
|
|
52163
|
+
imageProjectPictures = async (rt, root) => {
|
|
52164
|
+
const manifest = await readJsonAt(rt, rt.path.join(root, MANIFEST_NAME));
|
|
52165
|
+
if (!isRecord(manifest)) return [];
|
|
52166
|
+
const references = asArray(manifest.sources).map((s) => isRecord(s) && s.kind === "local-reference" ? inProject4(rt, root, str2(s.path)) : void 0);
|
|
52167
|
+
const uploads = asArray(manifest.assets).map((a) => isRecord(a) && EDITOR_UPLOAD.test(str2(a.path) ?? "") ? inProject4(rt, root, str2(a.path)) : void 0);
|
|
52168
|
+
return [...tag3("reference", references), ...tag3("upload", uploads)];
|
|
52169
|
+
};
|
|
52170
|
+
inputCandidates = async (rt, root) => {
|
|
52171
|
+
const all = [
|
|
52172
|
+
...tag3("product", await productPictures(rt, root)),
|
|
52173
|
+
...tag3("cast", await castPictures(rt, root)),
|
|
52174
|
+
...tag3("anchor", await assetsNamed(rt, root, /^anchor-image\.(png|jpe?g|webp)$/i)),
|
|
52175
|
+
...tag3("character", await assetsNamed(rt, root, /^character-[^/]+\.(png|jpe?g|webp)$/i)),
|
|
52176
|
+
...await imageProjectPictures(rt, root)
|
|
52177
|
+
];
|
|
52178
|
+
return all.filter((c, i) => all.findIndex((other) => other.file === c.file) === i);
|
|
52179
|
+
};
|
|
52180
|
+
workDirs = (rt, root) => {
|
|
52181
|
+
const above = [root];
|
|
52182
|
+
for (let i = 0; i < PARENTS_SEARCHED; i++) above.push(rt.path.dirname(above.at(-1)));
|
|
52183
|
+
const given2 = rt.env.POPOST_VIDEO_WORK?.trim();
|
|
52184
|
+
const dirs = [...given2 ? [rt.path.resolve(rt.cwd, given2)] : [], rt.path.join(rt.cwd, ".popost", "video"), ...above.map((dir) => rt.path.join(dir, ".popost", "video"))];
|
|
52185
|
+
return [...new Set(dirs)];
|
|
52186
|
+
};
|
|
52187
|
+
lastRecordedRender = async (rt, root) => {
|
|
52188
|
+
const found = [];
|
|
52189
|
+
for (const work of workDirs(rt, root))
|
|
52190
|
+
for (const entry2 of [...await recordedRenders(rt, work, root).catch(() => [])].reverse())
|
|
52191
|
+
if ((await rt.fs.stat(entry2.out))?.isFile) {
|
|
52192
|
+
found.push({ file: entry2.out, from: "render", at: Date.parse(entry2.at) || 0 });
|
|
52193
|
+
break;
|
|
52194
|
+
}
|
|
52195
|
+
return found.sort((a, b) => b.at - a.at)[0];
|
|
52196
|
+
};
|
|
52197
|
+
studioRenders = async (rt, root) => {
|
|
52198
|
+
const last = await readJsonAt(rt, rt.path.join(root, ".studio", "last-export.json"));
|
|
52199
|
+
const exported = isRecord(last) && last.state === "done" ? str2(last.file) : void 0;
|
|
52200
|
+
const finished = isRecord(last) && typeof last.finished === "number" ? last.finished : void 0;
|
|
52201
|
+
const dated = await Promise.all(
|
|
52202
|
+
[
|
|
52203
|
+
{ file: exported, at: finished },
|
|
52204
|
+
{ file: rt.path.join(root, "out.mp4"), at: void 0 }
|
|
52205
|
+
].map(async ({ file, at: at7 }) => {
|
|
52206
|
+
const stat2 = file && isInside(rt, root, file) ? await rt.fs.stat(file) : null;
|
|
52207
|
+
return file && stat2?.isFile ? { file, from: "studio-export", at: at7 ?? stat2.mtimeMs } : void 0;
|
|
52208
|
+
})
|
|
52209
|
+
);
|
|
52210
|
+
return dated.filter((d) => d !== void 0);
|
|
52211
|
+
};
|
|
52212
|
+
resultCandidate = async (rt, root) => {
|
|
52213
|
+
const all = [await lastRecordedRender(rt, root), ...await studioRenders(rt, root)].filter((d) => d !== void 0);
|
|
52214
|
+
const newest = all.sort((a, b) => b.at - a.at)[0];
|
|
52215
|
+
return newest ? { role: "result", from: newest.from, file: newest.file } : void 0;
|
|
52216
|
+
};
|
|
52217
|
+
sniffVideoMime2 = (head) => {
|
|
52218
|
+
if (head.length < 12) return null;
|
|
52219
|
+
const ascii5 = (from, to) => String.fromCharCode(...head.subarray(from, to));
|
|
52220
|
+
const box2 = ascii5(4, 8);
|
|
52221
|
+
if (box2 === "ftyp") return ascii5(8, 12) === "qt " ? "video/quicktime" : "video/mp4";
|
|
52222
|
+
return ["moov", "wide", "mdat", "free", "skip", "pnot"].includes(box2) ? "video/quicktime" : null;
|
|
52223
|
+
};
|
|
52224
|
+
PICTURE_TYPES2 = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
52225
|
+
nameOf2 = (rt, file) => {
|
|
52226
|
+
const base = rt.path.basename(file).replace(new RegExp("\\p{Cc}", "gu"), "").replace(/[\\/]/g, "_").trim() || "file";
|
|
52227
|
+
let out2 = "";
|
|
52228
|
+
for (const ch of base) {
|
|
52229
|
+
if (out2.length + ch.length > 200) break;
|
|
52230
|
+
out2 += ch;
|
|
52231
|
+
}
|
|
52232
|
+
return out2;
|
|
52233
|
+
};
|
|
52234
|
+
take = async (rt, c, video) => {
|
|
52235
|
+
const stat2 = await rt.fs.stat(c.file);
|
|
52236
|
+
if (!stat2?.isFile) return { ...c, reason: "unreadable" };
|
|
52237
|
+
if (stat2.size > (video ? MAX_VIDEO_BYTES2 : MAX_PICTURE_BYTES3)) return { ...c, reason: "too-large", bytes: stat2.size };
|
|
52238
|
+
const data = await rt.fs.readFile(c.file).catch(() => void 0);
|
|
52239
|
+
if (!data?.length) return { ...c, reason: "unreadable" };
|
|
52240
|
+
const type = video ? sniffVideoMime2(data.subarray(0, 16)) : sniffImageMime(data.subarray(0, 16));
|
|
52241
|
+
if (!type || !video && !PICTURE_TYPES2.has(type)) return { ...c, reason: "unsupported-type", bytes: data.length };
|
|
52242
|
+
return { ...c, name: nameOf2(rt, c.file), contentType: type, bytes: data.length, sha256: sha256(data), data };
|
|
52243
|
+
};
|
|
52244
|
+
isTaken = (item2) => "data" in item2;
|
|
52245
|
+
collectMedia = async (rt, root) => {
|
|
52246
|
+
const files = [];
|
|
52247
|
+
const skipped2 = [];
|
|
52248
|
+
for (const c of await inputCandidates(rt, root)) {
|
|
52249
|
+
if (files.length >= MAX_PICTURES2) {
|
|
52250
|
+
skipped2.push({ ...c, reason: "over-limit" });
|
|
52251
|
+
continue;
|
|
52252
|
+
}
|
|
52253
|
+
const item2 = await take(rt, c, false);
|
|
52254
|
+
if (!isTaken(item2)) skipped2.push(item2);
|
|
52255
|
+
else if (!files.some((f) => f.sha256 === item2.sha256)) files.push(item2);
|
|
52256
|
+
}
|
|
52257
|
+
const result = await resultCandidate(rt, root);
|
|
52258
|
+
const video = result ? await take(rt, result, true) : void 0;
|
|
52259
|
+
if (video && isTaken(video)) files.push(video);
|
|
52260
|
+
else if (video) skipped2.push(video);
|
|
52261
|
+
return { files, skipped: skipped2 };
|
|
52262
|
+
};
|
|
52263
|
+
}
|
|
52264
|
+
});
|
|
52265
|
+
|
|
51753
52266
|
// src/feedback/project-files.ts
|
|
51754
52267
|
var MAX_DEPTH2, MAX_LISTED, DOCUMENT_MAX_BYTES, DOCUMENTS_MAX_BYTES, TEXT_EXTENSIONS, SKIPPED_DIRS, PRIVATE_NAME, extensionOf2, listFiles, isDocument, collectProjectFiles;
|
|
51755
52268
|
var init_project_files = __esm({
|
|
@@ -51807,6 +52320,103 @@ var init_project_files = __esm({
|
|
|
51807
52320
|
}
|
|
51808
52321
|
});
|
|
51809
52322
|
|
|
52323
|
+
// src/feedback/request.ts
|
|
52324
|
+
var REQUEST_MESSAGES, REQUEST_MAX_CHARS, SEPARATOR, MAX_LINES_SCANNED, CLAUDE_NOT_WORDS, CODEX_NOT_WORDS, REMINDER, textParts, slashCommand, claudeWords, codexEvent, codexMessage, scanLines, firstWords2, cutText, wordsOf2, extractRequest;
|
|
52325
|
+
var init_request = __esm({
|
|
52326
|
+
"src/feedback/request.ts"() {
|
|
52327
|
+
"use strict";
|
|
52328
|
+
init_base();
|
|
52329
|
+
REQUEST_MESSAGES = 3;
|
|
52330
|
+
REQUEST_MAX_CHARS = 4e3;
|
|
52331
|
+
SEPARATOR = "\n\n---\n\n";
|
|
52332
|
+
MAX_LINES_SCANNED = 5e3;
|
|
52333
|
+
CLAUDE_NOT_WORDS = /^(<local-command-|<bash-(input|stdout|stderr)>|Caveat: |\[Request interrupted)/;
|
|
52334
|
+
CODEX_NOT_WORDS = /^(<environment_context>|<user_instructions>|<INSTRUCTIONS>|# AGENTS\.md instructions|<user_shell_command>)/;
|
|
52335
|
+
REMINDER = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
52336
|
+
textParts = (content, kinds) => {
|
|
52337
|
+
if (typeof content === "string") return content;
|
|
52338
|
+
if (!Array.isArray(content)) return void 0;
|
|
52339
|
+
if (content.some((part) => isRecord(part) && part.type === "tool_result")) return void 0;
|
|
52340
|
+
const texts = content.filter((part) => isRecord(part) && kinds.includes(String(part.type)) && typeof part.text === "string");
|
|
52341
|
+
return texts.map((part) => part.text).join("\n");
|
|
52342
|
+
};
|
|
52343
|
+
slashCommand = (text13) => {
|
|
52344
|
+
if (!text13.startsWith("<command-")) return text13;
|
|
52345
|
+
const name = /<command-name>([\s\S]*?)<\/command-name>/.exec(text13)?.[1]?.trim();
|
|
52346
|
+
const args2 = /<command-args>([\s\S]*?)<\/command-args>/.exec(text13)?.[1]?.trim();
|
|
52347
|
+
return name && args2 ? `${name} ${args2}` : void 0;
|
|
52348
|
+
};
|
|
52349
|
+
claudeWords = (line) => {
|
|
52350
|
+
if (line.type !== "user" || line.isMeta === true || line.isSidechain === true || line.isCompactSummary === true) return void 0;
|
|
52351
|
+
const message2 = line.message;
|
|
52352
|
+
if (!isRecord(message2) || message2.role !== void 0 && message2.role !== "user") return void 0;
|
|
52353
|
+
const text13 = textParts(message2.content, ["text"])?.replace(REMINDER, "").trim();
|
|
52354
|
+
if (!text13 || CLAUDE_NOT_WORDS.test(text13)) return void 0;
|
|
52355
|
+
return slashCommand(text13);
|
|
52356
|
+
};
|
|
52357
|
+
codexEvent = (line) => {
|
|
52358
|
+
const payload2 = line.payload;
|
|
52359
|
+
if (line.type !== "event_msg" || !isRecord(payload2) || payload2.type !== "user_message") return void 0;
|
|
52360
|
+
return typeof payload2.message === "string" ? payload2.message.trim() || void 0 : void 0;
|
|
52361
|
+
};
|
|
52362
|
+
codexMessage = (line) => {
|
|
52363
|
+
const item2 = line.type === "response_item" && isRecord(line.payload) ? line.payload : line;
|
|
52364
|
+
if (item2.type !== "message" || item2.role !== "user") return void 0;
|
|
52365
|
+
const text13 = textParts(item2.content, ["input_text", "text"])?.trim();
|
|
52366
|
+
return text13 && !CODEX_NOT_WORDS.test(text13) ? text13 : void 0;
|
|
52367
|
+
};
|
|
52368
|
+
scanLines = (jsonl, visit) => {
|
|
52369
|
+
let start = 0;
|
|
52370
|
+
for (let n = 0; n < MAX_LINES_SCANNED && start < jsonl.length; n++) {
|
|
52371
|
+
const end = jsonl.indexOf("\n", start);
|
|
52372
|
+
const raw = jsonl.slice(start, end < 0 ? jsonl.length : end);
|
|
52373
|
+
start = end < 0 ? jsonl.length : end + 1;
|
|
52374
|
+
let value;
|
|
52375
|
+
try {
|
|
52376
|
+
value = raw.trim() ? JSON.parse(raw) : void 0;
|
|
52377
|
+
} catch {
|
|
52378
|
+
value = void 0;
|
|
52379
|
+
}
|
|
52380
|
+
if (isRecord(value) && visit(value)) return;
|
|
52381
|
+
}
|
|
52382
|
+
};
|
|
52383
|
+
firstWords2 = (jsonl, pick) => {
|
|
52384
|
+
const found = [];
|
|
52385
|
+
scanLines(jsonl, (line) => {
|
|
52386
|
+
const words = pick(line);
|
|
52387
|
+
if (words) found.push(words);
|
|
52388
|
+
return found.length >= REQUEST_MESSAGES;
|
|
52389
|
+
});
|
|
52390
|
+
return found;
|
|
52391
|
+
};
|
|
52392
|
+
cutText = (text13, max) => {
|
|
52393
|
+
if (text13.length <= max) return text13;
|
|
52394
|
+
let out2 = "";
|
|
52395
|
+
for (const ch of text13) {
|
|
52396
|
+
if (out2.length + ch.length > max - 1) break;
|
|
52397
|
+
out2 += ch;
|
|
52398
|
+
}
|
|
52399
|
+
return out2.trimEnd() + "\u2026";
|
|
52400
|
+
};
|
|
52401
|
+
wordsOf2 = (jsonl, format) => {
|
|
52402
|
+
const claude = () => firstWords2(jsonl, claudeWords);
|
|
52403
|
+
const codex = () => {
|
|
52404
|
+
const events = firstWords2(jsonl, codexEvent);
|
|
52405
|
+
return events.length ? events : firstWords2(jsonl, codexMessage);
|
|
52406
|
+
};
|
|
52407
|
+
if (format === "claude-code-jsonl") return claude();
|
|
52408
|
+
if (format === "codex-jsonl") return codex();
|
|
52409
|
+
const either = claude();
|
|
52410
|
+
return either.length ? either : codex();
|
|
52411
|
+
};
|
|
52412
|
+
extractRequest = (cleanedText, format) => {
|
|
52413
|
+
if (format === "text") return void 0;
|
|
52414
|
+
const words = wordsOf2(cleanedText, format);
|
|
52415
|
+
return words.length ? cutText(words.join(SEPARATOR), REQUEST_MAX_CHARS) : void 0;
|
|
52416
|
+
};
|
|
52417
|
+
}
|
|
52418
|
+
});
|
|
52419
|
+
|
|
51810
52420
|
// src/feedback/transcript.ts
|
|
51811
52421
|
var TRANSCRIPT_MAX_BYTES, TRANSCRIPT_READ_MAX_BYTES, SESSION_ID, CODEX_DAYS_SEARCHED, FeedbackError, envValue2, detectAgent, isFileAt, listDir, moved, findClaudeCode, newestFirst, codexRollout, findCodex, locate3, tail3, missing3, readTranscript;
|
|
51812
52422
|
var init_transcript = __esm({
|
|
@@ -51815,6 +52425,7 @@ var init_transcript = __esm({
|
|
|
51815
52425
|
init_agents();
|
|
51816
52426
|
init_i18n();
|
|
51817
52427
|
init_clean2();
|
|
52428
|
+
init_request();
|
|
51818
52429
|
TRANSCRIPT_MAX_BYTES = 40 * 1024 * 1024;
|
|
51819
52430
|
TRANSCRIPT_READ_MAX_BYTES = 256 * 1024 * 1024;
|
|
51820
52431
|
SESSION_ID = /^[A-Za-z0-9_-]{1,200}$/;
|
|
@@ -51909,14 +52520,16 @@ var init_transcript = __esm({
|
|
|
51909
52520
|
const kept3 = tail3(bytes, TRANSCRIPT_MAX_BYTES);
|
|
51910
52521
|
const text13 = kept3.cut ? new TextDecoder().decode(kept3.data) : cleaned.text;
|
|
51911
52522
|
const lines2 = kept3.cut ? text13.split("\n").filter((line) => line.trim() !== "").length : cleaned.lines;
|
|
51912
|
-
|
|
52523
|
+
const format = found.format ?? "jsonl";
|
|
52524
|
+
const request = extractRequest(cleaned.text, format);
|
|
52525
|
+
return { status: "found", path: found.path, format, text: text13, lines: lines2, bytes: kept3.data.length, truncated: raw.cut || kept3.cut, ...request ? { request } : {} };
|
|
51913
52526
|
};
|
|
51914
52527
|
}
|
|
51915
52528
|
});
|
|
51916
52529
|
|
|
51917
52530
|
// src/feedback/bundle.ts
|
|
51918
52531
|
import { gzipSync } from "fflate";
|
|
51919
|
-
var FORMAT5, MESSAGE_MAX_CHARS, MAX_BUNDLE_BYTES, tildify, projectDirOf, cleanMessage, documentOf, buildFeedback;
|
|
52532
|
+
var FORMAT5, MESSAGE_MAX_CHARS, MAX_BUNDLE_BYTES, tildify, projectDirOf, cleanMessage, mediaPath, mediaList, documentOf, buildFeedback;
|
|
51920
52533
|
var init_bundle = __esm({
|
|
51921
52534
|
"src/feedback/bundle.ts"() {
|
|
51922
52535
|
"use strict";
|
|
@@ -51925,6 +52538,7 @@ var init_bundle = __esm({
|
|
|
51925
52538
|
init_task();
|
|
51926
52539
|
init_version();
|
|
51927
52540
|
init_clean2();
|
|
52541
|
+
init_media2();
|
|
51928
52542
|
init_project_files();
|
|
51929
52543
|
init_transcript();
|
|
51930
52544
|
FORMAT5 = "popost-feedback/1";
|
|
@@ -51948,10 +52562,16 @@ var init_bundle = __esm({
|
|
|
51948
52562
|
throw new FeedbackError("MESSAGE_TOO_LONG", msg(`--message is longer than ${MESSAGE_MAX_CHARS} characters; shorten it`, `--message \u8D85\u8FC7 ${MESSAGE_MAX_CHARS} \u4E2A\u5B57\u7B26\uFF0C\u8BF7\u7F29\u77ED`));
|
|
51949
52563
|
return clean2(message2);
|
|
51950
52564
|
};
|
|
52565
|
+
mediaPath = (rt, projectDir, file) => {
|
|
52566
|
+
const rel2 = projectDir ? rt.path.relative(projectDir, file) : "";
|
|
52567
|
+
return rel2 && !rel2.startsWith("..") && !rt.path.isAbsolute(rel2) ? rel2.split(rt.path.sep).join("/") : tildify(rt, file);
|
|
52568
|
+
};
|
|
52569
|
+
mediaList = (rt, built) => (built.media?.files ?? []).map((f) => ({ role: f.role, from: f.from, path: mediaPath(rt, built.projectDir, f.file), name: f.name, contentType: f.contentType, bytes: f.bytes, sha256: f.sha256 }));
|
|
51951
52570
|
documentOf = (rt, built, createdAt) => ({
|
|
51952
52571
|
format: FORMAT5,
|
|
51953
52572
|
createdAt,
|
|
51954
52573
|
message: built.message,
|
|
52574
|
+
...built.transcript.request ? { request: built.transcript.request } : {},
|
|
51955
52575
|
client: { version: VERSION, platform: rt.platform ?? "unknown", ...rt.arch ? { arch: rt.arch } : {}, ...rt.nodeVersion ? { node: rt.nodeVersion } : {}, lang: currentLang() },
|
|
51956
52576
|
agent: { id: built.agent.id, ...built.agent.sessionId ? { sessionId: built.agent.sessionId } : {}, ...built.transcript.path ? { transcriptPath: tildify(rt, built.transcript.path) } : {} },
|
|
51957
52577
|
task: {
|
|
@@ -51970,7 +52590,8 @@ var init_bundle = __esm({
|
|
|
51970
52590
|
truncated: built.transcript.truncated,
|
|
51971
52591
|
omittedImages: built.transcript.omittedImages
|
|
51972
52592
|
},
|
|
51973
|
-
redactions: built.stats.redactions
|
|
52593
|
+
redactions: built.stats.redactions,
|
|
52594
|
+
media: mediaList(rt, built)
|
|
51974
52595
|
});
|
|
51975
52596
|
buildFeedback = async (rt, options) => {
|
|
51976
52597
|
const cleaner = createCleaner({ homeDir: rt.homeDir, secrets: environmentSecrets(rt.env) });
|
|
@@ -51982,7 +52603,8 @@ var init_bundle = __esm({
|
|
|
51982
52603
|
const projectDir = await projectDirOf(rt, options.dir);
|
|
51983
52604
|
const task = projectDir ? await projectTask(rt, { dir: projectDir, kind: "found" }, false).catch(() => void 0) : void 0;
|
|
51984
52605
|
const project = projectDir ? await collectProjectFiles(rt, projectDir, cleaner) : void 0;
|
|
51985
|
-
const
|
|
52606
|
+
const media = projectDir && !options.noMedia ? await collectMedia(rt, projectDir) : void 0;
|
|
52607
|
+
const parts = { message: message2, agent, transcript: { ...transcript2, omittedImages: transcriptImages }, projectDir, task, project, media, stats: { ...cleaner.stats } };
|
|
51986
52608
|
const json4 = JSON.stringify(documentOf(rt, parts, rt.now().toISOString()));
|
|
51987
52609
|
const gzip = gzipSync(new TextEncoder().encode(json4), { level: 6, mtime: 0 });
|
|
51988
52610
|
return { ...parts, gzip, sha256: sha256(gzip) };
|
|
@@ -51991,7 +52613,7 @@ var init_bundle = __esm({
|
|
|
51991
52613
|
});
|
|
51992
52614
|
|
|
51993
52615
|
// src/feedback/upload.ts
|
|
51994
|
-
var RATE_RETRIES2, MAX_WAIT_SEC2, UPLOAD_ATTEMPTS, AGENT_ID, rateAware2, reservation, badAnswer, ticketOf, uploadMissing, attempt2, sendFeedback;
|
|
52616
|
+
var RATE_RETRIES2, MAX_WAIT_SEC2, UPLOAD_ATTEMPTS, AGENT_ID, rateAware2, mediaOf2, reservation, badAnswer, mediaUploadsOf, ticketOf, MEDIA_STATES, mediaStatesOf, sendMedia, uploadMissing, attempt2, sendFeedback;
|
|
51995
52617
|
var init_upload = __esm({
|
|
51996
52618
|
"src/feedback/upload.ts"() {
|
|
51997
52619
|
"use strict";
|
|
@@ -52016,6 +52638,7 @@ var init_upload = __esm({
|
|
|
52016
52638
|
}
|
|
52017
52639
|
}
|
|
52018
52640
|
};
|
|
52641
|
+
mediaOf2 = (built) => built.media?.files ?? [];
|
|
52019
52642
|
reservation = (rt, built, operationKey) => {
|
|
52020
52643
|
const title = cleanTitle(built.task?.title);
|
|
52021
52644
|
const task = {
|
|
@@ -52039,28 +52662,48 @@ var init_upload = __esm({
|
|
|
52039
52662
|
redactions: built.stats.redactions,
|
|
52040
52663
|
omittedImages: built.stats.omittedImages,
|
|
52041
52664
|
truncated: built.transcript.truncated
|
|
52042
|
-
}
|
|
52665
|
+
},
|
|
52666
|
+
...built.transcript.request ? { request: built.transcript.request } : {},
|
|
52667
|
+
...mediaOf2(built).length ? { media: mediaOf2(built).map((f) => ({ role: f.role, name: f.name, contentType: f.contentType, sizeBytes: f.bytes, sha256: f.sha256 })) } : {}
|
|
52043
52668
|
};
|
|
52044
52669
|
};
|
|
52045
52670
|
badAnswer = (what) => new PopostApiError(msg(`popost.ai answered ${what} in an unexpected format`, `popost.ai \u5BF9 ${what} \u7684\u8FD4\u56DE\u683C\u5F0F\u4E0D\u7B26`), { code: "BAD_RESPONSE" });
|
|
52671
|
+
mediaUploadsOf = (value) => new Map(
|
|
52672
|
+
(Array.isArray(value) ? value : []).filter((u) => isRecord(u) && Number.isInteger(u.index) && typeof u.uploadUrl === "string").map((u) => [u.index, u.uploadUrl])
|
|
52673
|
+
);
|
|
52046
52674
|
ticketOf = (data) => {
|
|
52047
52675
|
if (!isRecord(data) || typeof data.id !== "string" || !/^[A-Za-z0-9-]{1,64}$/.test(data.id) || data.uploadUrl !== null && typeof data.uploadUrl !== "string")
|
|
52048
52676
|
throw badAnswer("POST /feedback");
|
|
52049
52677
|
const reference2 = typeof data.reference === "string" && data.reference ? data.reference : data.id.slice(0, 8);
|
|
52050
|
-
return { id: data.id, reference: reference2, uploadUrl: data.uploadUrl, state: String(data.state ?? "") };
|
|
52678
|
+
return { id: data.id, reference: reference2, uploadUrl: data.uploadUrl, state: String(data.state ?? ""), mediaUploads: mediaUploadsOf(data.mediaUploads) };
|
|
52679
|
+
};
|
|
52680
|
+
MEDIA_STATES = ["received", "missing", "invalid"];
|
|
52681
|
+
mediaStatesOf = (built, answer3) => {
|
|
52682
|
+
const states = new Map(
|
|
52683
|
+
(Array.isArray(answer3) ? answer3 : []).filter((m) => isRecord(m) && Number.isInteger(m.index) && MEDIA_STATES.includes(String(m.state))).map((m) => [m.index, m.state])
|
|
52684
|
+
);
|
|
52685
|
+
return mediaOf2(built).map((file, index) => ({ file, state: states.get(index) ?? "missing" }));
|
|
52686
|
+
};
|
|
52687
|
+
sendMedia = async (client2, built, ticket2) => {
|
|
52688
|
+
for (const [index, file] of mediaOf2(built).entries()) {
|
|
52689
|
+
const url = ticket2.mediaUploads.get(index);
|
|
52690
|
+
if (url) await client2.putSigned(url, file.data, file.contentType, file.name, "").catch(() => void 0);
|
|
52691
|
+
}
|
|
52051
52692
|
};
|
|
52052
52693
|
uploadMissing = (error2) => error2 instanceof PopostApiError && (error2.code === "UPLOAD_FAILED" || error2.code === "INVALID_REQUEST" && Array.isArray(error2.details.issues) && error2.details.issues.some((issue4) => isRecord(issue4) && issue4.path === "upload"));
|
|
52053
52694
|
attempt2 = async (rt, client2, built, body) => {
|
|
52054
52695
|
const ticket2 = ticketOf(await rateAware2(rt, () => client2.request("POST", "/feedback", { body })));
|
|
52055
|
-
if (ticket2.state === "received" && !ticket2.uploadUrl) return { id: ticket2.id, reference: ticket2.reference, receivedAt: rt.now().toISOString() };
|
|
52696
|
+
if (ticket2.state === "received" && !ticket2.uploadUrl) return { id: ticket2.id, reference: ticket2.reference, receivedAt: rt.now().toISOString(), media: [] };
|
|
52056
52697
|
if (ticket2.uploadUrl)
|
|
52057
52698
|
await client2.putSigned(ticket2.uploadUrl, built.gzip, "application/gzip", "feedback.json.gz", msg("run the same popost feedback command again", "\u8BF7\u518D\u6B21\u8FD0\u884C\u540C\u4E00\u6761 popost feedback \u547D\u4EE4"));
|
|
52699
|
+
await sendMedia(client2, built, ticket2);
|
|
52058
52700
|
const done2 = await rateAware2(rt, () => client2.request("POST", `/feedback/${encodeURIComponent(ticket2.id)}/complete`, { body: {} }));
|
|
52059
52701
|
if (!isRecord(done2) || done2.id !== ticket2.id) throw badAnswer(`POST /feedback/${ticket2.id}/complete`);
|
|
52060
52702
|
return {
|
|
52061
52703
|
id: ticket2.id,
|
|
52062
52704
|
reference: typeof done2.reference === "string" && done2.reference ? done2.reference : ticket2.reference,
|
|
52063
|
-
receivedAt: typeof done2.receivedAt === "string" ? done2.receivedAt : rt.now().toISOString()
|
|
52705
|
+
receivedAt: typeof done2.receivedAt === "string" ? done2.receivedAt : rt.now().toISOString(),
|
|
52706
|
+
media: mediaStatesOf(built, done2.media)
|
|
52064
52707
|
};
|
|
52065
52708
|
};
|
|
52066
52709
|
sendFeedback = async (rt, client2, built) => {
|
|
@@ -52081,13 +52724,14 @@ var feedback_exports = {};
|
|
|
52081
52724
|
__export(feedback_exports, {
|
|
52082
52725
|
main: () => main22
|
|
52083
52726
|
});
|
|
52084
|
-
var spec9, quote15, wouldSend, tooLarge, report3, run5, main22;
|
|
52727
|
+
var spec9, quote15, MB, skipWhy, mediaToSend, wouldSend, tooLarge, report3, run5, main22;
|
|
52085
52728
|
var init_feedback = __esm({
|
|
52086
52729
|
"src/commands/feedback.ts"() {
|
|
52087
52730
|
"use strict";
|
|
52088
52731
|
init_args();
|
|
52089
52732
|
init_util();
|
|
52090
52733
|
init_bundle();
|
|
52734
|
+
init_media2();
|
|
52091
52735
|
init_transcript();
|
|
52092
52736
|
init_upload();
|
|
52093
52737
|
init_i18n();
|
|
@@ -52096,8 +52740,8 @@ var init_feedback = __esm({
|
|
|
52096
52740
|
spec9 = () => ({
|
|
52097
52741
|
prog: "popost feedback",
|
|
52098
52742
|
description: msg(
|
|
52099
|
-
"Report a problem to the popost team, only when the user asks for it (free). Without --confirm nothing is sent: it prints what would go, which is the message, this Agent session's transcript with secrets and pictures removed,
|
|
52100
|
-
"\u5411 popost \u56E2\u961F\u53CD\u9988\u95EE\u9898\uFF0C\u4EC5\u5728\u7528\u6237\u8981\u6C42\u65F6\u4F7F\u7528\uFF08\u514D\u8D39\uFF09\u3002\u4E0D\u52A0 --confirm \u65F6\u4E0D\u53D1\u9001\u4EFB\u4F55\u5185\u5BB9\uFF1A\u53EA\u5217\u51FA\u5C06\u8981\u53D1\u9001\u7684\u5185\u5BB9\uFF0C\u5373\u95EE\u9898\u63CF\u8FF0\u3001\u53BB\u6389\u5BC6\u94A5\u548C\u56FE\u7247\u540E\u7684\u5F53\u524D Agent \u4F1A\u8BDD\u8BB0\u5F55\u3001\u5DE5\u7A0B\u7684\u6587\u4EF6\u5217\u8868\u53CA\u5176\u4E2D\u7684\u5C0F\u6587\u672C\u6587\u4EF6\u3002\u628A\u8FD9\u4E9B\u7ED9\u7528\u6237\u770B\uFF0C\u7528\u6237\u540C\u610F\u540E\u518D\u52A0 --confirm\u3002"
|
|
52743
|
+
"Report a problem to the popost team, only when the user asks for it (free). Without --confirm nothing is sent: it prints what would go, which is the message, the user's first words of this session, this Agent session's transcript with secrets and pictures removed, the project's file list with its small text files, and the pictures the user gave for the task with the video it produced (--no-media leaves those out). Show that to the user and add --confirm only after they agree.",
|
|
52744
|
+
"\u5411 popost \u56E2\u961F\u53CD\u9988\u95EE\u9898\uFF0C\u4EC5\u5728\u7528\u6237\u8981\u6C42\u65F6\u4F7F\u7528\uFF08\u514D\u8D39\uFF09\u3002\u4E0D\u52A0 --confirm \u65F6\u4E0D\u53D1\u9001\u4EFB\u4F55\u5185\u5BB9\uFF1A\u53EA\u5217\u51FA\u5C06\u8981\u53D1\u9001\u7684\u5185\u5BB9\uFF0C\u5373\u95EE\u9898\u63CF\u8FF0\u3001\u7528\u6237\u5728\u672C\u6B21\u4F1A\u8BDD\u5F00\u5934\u8BF4\u7684\u8BDD\u3001\u53BB\u6389\u5BC6\u94A5\u548C\u56FE\u7247\u540E\u7684\u5F53\u524D Agent \u4F1A\u8BDD\u8BB0\u5F55\u3001\u5DE5\u7A0B\u7684\u6587\u4EF6\u5217\u8868\u53CA\u5176\u4E2D\u7684\u5C0F\u6587\u672C\u6587\u4EF6\uFF0C\u4EE5\u53CA\u7528\u6237\u4E3A\u8FD9\u4E2A\u4EFB\u52A1\u63D0\u4F9B\u7684\u56FE\u7247\u548C\u4EFB\u52A1\u505A\u51FA\u7684\u89C6\u9891\uFF08\u52A0 --no-media \u4E0D\u53D1\u9001\u56FE\u7247\u548C\u89C6\u9891\uFF09\u3002\u628A\u8FD9\u4E9B\u7ED9\u7528\u6237\u770B\uFF0C\u7528\u6237\u540C\u610F\u540E\u518D\u52A0 --confirm\u3002"
|
|
52101
52745
|
),
|
|
52102
52746
|
options: [
|
|
52103
52747
|
{ flag: "--message", required: true, metavar: "TEXT", help: msg("what went wrong, in the user's own words (at most 4000 characters)", "\u51FA\u4E86\u4EC0\u4E48\u95EE\u9898\uFF0C\u7528\u7528\u6237\u81EA\u5DF1\u7684\u8BDD\uFF08\u6700\u591A 4000 \u4E2A\u5B57\u7B26\uFF09") },
|
|
@@ -52105,16 +52749,37 @@ var init_feedback = __esm({
|
|
|
52105
52749
|
{ flag: "--transcript", metavar: "FILE", help: msg("the Agent session's transcript file, when popost cannot find it by itself", "Agent \u4F1A\u8BDD\u8BB0\u5F55\u6587\u4EF6\uFF0Cpopost \u81EA\u5DF1\u627E\u4E0D\u5230\u65F6\u6307\u5B9A") },
|
|
52106
52750
|
{ flag: "--no-transcript", kind: "flag", help: msg("send no session transcript", "\u4E0D\u53D1\u9001\u4F1A\u8BDD\u8BB0\u5F55") },
|
|
52107
52751
|
{ flag: "--session", metavar: "ID", help: msg("the Agent session id, when the Agent does not set it", "Agent \u4F1A\u8BDD id\uFF0CAgent \u6CA1\u6709\u63D0\u4F9B\u65F6\u6307\u5B9A") },
|
|
52752
|
+
{ flag: "--no-media", kind: "flag", help: msg("send none of the pictures the user gave and not the task's video", "\u4E0D\u53D1\u9001\u7528\u6237\u63D0\u4F9B\u7684\u56FE\u7247\u548C\u4EFB\u52A1\u7684\u89C6\u9891") },
|
|
52108
52753
|
{ flag: "--out", metavar: "FILE", help: msg("also write the report (gzip JSON) to this file", "\u540C\u65F6\u628A\u62A5\u544A\uFF08gzip \u538B\u7F29\u7684 JSON\uFF09\u5199\u5230\u8FD9\u4E2A\u6587\u4EF6") },
|
|
52109
52754
|
{ flag: "--confirm", kind: "flag", help: msg("send it; only after the user has seen the dry run and agreed", "\u53D1\u9001\uFF1B\u4EC5\u5728\u7528\u6237\u770B\u8FC7\u8BD5\u8FD0\u884C\u7ED3\u679C\u5E76\u540C\u610F\u4E4B\u540E") }
|
|
52110
52755
|
]
|
|
52111
52756
|
});
|
|
52112
52757
|
quote15 = (word2) => /^[A-Za-z0-9_./:=,@+-]+$/.test(word2) ? word2 : `'${word2.replace(/'/g, `'\\''`)}'`;
|
|
52113
|
-
|
|
52758
|
+
MB = 1024 * 1024;
|
|
52759
|
+
skipWhy = (item2) => {
|
|
52760
|
+
const video = item2.role === "result";
|
|
52761
|
+
if (item2.reason === "too-large")
|
|
52762
|
+
return video ? msg(`larger than ${MAX_VIDEO_BYTES2 / MB} MB`, `\u8D85\u8FC7 ${MAX_VIDEO_BYTES2 / MB} MB`) : msg(`larger than ${MAX_PICTURE_BYTES3 / MB} MB`, `\u8D85\u8FC7 ${MAX_PICTURE_BYTES3 / MB} MB`);
|
|
52763
|
+
if (item2.reason === "over-limit") return msg(`only the first ${MAX_PICTURES2} pictures go`, `\u6700\u591A\u53D1\u9001\u524D ${MAX_PICTURES2} \u5F20\u56FE\u7247`);
|
|
52764
|
+
if (item2.reason === "unsupported-type")
|
|
52765
|
+
return video ? msg("not an MP4 or QuickTime video", "\u4E0D\u662F MP4 \u6216 QuickTime \u89C6\u9891") : msg("not a JPEG, PNG or WebP picture", "\u4E0D\u662F JPEG\u3001PNG \u6216 WebP \u56FE\u7247");
|
|
52766
|
+
return msg("cannot be read", "\u65E0\u6CD5\u8BFB\u53D6");
|
|
52767
|
+
};
|
|
52768
|
+
mediaToSend = (rt, built, noMedia) => {
|
|
52769
|
+
if (noMedia) return { off: true, send: [], skipped: [] };
|
|
52770
|
+
const files = built.media?.files ?? [];
|
|
52771
|
+
return {
|
|
52772
|
+
send: files.map((f) => ({ role: f.role, from: f.from, path: mediaPath(rt, built.projectDir, f.file), contentType: f.contentType, bytes: f.bytes })),
|
|
52773
|
+
skipped: (built.media?.skipped ?? []).map((f) => ({ role: f.role, from: f.from, path: mediaPath(rt, built.projectDir, f.file), reason: f.reason, why: skipWhy(f), ...f.bytes !== void 0 ? { bytes: f.bytes } : {} })),
|
|
52774
|
+
bytes: files.reduce((sum2, f) => sum2 + f.bytes, 0)
|
|
52775
|
+
};
|
|
52776
|
+
};
|
|
52777
|
+
wouldSend = (rt, built, noMedia) => {
|
|
52114
52778
|
const { transcript: transcript2, project } = built;
|
|
52115
52779
|
const sent = project ? project.files.filter((file) => file.path in project.documents) : [];
|
|
52116
52780
|
return {
|
|
52117
52781
|
message: built.message,
|
|
52782
|
+
request: transcript2.request ?? null,
|
|
52118
52783
|
agent: { id: built.agent.id, label: built.agent.label, ...built.agent.sessionId ? { sessionId: built.agent.sessionId } : {} },
|
|
52119
52784
|
transcript: {
|
|
52120
52785
|
status: transcript2.status,
|
|
@@ -52133,6 +52798,7 @@ var init_feedback = __esm({
|
|
|
52133
52798
|
listedOnly: project.files.length - sent.length,
|
|
52134
52799
|
...project.listTruncated ? { listTruncated: true } : {}
|
|
52135
52800
|
} : null,
|
|
52801
|
+
media: mediaToSend(rt, built, noMedia),
|
|
52136
52802
|
redactions: built.stats.redactions,
|
|
52137
52803
|
omittedImages: built.stats.omittedImages,
|
|
52138
52804
|
bytes: built.gzip.length
|
|
@@ -52156,12 +52822,13 @@ var init_feedback = __esm({
|
|
|
52156
52822
|
"Nothing was sent. Show the user what would be sent; run next only after they agree.",
|
|
52157
52823
|
"\u672A\u53D1\u9001\u4EFB\u4F55\u5185\u5BB9\u3002\u5148\u628A\u5C06\u8981\u53D1\u9001\u7684\u5185\u5BB9\u7ED9\u7528\u6237\u770B\uFF1B\u7528\u6237\u540C\u610F\u540E\u518D\u8FD0\u884C next\u3002"
|
|
52158
52824
|
);
|
|
52159
|
-
printJson(rt, { ok: true, dryRun: true, wouldSend: wouldSend(rt, built), ...written2, next, note }, true);
|
|
52825
|
+
printJson(rt, { ok: true, dryRun: true, wouldSend: wouldSend(rt, built, options.noMedia), ...written2, next, note }, true);
|
|
52160
52826
|
return 0;
|
|
52161
52827
|
}
|
|
52162
52828
|
const sent = await sendFeedback(rt, new PopostClient({ ...rt, project: void 0 }), built);
|
|
52163
52829
|
const thanks = msg(`Sent. Give the user the reference ${sent.reference} for any follow-up.`, `\u5DF2\u53D1\u9001\u3002\u8BF7\u628A\u7F16\u53F7 ${sent.reference} \u544A\u8BC9\u7528\u6237\uFF0C\u65B9\u4FBF\u540E\u7EED\u6C9F\u901A\u3002`);
|
|
52164
|
-
|
|
52830
|
+
const media = sent.media.map((m) => ({ path: mediaPath(rt, built.projectDir, m.file.file), state: m.state }));
|
|
52831
|
+
printJson(rt, { ok: true, id: sent.id, reference: sent.reference, bytes: built.gzip.length, receivedAt: sent.receivedAt, ...media.length ? { media } : {}, ...written2, note: thanks });
|
|
52165
52832
|
return 0;
|
|
52166
52833
|
};
|
|
52167
52834
|
run5 = async (rt, argv, options) => {
|
|
@@ -52187,6 +52854,7 @@ var init_feedback = __esm({
|
|
|
52187
52854
|
transcript: args2.string("transcript"),
|
|
52188
52855
|
noTranscript: args2.flag("no-transcript"),
|
|
52189
52856
|
session: args2.string("session"),
|
|
52857
|
+
noMedia: args2.flag("no-media"),
|
|
52190
52858
|
out: args2.string("out"),
|
|
52191
52859
|
confirm: args2.flag("confirm")
|
|
52192
52860
|
})
|
|
@@ -52381,9 +53049,9 @@ ${usage()}`);
|
|
|
52381
53049
|
const own3 = updates.rt;
|
|
52382
53050
|
try {
|
|
52383
53051
|
const main24 = await group.load();
|
|
52384
|
-
const { dirArg: dirArg2, inProject:
|
|
53052
|
+
const { dirArg: dirArg2, inProject: inProject5 } = await Promise.resolve().then(() => (init_task(), task_exports));
|
|
52385
53053
|
const dir = dirArg2(rest);
|
|
52386
|
-
return await main24(group.keepName ? argv : rest, dir ?
|
|
53054
|
+
return await main24(group.keepName ? argv : rest, dir ? inProject5(own3, dir, "found") : own3);
|
|
52387
53055
|
} catch (error2) {
|
|
52388
53056
|
printJson(own3, { ok: false, error: errorText(error2) });
|
|
52389
53057
|
return 1;
|
|
@@ -52509,9 +53177,9 @@ var browserCommands = (os, env2, preferred, url) => {
|
|
|
52509
53177
|
}
|
|
52510
53178
|
if (os !== "linux" || !env2.DISPLAY && !env2.WAYLAND_DISPLAY) return [];
|
|
52511
53179
|
const apps = ["google-chrome", "chromium", "chromium-browser", "firefox", "microsoft-edge", "brave-browser", "opera"];
|
|
52512
|
-
const
|
|
53180
|
+
const first2 = apps.find((app) => preferred.startsWith(app + ".") || preferred.startsWith(app + "-"));
|
|
52513
53181
|
const roots2 = ["/usr/bin", "/usr/local/bin", "/opt/bin", "/snap/bin"];
|
|
52514
|
-
return [.../* @__PURE__ */ new Set([...
|
|
53182
|
+
return [.../* @__PURE__ */ new Set([...first2 ? [first2] : [], ...apps])].flatMap((app) => roots2.map((root) => ({ command: path2.posix.join(root, app), args: [url] })));
|
|
52515
53183
|
};
|
|
52516
53184
|
var openSystemBrowser = async (url, host) => {
|
|
52517
53185
|
try {
|