Skip to content

Open source CapCut alternative.

TypeScript

fix(site): start a camera track on the cut it was given [rebuild]

David Le9a11cc337963
diff --git a/site/src/cut/lib/measure/sourceMeasure.ts b/site/src/cut/lib/measure/sourceMeasure.ts
index 6b94f1c6..106884d9 100644
--- a/site/src/cut/lib/measure/sourceMeasure.ts
+++ b/site/src/cut/lib/measure/sourceMeasure.ts
@@ -32,6 +32,10 @@ const COLOR_LONG_SIDE = 1920;
const TRACK_LONG_SIDE = 720;
/** Reads a pass back off by this much so the frame on `from` is scored. */
const LEAD_S = 0.001;
+/** A time handed back to the millisecond sits up to half of one either side
+ * of the frame start it names, so a frame ending that close past `from` is
+ * the one before it. */
+const HALF_MS = 0.0005;
/** Long side the picture box is found at: a pixel is 0.16% of the frame. */
const PICTURE_LONG_SIDE = 640;
/** Frames sampled across a source to find its picture. */
@@ -413,6 +417,8 @@ export async function trackCamera(
await withSourceVideo(url, async (v) => {
const at = sizeAt(v.width, v.height, CAMERA_LONG_SIDE, area);
for await (const f of v.frames(Math.max(0, opts.from - LEAD_S), opts.to, at)) {
+ // The shot before a cut would anchor every pose to the wrong picture.
+ if (f.t + f.duration <= opts.from + HALF_MS) continue;
if (frames.length >= opts.maxFrames) {
truncated = true;
coveredTo = times[times.length - 1];
diff --git a/site/src/cut/lib/measureTools.test.ts b/site/src/cut/lib/measureTools.test.ts
index 8c40623d..f08d762a 100644
--- a/site/src/cut/lib/measureTools.test.ts
+++ b/site/src/cut/lib/measureTools.test.ts
@@ -188,6 +188,15 @@ test("track_camera reads a held shot as one picture that never moves", async ()
expect(out.moves).toEqual([]);
});
+test("track_camera from a cut detect_cuts gave starts on that shot's first frame", async () => {
+ // The cut lands on frame 65 (1.0833 s); detect_cuts hands it back to the
+ // millisecond, which can sit either side of the frame's own start.
+ for (const from of [1.083, 1.084]) {
+ const out = (await runAiTool("track_camera", { asset_id: "ref", from, to: 1.3 })) as { path: { t: number }[] };
+ expect(out.path[0].t).toBeCloseTo(65 / FPS, 3);
+ }
+});
+
test("track_camera needs the stretch's end", async () => {
expect(await message(runAiTool("track_camera", { asset_id: "ref", from: 1.1 }))).toContain("to");
});