// A JOIN PREVIEW (release 38 lane E): a few seconds either side of the first // few joins of a cut, in the cut's own look -- the quick render the video // assistant's Ask box and the Look panel play to judge a join's length, // style, slide and room before a full build. `build-video.mjs // --join-preview [--join-from ]` writes out/join-preview.mp4 (and // out/join-preview.json, what it was made from) through the heavy slot, as a // full build does; nothing of the cut's own out/ files is touched. // // The cut: JOIN_PREVIEW_CLIPS consecutive clips (from `from`, else the first), // every other entry left out; each clip keeps the last JOIN_PREVIEW_SECONDS // of its cut (so its tail -- where room and the join act -- is its own), the // last one the first JOIN_PREVIEW_SECONDS. The windows are untouched, so the // media already fetched for the cut is what the preview cuts from. // // PURE: the manifest in, a timeline out. export const JOIN_PREVIEW_CLIPS = 4; export const JOIN_PREVIEW_SECONDS = 3; export const JOIN_PREVIEW_FILE = "join-preview.mp4"; export const JOIN_PREVIEW_RECORD = "join-preview.json"; const fin = (v) => typeof v === "number" && Number.isFinite(v); const r2 = (n) => Math.round(n * 100) / 100; /** * The preview's timeline, or a thrown reason it cannot be made. * * @param {{ render?: Record, timeline?: Record[] }} manifest * @param {{ from?: string | null, clips?: number, seconds?: number }} [o] */ export function joinPreviewTimeline(manifest, { from = null, clips = JOIN_PREVIEW_CLIPS, seconds = JOIN_PREVIEW_SECONDS } = {}) { const render = manifest?.render ?? {}; if (render.chrome !== undefined && render.chrome !== null) throw new Error("a join preview is a plain cut's: this one is drawn under the deck (a full build or --chrome-preview shows its joins)"); if (render.montage !== undefined && render.montage !== null) throw new Error("a join preview is a plain cut's: a montage cuts to its phrases"); if (!(fin(render.transition) ? render.transition > 0 : true)) throw new Error("this cut has hard cuts (render.transition 0): there is no join to preview"); const all = (manifest?.timeline ?? []).filter((e) => e?.type === "clip"); const at = from ? all.findIndex((e) => e.id === from) : 0; if (at < 0) throw new Error(`no clip ${from} in the cut`); const picked = all.slice(at, at + clips); if (picked.length < 2) throw new Error("a join preview needs two clips after it starts"); return picked.map((e, i) => { const a = fin(e.cutStart) && fin(e.cutEnd) ? e.cutStart : e.start; const b = fin(e.cutStart) && fin(e.cutEnd) ? e.cutEnd : e.end; if (!fin(a) || !fin(b) || b - a <= seconds) return { ...e }; const last = i === picked.length - 1; const cut = last ? { cutStart: r2(a), cutEnd: r2(a + seconds) } : { cutStart: r2(b - seconds), cutEnd: r2(b) }; // A mute mark stays: before the shortened cut it mutes all of it, as it // mutes that stretch of the full cut; past it, nothing, as in the cut. return { ...e, ...cut }; }); }