Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(cli): measure the caption inset to the plate, not the region

EtienneLescot79849cddc03c
diff --git a/src/cli/captionAnnotations.test.ts b/src/cli/captionAnnotations.test.ts
index e42ca60f2..c595cebc1 100644
--- a/src/cli/captionAnnotations.test.ts
+++ b/src/cli/captionAnnotations.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_CAPTION_SETTINGS } from "@/lib/ai-edition/captions/settings";
import type { CaptionSegment } from "@/lib/captioning/transcribe";
-import { captionSegmentsToAnnotationRegions } from "./captionAnnotations";
+import { CAPTION_PLATE_HEIGHT, captionSegmentsToAnnotationRegions } from "./captionAnnotations";
const words = (...texts: string[]): CaptionSegment[] =>
texts.map((text, i) => ({ text, startSec: i * 0.5, endSec: i * 0.5 + 0.4 }));
@@ -42,9 +42,13 @@ describe("captionSegmentsToAnnotationRegions", () => {
color: DEFAULT_CAPTION_SETTINGS.color,
backgroundColor: "rgba(0, 0, 0, 0.55)",
});
- // Inside the 16:9 safe column, bottom edge 1.5% off the frame's.
+ // Inside the 16:9 safe column.
expect(region.position.x).toBe(16);
expect(region.size.width).toBe(68);
- expect(region.position.y + region.size.height).toBeCloseTo(98.5);
+ // The PLATE, centred in the region, ends 1.5% off the frame's bottom edge, like the
+ // editor's inset. The region itself extends below it.
+ const plateBottom = region.position.y + region.size.height / 2 + CAPTION_PLATE_HEIGHT / 2;
+ expect(plateBottom).toBeCloseTo(98.5);
+ expect(region.position.y + region.size.height).toBeGreaterThan(98.5);
});
});
diff --git a/src/cli/captionAnnotations.ts b/src/cli/captionAnnotations.ts
index 66875c7d7..651f48eca 100644
--- a/src/cli/captionAnnotations.ts
+++ b/src/cli/captionAnnotations.ts
@@ -28,9 +28,21 @@ const LANDSCAPE = 16 / 9;
const CAPTION_HEIGHT = 12;
const CAPTION_COLUMN = captionSafeColumn(LANDSCAPE);
+// The inset measures to the PLATE's bottom edge, as the editor's does, not to the region's.
+// An annotation centres its text block (and the plate that hugs it) in its region, so the
+// region is placed to put a one-line plate's bottom there. The region stays 12% tall for
+// headroom: a line that wraps grows its plate both ways instead of being clipped.
+const ANNOTATION_REFERENCE_HEIGHT = 1080;
+/** One line plus the plate's vertical padding (`text_plate.rs::PAD_Y_EM` twice), in em.
+ * 1.3 em is DirectWrite's line box for bold Inter: a Windows export measured the plate at
+ * 1.51 em. Other rasterizers differ slightly; cosmic-text (Linux) lays out 1.4 em. */
+const PLATE_HEIGHT_EM = 1.3 + 2 * 0.1;
+export const CAPTION_PLATE_HEIGHT =
+ ((DEFAULT_CAPTION_SETTINGS.fontSize * PLATE_HEIGHT_EM) / ANNOTATION_REFERENCE_HEIGHT) * 100;
+
const CAPTION_POSITION = {
x: CAPTION_COLUMN.x,
- y: 100 - CAPTION_HEIGHT - defaultCaptionInsetY(LANDSCAPE),
+ y: 100 - defaultCaptionInsetY(LANDSCAPE) - (CAPTION_HEIGHT + CAPTION_PLATE_HEIGHT) / 2,
};
const CAPTION_SIZE = { width: CAPTION_COLUMN.width, height: CAPTION_HEIGHT };