mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-06 05:33:38 -10:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94bb5e6f9c | ||
|
|
12ad441266 | ||
|
|
8e7c5a13e7 | ||
|
|
a380418ed5 |
No files matched your search
@@ -124,3 +124,37 @@ Feature: raea cloud: raea and an ACP agent on a server of your own (sdk/cloud)
|
||||
back, a second container handing its render to the first, an ACP turn round-tripped
|
||||
And with Kimi Code signed in, one real turn renders a title card with raea in the container, and the file
|
||||
comes back through /v1/files
|
||||
|
||||
Rule: a box edits on light copies, the farm renders from originals (12-05)
|
||||
Scenario: CL17. Nothing on the box takes a light copy's place
|
||||
Given raea cloud brought a run's footage as 540p light copies (footage/NAME.mp4, listed in .raea-cloud/light.txt)
|
||||
Then every look the agent takes (a still, a frame, a probe, a check of its words) reads the light copy
|
||||
And no file ever replaces footage/NAME.mp4 on the box, before a render or after one
|
||||
|
||||
Scenario: CL18. A farm render reads each light copy as its original, fetched by the farm
|
||||
Given .raea-cloud/originals.json names a light copy's original: its hash, size and a link that hasn't ended
|
||||
When a render that reads the light copy goes to the farm (server/offload.ts)
|
||||
Then its media manifest names the original under the light copy's path, with its link, and the light copy's own
|
||||
bytes go nowhere
|
||||
And the farm fetches the original from the library into its cache, checks it against its hash, and keeps it for
|
||||
every later render; the box never downloads it, hashes it or sends it
|
||||
And a light copy the render doesn't read is left out, its original included
|
||||
And a size raea cloud doesn't know goes as 0, which the farm takes with a link and never without one
|
||||
|
||||
Scenario: CL19. An original with no link goes from the box
|
||||
Given a light copy whose original has no hash, or whose link ends within 5 minutes
|
||||
When its original is in footage/originals/ under the light copy's name (any extension)
|
||||
Then the render sends that file by its own hash, under the light copy's path
|
||||
And only a farm with its media cache gets an original by its file (by LFS or in the tar it would go as the light
|
||||
copy), and only that farm an original of unknown size: for any other the take is rendered as its light copy
|
||||
And .raea-cloud/proxies/ never goes in a render's tar, and an original no source names stays on the box
|
||||
|
||||
Scenario: CL20. A render that read a light copy says so
|
||||
Given a light copy with no original either way
|
||||
Then the render prints NO ORIGINAL with its name, and is rendered from the light copy
|
||||
And its manifest records {"originals": {"read": [...], "light": [...]}} (a still's in OUT.render.json beside it),
|
||||
checked or not, from which raea cloud marks it a draft that is never shown or published
|
||||
And the farm's media list holds each original by its link in its light copy's place, with everything else that
|
||||
went (12-05 review: the farm-cache path dropped the links while the manifest said they were read)
|
||||
And an original of unknown size over 40 GB is refused as it downloads, before it fills the farm's volume
|
||||
And test/originals.ts and test/farm_media.py check CL17-CL20
|
||||
@@ -4,13 +4,14 @@
|
||||
#
|
||||
# MODAL_PROFILE=raea modal deploy deploy/modal/farm.py
|
||||
#
|
||||
# POST /v1/jobs?args=JSON[&gpus=N][&gpu=KIND][&max_usd=X] body: the project as a tar. {id}
|
||||
# POST /v1/jobs?args=JSON[&gpus=N][&gpu=KIND][&max_usd=X][&nv=1|0] body: the project as a tar. {id}
|
||||
# GET /v1/jobs/ID?from=N {log, next, exit?}, held up to 20 s for more
|
||||
# GET /v1/jobs/ID/out?as=zst|gz|tar the files the job made or changed; the job is removed
|
||||
# GET /v1/jobs/ID/media with media=1: the job's media outputs [{path, oid, size}],
|
||||
# left out of /out
|
||||
# POST /v1/jobs/ID/media {objects: [{path, oid, href, header}]} PUTs each to its signed URL in R2 (farm_media.py)
|
||||
# POST /v1/blobs/have {objects: [{oid, size}]} which of a project's media the farm holds: {have: [oid]}
|
||||
# POST /v1/blobs/have {objects: [{oid, size}]} which of a project's media the farm holds: {have: [oid],
|
||||
# links: 1} (links: it fetches an original of unknown size)
|
||||
# PUT /v1/blobs/OID?size=N one media file into the farm's cache, kept when it
|
||||
# hashes to OID (a box's project not in raea's LFS)
|
||||
# A job's folder may hold .raea-cloud-media.json: its media by Git LFS object id with URLs signed for it, fetched from
|
||||
@@ -813,7 +814,7 @@ def api():
|
||||
if not isinstance(args, list) or not all(isinstance(a, str) for a in args):
|
||||
raise HTTPException(400, "args must be a JSON array of strings: raea's own arguments")
|
||||
q = req.query_params
|
||||
opts = {"gpus": min(int(q.get("gpus", JOB_GPUS)), GPUS), "cpus": min(int(q.get("cpus", JOB_CPUS)), CPUS), "kept": q.get("kept", "1") != "0", "gpu": q.get("gpu"), "max_usd": float(q["max_usd"]) if "max_usd" in q else None, "media": q.get("media") == "1"}
|
||||
opts = {"gpus": min(int(q.get("gpus", JOB_GPUS)), GPUS), "cpus": min(int(q.get("cpus", JOB_CPUS)), CPUS), "kept": q.get("kept", "1") != "0", "gpu": q.get("gpu"), "nv": q.get("nv") if q.get("nv") in ("0", "1") else None, "max_usd": float(q["max_usd"]) if "max_usd" in q else None, "media": q.get("media") == "1"}
|
||||
id = str(uuid.uuid4())
|
||||
work = f"{JOBS}/{id}/work"
|
||||
async with gate.use():
|
||||
@@ -848,7 +849,7 @@ def api():
|
||||
blob = f"{ROOT}/blobs/{oid}"
|
||||
if len(oid) == 64 and all(c in "0123456789abcdef" for c in oid) and os.path.exists(blob) and os.path.getsize(blob) == size:
|
||||
have.append(oid)
|
||||
return {"have": have}
|
||||
return {"have": have, "links": 1}
|
||||
|
||||
@web.put("/v1/blobs/{oid}")
|
||||
async def blob_put(oid: str, req: Request):
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# outputs(work, changed) the job's media among what it made or changed: [{"path", "oid", "size"}]
|
||||
# upload(work, objects) PUTs each to its signed URL: [{"path", "oid", "href", "header"}]
|
||||
|
||||
import uuid
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -43,9 +44,21 @@ def inside(work, rel):
|
||||
return p == os.path.realpath(work) or p.startswith(os.path.realpath(work) + os.sep)
|
||||
|
||||
|
||||
def get(href, header, dest):
|
||||
# the most an original of unknown size may be: a link that answers with more is refused before it fills the volume
|
||||
UNKNOWN_MAX = 40 << 30
|
||||
|
||||
|
||||
def get(href, header, dest, limit=None):
|
||||
req = urllib.request.Request(href, headers={**AGENT, **(header or {})})
|
||||
with urllib.request.urlopen(req, timeout=600) as r, open(dest, "wb") as f:
|
||||
if limit:
|
||||
n = 0
|
||||
while chunk := r.read(8 << 20):
|
||||
n += len(chunk)
|
||||
if n > limit:
|
||||
raise ValueError(f"media: {href.split('?')[0]} is over {limit >> 30} GB, more than an original of unknown size may be")
|
||||
f.write(chunk)
|
||||
return
|
||||
shutil.copyfileobj(r, f, CHUNK)
|
||||
|
||||
|
||||
@@ -80,38 +93,64 @@ def fetch(work, cache, log=print, download=get, check=probe):
|
||||
if len(oid) != 64 or any(c not in "0123456789abcdef" for c in oid) or not inside(work, path):
|
||||
raise ValueError(f"media: {path!r} ({oid}) isn't a path in the job or an object id")
|
||||
blob = os.path.join(cache, oid)
|
||||
# size 0: a library original whose size raea cloud doesn't know (it comes with its link); its hash alone says
|
||||
# it's the one. What the box sent (no link) is held only at its own size
|
||||
held = os.path.exists(blob) and (os.path.getsize(blob) == size or (size <= 0 and bool(o.get("href"))))
|
||||
if not o.get("href"):
|
||||
# sent by the box over the farm's own token (PUT /v1/blobs), checked against its hash as it came
|
||||
if not (os.path.exists(blob) and os.path.getsize(blob) == size):
|
||||
if not held:
|
||||
raise ValueError(f"media: {path} ({oid[:12]}…) was never sent to the farm")
|
||||
cached += size
|
||||
elif os.path.exists(blob) and os.path.getsize(blob) == size:
|
||||
elif held:
|
||||
# a hash alone doesn't open the cache: the job's URL, signed for its account, has to answer
|
||||
check(o["href"], o.get("header"))
|
||||
cached += size
|
||||
cached += os.path.getsize(blob)
|
||||
else:
|
||||
tmp = f"{blob}.part-{os.getpid()}"
|
||||
download(o["href"], o.get("header"), tmp)
|
||||
tmp = f"{blob}.part-{uuid.uuid4().hex}"
|
||||
try:
|
||||
download(o["href"], o.get("header"), tmp, *([UNKNOWN_MAX] if size <= 0 else []))
|
||||
except Exception:
|
||||
if os.path.exists(tmp):
|
||||
os.remove(tmp)
|
||||
raise
|
||||
got = sha256(tmp)
|
||||
if got != oid or os.path.getsize(tmp) != size:
|
||||
if got != oid or (size > 0 and os.path.getsize(tmp) != size):
|
||||
os.remove(tmp)
|
||||
raise ValueError(f"media: {path} came back as {got[:12]}…, not {oid[:12]}…")
|
||||
fetched += os.path.getsize(tmp)
|
||||
os.replace(tmp, blob)
|
||||
fetched += size
|
||||
dest = os.path.join(work, path)
|
||||
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
||||
if os.path.lexists(dest):
|
||||
os.remove(dest)
|
||||
# a link into the cache, not a copy: a project's footage is gigabytes, the same across every job (11-25); every
|
||||
# container of the job mounts the volume at the same place, so the link resolves on the GPUs too
|
||||
# container of the job mounts the volume at the same place, so the link resolves on the GPUs too. It ends at a
|
||||
# file with the take's own name (cache/named/OID/NAME, a hard link to the blob): a bundler follows the link, and
|
||||
# a composition that knows its takes by name (Framed's faces) found only a hash and framed every shot centred
|
||||
try:
|
||||
os.symlink(blob, dest)
|
||||
os.symlink(named(cache, oid, path), dest)
|
||||
except OSError:
|
||||
shutil.copyfile(blob, dest)
|
||||
log(f"raea farm: {len(objects)} media files by hash, {fetched / 1e6:.1f} MB from R2, {cached / 1e6:.1f} MB already here")
|
||||
return {"objects": len(objects), "fetched": fetched, "cached": cached}
|
||||
|
||||
|
||||
def named(cache, oid, path):
|
||||
"""the blob under the take's own name, cache/named/OID/NAME: a hard link (the same file, no space), else the blob"""
|
||||
blob = os.path.join(cache, oid)
|
||||
out = os.path.join(cache, "named", oid, os.path.basename(path))
|
||||
if os.path.exists(out) and os.path.getsize(out) == os.path.getsize(blob):
|
||||
return out
|
||||
try:
|
||||
os.makedirs(os.path.dirname(out), exist_ok=True)
|
||||
tmp = f"{out}.part-{uuid.uuid4().hex}"
|
||||
os.link(blob, tmp)
|
||||
os.replace(tmp, out)
|
||||
return out
|
||||
except OSError:
|
||||
return blob
|
||||
|
||||
|
||||
def is_media(path, size):
|
||||
ext = path.rsplit(".", 1)[-1].lower() if "." in os.path.basename(path) else ""
|
||||
return ext in MEDIA or size >= LARGE
|
||||
|
||||
@@ -365,7 +365,7 @@ def raea_render(args, opts, work, log, render, cpu_env, run, reload=lambda: None
|
||||
t = threading.Thread(target=lambda: run(["raea", *rest, "-o", sound], cwd=work, env=cpu_env))
|
||||
t.start()
|
||||
video = out.endswith(VIDEO)
|
||||
can_flat = bool(video and cpu_render and not opts.get("gpu"))
|
||||
can_flat = bool(video and cpu_render and not opts.get("gpu") and opts.get("nv") != "1")
|
||||
# what each frame draws, as a key (farm_keys.py): read here with nothing drawn, when this raea has --keys
|
||||
keyed, keys_s = farm_keys.read(rest, work, run, cpu_env, f"/tmp/{id}-keys.json") if video and opts.get("keys") else (None, 0)
|
||||
|
||||
@@ -409,8 +409,9 @@ def raea_render(args, opts, work, log, render, cpu_env, run, reload=lambda: None
|
||||
gpu_render, gpu_kind = render, kind
|
||||
# a piece with 3D in it keeps its GPU, and its runs use the GPU's encoder and decoder too (CR34): on a 2D piece NVENC
|
||||
# bought nothing (300 frames: 210 s against libx264's 215 s, 11% more bytes), the page and the clips are the work
|
||||
nv = bool((p.get("manifest") or {}).get("has3d"))
|
||||
flat = bool(video and cpu_render and not opts.get("gpu") and (p.get("manifest") or {}).get("has3d") is False)
|
||||
# (opts nv "1" or "0" says so for the job, and "1" keeps it on GPUs: to measure what NVENC and NVDEC buy a cut)
|
||||
nv = opts.get("nv") == "1" or (opts.get("nv") != "0" and bool((p.get("manifest") or {}).get("has3d")))
|
||||
flat = bool(video and cpu_render and not opts.get("gpu") and opts.get("nv") != "1" and (p.get("manifest") or {}).get("has3d") is False)
|
||||
r0 = None
|
||||
# a flat video whose keys said so goes out at once: no timed first run (FLAT_PART)
|
||||
quick = bool(flat and p.get("keys"))
|
||||
|
||||
+23
-12
@@ -144,8 +144,9 @@ const SMALL = 256 << 10
|
||||
|
||||
/** the farm's cache of media (farm.py POST /v1/blobs/have, PUT /v1/blobs/OID), over its own token */
|
||||
export interface FarmBlobs {
|
||||
/** which of these it holds; null when this farm has no cache (an older one): the media goes in the tar */
|
||||
have(objects: { oid: string; size: number }[]): Promise<Set<string> | null>
|
||||
/** which of these it holds, and whether it fetches an original of unknown size by its link; null when this farm has
|
||||
* no cache (an older one): the media goes in the tar */
|
||||
have(objects: { oid: string; size: number }[]): Promise<{ held: Set<string>; links: boolean } | null>
|
||||
put(file: string, oid: string, size: number): Promise<void>
|
||||
}
|
||||
|
||||
@@ -156,7 +157,8 @@ export function farmBlobs(url: string, token: string): FarmBlobs {
|
||||
const r = await fetch(`${url}/v1/blobs/have`, { method: "POST", headers: { ...auth, "content-type": "application/json" }, body: JSON.stringify({ objects }) })
|
||||
if (r.status === 404) return null
|
||||
if (!r.ok) throw new Error(`the farm's media cache answered ${r.status}: ${(await r.text()).slice(0, 200)}`)
|
||||
return new Set(((await r.json()) as { have: string[] }).have)
|
||||
const j = (await r.json()) as { have: string[]; links?: number }
|
||||
return { held: new Set(j.have), links: j.links === 1 }
|
||||
},
|
||||
async put(file, oid, size) {
|
||||
// streamed from the disk: a file is never held in memory (a project's interviews are gigabytes)
|
||||
@@ -199,7 +201,7 @@ function hashes(file: string) {
|
||||
* farm's cache and named in the job's manifest with no href, so a render's tar holds the code and not the footage
|
||||
* (StreetTalk's 1.9 GB of interviews went in every render's tar, even one frame's). null when the farm has no cache.
|
||||
* `skip`: the tar's excludes. Links are left to the tar, as before. */
|
||||
export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string) => boolean = () => false, said: (s: string) => void = () => {}, store = path.join(os.homedir(), ".cache", "raea-offload", "hashes.json")): Promise<{ media: Media[]; sent: number } | null> {
|
||||
export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string) => boolean = () => false, said: (s: string) => void = () => {}, store = path.join(os.homedir(), ".cache", "raea-offload", "hashes.json"), instead: Map<string, string> = new Map()): Promise<{ media: Media[]; sent: number; links: boolean } | null> {
|
||||
const found: { path: string; abs: string; id: string; size: number; mtime: number }[] = []
|
||||
const walk = (dir: string) => {
|
||||
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
||||
@@ -208,20 +210,26 @@ export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string
|
||||
if (skip(rel)) continue
|
||||
if (e.isDirectory()) walk(abs)
|
||||
else if (e.isFile()) {
|
||||
const st = statSync(abs)
|
||||
// `instead`: a light copy whose original is here goes as that file, under the light copy's path (originals.ts)
|
||||
const file = instead.get(rel) ?? abs
|
||||
const st = statSync(file)
|
||||
const ext = e.name.includes(".") ? e.name.split(".").pop()!.toLowerCase() : ""
|
||||
if (st.size >= LARGE || (st.size >= SMALL && MEDIA.has(ext))) found.push({ path: rel, abs, id: `${st.dev}:${st.ino}`, size: st.size, mtime: st.mtimeMs })
|
||||
if (st.size >= LARGE || (st.size >= SMALL && MEDIA.has(ext))) found.push({ path: rel, abs: file, id: `${st.dev}:${st.ino}`, size: st.size, mtime: st.mtimeMs })
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(root)
|
||||
if (!found.length) return { media: [], sent: 0 }
|
||||
if (!found.length) {
|
||||
const can = await farm.have([])
|
||||
return can ? { media: [], sent: 0, links: can.links } : null
|
||||
}
|
||||
const h = hashes(store)
|
||||
const media: (Media & { abs: string })[] = []
|
||||
for (const f of found) media.push({ path: f.path, oid: await h.of(f.abs, f.id, f.size, f.mtime), size: f.size, abs: f.abs })
|
||||
h.save()
|
||||
const have = await farm.have(media.map(({ oid, size }) => ({ oid, size })))
|
||||
if (!have) return null
|
||||
const can = await farm.have(media.map(({ oid, size }) => ({ oid, size })))
|
||||
if (!can) return null
|
||||
const have = can.held
|
||||
let sent = 0
|
||||
const todo = media.filter((m, i) => !have.has(m.oid) && media.findIndex((x) => x.oid === m.oid) === i)
|
||||
if (todo.length) said(`sending ${todo.length} media files (${(todo.reduce((n, m) => n + m.size, 0) / 1e6).toFixed(1)} MB) to the farm's cache, once`)
|
||||
@@ -234,7 +242,7 @@ export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string
|
||||
}
|
||||
}
|
||||
await Promise.all(Array.from({ length: Math.min(4, todo.length) }, one))
|
||||
return { media: media.map(({ abs: _, ...m }) => m), sent }
|
||||
return { media: media.map(({ abs: _, ...m }) => m), sent, links: can.links }
|
||||
}
|
||||
|
||||
/** the project's video and audio that no source file names, which a render doesn't need: neither sent to the farm nor
|
||||
@@ -270,7 +278,9 @@ export function unusedMedia(root: string, skip: (p: string) => boolean = () => f
|
||||
return text.includes(rel) || text.includes(name) || (stem.length >= 3 && text.includes(stem) && (!folder || text.includes(folder)))
|
||||
}
|
||||
const used = av.filter(named)
|
||||
return used.length ? av.filter((f) => !used.includes(f)) : []
|
||||
// footage/originals/ (the full-size takes, gigabytes) goes only when a source names it, even when none names anything
|
||||
// (12-05 review): an original by its file goes in its light copy's place (originals.ts), not as itself
|
||||
return used.length ? av.filter((f) => !used.includes(f)) : av.filter((f) => f.startsWith("footage/originals/"))
|
||||
}
|
||||
|
||||
/** tar's exclude-from lines for paths that go by hash: each matched as written (glob characters escaped) */
|
||||
@@ -285,7 +295,8 @@ export function localSources(manifest: { sounds?: { clips?: { src: string }[] }
|
||||
const byOid = new Map(media.map((m) => [m.oid, m.path]))
|
||||
let n = 0
|
||||
for (const c of manifest.sounds?.clips ?? []) {
|
||||
const oid = /(?:^|\/)(?:blobs\/)?([0-9a-f]{64})$/.exec(c.src)?.[1]
|
||||
// the farm's blob (blobs/OID) or the same under its own name (blobs/named/OID/NAME)
|
||||
const oid = /(?:^|\/)(?:blobs\/)?(?:named\/)?([0-9a-f]{64})(?:\/[^/]+)?$/.exec(c.src)?.[1]
|
||||
const p = oid ? byOid.get(oid) : undefined
|
||||
if (p) {
|
||||
c.src = path.join(root, p)
|
||||
|
||||
+61
-15
@@ -22,6 +22,7 @@ import path from "node:path"
|
||||
import { pathToFileURL } from "node:url"
|
||||
import { RaeaCloud } from "../src/index.ts"
|
||||
import { excluded, excludes as mediaExcludes, farmBlobs, farmInputs, inputs, lfsOf, localSources, outputs, unusedMedia } from "./media.ts"
|
||||
import { lightCopies, originalsRecord, recordOriginals, resolveOriginals, settle, withOriginals } from "./originals.ts"
|
||||
|
||||
const REAL = process.env.RAEA_REAL ?? "/opt/raea/bin/raea"
|
||||
// flags whose value is a path raea writes; the rest of a render's path arguments are read
|
||||
@@ -31,12 +32,24 @@ const COMPOSITION = /\.(tsx|ts|jsx|js|mjs|html)$/
|
||||
|
||||
const say = (s: string) => process.stderr.write(`raea cloud: ${s}\n`)
|
||||
|
||||
function local(args: string[], why?: string): never {
|
||||
function local(args: string[], why?: string, root?: string): never {
|
||||
if (why) say(`${why}, so this runs here, on the CPU`)
|
||||
// here every take is its light copy: the record says so, as the farm's would (CL20)
|
||||
const lit = lightCopies(root ?? process.cwd())
|
||||
if (lit.length) say(`NO ORIGINAL: a render here reads footage's light copies, so it's a draft that's never shown or published`)
|
||||
const r = spawnSync(REAL, args, { stdio: "inherit" })
|
||||
const oi = args.indexOf("-o")
|
||||
const mi = args.indexOf("--manifest")
|
||||
const out = oi >= 0 ? path.resolve(process.cwd(), args[oi + 1] ?? "") : ""
|
||||
if (lit.length && !r.status && out && existsSync(out)) keep(out, mi >= 0 ? path.resolve(process.cwd(), args[mi + 1] ?? "") : null, { read: [], light: [...lit].sort() })
|
||||
process.exit(r.status ?? 1)
|
||||
}
|
||||
|
||||
/** the render's record of what it read (originals.ts recordOriginals), said aloud when it couldn't be kept */
|
||||
function keep(out: string, manifest: string | null, rec: { read: string[]; light: string[] }) {
|
||||
for (const f of recordOriginals(out, manifest, rec).failed) say(`WARNING: couldn't add what this render read to ${f} (not a JSON object): raea cloud can't tell whether it read a light copy`)
|
||||
}
|
||||
|
||||
const inside = (root: string, p: string) => p === root || p.startsWith(root + path.sep)
|
||||
|
||||
/** The project a render's composition is in: its folder, or the nearest above it that holds a project's files. */
|
||||
@@ -92,7 +105,7 @@ async function main() {
|
||||
{
|
||||
const oi = args.indexOf("-o")
|
||||
const o = oi >= 0 ? (args[oi + 1] ?? "") : ""
|
||||
if (args[0] === "render" && /\.(mp4|mov|m4v|webm)$/i.test(o) && !args.includes("--manifest") && process.env.RAEA_CLOUD_CHECK !== "0")
|
||||
if (args[0] === "render" && /\.(mp4|mov|m4v|webm)$/i.test(o) && !args.includes("--manifest"))
|
||||
args.push("--manifest", `${o.slice(0, o.length - path.extname(o).length)}.render.json`)
|
||||
}
|
||||
const url = process.env.RAEA_CLOUD_GPU_URL
|
||||
@@ -105,7 +118,7 @@ async function main() {
|
||||
try {
|
||||
// kits/ (raea-game-kit) is a link into the box's shared cache, hundreds of MB, that the farm can't follow: a
|
||||
// composition uses copies of the kit files it needs in its own folder (11-21: the dangling link hung farm jobs)
|
||||
const excludes = (process.env.RAEA_CLOUD_GPU_EXCLUDE ?? "./.git ./out/* ./.raea-cloud-out ./.raea-cloud-out-* ./kits").split(/\s+/).filter(Boolean)
|
||||
const excludes = (process.env.RAEA_CLOUD_GPU_EXCLUDE ?? "./.git ./out/* ./.raea-cloud-out ./.raea-cloud-out-* ./kits ./.raea-cloud/proxies").split(/\s+/).filter(Boolean)
|
||||
// zstd with GNU tar (the image's); gzip with another tar (a Mac's), whose zstd needs a program of its own
|
||||
const gnu = spawnSync("tar", ["--version"], { encoding: "utf8" }).stdout?.includes("GNU")
|
||||
const sent = path.join(tmp, "in.tar")
|
||||
@@ -115,15 +128,29 @@ async function main() {
|
||||
const unused = new Set(unusedMedia(p.root, excluded(excludes)))
|
||||
if (unused.size) say(`${unused.size} video and audio files no source names stay here`)
|
||||
const skip = (rel: string) => excluded(excludes)(rel) || unused.has(rel)
|
||||
let byHash = typeof lfs === "string" ? [] : await inputs(p.root, lfs, skip)
|
||||
// each light copy the render reads goes as its full-size original (originals.ts): by its link, fetched by the farm
|
||||
// itself, else by its file here. The light copy's own bytes never go
|
||||
let orig = resolveOriginals(p.root, (rel) => !skip(rel))
|
||||
const linked = new Set(orig.byLink.map((m) => m.path))
|
||||
// what stays out of the farm's cache and LFS: what's skipped, and each light copy whose original goes by its link
|
||||
const unsent = (rel: string) => skip(rel) || linked.has(rel)
|
||||
let byHash = typeof lfs === "string" ? [] : await inputs(p.root, lfs, unsent)
|
||||
// not in raea's LFS: the media goes into the farm's own cache by hash, once, instead of in every render's tar
|
||||
// (RAEA_CLOUD_GPU_BLOBS=0 puts it back in the tar). A farm without the cache, or one that can't be reached here,
|
||||
// leaves it in the tar, and the health check below says why the farm can't be reached
|
||||
let viaFarm: { media: typeof byHash; sent: number } | null = null
|
||||
let viaFarm: { media: typeof byHash; sent: number; links: boolean } | null = null
|
||||
if (typeof lfs === "string" && process.env.RAEA_CLOUD_GPU_BLOBS !== "0") {
|
||||
viaFarm = await farmInputs(p.root, farmBlobs(url, token), skip, say).catch((e) => (say(`the farm's media cache: ${(e as Error).message}; the media goes in the tar`), null))
|
||||
viaFarm = await farmInputs(p.root, farmBlobs(url, token), unsent, say, undefined, orig.byFile).catch((e) => (say(`the farm's media cache: ${(e as Error).message}; the media goes in the tar`), null))
|
||||
if (viaFarm) byHash = viaFarm.media
|
||||
}
|
||||
// what reaches the farm decides what the render reads, decided once for every path: each original by its link in its
|
||||
// light copy's place; what can't go is the light copy, recorded
|
||||
// (LFS: the farm fetches by size from R2, so an original of unknown size or by its file can't go)
|
||||
orig = settle(orig, viaFarm ? { links: viaFarm.links } : null)
|
||||
byHash = withOriginals(byHash, orig)
|
||||
if (orig.byLink.length || orig.byFile.size) say(`${orig.byLink.length + orig.byFile.size} takes go as their full-size originals${orig.byLink.length ? ` (${orig.byLink.length} fetched by the farm from the library)` : ""}`)
|
||||
for (const w of orig.why) say(w)
|
||||
if (orig.light.length) say(`NO ORIGINAL for ${orig.light.join(", ")}: rendered from the light copy, so this render is a draft that's never shown or published`)
|
||||
const extra: string[] = []
|
||||
if (unused.size) {
|
||||
writeFileSync(path.join(tmp, "unused-excludes"), mediaExcludes([...unused].map((f) => ({ path: f, oid: "", size: 0 }))))
|
||||
@@ -144,16 +171,20 @@ async function main() {
|
||||
try {
|
||||
h = await cloud.health()
|
||||
} catch (e) {
|
||||
if (process.env.RAEA_CLOUD_GPU_FALLBACK === "cpu") local(args, `the GPU worker at ${url} didn't answer (${(e as Error).message})`)
|
||||
if (process.env.RAEA_CLOUD_GPU_FALLBACK === "cpu") local(args, `the GPU worker at ${url} didn't answer (${(e as Error).message})`, p.root)
|
||||
throw new Error(`the GPU worker at ${url} didn't answer: ${(e as Error).message} (RAEA_CLOUD_GPU_FALLBACK=cpu renders here instead)`)
|
||||
}
|
||||
say(`rendering on ${new URL(url).host}, ${h.device.renders === "gpu" ? `GPU ${h.device.name}` : `its CPU (${h.device.name})`}: ${p.root} (${(folder.length / 1e6).toFixed(1)} MB) sent`)
|
||||
if (viaFarm && byHash.length) say(`${byHash.length} media files (${(byHash.reduce((n, m) => n + m.size, 0) / 1e6).toFixed(1)} MB) go by hash from the farm's cache${viaFarm.sent ? `, ${(viaFarm.sent / 1e6).toFixed(1)} MB of it sent now` : ""}`)
|
||||
else if (byHash.length) say(`${byHash.length} media files (${(byHash.reduce((n, m) => n + m.size, 0) / 1e6).toFixed(1)} MB) go by hash: the farm fetches them from R2`)
|
||||
// what's fetched from the library by its link is counted apart: its size may be unknown
|
||||
const cached = byHash.filter((m) => !("href" in m && orig.byLink.some((l) => l.path === m.path)))
|
||||
const mb = (ms: { size: number }[]) => (ms.reduce((n, m) => n + m.size, 0) / 1e6).toFixed(1)
|
||||
if (viaFarm && cached.length) say(`${cached.length} media files (${mb(cached)} MB) go by hash from the farm's cache${viaFarm.sent ? `, ${(viaFarm.sent / 1e6).toFixed(1)} MB of it sent now` : ""}`)
|
||||
else if (cached.length) say(`${cached.length} media files (${mb(cached)} MB) go by hash: the farm fetches them from R2`)
|
||||
else if (typeof lfs === "string" && existsSync(path.join(p.root, ".lfsconfig"))) say(`media goes in the tar: ${lfs}`)
|
||||
// a render farm's choices (deploy/modal/farm.py): RAEA_CLOUD_GPUS, RAEA_CLOUD_GPU_KIND, RAEA_CLOUD_MAX_USD
|
||||
// a render farm's choices (deploy/modal/farm.py): RAEA_CLOUD_GPUS, RAEA_CLOUD_GPU_KIND (the card: it went as "gpu",
|
||||
// which the client never read, so a named card never reached the farm), RAEA_CLOUD_MAX_USD, RAEA_CLOUD_NV (1 or 0)
|
||||
const n = (v?: string) => (v ? Number(v) : undefined)
|
||||
const farm = { gpus: n(process.env.RAEA_CLOUD_GPUS), cpus: n(process.env.RAEA_CLOUD_CPUS), kept: process.env.RAEA_CLOUD_KEPT === "0" ? false : undefined, gpu: process.env.RAEA_CLOUD_GPU_KIND, maxUsd: n(process.env.RAEA_CLOUD_MAX_USD), media: typeof lfs !== "string" }
|
||||
const farm = { gpus: n(process.env.RAEA_CLOUD_GPUS), cpus: n(process.env.RAEA_CLOUD_CPUS), kept: process.env.RAEA_CLOUD_KEPT === "0" ? false : undefined, card: process.env.RAEA_CLOUD_GPU_KIND || undefined, maxUsd: n(process.env.RAEA_CLOUD_MAX_USD), nv: process.env.RAEA_CLOUD_NV === "1" ? true : process.env.RAEA_CLOUD_NV === "0" ? false : undefined, media: typeof lfs !== "string" }
|
||||
let finish: (() => Promise<number>) | undefined
|
||||
const media = typeof lfs === "string" ? undefined : async (made: Parameters<typeof outputs>[2]) => {
|
||||
const o = await outputs(p.root, lfs, made)
|
||||
@@ -181,6 +212,13 @@ async function main() {
|
||||
}
|
||||
rmSync(path.join(p.root, ".raea-cloud-out"), { recursive: true, force: true })
|
||||
for (const m of p.moves) rmSync(path.join(p.root, m.from), { force: true })
|
||||
// what it read, kept with it whether it's checked or not, video or still (CL20)
|
||||
{
|
||||
const oi = args.indexOf("-o")
|
||||
const mi = args.indexOf("--manifest")
|
||||
const out = oi >= 0 ? path.resolve(process.cwd(), args[oi + 1] ?? "") : ""
|
||||
if (out && existsSync(out)) keep(out, mi >= 0 ? path.resolve(process.cwd(), args[mi + 1] ?? "") : null, originalsRecord(orig))
|
||||
}
|
||||
if (finish) {
|
||||
const bytes = await finish()
|
||||
say(`its media (${(bytes / 1e6).toFixed(1)} MB) went from the farm to R2; here it's pointers (git lfs pull PATH brings one here)`)
|
||||
@@ -201,20 +239,25 @@ async function main() {
|
||||
const man = mi >= 0 ? path.resolve(process.cwd(), args[mi + 1] ?? "") : ""
|
||||
const beside = `${made.slice(0, made.length - path.extname(made).length)}.render.json`
|
||||
if (man && man !== beside && existsSync(man)) writeFileSync(beside, readFileSync(man))
|
||||
// its takes named as they are here, not as the farm's cache holds them, so every edit point is checked
|
||||
if (byHash.length && existsSync(beside)) {
|
||||
// its takes named as they are here, not as the farm's cache holds them, so every edit point is checked; and which
|
||||
// light copies it read as their originals and which as themselves (raea cloud shows none of the latter)
|
||||
if (existsSync(beside)) {
|
||||
try {
|
||||
const m = JSON.parse(readFileSync(beside, "utf8"))
|
||||
if (localSources(m, byHash, p.root)) writeFileSync(beside, JSON.stringify(m))
|
||||
if (byHash.length && localSources(m, byHash, p.root)) writeFileSync(beside, JSON.stringify(m))
|
||||
} catch (e) {
|
||||
say(`${path.basename(beside)}: ${(e as Error).message}`)
|
||||
}
|
||||
}
|
||||
say(`raea goal check ${path.basename(made)} --at render`)
|
||||
const r = spawnSync(REAL, ["make", "check", made, "--at", "render"], { stdio: "inherit", env: { ...process.env, RAEA_REAL: REAL } })
|
||||
const r = spawnSync(REAL, CHECK_ARGS(made), { stdio: "inherit", env: { ...process.env, RAEA_REAL: REAL } })
|
||||
if (r.status === 1) {
|
||||
say(`${path.basename(made)} fails its checks: fix every ERROR above (each says what to change), then render again before any review`)
|
||||
process.exitCode = 1
|
||||
} else if (r.status !== 0) {
|
||||
// a refused or crashed check is loud: called by an old name, it was refused with exit 2 and every cloud render went unchecked
|
||||
say(`raea goal check couldn't check ${path.basename(made)} (exit ${r.status ?? r.signal}): the render isn't done until it can`)
|
||||
process.exitCode = r.status || 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -222,6 +265,9 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
/** raea's one check on a finished render, as the box runs it */
|
||||
export const CHECK_ARGS = (made: string) => ["goal", "check", made, "--at", "render"]
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
||||
main().catch((e) => {
|
||||
say((e as Error).message)
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
// Light copies on the box, originals on the farm (docs/cloud.feature CL17-CL20). raea cloud brings a run's footage onto
|
||||
// its box as 540p light copies (footage/NAME.mp4, listed in .raea-cloud/light.txt): every look the agent takes reads
|
||||
// them, and nothing on the box ever puts anything else in their place. A render on the farm reads each one's full-size
|
||||
// original instead, resolved here as the render is sent:
|
||||
//
|
||||
// by its link .raea-cloud/originals.json, written by raea cloud at the run's start and again before each render:
|
||||
// {"footage/NAME.mp4": {"sha256", "bytes", "url", "expires"}}. The farm fetches the original from the
|
||||
// library itself and keeps it by its hash, so the box never downloads it or sends it on (12-05, Dutch
|
||||
// run 24: each run's box fetched 2.4 GB of originals and hashed and sent them to the farm again)
|
||||
// by its file footage/originals/NAME.EXT, fetched onto the box for a take the library has no hash for: sent in the
|
||||
// light copy's place, by its own hash
|
||||
//
|
||||
// A light copy with neither is rendered as itself and named in the render's manifest ("originals": {"light": [...]}),
|
||||
// so raea cloud never shows or publishes what was made from it.
|
||||
|
||||
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"
|
||||
import path from "node:path"
|
||||
import type { Media } from "../src/index.ts"
|
||||
|
||||
export const LIGHT_LIST = ".raea-cloud/light.txt"
|
||||
export const ORIGINALS_MAP = ".raea-cloud/originals.json"
|
||||
export const ORIGINALS_DIR = "footage/originals"
|
||||
/** a link that ends sooner than this isn't handed to the farm: it would be gone before the farm asks for it */
|
||||
export const LINK_MARGIN_MS = 5 * 60_000
|
||||
|
||||
export interface Original {
|
||||
sha256?: string
|
||||
bytes?: number
|
||||
url?: string
|
||||
/** when the link stops working (ms since 1970); none, it's taken as working */
|
||||
expires?: number
|
||||
}
|
||||
|
||||
/** where each light copy a render reads comes from */
|
||||
export interface Resolved {
|
||||
/** fetched by the farm from its link: the light copy's path, the original's hash, size and link */
|
||||
byLink: (Media & { href: string })[]
|
||||
/** sent from the box: the light copy's path, the original's file here */
|
||||
byFile: Map<string, string>
|
||||
/** rendered as themselves: no usable link and no file */
|
||||
light: string[]
|
||||
/** why a light copy's link wasn't used, a line each */
|
||||
why: string[]
|
||||
}
|
||||
|
||||
const read = (f: string) => {
|
||||
try {
|
||||
return readFileSync(f, "utf8")
|
||||
} catch {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
const stem = (n: string) => n.replace(/\.[^./]*$/, "")
|
||||
const HASH = /^[0-9a-f]{64}$/
|
||||
|
||||
/** the light copies here, as paths from the project's top (footage/NAME.mp4) */
|
||||
export function lightCopies(root: string): string[] {
|
||||
const names = read(path.join(root, LIGHT_LIST)).split("\n").map((s) => s.trim()).filter(Boolean)
|
||||
return [...new Set(names.map((n) => (n.startsWith("footage/") ? n : `footage/${n}`)))].filter((p) => !p.includes("..") && existsSync(path.join(root, p)))
|
||||
}
|
||||
|
||||
/** .raea-cloud/originals.json, each entry kept only when it's a light copy's path and an object */
|
||||
export function originalsMap(root: string): Record<string, Original> {
|
||||
let j: unknown
|
||||
try {
|
||||
j = JSON.parse(read(path.join(root, ORIGINALS_MAP)) || "{}")
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
const out: Record<string, Original> = {}
|
||||
if (!j || typeof j !== "object" || Array.isArray(j)) return out
|
||||
for (const [k, v] of Object.entries(j as Record<string, unknown>)) if (v && typeof v === "object" && !Array.isArray(v)) out[k.startsWith("footage/") ? k : `footage/${k}`] = v as Original
|
||||
return out
|
||||
}
|
||||
|
||||
/** a light copy's original fetched onto the box: footage/originals/ holds it under the light copy's name, any extension */
|
||||
export function originalFile(root: string, light: string): string | null {
|
||||
// prep puts every light copy straight in footage/: one in a folder of its own has no original here by its name
|
||||
if (path.posix.dirname(light) !== "footage") return null
|
||||
const dir = path.join(root, ORIGINALS_DIR)
|
||||
const want = stem(path.basename(light)).toLowerCase()
|
||||
let names: string[] = []
|
||||
try {
|
||||
names = readdirSync(dir)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
for (const n of names.sort()) {
|
||||
if (n === "STATUS" || n.startsWith(".") || /\.(json|txt|part|lock|tsv)$/i.test(n) || stem(n).toLowerCase() !== want) continue
|
||||
const abs = path.join(dir, n)
|
||||
try {
|
||||
const st = statSync(abs)
|
||||
if (st.isFile() && st.size > 0) return abs
|
||||
} catch {}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Each light copy a render reads (`uses`: the render's media walk would send it), resolved to its original. */
|
||||
export function resolveOriginals(root: string, uses: (p: string) => boolean, now = Date.now()): Resolved {
|
||||
const map = originalsMap(root)
|
||||
const r: Resolved = { byLink: [], byFile: new Map(), light: [], why: [] }
|
||||
for (const l of lightCopies(root)) {
|
||||
if (!uses(l)) continue
|
||||
const o = map[l]
|
||||
if (o) {
|
||||
const bad =
|
||||
typeof o.sha256 !== "string" || !HASH.test(o.sha256) ? "no hash"
|
||||
: typeof o.url !== "string" || !/^https:\/\//.test(o.url) ? "no link"
|
||||
: typeof o.expires === "number" && o.expires < now + LINK_MARGIN_MS ? "its link has ended"
|
||||
: null
|
||||
if (!bad) {
|
||||
r.byLink.push({ path: l, oid: o.sha256!, size: typeof o.bytes === "number" && o.bytes > 0 ? Math.round(o.bytes) : 0, href: o.url! })
|
||||
continue
|
||||
}
|
||||
r.why.push(`${l}: ${bad}`)
|
||||
}
|
||||
const f = originalFile(root, l)
|
||||
if (f) r.byFile.set(l, f)
|
||||
else r.light.push(l)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
/** what can reach the farm: an original by its file goes only into the farm's cache (by LFS or in the tar it would go as
|
||||
* the light copy), and one of unknown size only to a farm that says it fetches those (`links` from /v1/blobs/have: an
|
||||
* older farm checks every size). What can't is rendered as its light copy, and said */
|
||||
export function settle(r: Resolved, farm: { links: boolean } | null): Resolved {
|
||||
if (farm?.links) return r
|
||||
const out: Resolved = { byLink: [], byFile: farm ? new Map(r.byFile) : new Map(), light: [...r.light], why: [...r.why] }
|
||||
for (const m of r.byLink) {
|
||||
if (m.size > 0) out.byLink.push(m)
|
||||
else (out.light.push(m.path), out.why.push(`${m.path}: this farm doesn't fetch an original of unknown size`))
|
||||
}
|
||||
if (!farm) for (const l of r.byFile.keys()) (out.light.push(l), out.why.push(`${l}: this farm has no media cache, so its original's file can't go to it`))
|
||||
return out
|
||||
}
|
||||
|
||||
/** the paths a render's manifest names as its sources (any "src" in it, as footage/NAME), or null when it names none */
|
||||
export function manifestSources(m: unknown): Set<string> | null {
|
||||
const out = new Set<string>()
|
||||
const walk = (v: unknown) => {
|
||||
if (Array.isArray(v)) for (const x of v) walk(x)
|
||||
else if (v && typeof v === "object")
|
||||
for (const [k, x] of Object.entries(v)) {
|
||||
if (k === "src" && typeof x === "string") {
|
||||
const f = /(?:^|\/)footage\/([^/?#]+)$/.exec(x.replace(/\\/g, "/"))
|
||||
if (f) out.add(`footage/${f[1]}`)
|
||||
} else walk(x)
|
||||
}
|
||||
}
|
||||
walk(m)
|
||||
return out.size ? out : null
|
||||
}
|
||||
|
||||
/** the render's media by hash: what went (by LFS or into the farm's cache) with each original by its link in its light
|
||||
* copy's place */
|
||||
export function withOriginals<M extends { path: string }>(media: M[], r: Resolved): (M | (Media & { href: string }))[] {
|
||||
const linked = new Set(r.byLink.map((m) => m.path))
|
||||
return [...media.filter((m) => !linked.has(m.path)), ...r.byLink]
|
||||
}
|
||||
|
||||
/** a render's record of what it read, in its manifest (its --manifest, else OUT.render.json beside it, made when there's
|
||||
* none: a still), so raea cloud never shows or publishes what was made from a light copy */
|
||||
export function recordOriginals(out: string, manifest: string | null, rec: { read: string[]; light: string[] }): { files: string[]; failed: string[] } {
|
||||
const beside = `${out.slice(0, out.length - path.extname(out).length)}.render.json`
|
||||
const files: string[] = []
|
||||
const failed: string[] = []
|
||||
// into the --manifest and beside the output both: whichever raea cloud reads, it holds the record
|
||||
const targets = [...new Set([...(manifest && existsSync(manifest) ? [manifest] : []), beside])]
|
||||
let named: Set<string> | null = null
|
||||
for (const file of targets) {
|
||||
let m: Record<string, unknown> = {}
|
||||
try {
|
||||
if (existsSync(file)) m = JSON.parse(readFileSync(file, "utf8"))
|
||||
} catch {
|
||||
failed.push(file)
|
||||
continue
|
||||
}
|
||||
if (!m || typeof m !== "object" || Array.isArray(m)) {
|
||||
failed.push(file)
|
||||
continue
|
||||
}
|
||||
named ??= manifestSources(m)
|
||||
// only what this render read, when its manifest says what it read
|
||||
const r = named ? { read: rec.read.filter((f) => named!.has(f)), light: rec.light.filter((f) => named!.has(f)) } : rec
|
||||
if (!r.read.length && !r.light.length) {
|
||||
// a clean render: an earlier render's record goes, and no file is made for nothing
|
||||
if (!("originals" in m)) continue
|
||||
delete m.originals
|
||||
} else m.originals = r
|
||||
writeFileSync(file, JSON.stringify(m))
|
||||
files.push(file)
|
||||
}
|
||||
return { files, failed }
|
||||
}
|
||||
|
||||
/** what a render read, for its manifest: the light copies sent as their originals, and those sent as themselves */
|
||||
export function originalsRecord(r: Resolved): { read: string[]; light: string[] } {
|
||||
return { read: [...r.byLink.map((m) => m.path), ...r.byFile.keys()].sort(), light: [...r.light].sort() }
|
||||
}
|
||||
@@ -39,6 +39,9 @@ export interface Farm {
|
||||
kept?: boolean
|
||||
card?: string
|
||||
maxUsd?: number
|
||||
/** NVIDIA's encoder and decoder (RAEA_NV) for every run: true on, false off; unset, only a piece with 3D in it (CR34).
|
||||
* On forces the job onto GPUs */
|
||||
nv?: boolean
|
||||
/** the job's media outputs stay on the farm for `media` to send to R2 (docs/cloud-render.feature CR23) */
|
||||
media?: boolean
|
||||
}
|
||||
@@ -169,6 +172,7 @@ export class RaeaCloud {
|
||||
if (farm.card) q.set("gpu", farm.card)
|
||||
if (farm.maxUsd !== undefined) q.set("max_usd", String(farm.maxUsd))
|
||||
if (farm.media) q.set("media", "1")
|
||||
if (farm.nv !== undefined) q.set("nv", farm.nv ? "1" : "0")
|
||||
const r = await this.fetch(`/v1/jobs?${q}`, { method: "POST", body: new Blob([folder as Uint8Array<ArrayBuffer>]), headers: { "content-type": "application/octet-stream" }, signal })
|
||||
return ((await r.json()) as { id: string }).id
|
||||
}
|
||||
|
||||
@@ -79,13 +79,17 @@ ws = job([{"path": "media/int1.MOV", "oid": soid, "size": len(sent)}])
|
||||
gets = hits["GET"]
|
||||
ss = fm.fetch(ws, cache, log=lambda _: None)
|
||||
assert open(os.path.join(ws, "media/int1.MOV"), "rb").read() == sent and os.path.islink(os.path.join(ws, "media/int1.MOV"))
|
||||
# followed to the end, the link is a file with the take's own name: a bundler resolves it, and a composition that knows
|
||||
# its takes by name (Framed's faces) still finds this one
|
||||
real = os.path.realpath(os.path.join(ws, "media/int1.MOV"))
|
||||
assert os.path.basename(real) == "int1.MOV" and os.path.samefile(real, os.path.join(cache, soid)), real
|
||||
assert ss == {"objects": 1, "fetched": 0, "cached": len(sent)} and hits["GET"] == gets, ss
|
||||
try:
|
||||
fm.fetch(job([{"path": "media/gone.MOV", "oid": "ab" * 32, "size": 10}]), cache, log=lambda _: None)
|
||||
raise AssertionError("footage never sent was used")
|
||||
except ValueError as e:
|
||||
assert "never sent" in str(e)
|
||||
ok("footage the box sent the farm itself comes from the cache as a link, and footage it never sent is refused")
|
||||
ok("footage the box sent the farm itself comes from the cache as a link that ends at its own name, and footage it never sent is refused")
|
||||
|
||||
w1 = job([obj])
|
||||
s1 = fm.fetch(w1, cache, log=lambda _: None)
|
||||
@@ -120,6 +124,27 @@ except ValueError:
|
||||
pass
|
||||
ok("a file that isn't its hash, and a path out of the job, are refused")
|
||||
|
||||
# a library original whose size raea cloud doesn't know (size 0, its link given): fetched and kept by its hash alone,
|
||||
# then held for the next job; a size-0 entry with no link is never held
|
||||
c0 = tempfile.mkdtemp()
|
||||
z = dict(obj, size=0)
|
||||
w3 = job([z])
|
||||
s3 = fm.fetch(w3, c0, log=lambda _: None)
|
||||
assert open(os.path.join(w3, "footage/take.mov"), "rb").read() == take and s3["fetched"] == len(take), s3
|
||||
s4 = fm.fetch(job([z]), c0, log=lambda _: None)
|
||||
assert s4["fetched"] == 0 and s4["cached"] == len(take), s4
|
||||
try:
|
||||
fm.fetch(job([dict(z, oid="0" * 64)]), tempfile.mkdtemp(), log=lambda _: None)
|
||||
raise SystemExit("FAIL a size-0 original with the wrong hash was taken")
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
fm.fetch(job([{"path": "footage/take.mov", "oid": oid, "size": 0}]), c0, log=lambda _: None)
|
||||
raise SystemExit("FAIL a size-0 entry with no link was held")
|
||||
except ValueError as e:
|
||||
assert "never sent" in str(e)
|
||||
ok("an original of unknown size is fetched and held by its hash, a wrong one refused, and none held without its link")
|
||||
|
||||
out = tempfile.mkdtemp()
|
||||
os.makedirs(os.path.join(out, "out"))
|
||||
render = os.urandom(200_000)
|
||||
|
||||
@@ -263,6 +263,14 @@ g = Flat(root, name="T4")
|
||||
assert fp.raea_render(["render", "a.tsx", "-o", "out/a.mp4"], {"id": "jn", "gpus": 2, "cpus": 0}, os.path.join(root, "jobs", "jn", "work"), log, g, {}, run) == 0, lines
|
||||
assert g.nv and not any(g.nv), g.nv
|
||||
ok("a piece with 3D draws on GPUs with NVENC and NVDEC asked for; a 2D piece kept on GPUs doesn't ask")
|
||||
# the job says so (opts nv): "1" puts a 2D piece on GPUs with them, "0" keeps a 3D piece's GPU without them
|
||||
g, c = Flat(root, name="T4"), Flat(root)
|
||||
assert fp.raea_render(["render", "a.tsx", "-o", "out/a.mp4"], {"id": "jn", "gpus": 2, "cpus": 8, "nv": "1"}, os.path.join(root, "jobs", "jn", "work"), log, g, {}, run, cpu_render=c) == 0, lines
|
||||
assert not c.calls and g.nv and all(g.nv), (c.calls, g.nv)
|
||||
g, c = Flat(root, name="T4", has3d=True), Flat(root)
|
||||
assert fp.raea_render(["render", "a.tsx", "-o", "out/a.mp4"], {"id": "jn", "gpus": 2, "cpus": 8, "nv": "0"}, os.path.join(root, "jobs", "jn", "work"), log, g, {}, run, cpu_render=c) == 0, lines
|
||||
assert not c.calls and g.nv and not any(g.nv), (c.calls, g.nv)
|
||||
ok("a job's nv=1 draws a 2D piece on GPUs with NVENC and NVDEC; nv=0 keeps a 3D piece's GPU without them")
|
||||
|
||||
# the join keeps every frame of runs that have B-frames, with the piece's sound (11-30: -shortest ended the joined
|
||||
# video 2 frames early, 892 of an 894-frame ad)
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
// Light copies on the box, originals on the farm (server/originals.ts, docs/cloud.feature CL17-CL20): node
|
||||
// test/originals.ts from sdk/cloud.
|
||||
// Checked: a light copy the render reads goes as its original by its link (the light copy's own bytes never go); one
|
||||
// the render doesn't read goes nowhere; a link that has ended, or an entry with no hash, falls back to the original's
|
||||
// file under footage/originals/; with neither, the light copy is rendered as itself and named for the manifest; the
|
||||
// original's file is sent by its own hash under the light copy's path; footage/originals/ and the kept light copies
|
||||
// never go in the tar.
|
||||
|
||||
import { createHash } from "node:crypto"
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs"
|
||||
import { createServer } from "node:http"
|
||||
import type { AddressInfo } from "node:net"
|
||||
import { tmpdir } from "node:os"
|
||||
import path from "node:path"
|
||||
import { excluded, farmBlobs, farmInputs } from "../server/media.ts"
|
||||
import { lightCopies, originalFile, originalsRecord, recordOriginals, resolveOriginals, settle, withOriginals } from "../server/originals.ts"
|
||||
|
||||
const ok = (m: string) => console.log(`ok ${m}`)
|
||||
const assert = (c: unknown, m: string) => {
|
||||
if (!c) throw new Error(`not ok: ${m}`)
|
||||
}
|
||||
const sha = (b: Buffer | string) => createHash("sha256").update(b).digest("hex")
|
||||
|
||||
const root = mkdtempSync(path.join(tmpdir(), "originals-"))
|
||||
const put = (rel: string, body: Buffer | string) => {
|
||||
mkdirSync(path.dirname(path.join(root, rel)), { recursive: true })
|
||||
writeFileSync(path.join(root, rel), body)
|
||||
}
|
||||
// four light copies; a's and b's originals have links, c's link has ended and its original is here, d has nothing
|
||||
const light = (n: string) => Buffer.alloc(300_000, n)
|
||||
for (const n of ["a", "b", "c", "d"]) put(`footage/${n}.mp4`, light(n))
|
||||
put("footage/e.mp4", light("e")) // not a light copy: the agent's own file
|
||||
put(".raea-cloud/light.txt", "a.mp4\nb.mp4\nfootage/c.mp4\nd.mp4\nmissing.mp4\n")
|
||||
const A = "a".repeat(64)
|
||||
const now = 1_000_000_000
|
||||
put(
|
||||
".raea-cloud/originals.json",
|
||||
JSON.stringify({
|
||||
"footage/a.mp4": { sha256: A, bytes: 693_000_000, url: "https://r2.example/a?sig=1", expires: now + 86_400_000 },
|
||||
"b.mp4": { sha256: "b".repeat(64), url: "https://drive.example/b" },
|
||||
"footage/c.mp4": { sha256: "c".repeat(64), bytes: 9, url: "https://r2.example/c", expires: now + 60_000 },
|
||||
"footage/d.mp4": { url: "https://r2.example/d" },
|
||||
}),
|
||||
)
|
||||
const cOrig = Buffer.alloc(5_000_000, "C")
|
||||
put("footage/originals/c.MOV", cOrig)
|
||||
put("footage/originals/STATUS", "done")
|
||||
put("footage/originals/d.mp4.part", "half")
|
||||
|
||||
assert(lightCopies(root).join() === "footage/a.mp4,footage/b.mp4,footage/c.mp4,footage/d.mp4", "light.txt read as paths, a name with no file left out")
|
||||
assert(originalFile(root, "footage/c.mp4")?.endsWith("footage/originals/c.MOV"), "an original's file found by its name, any extension")
|
||||
assert(originalFile(root, "footage/d.mp4") === null, "a part-fetched original isn't one")
|
||||
ok("light copies and originals' files found")
|
||||
|
||||
const reads = new Set(["footage/a.mp4", "footage/b.mp4", "footage/c.mp4", "footage/d.mp4"])
|
||||
const r = resolveOriginals(root, (p) => reads.has(p), now)
|
||||
assert(r.byLink.length === 2, `two by their links (${r.byLink.map((m) => m.path)})`)
|
||||
const a = r.byLink.find((m) => m.path === "footage/a.mp4")!
|
||||
assert(a.oid === A && a.size === 693_000_000 && a.href === "https://r2.example/a?sig=1", "a's original: its hash, size and link, under the light copy's path")
|
||||
const b = r.byLink.find((m) => m.path === "footage/b.mp4")!
|
||||
assert(b.size === 0 && !("expires" in b), "a size raea cloud doesn't know goes as 0; a link with no end is used")
|
||||
assert(r.byFile.get("footage/c.mp4")?.endsWith("footage/originals/c.MOV"), "an ended link falls back to the original's file")
|
||||
assert(r.light.join() === "footage/d.mp4", "no hash and no file: the light copy as itself")
|
||||
assert(r.why.some((w) => w.startsWith("footage/c.mp4: its link has ended")) && r.why.some((w) => w.startsWith("footage/d.mp4: no hash")), `why each link wasn't used (${r.why})`)
|
||||
ok("each light copy resolved to its original's link, its file, or itself")
|
||||
|
||||
const some = resolveOriginals(root, (p) => p === "footage/a.mp4", now)
|
||||
assert(some.byLink.length === 1 && !some.byFile.size && !some.light.length, "a light copy the render doesn't read goes nowhere, its original included")
|
||||
ok("only what the render reads")
|
||||
|
||||
const rec = originalsRecord(r)
|
||||
assert(rec.read.join() === "footage/a.mp4,footage/b.mp4,footage/c.mp4" && rec.light.join() === "footage/d.mp4", "the manifest's record")
|
||||
ok("the record: read as originals, and as themselves")
|
||||
|
||||
writeFileSync(path.join(root, ".raea-cloud/originals.json"), "{not json")
|
||||
assert(resolveOriginals(root, () => true, now).byLink.length === 0, "a broken map is no map")
|
||||
writeFileSync(path.join(root, ".raea-cloud/originals.json"), JSON.stringify([1, 2]))
|
||||
assert(resolveOriginals(root, () => true, now).byLink.length === 0, "an array is no map")
|
||||
ok("a broken map renders from files or light copies, never crashes")
|
||||
|
||||
// the original's file goes to the farm by its own hash, under the light copy's path; the tar's excludes keep
|
||||
// footage/originals/ and the kept light copies out
|
||||
put(".raea-cloud/proxies/x.mp4", light("x"))
|
||||
const held = new Map<string, number>()
|
||||
const farm = createServer((req, res) => {
|
||||
const u = new URL(req.url!, "http://x")
|
||||
if (req.method === "POST" && u.pathname === "/v1/blobs/have") {
|
||||
let s = ""
|
||||
req.on("data", (c) => (s += c)).on("end", () => {
|
||||
const objects = (JSON.parse(s).objects ?? []) as { oid: string }[]
|
||||
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ have: objects.filter((o) => held.has(o.oid)).map((o) => o.oid), links: 1 }))
|
||||
})
|
||||
return
|
||||
}
|
||||
const m = /^\/v1\/blobs\/([0-9a-f]{64})$/.exec(u.pathname)
|
||||
if (req.method === "PUT" && m) {
|
||||
const h = createHash("sha256")
|
||||
let n = 0
|
||||
req.on("data", (c: Buffer) => (h.update(c), (n += c.length))).on("end", () => {
|
||||
if (h.digest("hex") !== m[1]) return void res.writeHead(400).end("wrong hash")
|
||||
held.set(m[1], n)
|
||||
res.writeHead(200).end()
|
||||
})
|
||||
return
|
||||
}
|
||||
res.writeHead(404).end()
|
||||
})
|
||||
await new Promise<void>((ok) => farm.listen(0, "127.0.0.1", ok))
|
||||
const url = `http://127.0.0.1:${(farm.address() as AddressInfo).port}`
|
||||
const tar = excluded(["./.git", "./out/*", "./.raea-cloud/proxies", "./footage/originals"])
|
||||
const linked = new Set(r.byLink.map((m) => m.path))
|
||||
const store = path.join(root, ".hashes.json")
|
||||
const got = await farmInputs(root, farmBlobs(url, "t"), (p) => tar(p) || linked.has(p), () => {}, store, r.byFile)
|
||||
farm.close()
|
||||
assert(got, "the farm has a cache")
|
||||
const paths = got!.media.map((m) => m.path).sort()
|
||||
assert(!paths.includes("footage/a.mp4") && !paths.includes("footage/b.mp4"), `light copies with links aren't sent (${paths})`)
|
||||
assert(!paths.some((p) => p.startsWith("footage/originals/") || p.startsWith(".raea-cloud/proxies/")), `footage/originals/ and the kept light copies stay out (${paths})`)
|
||||
const c = got!.media.find((m) => m.path === "footage/c.mp4")!
|
||||
assert(c.oid === sha(cOrig) && c.size === cOrig.length && held.get(c.oid) === cOrig.length, "c goes as its original's bytes, by their hash, under its own path")
|
||||
const d = got!.media.find((m) => m.path === "footage/d.mp4")!
|
||||
assert(d.oid === sha(readFileSync(path.join(root, "footage/d.mp4"))), "d, with no original, goes as itself")
|
||||
ok("an original's file sent in its light copy's place; footage/originals/ and kept light copies never sent")
|
||||
// the one list the farm gets: what went, with each original by its link in its light copy's place (12-05 review: the
|
||||
// farm-cache path kept only what went, and the links were dropped while the manifest said they were read)
|
||||
const went = [{ path: "footage/c.mp4", oid: "c".repeat(64), size: 5 }, { path: "media/logo.png", oid: "d".repeat(64), size: 9 }, { path: "footage/a.mp4", oid: "e".repeat(64), size: 7 }]
|
||||
const all = withOriginals(went, r)
|
||||
assert(all.length === 4 && all.filter((m) => m.path === "footage/a.mp4").length === 1, `each path once (${all.map((m) => m.path)})`)
|
||||
assert((all.find((m) => m.path === "footage/a.mp4") as { href?: string }).href === "https://r2.example/a?sig=1", "the light copy's path carries its original's link")
|
||||
assert(all.some((m) => m.path === "footage/b.mp4") && all.some((m) => m.path === "media/logo.png"), "the links and the rest, together")
|
||||
ok("the farm's list holds every original by its link, and what went")
|
||||
|
||||
// what a farm can take: one that fetches by link takes them all; an older cache farm, no unknown size; no cache, no file
|
||||
assert(settle(r, { links: true }) === r, "a farm that fetches by link takes them all")
|
||||
const older = settle(r, { links: false })
|
||||
assert(older.byLink.map((m) => m.path).join() === "footage/a.mp4" && older.byFile.size === 1, `an older cache farm: known sizes and files (${older.byLink.map((m) => m.path)})`)
|
||||
assert(older.light.join() === "footage/d.mp4,footage/b.mp4", `the unknown size light (${older.light})`)
|
||||
const old = settle(r, null)
|
||||
assert(old.byLink.map((m) => m.path).join() === "footage/a.mp4", `only a known size by link (${old.byLink.map((m) => m.path)})`)
|
||||
assert(old.byFile.size === 0 && old.light.join() === "footage/d.mp4,footage/b.mp4,footage/c.mp4", `the rest light (${old.light})`)
|
||||
assert(old.why.filter((w) => w.includes("no media cache")).length === 1 && old.why.some((w) => w.includes("unknown size")), "and said")
|
||||
ok("a farm gets only what it says it can take; the rest is recorded light")
|
||||
|
||||
// the record: into the manifest and beside the output, only what the render read, cleared when clean
|
||||
const rec2 = originalsRecord(old)
|
||||
const man = path.join(root, "out/m.json")
|
||||
put("out/cut.mp4", "v")
|
||||
put("out/m.json", JSON.stringify({ frames: [1], sounds: { clips: [{ src: "/farm/cache/named/x/footage/b.mp4" }, { src: "footage/a.mp4" }] } }))
|
||||
const rc = recordOriginals(path.join(root, "out/cut.mp4"), man, rec2)
|
||||
assert(rc.failed.length === 0 && rc.files.length === 2, `into both (${rc.files})`)
|
||||
const mj = JSON.parse(readFileSync(man, "utf8"))
|
||||
assert(mj.frames[0] === 1 && mj.originals.light.join() === "footage/b.mp4" && mj.originals.read.join() === "footage/a.mp4", `only what it read (${JSON.stringify(mj.originals)})`)
|
||||
assert(JSON.parse(readFileSync(path.join(root, "out/cut.render.json"), "utf8")).originals.light.join() === "footage/b.mp4", "beside it too")
|
||||
put("out/still.png", "p")
|
||||
recordOriginals(path.join(root, "out/still.png"), null, rec2)
|
||||
const side = path.join(root, "out/still.render.json")
|
||||
assert(JSON.parse(readFileSync(side, "utf8")).originals.read.join() === "footage/a.mp4", "beside a still, which names no sources: all of it")
|
||||
recordOriginals(path.join(root, "out/still.png"), null, { read: [], light: [] })
|
||||
assert(!("originals" in JSON.parse(readFileSync(side, "utf8"))), "a clean render again clears the old record")
|
||||
assert(recordOriginals(path.join(root, "out/x.png"), null, { read: [], light: [] }).files.length === 0 && !existsSync(path.join(root, "out/x.render.json")), "nothing to record, nothing made")
|
||||
put("out/bad.json", "[1]")
|
||||
assert(recordOriginals(path.join(root, "out/cut.mp4"), path.join(root, "out/bad.json"), rec2).failed.join().endsWith("out/bad.json"), "a manifest that isn't an object is said")
|
||||
ok("every render keeps its record of what it read, a still beside it, and a clean one clears it")
|
||||
|
||||
put("footage/day1/take.mp4", light("t"))
|
||||
put("footage/originals/take.mov", "T")
|
||||
assert(originalFile(root, "footage/day1/take.mp4") === null, "a light copy in a folder of its own isn't matched by name")
|
||||
ok("an original's file is matched only for a light copy straight in footage/")
|
||||
console.log("originals: all ok")
|
||||
@@ -213,6 +213,10 @@ console.log("units: ok")
|
||||
assert.equal(localSources(m, [{ path: "media/raw/a1_hl1.mov", oid }], "/work/project"), 1)
|
||||
assert.deepEqual(m.sounds.clips.map((c) => c.src), ["/work/project/media/raw/a1_hl1.mov", "/work/abc/media/music.mp3", "f".repeat(64)])
|
||||
assert.equal(localSources({}, [], "/x"), 0)
|
||||
// the farm's blob under the take's own name (blobs/named/OID/NAME) maps back the same
|
||||
const named = { sounds: { clips: [{ src: `/__modal/volumes/vo-F8fh/blobs/named/${oid}/a1_hl1.mov` }] } }
|
||||
assert.equal(localSources(named, [{ path: "media/raw/a1_hl1.mov", oid }], "/work/project"), 1)
|
||||
assert.equal(named.sounds.clips[0].src, "/work/project/media/raw/a1_hl1.mov")
|
||||
console.log("ok localSources")
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ same(unusedMedia(project({ ...takes, "cut_a.tsx": `<Video src="footage/Angle1-Ta
|
||||
same(unusedMedia(project({ ...takes, "cut_a.tsx": "const src = (id: string) => `footage/originals/${id}.mov`", "cuts.json": JSON.stringify({ shots: ["Angle1-Take1"] }) })),
|
||||
["footage/Angle1-Take2.mp4", "footage/Angle2-Take1.mp4", "footage/originals/Angle1-Take2.mov", "footage/originals/Angle2-Take1.mov", "media/music/bed.mp3"], "the final render on the originals")
|
||||
|
||||
// nothing names any media: all of it is used, as before
|
||||
same(unusedMedia(project({ ...takes, "cut_a.tsx": "export default () => null" })), [], "no source names any")
|
||||
// nothing names any media: all of it is used, as before, but footage/originals/ (gigabytes; each original goes in its
|
||||
// light copy's place when it goes at all: originals.ts)
|
||||
same(unusedMedia(project({ ...takes, "cut_a.tsx": "export default () => null" })), ["footage/originals/Angle1-Take1.mov", "footage/originals/Angle1-Take2.mov", "footage/originals/Angle2-Take1.mov"], "no source names any")
|
||||
console.log("ok")
|
||||
@@ -121,6 +121,27 @@ export function seams(words: Word[]): { at: number; before: string; after: strin
|
||||
return out
|
||||
}
|
||||
|
||||
/** a manifest's clips with every seam that isn't an edit joined: a take that plays straight on across two clips (the
|
||||
* same source and level, touching in the cut and in the take, no fade between) is one clip, so its seam is never read
|
||||
* as an edit point. A composition splits a clip that way when it reframes or restyles a shot mid-clip */
|
||||
export function joined(clips: Clip[], fps: number): Clip[] {
|
||||
const out: Clip[] = []
|
||||
const frame = 1.5 / fps
|
||||
for (const c of [...clips].sort((p, q) => p.from - q.from)) {
|
||||
const prev = out.findLast((p) => p.src === c.src && Math.abs(p.to - c.from) <= 1)
|
||||
const on =
|
||||
prev &&
|
||||
(prev.gainDb ?? 0) === (c.gainDb ?? 0) &&
|
||||
prev.bus === c.bus &&
|
||||
!prev.fadeOut &&
|
||||
!c.fadeIn &&
|
||||
Math.abs(prev.at + (prev.to - prev.from) / fps - c.at) <= frame
|
||||
if (prev && on) Object.assign(prev, { to: c.to, fadeOut: c.fadeOut })
|
||||
else out.push({ ...c })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** a voice clip's in and out: inside a word, or on sound */
|
||||
export function editPoints(c: Clip, fps: number, words: Word[], l: Levels): Finding[] {
|
||||
const out: Finding[] = []
|
||||
@@ -210,7 +231,7 @@ export async function soundOf(f: FileFacts): Promise<{ findings: Finding[]; voic
|
||||
out.push({ level: "error", kind: "manifest", at: null, says: `its render manifest holds ${frames} of the cut's ${length} frames, so its edit can't be checked: render the cut again` })
|
||||
const heard: Heard[] = []
|
||||
let voice = 0
|
||||
for (const c of m.sounds?.clips ?? []) {
|
||||
for (const c of joined(m.sounds?.clips ?? [], fps)) {
|
||||
const kind = busOf(c)
|
||||
const file = f.take(c.src)
|
||||
if (!file) {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { test } from "bun:test"
|
||||
import assert from "node:assert/strict"
|
||||
import type { Clip } from "../src/facts.ts"
|
||||
import type { Levels } from "../src/media.ts"
|
||||
import { balance, busOf, editPoints, nearestGap, soundOf, type Heard } from "../src/packs/sound.ts"
|
||||
import { balance, busOf, editPoints, joined, nearestGap, soundOf, type Heard } from "../src/packs/sound.ts"
|
||||
|
||||
test("the sound pack's measures", async () => {
|
||||
// the sound pack's measures, on made-up takes
|
||||
@@ -114,3 +114,15 @@ test("a word timed longer than a word runs is no word to cut in two (12-04, Elfs
|
||||
// a cut 4 s into the stretch, on quiet: nothing to say about a word
|
||||
assert.equal(editPoints(clip, 30, words, take).filter((f) => f.kind === "edit-in-word").length, 0)
|
||||
})
|
||||
|
||||
test("a take that plays straight on across two clips is one clip: its seam is no edit point", () => {
|
||||
const take = "/w/footage/Acme_Interview.mp4"
|
||||
const a: Clip = { from: 76, to: 96, src: take, at: 53.7, gainDb: 5.5 }
|
||||
const b: Clip = { from: 96, to: 183, src: take, at: 54.3667, gainDb: 5.5 }
|
||||
assert.deepEqual(joined([b, a], 30), [{ ...a, to: 183, fadeOut: undefined }])
|
||||
// a real cut: the take jumps, or the level changes, or the two meet in a fade
|
||||
assert.equal(joined([a, { ...b, at: 92.9 }], 30).length, 2)
|
||||
assert.equal(joined([a, { ...b, gainDb: -1 }], 30).length, 2)
|
||||
assert.equal(joined([{ ...a, fadeOut: 0.2 }, b], 30).length, 2)
|
||||
assert.equal(joined([a, { ...b, src: "/w/footage/Other.mp4" }], 30).length, 2)
|
||||
})
|
||||
@@ -114,7 +114,8 @@ function CaptionLine({ g, saying, px, accent, style, className, children }: { g:
|
||||
fontSize: px,
|
||||
lineHeight: 1.05,
|
||||
color: "var(--brand-text, #fff)",
|
||||
textShadow: "0 4px 24px rgba(0,0,0,0.55)",
|
||||
// a crisp dark edge under the soft shadow: the words hold 3:1 over a white product shot or sky, not only over faces
|
||||
textShadow: "0 0 2px rgba(0,0,0,0.95), 0 0 6px rgba(0,0,0,0.8), 0 4px 24px rgba(0,0,0,0.55)",
|
||||
overflowWrap: "break-word",
|
||||
...style,
|
||||
}}
|
||||
|
||||
@@ -42,7 +42,9 @@ pub fn stats(rgba: &[u8]) -> Option<Exposure> {
|
||||
let enc = if y <= 0.0031308 { 12.92 * y } else { 1.055 * y.powf(1.0 / 2.4) - 0.055 };
|
||||
sum_luma += enc;
|
||||
hist[(enc * 255.0).round().clamp(0.0, 255.0) as usize] += 1;
|
||||
if p[0].max(p[1]).max(p[2]) >= 254 {
|
||||
// white is every channel at the top: a saturated colour (a flat yellow sun, pale sand) has one channel there and
|
||||
// isn't clipped
|
||||
if p[0].min(p[1]).min(p[2]) >= 254 {
|
||||
hi += 1;
|
||||
}
|
||||
if p[0].max(p[1]).max(p[2]) <= 1 {
|
||||
@@ -170,6 +172,15 @@ mod tests {
|
||||
assert!(b.found("f").iter().any(|(_, s)| s.contains("crush to black")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_saturated_colour_is_not_clipped_white() {
|
||||
let sun: Vec<u8> = (0..100).flat_map(|_| [255, 184, 0, 255]).collect();
|
||||
let sand: Vec<u8> = (0..100).flat_map(|_| [255, 229, 165, 255]).collect();
|
||||
assert_eq!(stats(&sun).unwrap().clipped_high, 0.0);
|
||||
assert_eq!(stats(&sand).unwrap().clipped_high, 0.0);
|
||||
assert!(stats(&sun).unwrap().found("f").iter().all(|(_, s)| !s.contains("clip to white")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn percentiles_and_transparency() {
|
||||
// half black, half white: p01 black, p99 white; transparent pixels ignored
|
||||
|
||||
@@ -25,6 +25,7 @@ NAMES=(
|
||||
'raea-runtime-(cut|goal)-plan => sdk/goal (raea/goal)'
|
||||
'naming-check\.ts => raea/goal'"'"'s naming pack'
|
||||
'raea make (check|seen|look|judge|gates)\b => raea goal check|seen|judge|gates (MK45: goal is the loop, make the asset tools)'
|
||||
'"make", *"(check|seen|look|judge|gates)" => ["goal", "check", ...]: a spawned raea make check is refused with exit 2'
|
||||
'raea make plan\b => raea make blockout (a project'"'"'s tasks: raea goal tasks)'
|
||||
'raea next\b => raea goal next'
|
||||
'raea (clothes|motion|solid|wear|splat|physics|bake|sao|tokensynth|sounds|component)( |`|$) => raea make clothes, motion, solid... (MK45: the asset tools are under make)'
|
||||
|
||||
Reference in new issue
Block a user