mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36298b4166 |
No files matched your search
@@ -208,10 +208,23 @@ export async function words(file: string, anyAge = false): Promise<Word[]> {
|
||||
/** frames read a second for the scene, and the width they're read at (places are in shares of the picture) */
|
||||
export const RATE = 2
|
||||
const SIDE = 540
|
||||
/** a video's scene reading, kept beside it */
|
||||
export const SCENE_EXT = "scene.json"
|
||||
|
||||
/** what's in a file's frames (`at`: those seconds, else RATE a second): each frame's faces and seams, and its scene
|
||||
* (people, faces, things, words in the shot) for placement. The farm reads them; with no farm here, Unmet */
|
||||
export async function scene(file: string, at?: number[]): Promise<{ rate: number; faces: Faces[]; scenes: Scene[] }> {
|
||||
// a video's whole reading is kept beside it, as its words are, and read again only when the file is newer: a cut
|
||||
// checked at its render was read again at publish and again at done, 30 s a file each time, so a done check of 11
|
||||
// files took 334 s (12-01)
|
||||
const whole = !at?.length && !/\.(png|jpe?g|webp)$/i.test(file)
|
||||
if (whole) {
|
||||
const kept = freshBeside(file, SCENE_EXT)
|
||||
try {
|
||||
const k = kept ? (JSON.parse(readFileSync(kept, "utf8")) as { rate: number; side: number; faces: Faces[]; scenes: Scene[] }) : null
|
||||
if (k && k.rate === RATE && k.side === SIDE && Array.isArray(k.scenes) && k.scenes.length) return { rate: k.rate, faces: k.faces, scenes: k.scenes }
|
||||
} catch {}
|
||||
}
|
||||
if (!farm()) throw new Unmet(`no scene reader on this machine for ${path.basename(file)} (people, faces and things are read by raea cloud's farm: set RAEA_CLOUD_GPU_URL)`)
|
||||
const dir = mkdtempSync(path.join(os.tmpdir(), "raea-scene-"))
|
||||
try {
|
||||
@@ -238,6 +251,11 @@ export async function scene(file: string, at?: number[]): Promise<{ rate: number
|
||||
scenes.push({ w: g.w, h: g.h, grid: g.grid, things: g.things ?? [], faces: fs, ...(Array.isArray(g.texts) ? { texts: g.texts } : {}) } as Scene)
|
||||
}
|
||||
}
|
||||
if (whole && scenes.length) {
|
||||
try {
|
||||
writeFileSync(`${stem(file)}.${SCENE_EXT}`, `${JSON.stringify({ rate: RATE, side: SIDE, faces, scenes })}\n`)
|
||||
} catch {}
|
||||
}
|
||||
return { rate: at?.length ? 0 : RATE, faces, scenes }
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
|
||||
@@ -19,6 +19,11 @@ export const TIMEOUT = 300
|
||||
/** folders that aren't the work: what the job writes about itself, and what tools keep */
|
||||
const NOT_WORK = new Set(["review", ".git", "node_modules", ".raea", "target", ".cache", ".raea-cloud"])
|
||||
|
||||
/** what a check keeps beside a file it read (its report, its words, its scene): a reading of the work, not a change
|
||||
* to it. A done check that heard a cut's words wrote them beside it, and the critic's verdict of a minute before read
|
||||
* as older than the work (12-01) */
|
||||
const READING = /\.(check|words|scene)\.json$/
|
||||
|
||||
/** when the work last changed (ms): the newest file under dir, its own bookkeeping left out (a bounded walk) */
|
||||
export function newest(dir: string): number | null {
|
||||
let best: number | null = null
|
||||
@@ -43,7 +48,7 @@ export function newest(dir: string): number | null {
|
||||
}
|
||||
if (st.isDirectory()) {
|
||||
if (!(d === dir && NOT_WORK.has(name)) && name !== "node_modules" && name !== ".git") stack.push(p)
|
||||
} else if (st.isFile() && name !== "NOTES.md" && !name.endsWith(".check.json")) best = Math.max(best ?? 0, st.mtimeMs)
|
||||
} else if (st.isFile() && name !== "NOTES.md" && !READING.test(name)) best = Math.max(best ?? 0, st.mtimeMs)
|
||||
}
|
||||
}
|
||||
return best
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// itself, and the box around them a little), then the edges a phone's own buttons and captions cover; open ground is
|
||||
// free. A text's cost is the mean of the cells it covers. A text is badly placed when it covers a face or a thing, or
|
||||
// a person, and a place of the same size costs much less; that place is what's said.
|
||||
// Over a face or a thing it's an error; over a person's body alone, a warning.
|
||||
//
|
||||
// raea make place FILE [--at S[,S...]] [--box WxH] [-o REPORT.json]
|
||||
// FILE (a take or an export, a picture or a video) read at those seconds (a video: one a second, at most 12):
|
||||
@@ -258,12 +257,8 @@ export function textOver(manifest: any, scenes: Scene[], rate: number): Finding[
|
||||
const q = `${on.text.length > 40 ? `“${on.text.slice(0, 40)}...”` : `“${on.text}”`}${on.lines > 1 ? ` (and the ${on.lines - 1} line${on.lines > 2 ? "s" : ""} under it)` : ""}`
|
||||
const when = on.to - on.from < 0.5 ? `at ${on.from.toFixed(1)} s` : `from ${on.from.toFixed(1)} s to ${on.to.toFixed(1)} s`
|
||||
if (best && best.cost <= here - BETTER) {
|
||||
// an error only for what a shot can't lose: a face, or the thing it shows (the product, the dog, a phone held
|
||||
// up). A caption over someone's coat with clearer ground elsewhere is a warning with the place said (12-01: two
|
||||
// people fill a 9:16 interview frame, each caption's clearest place is a different one, and an agent spent
|
||||
// hours cropping shots and rendering again to clear errors a steady caption position can't)
|
||||
const hard = under.some((u) => u !== "a person in the shot")
|
||||
out.push({ level: hard ? "error" : "warn", kind: "text-over", at: on.from, until: on.to, says: `${q} covers ${what} ${when}: move it to left ${px(best.box[0], W)} px, top ${px(best.box[1], H)} px (${Math.round(best.box[1] * 100)}% down), which is clear there. raea make place shows the clear places in a shot` })
|
||||
const face = under.includes("a face")
|
||||
out.push({ level: face || here >= BAD + 1.5 ? "error" : "warn", kind: "text-over", at: on.from, until: on.to, says: `${q} covers ${what} ${when}: move it to left ${px(best.box[0], W)} px, top ${px(best.box[1], H)} px (${Math.round(best.box[1] * 100)}% down), which is clear there. raea make place shows the clear places in a shot` })
|
||||
} else if (under.includes("a face")) {
|
||||
out.push({ level: "error", kind: "text-over", at: on.from, until: on.to, says: `${q} covers a face ${when} and no place of its size is clear: make it smaller, put it on a shot with room, or cut to one` })
|
||||
} else if (here >= BAD + 1.5) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// The rule packs (MK29, ported from Rust's goal gate tests): run rules pass or say why, says rules need a fresh critic;
|
||||
// any goal carries rules.
|
||||
import { expect, test } from "bun:test"
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"
|
||||
import { mkdirSync, mkdtempSync, utimesSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import path from "node:path"
|
||||
import { clefVerdict, lastVerdict, newest } from "../src/packs/goal.ts"
|
||||
@@ -80,3 +80,15 @@ test("clef judges a rule on the file it names, else on every video made, and say
|
||||
const empty = mkdtempSync(path.join(tmpdir(), "raea-goal-clef-"))
|
||||
expect(clefVerdict(g, empty, () => []).all?.why).toContain("names no file on disk")
|
||||
})
|
||||
|
||||
test("a reading kept beside a file isn't the work changing", () => {
|
||||
const d = mkdtempSync(path.join(tmpdir(), "raea-newest-"))
|
||||
mkdirSync(path.join(d, "out/cuts"), { recursive: true })
|
||||
const cut = path.join(d, "out/cuts/a_b_c_v1_9x16.mp4")
|
||||
writeFileSync(cut, "x")
|
||||
utimesSync(cut, 1000, 1000)
|
||||
for (const ext of ["words.json", "scene.json", "check.json"]) writeFileSync(path.join(d, `out/cuts/a_b_c_v1_9x16.${ext}`), "{}")
|
||||
expect(newest(d)).toBe(1_000_000)
|
||||
writeFileSync(path.join(d, "out/cuts/a_b_c_v1_9x16.render.json"), "{}")
|
||||
expect(newest(d)!).toBeGreaterThan(1_000_000)
|
||||
})
|
||||
@@ -1,6 +1,9 @@
|
||||
import { test } from "bun:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { readFileSync } from "node:fs"
|
||||
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import path from "node:path"
|
||||
import { RATE, scene, SCENE_EXT, useSender } from "../src/media.ts"
|
||||
import { placeReport, textOver } from "../src/packs/place.ts"
|
||||
|
||||
test("the place pack's model", async () => {
|
||||
@@ -42,13 +45,22 @@ test("the place pack's model", async () => {
|
||||
assert.ok(b.every((x) => x.level === "warn"), JSON.stringify(b))
|
||||
ok("a caption over a person who fills the frame is at most a warning")
|
||||
|
||||
// a: a caption across the woman's body with clear ground above her: a warning that names the place, never an error
|
||||
// (12-01: errors here had an agent cropping interview shots and rendering again for hours)
|
||||
for (const y of [300, 400, 500]) {
|
||||
const d = textOver(man([t("Did you know you", 480, y, 536, 88)]), [sc.a], 1).filter((x) => /covers a person in the shot (at|from)/.test(x.says))
|
||||
assert.ok(d.length === 1 && d[0].level === "warn", JSON.stringify(d))
|
||||
}
|
||||
assert.match(textOver(man([t("Did you know you", 480, 400, 536, 88)]), [sc.a], 1)[0].says, /covers a person in the shot at 0\.0 s: move it to left \d+ px, top \d+ px/)
|
||||
ok("a caption over a body with clearer ground elsewhere is a warning with the place said")
|
||||
})
|
||||
|
||||
test("a video's scene reading is kept beside it and read again only when the video is newer", async () => {
|
||||
const d = mkdtempSync(path.join(tmpdir(), "raea-scene-kept-"))
|
||||
const cut = path.join(d, "a_b_c_v1_9x16.mp4")
|
||||
writeFileSync(cut, "not a real video")
|
||||
const kept = { rate: RATE, side: 540, faces: [null], scenes: [{ w: 540, h: 960, grid: { cols: 1, rows: 1, people: ["0"] }, things: [], faces: [] }] }
|
||||
writeFileSync(path.join(d, `a_b_c_v1_9x16.${SCENE_EXT}`), JSON.stringify(kept))
|
||||
let asked = 0
|
||||
useSender(async () => (asked++, { status: 500, ok: false, text: "" }))
|
||||
delete process.env.RAEA_CLOUD_GPU_URL
|
||||
// no farm here at all, and the reading still comes back: from beside the file
|
||||
const r = await scene(cut)
|
||||
assert.equal(r.scenes.length, 1)
|
||||
assert.equal(r.rate, RATE)
|
||||
assert.equal(asked, 0)
|
||||
// a reading at named seconds is never the whole file's
|
||||
await assert.rejects(scene(cut, [1, 2]), /no scene reader/)
|
||||
})
|
||||
Reference in new issue
Block a user