mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c89470125 |
No files matched your search
@@ -208,23 +208,10 @@ 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 {
|
||||
@@ -251,11 +238,6 @@ 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,11 +19,6 @@ 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
|
||||
@@ -48,7 +43,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" && !READING.test(name)) best = Math.max(best ?? 0, st.mtimeMs)
|
||||
} else if (st.isFile() && name !== "NOTES.md" && !name.endsWith(".check.json")) best = Math.max(best ?? 0, st.mtimeMs)
|
||||
}
|
||||
}
|
||||
return best
|
||||
|
||||
@@ -11,11 +11,24 @@ import { check, found } from "raea/check"
|
||||
import type { Job } from "../facts.ts"
|
||||
import { adOf, bookkeeping, sizeOf } from "./naming.ts"
|
||||
|
||||
/** The size a made file is in, as a name says one (9x16): its name's, else a video's own shape (1080x1920 is 9x16).
|
||||
* A picture with no size in its name is a still of the work, a sheet or a strip, not a size of an ad. Told by pixels
|
||||
* alone, an ad named _9x16 beside its own 1080x1920 renders and one 540x960 still read as three sizes, and an agent
|
||||
* with one size made couldn't stop for its sign-off (12-01). */
|
||||
export function shapeOf(f: { path: string; kind?: string; width?: number; height?: number }): string | null {
|
||||
const named = sizeOf(f.path)
|
||||
if (named) return named
|
||||
if (f.kind !== "video" || !f.width || !f.height) return null
|
||||
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a)
|
||||
const g = gcd(f.width, f.height)
|
||||
return `${f.width / g}x${f.height / g}`
|
||||
}
|
||||
|
||||
export default check<Job>({ id: "sizes", text: "one size first: no other size before the first is approved", over: "job", at: ["render", "publish", "done"] }, async (j) => {
|
||||
const made = j.files.filter((f) => f.made && !bookkeeping(f.path) && (f.kind === "video" || f.kind === "image"))
|
||||
const sizes = new Map<string, string[]>()
|
||||
for (const f of made) {
|
||||
const s = sizeOf(f.path) ?? (f.width && f.height ? `${f.width}x${f.height}` : null)
|
||||
const s = shapeOf(f)
|
||||
if (s) sizes.set(s, [...(sizes.get(s) ?? []), f.path])
|
||||
}
|
||||
if (sizes.size < 2) return
|
||||
|
||||
@@ -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, utimesSync, writeFileSync } from "node:fs"
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import path from "node:path"
|
||||
import { clefVerdict, lastVerdict, newest } from "../src/packs/goal.ts"
|
||||
@@ -80,15 +80,3 @@ 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,9 +1,6 @@
|
||||
import { test } from "bun:test"
|
||||
import assert from "node:assert/strict"
|
||||
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 { readFileSync } from "node:fs"
|
||||
import { placeReport, textOver } from "../src/packs/place.ts"
|
||||
|
||||
test("the place pack's model", async () => {
|
||||
@@ -46,21 +43,3 @@ test("the place pack's model", async () => {
|
||||
ok("a caption over a person who fills the frame is at most a warning")
|
||||
|
||||
})
|
||||
|
||||
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/)
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { beforeAll, expect, test } from "bun:test"
|
||||
import { goalCheck } from "../src/run.ts"
|
||||
import { CLIP, project, put } from "./project.ts"
|
||||
import { readFileSync } from "node:fs"
|
||||
import { shapeOf } from "../src/packs/sizes.ts"
|
||||
|
||||
beforeAll(() => {
|
||||
process.env.RAEA_REAL = "/usr/bin/false"
|
||||
@@ -31,3 +32,13 @@ test("every size of the newest version passes; a person's answer can say fewer",
|
||||
expect((await all(answered, sizes)).filter((x) => x.check === "sizes-all")).toEqual([])
|
||||
expect((await all(answered, ["out/cuts/dutch_vetbill_hooka_v2_9x16.mp4"])).filter((x) => x.check === "sizes-all")).toEqual([])
|
||||
})
|
||||
|
||||
test("one size is one size however it's told: a name's 9x16, a 1080x1920 video, never a still", () => {
|
||||
expect(shapeOf({ path: "out/cuts/dutch_vetbill_hooka_v1_9x16.mp4", kind: "video", width: 1080, height: 1920 })).toBe("9x16")
|
||||
expect(shapeOf({ path: "out/cuts/hooka.mp4", kind: "video", width: 1080, height: 1920 })).toBe("9x16")
|
||||
expect(shapeOf({ path: "out/cuts/hooka_small.mp4", kind: "video", width: 540, height: 960 })).toBe("9x16")
|
||||
expect(shapeOf({ path: "out/cuts/hooka.mp4", kind: "video", width: 1080, height: 1350 })).toBe("4x5")
|
||||
expect(shapeOf({ path: "out/stills/a1_38.jpg", kind: "image", width: 540, height: 960 })).toBe(null)
|
||||
expect(shapeOf({ path: "out/stills/strip.png", kind: "image", width: 1080, height: 480 })).toBe(null)
|
||||
expect(shapeOf({ path: "out/stills/dutch_vetbill_end_v1_1x1.png", kind: "image", width: 1080, height: 1080 })).toBe("1x1")
|
||||
})
|
||||
Reference in new issue
Block a user