mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* feat(core): add gentle ramp-in, ramp-out and slow-mo-middle speed presets Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * fix(studio): drop the unstyled badge classes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * refactor(studio): read the committed crop from the inline clip-path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * fix(studio-server): import replaceFileAtomically from core atomic-file Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
4.2 KiB
TypeScript
159 lines
4.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { RATE_TARGET, type HfAutomationLane } from "./audioAutomation.js";
|
|
import {
|
|
SPEED_PRESETS,
|
|
parseRateLane,
|
|
rateAt,
|
|
resolveRateSpec,
|
|
shiftRateLane,
|
|
sourceTimeAt,
|
|
speedPresetLane,
|
|
timeAtSourceTime,
|
|
} from "./speedRamp.js";
|
|
|
|
const ramp = (points: Array<[number, number]>): HfAutomationLane => ({
|
|
target: RATE_TARGET,
|
|
points: points.map(([t, v]) => ({ t, v })),
|
|
});
|
|
|
|
describe("sourceTimeAt", () => {
|
|
it("is t * rate for a constant", () => {
|
|
expect(sourceTimeAt(2, 3)).toBe(6);
|
|
});
|
|
|
|
it("integrates a geometric 1x to 3x ramp: 2s * (3-1)/ln 3 source seconds", () => {
|
|
expect(
|
|
sourceTimeAt(
|
|
ramp([
|
|
[0, 1],
|
|
[2, 3],
|
|
]),
|
|
2,
|
|
),
|
|
).toBeCloseTo(3.641, 3);
|
|
});
|
|
|
|
it("holds the last rate past the final point", () => {
|
|
expect(
|
|
sourceTimeAt(
|
|
ramp([
|
|
[0, 1],
|
|
[2, 3],
|
|
]),
|
|
4,
|
|
),
|
|
).toBeCloseTo(3.641 + 2 * 3, 3);
|
|
});
|
|
|
|
it("round-trips through timeAtSourceTime", () => {
|
|
const lane = ramp([
|
|
[0, 0.5],
|
|
[1, 4],
|
|
[3, 0.25],
|
|
]);
|
|
for (const t of [0, 0.4, 1, 2.2, 3, 5]) {
|
|
expect(timeAtSourceTime(lane, sourceTimeAt(lane, t))).toBeCloseTo(t, 3);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("rateAt", () => {
|
|
it("interpolates geometrically: the midpoint of 1x to 3x is sqrt(3)", () => {
|
|
expect(
|
|
rateAt(
|
|
ramp([
|
|
[0, 1],
|
|
[2, 3],
|
|
]),
|
|
1,
|
|
),
|
|
).toBeCloseTo(Math.sqrt(3), 5);
|
|
});
|
|
});
|
|
|
|
describe("shiftRateLane", () => {
|
|
it("sees the lane from dt seconds in: integrating from 1s of a 4s 1x to 3x ramp", () => {
|
|
const lane = ramp([
|
|
[0, 1],
|
|
[4, 3],
|
|
]);
|
|
// source(3) - source(1) = 4.6586 - 1.1508
|
|
expect(sourceTimeAt(shiftRateLane(lane, 1), 2)).toBeCloseTo(3.5078, 2);
|
|
});
|
|
});
|
|
|
|
describe("shiftRateLane with a shaped segment", () => {
|
|
it("keeps the curve of a segment cut in the middle: shifted integral equals the original's difference", () => {
|
|
const lane: HfAutomationLane = {
|
|
target: RATE_TARGET,
|
|
points: [
|
|
{ t: 0, v: 1, curve: 0.8 },
|
|
{ t: 4, v: 3 },
|
|
],
|
|
};
|
|
const expected = sourceTimeAt(lane, 4) - sourceTimeAt(lane, 1);
|
|
expect(sourceTimeAt(shiftRateLane(lane, 1), 3)).toBeCloseTo(expected, 2);
|
|
});
|
|
});
|
|
|
|
describe("lane parsing", () => {
|
|
const attr = JSON.stringify({
|
|
version: 1,
|
|
lanes: [{ target: "rate", points: [{ t: 0, v: 20 }] }],
|
|
});
|
|
|
|
it("clamps a stored rate to the shared 0.1..10 range", () => {
|
|
expect(rateAt(resolveRateSpec(attr, 1), 0)).toBe(10);
|
|
});
|
|
|
|
it("falls back to the constant when the attribute is absent or unreadable", () => {
|
|
expect(resolveRateSpec(null, 1.5)).toBe(1.5);
|
|
expect(resolveRateSpec("{nope", 2)).toBe(2);
|
|
expect(parseRateLane("{nope")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("presets", () => {
|
|
it("stretches every preset over the clip and keeps it in range", () => {
|
|
for (const { id } of SPEED_PRESETS) {
|
|
const lane = speedPresetLane(id, 8);
|
|
expect(lane.points[lane.points.length - 1]!.t).toBe(8);
|
|
for (const p of lane.points) expect(p.v).toBeGreaterThanOrEqual(0.1);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("gentle ramp presets", () => {
|
|
const speeds = (id: "ramp-in" | "ramp-out" | "slowmo-middle", duration: number) =>
|
|
speedPresetLane(id, duration).points.map((p) => [p.t, p.v]);
|
|
|
|
it("ramp-in eases from half speed up to normal", () => {
|
|
expect(speeds("ramp-in", 4)).toEqual([
|
|
[0, 0.5],
|
|
[4, 1],
|
|
]);
|
|
});
|
|
|
|
it("ramp-out eases from normal down to half speed", () => {
|
|
expect(speeds("ramp-out", 4)).toEqual([
|
|
[0, 1],
|
|
[4, 0.5],
|
|
]);
|
|
});
|
|
|
|
it("slowmo-middle holds 0.35x through the middle third and returns to normal", () => {
|
|
const lane = speedPresetLane("slowmo-middle", 6);
|
|
expect(rateAt(lane, 0)).toBe(1);
|
|
expect(rateAt(lane, 2)).toBeCloseTo(0.35, 5);
|
|
expect(rateAt(lane, 3)).toBeCloseTo(0.35, 5);
|
|
expect(rateAt(lane, 4)).toBeCloseTo(0.35, 5);
|
|
expect(rateAt(lane, 6)).toBe(1);
|
|
});
|
|
|
|
it("each consumes less source than the clip at normal speed", () => {
|
|
for (const id of ["ramp-in", "ramp-out", "slowmo-middle"] as const) {
|
|
expect(sourceTimeAt(speedPresetLane(id, 6), 6)).toBeLessThan(6);
|
|
}
|
|
});
|
|
});
|