mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-06 05:33:38 -10:00
raea cut reads a take's jump cuts through ffmpeg, on every core
raea media cuts decodes with openh264 on a Linux box, on one core: 38 s for a 3.5-minute light copy and 66 s for a 6-minute one, the first raea cut on each take of a run (12-05, run 28). ffmpegCuts reads the luma at 160x90 through the ffmpeg CLI and scores each frame as raea media cuts does: the same cuts on three Body Shop light copies and a made take with two, in 5.8 s, 8.1 s and 0.5 s against 38 s, 65 s and 3.2 s. Where ffmpeg can't read the take, the engine reads it.
This commit is contained in:
1 parent
14a10fc2b0
commit
bad441493e
2 files changed
+45
-1
No files matched your search
@@ -255,6 +255,20 @@ ${Array.from({ length: 40 }, (_, i) => `.u${i} { margin: ${i}px; }`).join("\n")}
|
||||
}
|
||||
});
|
||||
|
||||
// a take's jump cuts read through the ffmpeg CLI (cutplan.ts ffmpegCuts): where raea media cuts finds them
|
||||
test.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("raea cut reads a take's jump cuts through ffmpeg, where the engine finds them", async () => {
|
||||
const { ffmpegCuts } = await import("../src/cutplan.ts");
|
||||
const dir = mkdtempSync(join(tmpdir(), "raea-ffcuts-"));
|
||||
try {
|
||||
const color = (c: string) => ["-f", "lavfi", "-i", `color=c=${c}:s=320x180:r=30:d=2`];
|
||||
spawnSync("ffmpeg", ["-v", "error", "-y", ...color("red"), ...color("blue"), ...color("green"), "-filter_complex", "[0][1][2]concat=n=3:v=1:a=0", "-c:v", "libx264", "-pix_fmt", "yuv420p", join(dir, "t.mp4")]);
|
||||
expect(ffmpegCuts(join(dir, "t.mp4"), 0.08)).toEqual([2, 4]);
|
||||
expect(ffmpegCuts(join(dir, "missing.mp4"), 0.08)).toBeNull();
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// raea cloud's footage/faces.json (prep's faces, found on its farm): perception.json takes each clip's face from it,
|
||||
// with no still and no raea-perceive (a box has none). A made clip and made-up faces, never real footage
|
||||
test.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("raea cut takes each clip's face from footage/faces.json", () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// How raea cut times a take's lines: the take's light copy when raea cloud keeps one, its jump cuts (kept in raea's
|
||||
// cache) and sound level, and pace.ts's timing, kept off the take's own jump cuts. native.ts gives it the engine.
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { homedir, tmpdir } from "node:os";
|
||||
@@ -11,6 +12,35 @@ export type TakeIO = { at: (p: string) => string; engineRun: (a: string[]) => st
|
||||
|
||||
const ms = (s: number) => Math.round(s * 1000) / 1000;
|
||||
|
||||
/** A take's jump cuts read through the ffmpeg CLI where there is one: its luma at 160x90, every frame, scored as raea
|
||||
* media cuts scores them (ffmpeg's select scene: each frame's mean absolute difference from the last, less the
|
||||
* difference before it, over 100). ffmpeg decodes on every core; the engine's own decoder on a Linux box is openh264 on
|
||||
* one (12-05: 38 s for a 3.5-minute light copy, 66 s for a 6-minute one, against 4 s for ffmpeg), and a box step has
|
||||
* 3 minutes. The small picture leaves a hard cut's score where it was and a frame's grain out. null where ffmpeg
|
||||
* can't read it: the engine reads it then. */
|
||||
export function ffmpegCuts(file: string, threshold: number): number[] | null {
|
||||
const [w, h] = [160, 90];
|
||||
const r = spawnSync("ffmpeg", ["-v", "info", "-nostats", "-i", file, "-an", "-vf", `scale=${w}:${h}:flags=area,format=gray,showinfo`, "-f", "rawvideo", "-"], { maxBuffer: 1 << 30 });
|
||||
if (r.error || r.status !== 0 || !r.stdout?.length) return null;
|
||||
// each frame's time, from showinfo's lines in order
|
||||
const times = [...String(r.stderr).matchAll(/\bn:\s*\d+\s+pts:\s*-?\d+\s+pts_time:(-?[\d.]+)/g)].map((m) => Number(m[1]));
|
||||
const n = w * h;
|
||||
const frames = Math.floor(r.stdout.length / n);
|
||||
if (!frames || times.length !== frames) return null;
|
||||
const y = r.stdout as Buffer;
|
||||
const out: number[] = [];
|
||||
let prev = 0;
|
||||
for (let f = 1; f < frames; f++) {
|
||||
let sad = 0;
|
||||
for (let i = f * n, j = (f - 1) * n, e = i + n; i < e; i++, j++) sad += Math.abs(y[i] - y[j]);
|
||||
const mafd = sad / n;
|
||||
const score = Math.min(Math.max(Math.min(mafd, Math.abs(mafd - prev)) / 100, 0), 1);
|
||||
prev = mafd;
|
||||
if (score > threshold) out.push(ms(times[f]));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** cutPlan and takeLevels over `io`, each take's levels kept for the run */
|
||||
export function timing({ at, engineRun, engineJson, isAudio }: TakeIO) {
|
||||
/** The take to read for timing: its light copy when raea cloud keeps one (.raea-cloud/proxies/NAME.mp4 in the project,
|
||||
@@ -37,7 +67,7 @@ export function timing({ at, engineRun, engineJson, isAudio }: TakeIO) {
|
||||
} catch {
|
||||
kept = "";
|
||||
}
|
||||
const cuts = (engineJson(["media", "cuts", file, "--threshold", "0.08"]).cuts as { at: number }[]).map((c) => c.at);
|
||||
const cuts = ffmpegCuts(file, 0.08) ?? (engineJson(["media", "cuts", file, "--threshold", "0.08"]).cuts as { at: number }[]).map((c) => c.at);
|
||||
if (kept)
|
||||
try {
|
||||
mkdirSync(dirname(kept), { recursive: true });
|
||||
|
||||
Reference in new issue
Block a user