The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Studio: Final Cut Pro subtitles keep their fill and scale with the frame (#106)
taavie-z3582b88e7509
diff --git a/.changeset/fcp-subtitle-style.md b/.changeset/fcp-subtitle-style.mdnew file mode 100644index 0000000..cdf9282--- /dev/null+++ b/.changeset/fcp-subtitle-style.md@@ -0,0 +1,6 @@+---+"openfilm": patch+"@openfilm/desktop": patch+---++Keep Final Cut Pro subtitles white with a black outline and a soft shadow. Correct Basic Title font scaling so subtitle size stays proportional in low-resolution, 4K and portrait sequences.diff --git a/packages/openfilm/studio/server/fcpxml.mjs b/packages/openfilm/studio/server/fcpxml.mjsindex c65e273..5eab2f2 100644--- a/packages/openfilm/studio/server/fcpxml.mjs+++ b/packages/openfilm/studio/server/fcpxml.mjs@@ -135,7 +135,10 @@ export function fcpxmlDocument(timeline, { cues = [] } = {}) {parent.children.push(...clipXml(clip, { ...placement, kind: 'video' }));}const subtitleCues = filmSubtitleCuesInRange(cues, 0, timeline.durationFrames / rate.fps * 1000);- const fontSize = decimal(Math.min(width, height) * 48 / 1080);+ // Basic Title scales its 1080-high template to the sequence; only the aspect ratio changes its point size.+ const fontSize = 48 * Math.min(width, height) / height;+ // FCPXML stores twice the Blur value shown in FCP’s text inspector.+ const shadowBlurRadius = decimal(fontSize * 0.22 * 2);let titleCount = 0;for (const { cue, end } of filmSubtitleSequence(subtitleCues)) {const span = frameSpan(cue.startMs / 1000, end / 1000, rate);@@ -148,11 +151,14 @@ export function fcpxmlDocument(timeline, { cues = [] } = {}) {`offset="${time(offset)}"`, 'start="0s"', `duration="${time(span.end - span.start)}"`, 'role="titles.OpenFilm Subtitles"',];// Ordinary titles stay with the picture layers; native captions use FCP's separate caption area.+ // A negative strokeWidth keeps both the face and outline.parent.children.push(` <title ${attrs.join(' ')}>`,` <text><text-style ref="${styleId}">${xmlEscape(filmSubtitleText(cue))}</text-style></text>`,` <text-style-def id="${styleId}">`,- ` <text-style font="Helvetica" fontSize="${fontSize}" fontColor="1 1 1 1" strokeColor="0 0 0 1" strokeWidth="2" alignment="center"/>`,+ ` <text-style font="Helvetica" fontSize="${decimal(fontSize)}" fontColor="1 1 1 1"`+ + ' strokeColor="0 0 0 1" strokeWidth="-2" shadowColor="0 0 0 0.72"'+ + ` shadowOffset="${decimal(fontSize * 0.05)} 270" shadowBlurRadius="${shadowBlurRadius}" alignment="center"/>`,' </text-style-def>',' <adjust-transform position="0 -40"/>',' </title>',diff --git a/packages/openfilm/studio/server/fcpxml.test.mjs b/packages/openfilm/studio/server/fcpxml.test.mjsindex e3e654e..ac5102c 100644--- a/packages/openfilm/studio/server/fcpxml.test.mjs+++ b/packages/openfilm/studio/server/fcpxml.test.mjs@@ -115,6 +115,28 @@ test('FCPXML includes editable subtitle titles above pictures, clipped to the seassert.doesNotMatch(fcpxmlDocument(timeline), /<title |<effect /);});+test('subtitle titles keep their relative size and white outlined text across sequence resolutions', () => {+ for (const [width, height, fontSize, shadowOffset, shadowBlurRadius] of [+ [320, 180, 48, '2.4 270', 21.12],+ [1920, 1080, 48, '2.4 270', 21.12],+ [3840, 2160, 48, '2.4 270', 21.12],+ [360, 640, 27, '1.35 270', 11.88],+ [1080, 1920, 27, '1.35 270', 11.88],+ [1080, 1080, 48, '2.4 270', 21.12],+ ]) {+ const xml = fcpxmlDocument({ ...timeline, width, height }, { cues: [{ startMs: 0, durMs: 1000, text: 'Subtitle' }] });+ const style = xml.match(/<text-style font=[^>]+/)?.[0];+ assert.ok(style);+ assert.equal(Number(style.match(/fontSize="([^"]+)"/)?.[1]), fontSize, `${width}×${height}`);+ assert.match(style, /fontColor="1 1 1 1"/);+ assert.match(style, /strokeColor="0 0 0 1"/);+ assert.match(style, /shadowColor="0 0 0 0.72"/);+ assert.equal(style.match(/shadowOffset="([^"]+)"/)?.[1], shadowOffset);+ assert.equal(Number(style.match(/shadowBlurRadius="([^"]+)"/)?.[1]), shadowBlurRadius);+ assert.equal(Number(style.match(/strokeWidth="([^"]+)"/)?.[1]), -2, 'negative stroke width keeps both fill and outline');+ }+});+test('subtitle titles on an audio-only timeline omit empty cues and end at the next subtitle', () => {const xml = fcpxmlDocument({ ...timeline, rate: nleRate(25), video: [], audio: [] }, { cues: [{ startMs: 1000, durMs: 1000, text: 'Second' },