Skip to content

Commit 000ccd4

Browse files
vanceingallsclaude
andauthored
feat(studio): speed presets, voice, look, crop presets and freeze frame in the clip menu (3/8) (#4815)
* feat(core): add gentle ramp-in, ramp-out and slow-mo-middle speed presets Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(studio): add voice, look and crop clip-menu items and clip badges Voice and Look are single-choice submenus writing data-fx-chain and data-color-grading; None clears. Crop opens the canvas crop preset bar. ClipBadges reads the live preview node and follows attribute edits. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(studio): drop the unstyled badge classes Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(studio): add crop aspect presets to the canvas crop handles Free, 16:9, 9:16, 1:1, 4:5, Reset and Done float above the clip opened from the clip menu. Presets commit a centred inset clip-path; Reset removes it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(studio): read the committed crop from the inline clip-path Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(studio-server): add freeze-frame file mutation Extracts the frame under the playhead with ffmpeg (media time honours data-media-start, playback rate and a rate lane) into assets/freeze/, then in one write splits the video, inserts a 2 s <img> still with the video's box styles, shifts the rest of the track and splits a data-link partner. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(studio-server): import replaceFileAtomically from core atomic-file Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(studio): add freeze frame to the clip menu Freeze frame on a video under the playhead posts the studio-server freeze-frame mutation and records its before/after as one undo step. onFreezeFrame is threaded through the timeline edit callbacks. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(studio-server): keep the freeze still inside assets/freeze The clip id from the project HTML went straight into ffmpeg's -y output path, so an id with ../ segments wrote outside the project. The id is now reduced to one safe filename component, the output is pinned inside assets/freeze before extraction, and the still's src is built from that name rather than from a filesystem path. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(studio-server): give every freeze still its own immutable name Two clip ids that sanitise alike (a.b / a_b), ids sharing an 80-character prefix, or a second freeze of one clip at the same playhead all produced the same still path, and ffmpeg's -y replaced the first still's pixels. The name now carries a hash of the raw id and a per-extraction token, the route refuses a name that already exists, and ffmpeg runs with -n so it can never overwrite. The freeze media time reads data-playback-start before data-media-start, as playback does. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3c299ac commit 000ccd4

31 files changed

Lines changed: 2438 additions & 98 deletions

‎packages/core/src/speedRamp.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,37 @@ describe("presets", () => {
122122
}
123123
});
124124
});
125+
126+
describe("gentle ramp presets", () => {
127+
const speeds = (id: "ramp-in" | "ramp-out" | "slowmo-middle", duration: number) =>
128+
speedPresetLane(id, duration).points.map((p) => [p.t, p.v]);
129+
130+
it("ramp-in eases from half speed up to normal", () => {
131+
expect(speeds("ramp-in", 4)).toEqual([
132+
[0, 0.5],
133+
[4, 1],
134+
]);
135+
});
136+
137+
it("ramp-out eases from normal down to half speed", () => {
138+
expect(speeds("ramp-out", 4)).toEqual([
139+
[0, 1],
140+
[4, 0.5],
141+
]);
142+
});
143+
144+
it("slowmo-middle holds 0.35x through the middle third and returns to normal", () => {
145+
const lane = speedPresetLane("slowmo-middle", 6);
146+
expect(rateAt(lane, 0)).toBe(1);
147+
expect(rateAt(lane, 2)).toBeCloseTo(0.35, 5);
148+
expect(rateAt(lane, 3)).toBeCloseTo(0.35, 5);
149+
expect(rateAt(lane, 4)).toBeCloseTo(0.35, 5);
150+
expect(rateAt(lane, 6)).toBe(1);
151+
});
152+
153+
it("each consumes less source than the clip at normal speed", () => {
154+
for (const id of ["ramp-in", "ramp-out", "slowmo-middle"] as const) {
155+
expect(sourceTimeAt(speedPresetLane(id, 6), 6)).toBeLessThan(6);
156+
}
157+
});
158+
});

‎packages/core/src/speedRamp.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,32 @@ export const SPEED_PRESETS = [
206206
[1, 0.3],
207207
],
208208
},
209+
{
210+
id: "ramp-in",
211+
label: "Ramp in",
212+
points: [
213+
[0, 0.5],
214+
[1, 1],
215+
],
216+
},
217+
{
218+
id: "ramp-out",
219+
label: "Ramp out",
220+
points: [
221+
[0, 1],
222+
[1, 0.5],
223+
],
224+
},
225+
{
226+
id: "slowmo-middle",
227+
label: "Slow-mo middle",
228+
points: [
229+
[0, 1],
230+
[1 / 3, 0.35],
231+
[2 / 3, 0.35],
232+
[1, 1],
233+
],
234+
},
209235
] as const satisfies readonly RatePreset[];
210236

211237
export type SpeedPresetId = (typeof SPEED_PRESETS)[number]["id"];

‎packages/studio-server/src/createStudioApi.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { registerRenderRoutes } from "./routes/render.js";
88
import { registerImageThumbnailRoutes } from "./routes/imageThumbnail.js";
99
import { registerThumbnailRoutes } from "./routes/thumbnail.js";
1010
import { registerWaveformRoutes } from "./routes/waveform.js";
11+
import { registerFreezeFrameRoutes } from "./routes/freezeFrame.js";
1112
import { registerFontRoutes } from "./routes/fonts.js";
1213
import { registerRegistryRoutes } from "./routes/registry.js";
1314
import { registerSelectionRoutes } from "./routes/selection.js";
@@ -61,6 +62,7 @@ export function createStudioApi(adapter: StudioApiAdapter): Hono {
6162
registerSelectionRoutes(api, adapter);
6263
registerMediaRoutes(api, adapter);
6364
registerWaveformRoutes(api, adapter);
65+
registerFreezeFrameRoutes(api, adapter);
6466
registerFontRoutes(api);
6567
registerRegistryRoutes(api, adapter);
6668
registerGlobalAssetRoutes(api);
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import { describe, expect, it } from "vitest";
2+
import { parseHTML } from "linkedom";
3+
import {
4+
applyFreezeFrameToHtml,
5+
freezeExtractArgs,
6+
freezeFrameMediaTime,
7+
freezeStillFileName,
8+
readFreezeSource,
9+
} from "./freezeFrame.js";
10+
11+
const rampLane = JSON.stringify({
12+
version: 1,
13+
lanes: [
14+
{
15+
target: "rate",
16+
points: [
17+
{ t: 0, v: 1 },
18+
{ t: 2, v: 3 },
19+
],
20+
},
21+
],
22+
});
23+
24+
describe("freezeFrameMediaTime", () => {
25+
it("is the in-point plus clip time at normal speed", () => {
26+
expect(
27+
freezeFrameMediaTime({
28+
clipStart: 1,
29+
playhead: 3.2,
30+
mediaStart: 5,
31+
playbackRate: 1,
32+
automation: null,
33+
}),
34+
).toBeCloseTo(7.2, 6);
35+
});
36+
37+
it("scales by a constant playback rate", () => {
38+
expect(
39+
freezeFrameMediaTime({
40+
clipStart: 0,
41+
playhead: 2,
42+
mediaStart: 1,
43+
playbackRate: 2,
44+
automation: null,
45+
}),
46+
).toBeCloseTo(5, 6);
47+
});
48+
49+
it("integrates a rate lane, which overrides the constant", () => {
50+
// 1x to 3x over 2s consumes 2 * (3 - 1) / ln 3 source seconds.
51+
expect(
52+
freezeFrameMediaTime({
53+
clipStart: 0,
54+
playhead: 2,
55+
mediaStart: 0.5,
56+
playbackRate: 4,
57+
automation: rampLane,
58+
}),
59+
).toBeCloseTo(0.5 + 3.641, 2);
60+
});
61+
});
62+
63+
describe("freezeExtractArgs", () => {
64+
it("seeks before the input and writes one frame, never over an existing file", () => {
65+
expect(freezeExtractArgs("/p/a.mp4", 7.2004, "/p/assets/freeze/a-3200.png")).toEqual([
66+
"-n",
67+
"-ss",
68+
"7.2",
69+
"-i",
70+
"/p/a.mp4",
71+
"-frames:v",
72+
"1",
73+
"/p/assets/freeze/a-3200.png",
74+
]);
75+
});
76+
});
77+
78+
const project = `<div data-composition-id="main" data-start="0" data-duration="10">
79+
<video id="talk" class="clip" src="talk.mp4" data-start="1" data-duration="6" data-media-start="2" data-track-index="0" data-link="L" style="left:10px;clip-path:inset(5px)"></video>
80+
<img id="later" class="clip" src="x.png" data-start="8" data-duration="1" data-track-index="0">
81+
<div id="other" class="clip" data-start="5" data-duration="2" data-track-index="2"></div>
82+
<audio id="talk-audio" class="clip" src="talk.mp4" data-start="1" data-duration="6" data-media-start="2" data-track-index="1" data-link="L"></audio>
83+
</div>`;
84+
85+
const at = (html: string, id: string) =>
86+
parseHTML(`<html><body>${html}</body></html>`).document.getElementById(id);
87+
const timing = (html: string, id: string) => {
88+
const el = at(html, id);
89+
return [el?.getAttribute("data-start"), el?.getAttribute("data-duration")];
90+
};
91+
92+
describe("readFreezeSource", () => {
93+
it("reads the frame under the playhead from the source attributes", () => {
94+
expect(readFreezeSource(project, { id: "talk" }, 3.2)).toEqual({
95+
id: "talk",
96+
src: "talk.mp4",
97+
mediaTime: 4.2,
98+
});
99+
});
100+
101+
it("reads the in-point as playback does: data-playback-start before data-media-start", () => {
102+
const both = project.replace(
103+
'data-media-start="2"',
104+
'data-media-start="2" data-playback-start="5"',
105+
);
106+
expect(readFreezeSource(both, { id: "talk" }, 3.2)?.mediaTime).toBe(7.2);
107+
});
108+
109+
it("refuses a playhead outside the clip or a non-video", () => {
110+
expect(readFreezeSource(project, { id: "talk" }, 0.5)).toBeNull();
111+
expect(readFreezeSource(project, { id: "later" }, 8.5)).toBeNull();
112+
});
113+
});
114+
115+
describe("applyFreezeFrameToHtml", () => {
116+
const result = applyFreezeFrameToHtml(project, {
117+
target: { id: "talk" },
118+
playhead: 3.2,
119+
imageSrc: "assets/freeze/talk-3200.png",
120+
});
121+
const html = result?.html ?? "";
122+
123+
it("splits the video and inserts a 2 s still with the video's box styles", () => {
124+
expect(result?.freezeId).toBe("talk-freeze");
125+
expect(timing(html, "talk")).toEqual(["1", "2.2"]);
126+
const still = at(html, "talk-freeze");
127+
expect(still?.tagName).toBe("IMG");
128+
expect(timing(html, "talk-freeze")).toEqual(["3.2", "2"]);
129+
expect(still?.getAttribute("style")).toBe("left:10px;clip-path:inset(5px)");
130+
expect(still?.getAttribute("data-track-index")).toBe("0");
131+
expect(still?.getAttribute("data-timeline-label")).toBe("Freeze");
132+
expect(still?.hasAttribute("data-link")).toBe(false);
133+
});
134+
135+
it("moves the right half and the rest of the track right by the hold", () => {
136+
expect(timing(html, "talk-split")).toEqual(["5.2", "3.8"]);
137+
expect(at(html, "talk-split")?.getAttribute("data-media-start")).toBe("4.2");
138+
expect(timing(html, "later")).toEqual(["10", "1"]);
139+
expect(timing(html, "other")).toEqual(["5", "2"]);
140+
});
141+
142+
it("splits the linked audio, leaving a silent gap, and links the right halves together", () => {
143+
expect(timing(html, "talk-audio")).toEqual(["1", "2.2"]);
144+
expect(timing(html, "talk-audio-split")).toEqual(["5.2", "3.8"]);
145+
expect(at(html, "talk-split")?.getAttribute("data-link")).toBe("L-2");
146+
expect(at(html, "talk-audio-split")?.getAttribute("data-link")).toBe("L-2");
147+
expect(at(html, "talk-audio")?.getAttribute("data-link")).toBe("L");
148+
});
149+
150+
it("grows the root to fit the pushed clips", () => {
151+
expect(
152+
parseHTML(`<html><body>${html}</body></html>`)
153+
.document.querySelector("[data-composition-id]")
154+
?.getAttribute("data-duration"),
155+
).toBe("11");
156+
});
157+
158+
it("returns null when the playhead is not inside the video", () => {
159+
expect(
160+
applyFreezeFrameToHtml(project, { target: { id: "talk" }, playhead: 9, imageSrc: "x.png" }),
161+
).toBeNull();
162+
});
163+
});
164+
165+
describe("freezeStillFileName", () => {
166+
it("reduces a clip id to one safe filename component", () => {
167+
expect(freezeStillFileName("talk", 2.5, "t0")).toMatch(/^talk-[0-9a-f]{10}-2500-t0\.png$/);
168+
expect(freezeStillFileName("../../etc/x", 1, "t0")).toMatch(
169+
/^______etc_x-[0-9a-f]{10}-1000-t0\.png$/,
170+
);
171+
expect(freezeStillFileName("a\\b:c", 1, "t0")).toMatch(/^a_b_c-[0-9a-f]{10}-1000-t0\.png$/);
172+
expect(freezeStillFileName("", 1, "t0")).toMatch(/^clip-[0-9a-f]{10}-1000-t0\.png$/);
173+
});
174+
175+
it("keeps ids that sanitise or truncate alike apart", () => {
176+
expect(freezeStillFileName("a.b", 2.5, "t0")).not.toBe(freezeStillFileName("a_b", 2.5, "t0"));
177+
const prefix = "v".repeat(80);
178+
expect(freezeStillFileName(`${prefix}1`, 2.5, "t0")).not.toBe(
179+
freezeStillFileName(`${prefix}2`, 2.5, "t0"),
180+
);
181+
});
182+
183+
it("names every extraction of one clip at one time differently", () => {
184+
expect(freezeStillFileName("talk", 2.5)).not.toBe(freezeStillFileName("talk", 2.5));
185+
});
186+
});

0 commit comments

Comments
 (0)