diff --git a/sdk/cloud/deploy/modal/farm_media.py b/sdk/cloud/deploy/modal/farm_media.py index 8e6b580d..5948a4ef 100644 --- a/sdk/cloud/deploy/modal/farm_media.py +++ b/sdk/cloud/deploy/modal/farm_media.py @@ -103,15 +103,33 @@ def fetch(work, cache, log=print, download=get, check=probe): 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-{os.getpid()}" + 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 diff --git a/sdk/cloud/server/media.ts b/sdk/cloud/server/media.ts index fc2f2bb9..d94a73d0 100644 --- a/sdk/cloud/server/media.ts +++ b/sdk/cloud/server/media.ts @@ -285,7 +285,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) diff --git a/sdk/cloud/test/farm_media.py b/sdk/cloud/test/farm_media.py index 04db0373..b5e3e518 100644 --- a/sdk/cloud/test/farm_media.py +++ b/sdk/cloud/test/farm_media.py @@ -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) diff --git a/sdk/cloud/test/units.ts b/sdk/cloud/test/units.ts index 58264b3e..ff168b06 100644 --- a/sdk/cloud/test/units.ts +++ b/sdk/cloud/test/units.ts @@ -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") } diff --git a/sdk/goal/src/packs/sound.ts b/sdk/goal/src/packs/sound.ts index 939ce5fc..c00ec34e 100644 --- a/sdk/goal/src/packs/sound.ts +++ b/sdk/goal/src/packs/sound.ts @@ -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) { diff --git a/sdk/goal/test/sound.test.ts b/sdk/goal/test/sound.test.ts index 10561d64..da997d75 100644 --- a/sdk/goal/test/sound.test.ts +++ b/sdk/goal/test/sound.test.ts @@ -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) +})