mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-06 05:33:38 -10:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d1dd9831c | ||
|
|
67277ab967 | ||
|
|
4695f03650 | ||
|
|
41fbcfc2ab |
No files matched your search
@@ -540,7 +540,10 @@ def joined(probe, parts):
|
||||
pieces = sorted((c for s in snd for c in s.get("clips") or []), key=lambda c: (c.get("from", 0), str(c.get("key"))))
|
||||
clips = []
|
||||
for c in pieces:
|
||||
prev = next((p for p in reversed(clips) if p.get("key") == c.get("key") and p.get("src") == c.get("src") and p.get("to") == c.get("from")), None)
|
||||
# the same source carried on across a run's seam, whatever its React key: each run numbers its nodes its own
|
||||
# way (12-04, StreetTalk round 22: Body Shop's clips came back keyed n3 and n11 by turns, split at frames 60,
|
||||
# 420, 720 and 807, and the sound check called each seam a cut inside a word)
|
||||
prev = next((p for p in reversed(clips) if p.get("src") == c.get("src") and p.get("to") == c.get("from")), None)
|
||||
if prev is not None and abs(prev.get("at", 0) + (prev["to"] - prev["from"]) / fps - c.get("at", 0)) < 1.5 / fps:
|
||||
prev["to"] = c["to"]
|
||||
if "fadeOut" in c:
|
||||
|
||||
@@ -75,6 +75,9 @@ def api():
|
||||
PROXY_SHORT = 540
|
||||
PROXY_LIGHT_BPS = 2_500_000
|
||||
PART = 64 << 20
|
||||
# every proxy says what it is in its comment tag, and ffmpeg carries the tag into what's made from it: a box's renders
|
||||
# and publishes read it (raea-platform harness/light.ts) so nothing made from a proxy is shown to a person as a final
|
||||
LIGHT_TAG = "raea-light-copy"
|
||||
AGENT = {"user-agent": "raea-ingest/1"}
|
||||
|
||||
|
||||
@@ -160,7 +163,7 @@ def proxy_job(url: str, put: str, ticket: str) -> dict:
|
||||
scale = f"scale='if(gt(iw,ih),-2,trunc(min({PROXY_SHORT},iw)/2)*2)':'if(gt(iw,ih),trunc(min({PROXY_SHORT},ih)/2)*2,-2)',format=yuv420p"
|
||||
r = subprocess.run(
|
||||
["ffmpeg", "-v", "error", "-y", "-i", src, "-map", "0:v:0", "-map", "0:a:0?", "-vf", scale, "-c:v", "libx264", "-preset", "veryfast", "-crf", "28",
|
||||
"-force_key_frames", "expr:gte(t,n_forced*1)", "-c:a", "aac", "-b:a", "96k", "-ac", "2", "-movflags", "+faststart", out],
|
||||
"-force_key_frames", "expr:gte(t,n_forced*1)", "-c:a", "aac", "-b:a", "96k", "-ac", "2", "-metadata", f"comment={LIGHT_TAG}", "-movflags", "+faststart", out],
|
||||
capture_output=True, text=True, timeout=3300,
|
||||
)
|
||||
if r.returncode != 0 or not os.path.exists(out):
|
||||
|
||||
@@ -225,13 +225,54 @@ export async function farmInputs(root: string, farm: FarmBlobs, skip: (p: string
|
||||
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`)
|
||||
for (const m of todo) {
|
||||
await farm.put(m.abs, m.oid, m.size)
|
||||
sent += m.size
|
||||
// four at a time: one by one, 50 takes took minutes on a box whose uplink sits mostly idle
|
||||
let next = 0
|
||||
const one = async () => {
|
||||
for (let i = next++; i < todo.length; i = next++) {
|
||||
await farm.put(todo[i].abs, todo[i].oid, todo[i].size)
|
||||
sent += todo[i].size
|
||||
}
|
||||
}
|
||||
await Promise.all(Array.from({ length: Math.min(4, todo.length) }, one))
|
||||
return { media: media.map(({ abs: _, ...m }) => m), sent }
|
||||
}
|
||||
|
||||
/** the project's video and audio that no source file names, which a render doesn't need: neither sent to the farm nor
|
||||
* packed. 12-03: footage/originals/ (the full-size takes, several GB) went to the farm on the first render of every
|
||||
* StreetTalk run, a still included, and the render ran past its 5 minutes. A file is named by its path, its file name,
|
||||
* or its stem with its folder's name ("originals/" + `${id}.mov`). When no source names any, all of it is used, as
|
||||
* before; RAEA_CLOUD_GPU_ALL_MEDIA=1 sends it all regardless */
|
||||
export function unusedMedia(root: string, skip: (p: string) => boolean = () => false): string[] {
|
||||
if (process.env.RAEA_CLOUD_GPU_ALL_MEDIA === "1") return []
|
||||
const AV = new Set(["mp4", "mov", "m4v", "webm", "mkv", "mxf", "avi", "wav", "mp3", "m4a", "aac", "flac", "ogg"])
|
||||
const SRC = new Set(["tsx", "ts", "jsx", "js", "mjs", "json", "css"])
|
||||
// folders of what's made for the agent or by a render, not what a composition reads from (footage/index.json lists
|
||||
// every take)
|
||||
const NOT_SOURCE = new Set(["footage", "brief_docs", "review", "out", "node_modules", "previews"])
|
||||
const av: string[] = []
|
||||
let text = ""
|
||||
const walk = (dir: string, source: boolean) => {
|
||||
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
||||
const abs = path.join(dir, e.name)
|
||||
const rel = path.relative(root, abs).split(path.sep).join("/")
|
||||
if (skip(rel) || e.name === ".git" || e.name.startsWith(".raea-cloud")) continue
|
||||
const ext = e.name.includes(".") ? e.name.split(".").pop()!.toLowerCase() : ""
|
||||
if (e.isDirectory()) walk(abs, source && !(dir === root && NOT_SOURCE.has(e.name)))
|
||||
else if (e.isFile() && AV.has(ext)) av.push(rel)
|
||||
else if (e.isFile() && source && SRC.has(ext) && statSync(abs).size < 2 << 20) text += readFileSync(abs, "utf8") + "\n"
|
||||
}
|
||||
}
|
||||
walk(root, true)
|
||||
const named = (rel: string) => {
|
||||
const name = rel.split("/").pop()!
|
||||
const stem = name.replace(/\.[^.]+$/, "")
|
||||
const folder = rel.includes("/") ? rel.split("/").slice(-2, -1)[0] + "/" : ""
|
||||
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)) : []
|
||||
}
|
||||
|
||||
/** tar's exclude-from lines for paths that go by hash: each matched as written (glob characters escaped) */
|
||||
export const excludes = (media: Media[]) => media.map((m) => "./" + m.path.replace(/[\\*?[\]]/g, (c) => "\\" + c)).join("\n") + "\n"
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import os from "node:os"
|
||||
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 } from "./media.ts"
|
||||
import { excluded, excludes as mediaExcludes, farmBlobs, farmInputs, inputs, lfsOf, localSources, outputs, unusedMedia } from "./media.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
|
||||
@@ -111,16 +111,24 @@ async function main() {
|
||||
const sent = path.join(tmp, "in.tar")
|
||||
// the media that goes by hash: out of the tar, named in its manifest
|
||||
const lfs = lfsOf(p.root)
|
||||
let byHash = typeof lfs === "string" ? [] : await inputs(p.root, lfs, excluded(excludes))
|
||||
// video and audio no source file names stays here, out of the tar and the farm's cache (media.ts unusedMedia)
|
||||
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)
|
||||
// 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
|
||||
if (typeof lfs === "string" && process.env.RAEA_CLOUD_GPU_BLOBS !== "0") {
|
||||
viaFarm = await farmInputs(p.root, farmBlobs(url, token), excluded(excludes), 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), skip, say).catch((e) => (say(`the farm's media cache: ${(e as Error).message}; the media goes in the tar`), null))
|
||||
if (viaFarm) byHash = viaFarm.media
|
||||
}
|
||||
const extra: string[] = []
|
||||
if (unused.size) {
|
||||
writeFileSync(path.join(tmp, "unused-excludes"), mediaExcludes([...unused].map((f) => ({ path: f, oid: "", size: 0 }))))
|
||||
extra.push("-X", path.join(tmp, "unused-excludes"))
|
||||
}
|
||||
if (byHash.length) {
|
||||
writeFileSync(path.join(tmp, "media-excludes"), mediaExcludes(byHash))
|
||||
writeFileSync(path.join(tmp, ".raea-cloud-media.json"), JSON.stringify({ objects: byHash }))
|
||||
|
||||
@@ -128,6 +128,14 @@ clips = sorted(man["sounds"]["clips"], key=lambda c: c["from"])
|
||||
assert [(c["key"], c["from"], c["to"]) for c in clips] == [("n3", 0, 40), ("n8", 40, 60)], clips
|
||||
assert abs(clips[0]["at"] - 1.0) < 1e-6 and abs(clips[1]["at"] - 9.0) < 1e-6 and clips[0].get("fadeIn") == 0.012 and clips[1].get("fadeOut") == 0.012, clips
|
||||
ok("a split render's manifest is its runs' joined: all 60 frames, and each clip whole with its source time")
|
||||
# 12-04 (StreetTalk round 22): each run numbers its React nodes its own way, so one clip came back as n3 then n11 by
|
||||
# turns; joined only by key, it stayed in pieces and the sound check called every seam a cut inside a word
|
||||
m2 = fp.joined({"frames": []}, [
|
||||
{"frames": [{"frame": 0}], "sounds": {"fps": 30, "clips": [{"key": "n3", "src": "t.mp4", "from": 0, "to": 60, "at": 194.667}]}},
|
||||
{"frames": [{"frame": 60}], "sounds": {"fps": 30, "clips": [{"key": "n11", "src": "t.mp4", "from": 60, "to": 90, "at": 196.667}]}},
|
||||
])
|
||||
assert [(c["src"], c["from"], c["to"]) for c in m2["sounds"]["clips"]] == [("t.mp4", 0, 90)], m2["sounds"]["clips"]
|
||||
ok("a clip carried across a run's seam under another key is joined whole")
|
||||
|
||||
lines.clear()
|
||||
long = FakeGpu(root, length=1000)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// What a render leaves on the box (server/media.ts unusedMedia): video and audio no source file names. 12-03: every
|
||||
// StreetTalk run's first render sent footage/originals/ (several GB) to the farm, a still included, and ran past its
|
||||
// 5 minutes. Run: node test/unused-media.ts (prints ok, or FAIL and exits 1)
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import path from "node:path"
|
||||
import { unusedMedia } from "../server/media.ts"
|
||||
|
||||
const fail = (m: string): never => {
|
||||
console.error(`FAIL ${m}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const project = (files: Record<string, string>) => {
|
||||
const root = mkdtempSync(path.join(tmpdir(), "raea-unused-"))
|
||||
for (const [f, c] of Object.entries(files)) {
|
||||
mkdirSync(path.dirname(path.join(root, f)), { recursive: true })
|
||||
writeFileSync(path.join(root, f), c)
|
||||
}
|
||||
return root
|
||||
}
|
||||
const same = (a: string[], b: string[], what: string) => JSON.stringify([...a].sort()) === JSON.stringify([...b].sort()) || fail(`${what}: ${JSON.stringify([...a].sort())}`)
|
||||
|
||||
// a cut on the light copies: the originals and the untouched takes stay; index.json (which lists every take) isn't source
|
||||
const takes = {
|
||||
"footage/Angle1-Take1.mp4": "x", "footage/Angle1-Take2.mp4": "x", "footage/Angle2-Take1.mp4": "x",
|
||||
"footage/originals/Angle1-Take1.mov": "x", "footage/originals/Angle1-Take2.mov": "x", "footage/originals/Angle2-Take1.mov": "x",
|
||||
"footage/index.json": JSON.stringify(["Angle1-Take1.mp4", "Angle1-Take2.mp4", "Angle2-Take1.mp4"]),
|
||||
"media/music/bed.mp3": "x",
|
||||
}
|
||||
same(unusedMedia(project({ ...takes, "cut_a.tsx": `<Video src="footage/Angle1-Take1.mp4" /><Video src={"footage/" + "Angle1-Take2.mp4"} /><Audio src="media/music/bed.mp3" />` })),
|
||||
["footage/Angle2-Take1.mp4", "footage/originals/Angle1-Take1.mov", "footage/originals/Angle1-Take2.mov", "footage/originals/Angle2-Take1.mov"], "a cut on the light copies")
|
||||
|
||||
// the final render on the originals by id: originals/ named, the stem from data. The take's light copy goes too
|
||||
// ("footage/" is in "footage/originals/"): a few MB, against the GB of originals that stay
|
||||
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")
|
||||
console.log("ok")
|
||||
Reference in new issue
Block a user