* Export videos for named platforms and check each file against its limits Exports only knew aspect ratios, so a cut could still be rejected or degraded on upload: too long for the platform, over its size limit, or far off its loudness. export_video now takes platforms (TikTok, Instagram Reels and Feed, YouTube Shorts and YouTube, Facebook Reels, LinkedIn, X, Pinterest, Snapchat Spotlight), up to six targets with the presets. Each platform is rendered to its frame with the export's fit, its frame rate cap, a bitrate cap that also keeps the file under the size limit, and its loudness target in one loudnorm pass. Every render is probed and measured afterwards. A file over the size limit is encoded once more at a bitrate scaled from what it averaged, and audio more than 2 LU off the target gets one linear loudness pass. The result is stored on the output as a pass, warn or fail check with language-neutral issue codes. A platform the video is too long or too short for is not rendered: the card lists it with the reason, the other targets still render, and the bot is told to trim first. The limits come from the earlier profile research, with its sources, review date and unverified flag; content, disclosure and caption rules are left out because they need inference or a review flow. Preset definitions move to their own module so the platform schemas can use their aspect ratios without an import cycle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u * Add remove_silence step to edit_video Talking-head clips are mostly cut by hand to drop pauses, and the bot had no way to find them: it could only keep segments it guessed. The new remove_silence step finds every pause quieter than threshold_db (default -35 dB) and at least min_silence long (default 0.6 s), keeps padding (default 0.12 s) on each side so word onsets survive, and cuts the rest through the existing keep-segments graph, so picture and sound stay in sync. Steps run in order, so silence is detected on the timeline the steps before it leave: the planner gets an analysis mode that sends that audio through silencedetect into a null output, and ametadata prints the marks to a file in the job directory. The detected speech is handed back to the planner per step. Nothing silent makes the step a no-op; nothing left fails with a clear error. At most 200 pieces are kept, bridging the shortest pauses first, so the filter graph stays a sensible size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u * Offer platforms in the media card's export menu and show their checks The card's Export menu now lists the platforms first, by brand name and untranslated, then the aspect ratios after a separator; the platform an output was made for is left out, like its own shape. A platform export shows the platform's name under the player, or, when its check did not pass, one line for the first issue instead ("Too long for TikTok (max 10:00)"), in the warning or destructive color. Skipped platforms get the same kind of line, and they stand in for the error of a job that skipped every platform, so the card does not say the same thing twice in two languages. The E2E spec seeds a platform export with a failed check and a skipped platform, and captures the card and the open menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u * Add analyze_video to find cut points for the bot To cut a social video well the bot has to know where the cuts fit, and it could not look at a video at all. analyze_video is a read-only media job: one ffmpeg pass prints scene changes (scene score above 0.3, one per cut), pauses (silencedetect with the remove_silence defaults) and short-term loudness (ebur128) to files in the job directory, and a transcript made from the video by transcribe (an SRT whose parent is the video) adds when each line is spoken. The job stores nothing; its card just says done. The result reaches the bot through the existing media job path: the job always wakes the bot that started it (the tool has no continue_after) and the summary carries a short legend plus compact JSON. The runtime's summary limit grows to 12,000 characters and the summary is fitted into it: at most 200 entries per list, then every list shrinks evenly, keeping the strongest cuts, the longest pauses and the start of the transcript, with omitted counts. The wake prompt no longer claims the card shows the result when a job made no files. Jobs read derived artifacts through a new fetchDerivedArtifact, scoped to the job's user like fetchArtifact. A migration admits the operation in the media_jobs check and adds the tool to existing Studio specialists that still edit video. The web card gets an icon; no new copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u * fix(media): keep one skipped entry per platform on the card A job that recovers after a crash runs again and reports the same skipped platforms; the newest reason per platform now replaces the earlier one instead of listing it twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u * chore(db): add the widened media job operation check as NOT VALID and validate it separately Follows the repository's migration convention: the constraint commits without scanning media_jobs, and a second migration validates it with a lock that lets reads and writes continue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u --------- Co-authored-by: Claude <noreply@anthropic.com>
262 lines
9.1 KiB
TypeScript
262 lines
9.1 KiB
TypeScript
import type { MediaJobBlock } from "@rakazo/contracts";
|
|
import type { ReactNode } from "react";
|
|
import { renderToString } from "react-dom/server";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("@lingui/react/macro", () => {
|
|
const t = (parts: TemplateStringsArray, ...values: unknown[]) =>
|
|
parts.reduce((text, part, index) => `${text}${part}${values[index] ?? ""}`, "");
|
|
return { useLingui: () => ({ t }), Trans: ({ children }: { children: ReactNode }) => children };
|
|
});
|
|
vi.mock("@lingui/core/macro", () => ({
|
|
t: (parts: TemplateStringsArray, ...values: unknown[]) =>
|
|
parts.reduce((out, part, index) => `${out}${String(values[index - 1])}${part}`),
|
|
}));
|
|
vi.mock("../../pages/shell/message-cards", () => ({
|
|
ArtifactImage: ({ artifactId, name }: { artifactId: string; name: string }) => (
|
|
<img data-artifact={artifactId} alt={name} />
|
|
),
|
|
}));
|
|
vi.mock("../ArtifactFileCard", () => ({
|
|
ArtifactFileCard: ({ name }: { name: string }) => <span data-file-card="">{name}</span>,
|
|
}));
|
|
vi.mock("./MediaPlayer", () => ({
|
|
MediaPlayer: ({ artifactId, kind }: { artifactId: string; kind: string }) => (
|
|
<span data-player={kind} data-artifact={artifactId} />
|
|
),
|
|
}));
|
|
vi.mock("../../lib/rpc", () => ({ rpc: {}, selectedSpaceId: () => null }));
|
|
vi.mock("../../lib/artifact-url", () => ({
|
|
artifactUrl: (artifactId: string, options?: { download?: boolean }) =>
|
|
`/artifact/${artifactId}${options?.download ? "?download=1" : ""}`,
|
|
}));
|
|
|
|
import { exportPresetsFor, isActiveMediaStatus, MediaCardView } from "./MediaCard";
|
|
|
|
const video = {
|
|
artifactId: "video-1",
|
|
kind: "video" as const,
|
|
mimeType: "video/mp4",
|
|
name: "clip.mp4",
|
|
size: 2048,
|
|
width: 1920,
|
|
height: 1080,
|
|
};
|
|
|
|
function block(overrides: Partial<MediaJobBlock>): MediaJobBlock {
|
|
return {
|
|
kind: "media",
|
|
jobId: "job-1",
|
|
operation: "edit_video",
|
|
status: "done",
|
|
title: "Cut the intro",
|
|
outputs: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
const everything = { export: true, transcribe: true };
|
|
const noop = async () => undefined;
|
|
|
|
describe("media card", () => {
|
|
it.each([
|
|
["queued", "Queued"],
|
|
["waiting", "Waiting for GPU"],
|
|
["running", "Working…"],
|
|
["done", "Done"],
|
|
["failed", "Failed"],
|
|
["cancelled", "Cancelled"],
|
|
] as const)("labels a %s job as %s", (status, label) => {
|
|
const html = renderToString(<MediaCardView block={block({ status })} />);
|
|
expect(html).toContain(`data-status="${status}"`);
|
|
expect(html).toContain(label);
|
|
expect(html).toContain("Cut the intro");
|
|
});
|
|
|
|
it("shows progress and a cancel action while the job runs, and no result actions", () => {
|
|
const html = renderToString(
|
|
<MediaCardView
|
|
block={block({ status: "running", progress: 0.42, outputs: [video] })}
|
|
available={everything}
|
|
onAction={noop}
|
|
/>,
|
|
);
|
|
expect(html).toContain('role="progressbar"');
|
|
expect(html).toContain('aria-valuenow="42"');
|
|
expect(html).toContain("width:42%");
|
|
expect(html).toContain("Cancel");
|
|
expect(html).not.toContain("Export");
|
|
expect(html).not.toContain("Transcribe");
|
|
});
|
|
|
|
it("leaves the progress value out when the backend does not report one", () => {
|
|
const html = renderToString(<MediaCardView block={block({ status: "waiting" })} />);
|
|
expect(html).toContain('role="progressbar"');
|
|
expect(html).not.toContain("aria-valuenow");
|
|
});
|
|
|
|
it("offers download, export and transcribe for a finished video", () => {
|
|
const html = renderToString(
|
|
<MediaCardView block={block({ outputs: [video] })} available={everything} onAction={noop} />,
|
|
);
|
|
expect(html).toContain('data-player="video"');
|
|
expect(html).toContain('href="/artifact/video-1?download=1"');
|
|
expect(html).toContain('download="clip.mp4"');
|
|
expect(html).toContain('aria-label="Download clip.mp4"');
|
|
expect(html).toContain("Export");
|
|
expect(html).toContain("Transcribe");
|
|
expect(html).not.toContain("progressbar");
|
|
expect(html).not.toContain("Cancel");
|
|
});
|
|
|
|
it("shows a finished analysis as done, with nothing to open or act on", () => {
|
|
const html = renderToString(
|
|
<MediaCardView
|
|
block={block({ operation: "analyze_video", title: "Find the cut points" })}
|
|
available={everything}
|
|
onAction={noop}
|
|
/>,
|
|
);
|
|
expect(html).toContain('data-status="done"');
|
|
expect(html).toContain("Find the cut points");
|
|
expect(html).toContain("Done");
|
|
expect(html).toContain("lucide-scan-search");
|
|
expect(html).not.toContain("Download");
|
|
expect(html).not.toContain("Export");
|
|
expect(html).not.toContain("Transcribe");
|
|
});
|
|
|
|
it("offers only what the space can run and what fits the output", () => {
|
|
const audio = { ...video, artifactId: "audio-1", kind: "audio" as const, name: "take.m4a" };
|
|
const onlyTranscribe = renderToString(
|
|
<MediaCardView
|
|
block={block({ outputs: [audio] })}
|
|
available={{ export: true, transcribe: true }}
|
|
onAction={noop}
|
|
/>,
|
|
);
|
|
expect(onlyTranscribe).toContain('data-player="audio"');
|
|
expect(onlyTranscribe).toContain("Transcribe");
|
|
expect(onlyTranscribe).not.toContain("Export");
|
|
|
|
const nothingAvailable = renderToString(
|
|
<MediaCardView block={block({ outputs: [video] })} onAction={noop} />,
|
|
);
|
|
expect(nothingAvailable).toContain("Download clip.mp4");
|
|
expect(nothingAvailable).not.toContain("Export");
|
|
expect(nothingAvailable).not.toContain("Transcribe");
|
|
});
|
|
|
|
it("renders images as thumbnails and subtitle files as file cards", () => {
|
|
const html = renderToString(
|
|
<MediaCardView
|
|
block={block({
|
|
operation: "transcribe",
|
|
outputs: [
|
|
{ ...video, artifactId: "image-1", kind: "image", name: "still.png" },
|
|
{ ...video, artifactId: "srt-1", kind: "file", name: "clip.srt" },
|
|
{ ...video, artifactId: "vtt-1", kind: "file", name: "clip.vtt" },
|
|
],
|
|
})}
|
|
available={everything}
|
|
onAction={noop}
|
|
/>,
|
|
);
|
|
expect(html).toContain('data-artifact="image-1"');
|
|
expect(html).toContain("clip.srt");
|
|
expect(html).toContain("clip.vtt");
|
|
expect(html).not.toContain("Transcribe");
|
|
});
|
|
|
|
it("names the platform of an export, and its first problem only when the check did not pass", () => {
|
|
const tiktok = {
|
|
...video,
|
|
artifactId: "tiktok-1",
|
|
platform: "tiktok" as const,
|
|
check: { status: "pass" as const, issues: [] },
|
|
};
|
|
const shorts = {
|
|
...video,
|
|
artifactId: "shorts-1",
|
|
platform: "youtube-shorts" as const,
|
|
check: {
|
|
status: "warn" as const,
|
|
issues: [
|
|
{ code: "loudness_off" as const, targetLufs: -14, actualLufs: -18 },
|
|
{ code: "true_peak_high" as const, maxDb: -1, actualDb: 0 },
|
|
],
|
|
},
|
|
};
|
|
const html = renderToString(
|
|
<MediaCardView
|
|
block={block({ operation: "export_video", outputs: [tiktok, shorts, video] })}
|
|
/>,
|
|
);
|
|
expect(html).toContain('<p class="text-ui-body-sm text-muted-foreground">TikTok</p>');
|
|
expect(html).toContain(
|
|
'<p class="text-ui-body-sm text-warning">Too quiet for YouTube Shorts (target -14 LUFS)</p>',
|
|
);
|
|
expect(html).not.toContain("Peaks too high");
|
|
expect(html.match(/text-ui-body-sm text-(muted-foreground|warning|destructive)/g)).toHaveLength(
|
|
2,
|
|
);
|
|
});
|
|
|
|
it("lists skipped platforms, which also explain a job that rendered nothing", () => {
|
|
const skipped = [
|
|
{
|
|
platform: "snapchat-spotlight" as const,
|
|
issues: [{ code: "too_long" as const, maxMs: 60_000, actualMs: 75_000 }],
|
|
},
|
|
];
|
|
const partial = renderToString(
|
|
<MediaCardView block={block({ operation: "export_video", outputs: [video], skipped })} />,
|
|
);
|
|
expect(partial).toContain("Too long for Snapchat Spotlight (max 1:00)");
|
|
const failed = renderToString(
|
|
<MediaCardView
|
|
block={block({
|
|
operation: "export_video",
|
|
status: "failed",
|
|
error: "Not exported for Snapchat Spotlight: 75 s is longer than its 60 s limit",
|
|
skipped,
|
|
})}
|
|
/>,
|
|
);
|
|
expect(failed).toContain("Too long for Snapchat Spotlight (max 1:00)");
|
|
expect(failed).not.toContain("Not exported");
|
|
});
|
|
|
|
it("shows why a job failed", () => {
|
|
const html = renderToString(
|
|
<MediaCardView block={block({ status: "failed", error: "GPU server is unreachable" })} />,
|
|
);
|
|
expect(html).toContain("GPU server is unreachable");
|
|
});
|
|
});
|
|
|
|
describe("exportPresetsFor", () => {
|
|
it("leaves out the shape the video already has, labelled by aspect ratio elsewhere", () => {
|
|
expect(exportPresetsFor({ width: 1920, height: 1080 })).toEqual([
|
|
"vertical",
|
|
"square",
|
|
"portrait",
|
|
"classic",
|
|
"cinema",
|
|
]);
|
|
expect(exportPresetsFor({ width: 1080, height: 1920, preset: "vertical" })).not.toContain(
|
|
"vertical",
|
|
);
|
|
expect(exportPresetsFor({})).toHaveLength(6);
|
|
});
|
|
});
|
|
|
|
describe("isActiveMediaStatus", () => {
|
|
it("treats queued, waiting and running as active", () => {
|
|
expect(["queued", "waiting", "running"].every((s) => isActiveMediaStatus(s as never))).toBe(
|
|
true,
|
|
);
|
|
expect(isActiveMediaStatus("done")).toBe(false);
|
|
});
|
|
});
|