Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(annotations): keep a refitted annotation on the frame, convert only through its own clip
EtienneLescot5a075b031f17
diff --git a/src/lib/ai-edition/annotations/placement.test.ts b/src/lib/ai-edition/annotations/placement.test.tsindex 8c1d46fd1..6d6dfeaa0 100644--- a/src/lib/ai-edition/annotations/placement.test.ts+++ b/src/lib/ai-edition/annotations/placement.test.ts@@ -184,6 +184,14 @@ describe("convertAnnotationKind", () => {const patch = convertAnnotationKind(region(), "figure", { ...context, footage: null });expect(patch).toEqual({ textContent: "Hello", type: "figure", content: "" });});++ it("takes a blur off the frame even when no footage is known", () => {+ const text = region({ space: "frame" });+ const patch = convertAnnotationKind(text, "blur", { ...context, footage: null });+ expect(patch.type).toBe("blur");+ expect("space" in patch && patch.space === undefined).toBe(true);+ expect(patch.position).toBeUndefined();+ });});describe("refitFrameAnnotations", () => {@@ -202,6 +210,26 @@ describe("refitFrameAnnotations", () => {expect(after.position.y).toBe(40);});+ it("shrinks one that no longer fits the frame's width, its text with it", () => {+ const banner = region({+ space: "frame",+ position: { x: 30, y: 40 },+ size: { width: 40, height: 6 },+ });+ const [after] = refitFrameAnnotations([banner], WIDE, 9 / 16);+ // 40 % of a 16:9 frame is 126 % of a 9:16 one: brought back to the full width, around the+ // same centre, and shrunk as a whole.+ const shrink = 100 / (40 * (WIDE / (9 / 16)));+ expect(after.size.width).toBeCloseTo(100, 6);+ expect(after.position.x).toBe(0);+ expect(after.size.height).toBeCloseTo(6 * shrink, 6);+ expect(center(after).y).toBeCloseTo(43, 6);+ // Rounded down, so the words still fit the shrunk box.+ expect(after.style.fontSize).toBe(Math.floor(32 * shrink));+ const image = region({ type: "image", space: "frame", size: { width: 40, height: 6 } });+ expect(refitFrameAnnotations([image], WIDE, 9 / 16)[0].style).toBe(image.style);+ });+it("leaves the footage's annotations, and an unchanged format, alone", () => {const blur = region({ type: "blur" });expect(refitFrameAnnotations([blur], WIDE, 1)[0]).toBe(blur);diff --git a/src/lib/ai-edition/annotations/placement.ts b/src/lib/ai-edition/annotations/placement.tsindex a156bb4af..5b1699cbf 100644--- a/src/lib/ai-edition/annotations/placement.ts+++ b/src/lib/ai-edition/annotations/placement.ts@@ -219,7 +219,7 @@ export function fitTextBox(* sans bouger à l'image, à travers `footage`, le rect du footage dans le cadre. Une boîte de texte* épouse ses mots, bien trop petite pour une image, une flèche ou un flou : ceux-là repartent de la* taille par défaut, centrés au même endroit. `footage` inconnu (aucun clip sous l'annotation) :- * les nombres restent tels quels.+ * les nombres restent tels quels, et un flou quitte le cadre quand même.*/export function convertAnnotationKind(region: Region,@@ -251,7 +251,8 @@ export function convertAnnotationKind(: usable? footageToFrame(rectOf(region), usable): null;- if (!onFrame || !usable) return content;+ // Sans footage par où convertir, les nombres restent ; mais un flou ne vit jamais dans le cadre.+ if (!onFrame || !usable) return belongsInFrame(next) ? content : { ...content, space: undefined };const center = centerOf(onFrame);const fromText = region.type === "text";@@ -292,7 +293,8 @@ export function convertAnnotationKind(* sur hauteur). Chacune garde son centre, et sa forme à l'image : sa largeur est mesurée, comme* la police, sur la hauteur du cadre. Sans ça, un texte taillé en 16:9 garde en 9:16 le même* pourcentage d'une largeur trois fois plus petite en pixels, et le compositeur le renvoie à la- * ligne ; une flèche penche. Le reste ne bouge pas : un flou suit le footage, qui garde son ratio.+ * ligne ; une flèche penche. Celle qui ne tiendrait plus en largeur est réduite pour y tenir. Le+ * reste ne bouge pas : un flou suit le footage, qui garde son ratio.*/export function refitFrameAnnotations<T extends Region>(annotations: T[],@@ -306,6 +308,21 @@ export function refitFrameAnnotations<T extends Region>(return annotations.map((annotation) => {if (annotation.space !== "frame") return annotation;const rect = rectOf(annotation);- return { ...annotation, ...around(centerOf(rect), rect.width * scale, rect.height) };+ const width = rect.width * scale;+ // Plus large que le nouveau cadre : réduite d'un bloc, son texte avec elle, pour rester à+ // l'image au lieu d'en déborder.+ const shrink = Math.min(1, 100 / width);+ const refit = {+ ...annotation,+ ...around(centerOf(rect), width * shrink, rect.height * shrink),+ };+ if (shrink === 1 || annotation.type !== "text") return refit;+ // Arrondie vers le bas : un texte plus grand d'un cheveu que sa boîte réduite passerait à la+ // ligne.+ const fontSize = clampToBound(+ Math.floor(annotation.style.fontSize * shrink),+ "annotationFontSize",+ );+ return { ...refit, style: { ...annotation.style, fontSize } };});}diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.tsindex 515645a19..63ddcb6ba 100644--- a/src/native/sceneDescription.test.ts+++ b/src/native/sceneDescription.test.ts@@ -2441,6 +2441,13 @@ describe("buildSceneDescription.captions", () => {expect(rect?.width).toBeLessThan(1);expect(rect?.x).toBeCloseTo((1 - (rect?.width ?? 0)) / 2, 6);expect(annotationFootageRect(doc, "nope")).toBeNull();+ // Anchored to a clip that is no longer on the timeline: no footage of its own, and no+ // other clip's layout borrowed in its place.+ const orphan = {+ ...doc,+ annotations: [{ ...doc.annotations[0], clipId: "gone", sourceStartSec: 0, sourceEndSec: 1 }],+ } as AxcutDocument;+ expect(annotationFootageRect(orphan, "ann1")).toBeNull();});it("leaves the space key off an annotation still on the footage", () => {diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 0a7238e9d..b81e7f416 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -703,8 +703,9 @@ export function zoomScaleLimit(document: AxcutDocument, regionId: string): numbe/*** Where the footage under the annotation `annotationId` sits in the output frame, as fractions* of it: the layout of the clip the annotation is on, exactly as the scene lays it out. What the- * inspector converts through when an annotation changes box (`annotations/placement.ts`). The- * first clip's when the annotation is on none; `null` when there is no clip at all.+ * inspector converts through when an annotation changes box (`annotations/placement.ts`). `null`+ * when the annotation is on no clip (its own clip trimmed away, say): another clip's layout may+ * differ, and converting through it would move the annotation.*/export function annotationFootageRect(document: AxcutDocument,@@ -712,17 +713,16 @@ export function annotationFootageRect(): SceneRect | null {const region = (document.annotations ?? []).find((a) => a.id === annotationId);if (!region) return null;- const scene = buildSceneDescription(document);const [piece] = projectRegionsToSource([region],resolveVisibleClips(document),document.timeline.clips,() => "",);+ if (piece?.clipIndex === undefined) return null;+ const scene = buildSceneDescription(document);return (- scene.layout.layoutByClip?.[piece?.clipIndex ?? 0]?.screenRect ??- scene.layout.screenRect ??- null+ scene.layout.layoutByClip?.[piece.clipIndex]?.screenRect ?? scene.layout.screenRect ?? null);}