Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

feat: add video clips workflow

Joshuad9bc8feab529
diff --git a/apps/daemon/src/api/server.ts b/apps/daemon/src/api/server.ts
index 0b78a1d3..5e3180ba 100644
--- a/apps/daemon/src/api/server.ts
+++ b/apps/daemon/src/api/server.ts
@@ -102,6 +102,10 @@ import {
createVideoTranslationWorkflow,
type VideoTranslationWorkflow
} from '../creator/templates/video-translation-actions.js';
+import {
+ createAutoClipWorkflow,
+ type AutoClipWorkflow
+} from '../creator/templates/auto-clip-actions.js';
import {
createStickmanVideoWorkflow,
type StickmanVideoWorkflow
@@ -790,6 +794,7 @@ export async function buildServer(input: BuildServerInput) {
let coverWorkflow: CoverWorkflow | undefined;
let videoTranslationWorkflow: VideoTranslationWorkflow | undefined;
let stickmanVideoWorkflow: StickmanVideoWorkflow | undefined;
+ let autoClipWorkflow: AutoClipWorkflow | undefined;
const creatorStageRunner = input.creatorService === undefined
? createCreatorStageRunner({
repository: creatorRepository,
@@ -831,6 +836,9 @@ export async function buildServer(input: BuildServerInput) {
void stickmanVideoWorkflow?.handleStageChanged(stage).catch(error => {
console.warn(`Stickman video workflow continuation failed: ${formatError(error)}`);
});
+ void autoClipWorkflow?.handleStageChanged(stage).catch(error => {
+ console.warn(`Video clip workflow continuation failed: ${formatError(error)}`);
+ });
}
})
: undefined;
@@ -911,6 +919,12 @@ export async function buildServer(input: BuildServerInput) {
repository: creatorRepository,
providerLedger: creatorProviderRequestLedger
});
+ autoClipWorkflow = creatorStageRunner === undefined
+ ? undefined
+ : createAutoClipWorkflow({
+ creator: creatorService,
+ dispatcher: creatorCommandDispatcher
+ });
void coverWorkflow?.recover().catch(error => {
console.warn(`Cover workflow recovery failed: ${formatError(error)}`);
});
@@ -920,6 +934,9 @@ export async function buildServer(input: BuildServerInput) {
void stickmanVideoWorkflow?.recover().catch(error => {
console.warn(`Stickman video workflow recovery failed: ${formatError(error)}`);
});
+ void autoClipWorkflow?.recover().catch(error => {
+ console.warn(`Video clip workflow recovery failed: ${formatError(error)}`);
+ });
const scheduleRunInjector = createAgentScheduleRunInjector({
capabilities: agentCapabilityTokens,
getBaseUrl: getAgentToolBaseUrl,
diff --git a/apps/daemon/src/creator/clip/analyzer.ts b/apps/daemon/src/creator/clip/analyzer.ts
index 61865835..161d1ed0 100644
--- a/apps/daemon/src/creator/clip/analyzer.ts
+++ b/apps/daemon/src/creator/clip/analyzer.ts
@@ -2,14 +2,16 @@ import { z } from 'zod';
const candidateSchema = z.object({
id: z.string().min(1),
+ title: z.string().min(1),
start: z.number().nonnegative(),
end: z.number().positive(),
+ transcript: z.string().min(1),
reason: z.string().min(1),
scores: z.object({
- hook: z.number().min(0).max(10),
- information: z.number().min(0).max(10),
- emotion: z.number().min(0).max(10),
- completeness: z.number().min(0).max(10)
+ hook: z.number().min(0).max(100),
+ information: z.number().min(0).max(100),
+ emotion: z.number().min(0).max(100),
+ completeness: z.number().min(0).max(100)
}).strict()
}).strict();
@@ -22,6 +24,9 @@ export function parseClipCandidates(value: unknown, duration: number): ClipCandi
for (let index = 0; index < sorted.length; index += 1) {
const candidate = sorted[index]!;
if (candidate.end <= candidate.start || candidate.end > duration) throw new Error(`invalid_clip_range: ${candidate.id}`);
+ if (sorted.some((item, itemIndex) => itemIndex !== index && item.id === candidate.id)) {
+ throw new Error(`duplicate_clip_id: ${candidate.id}`);
+ }
if (index > 0 && candidate.start < sorted[index - 1]!.end) throw new Error(`overlapping_clip_range: ${candidate.id}`);
}
return sorted;
@@ -33,6 +38,10 @@ export async function analyzeClips(input: {
model: string;
transcript: string;
duration: number;
+ focus: 'balanced' | 'viral' | 'knowledge';
+ minDuration: number;
+ maxDuration: number;
+ count: number;
fetchImpl?: typeof fetch;
}): Promise<ClipCandidate[]> {
const response = await (input.fetchImpl ?? fetch)(`${input.baseUrl.replace(/\/$/, '') || 'https://api.openai.com/v1'}/chat/completions`, {
@@ -43,7 +52,7 @@ export async function analyzeClips(input: {
response_format: { type: 'json_object' },
messages: [{
role: 'user',
- content: `从字幕中选择不重叠的高光区间,输出 {"candidates":[{"id":"...","start":0,"end":10,"reason":"...","scores":{"hook":0,"information":0,"emotion":0,"completeness":0}}]}。媒体时长 ${input.duration} 秒。字幕:\n${input.transcript}`
+ content: buildClipAnalysisPrompt(input)
}]
})
});
@@ -51,5 +60,38 @@ export async function analyzeClips(input: {
const payload = await response.json() as { choices?: Array<{ message?: { content?: string } }> };
const content = payload.choices?.[0]?.message?.content;
if (!content) throw new Error('clip_analyzer_invalid_response');
- return parseClipCandidates(JSON.parse(content), input.duration);
+ const parsed = parseClipCandidates(JSON.parse(content), input.duration)
+ .filter(candidate => {
+ const duration = candidate.end - candidate.start;
+ return duration >= input.minDuration && duration <= input.maxDuration;
+ })
+ .slice(0, input.count);
+ if (parsed.length === 0) throw new Error('clip_analyzer_no_candidates');
+ return parsed;
+}
+
+function buildClipAnalysisPrompt(input: {
+ transcript: string;
+ duration: number;
+ focus: 'balanced' | 'viral' | 'knowledge';
+ minDuration: number;
+ maxDuration: number;
+ count: number;
+}): string {
+ const focus = input.focus === 'viral'
+ ? '优先寻找开头抓人、情绪明确、适合社交平台独立传播的片段'
+ : input.focus === 'knowledge'
+ ? '优先寻找观点完整、信息密度高、无需上下文也能理解的知识片段'
+ : '平衡开头吸引力、信息价值、情绪强度和观点完整度';
+ return [
+ '你是短视频剪辑分析器。请从字幕中选择互不重叠、脱离原视频也能独立成立的高光片段。',
+ `分析偏好:${focus}。`,
+ `返回最多 ${input.count} 个片段,每个片段时长必须在 ${input.minDuration}-${input.maxDuration} 秒之间。`,
+ '标题要简洁具体;transcript 必须是该时间范围内可直接展示给用户的完整字幕;reason 解释它为什么适合作为短视频。',
+ '四项评分均使用 0-100 的整数:hook 开头吸引力,information 信息价值,emotion 情绪强度,completeness 观点完整度。',
+ '只输出严格 JSON,不要 Markdown:',
+ '{"candidates":[{"id":"clip-1","title":"...","start":0,"end":30,"transcript":"...","reason":"...","scores":{"hook":0,"information":0,"emotion":0,"completeness":0}}]}',
+ `媒体总时长:${input.duration} 秒。`,
+ `字幕:\n${input.transcript}`
+ ].join('\n');
}
diff --git a/apps/daemon/src/creator/clip/executor.ts b/apps/daemon/src/creator/clip/executor.ts
index 4b003822..84791993 100644
--- a/apps/daemon/src/creator/clip/executor.ts
+++ b/apps/daemon/src/creator/clip/executor.ts
@@ -16,20 +16,59 @@ export function createClipExecutor(input: {
id: 'clip',
async run(stage) {
if (stage.stageRun.stageId === 'analyze') {
+ stage.reportProgress({
+ phase: 'validating',
+ percent: 5,
+ message: 'Checking the source video and analysis settings'
+ });
const config = await input.configStore.read();
if (!config.llm.apiKey) throw new CreatorExecutorError('creator_llm_config_missing', 'LLM configuration is incomplete');
const subtitle = stage.inputArtifacts.find(artifact => artifact.kind.includes('subtitle'))?.path;
const source = stage.inputArtifacts.find(artifact => artifact.kind === 'source_video')?.path;
if (!subtitle || !source) throw new CreatorExecutorError('creator_stage_input_missing', 'Video and subtitle are required');
const media = await validateMediaFile(source, input.ffprobePath);
+ const durationRange = readDurationRange(stage.job.state.duration);
+ const focus = readFocus(stage.job.state.focus);
+ const count = readClipCount(stage.job.state.clipCount);
+ stage.reportProgress({
+ phase: 'analyzing_clips',
+ percent: 30,
+ message: 'Finding the strongest standalone moments'
+ });
const candidates = await analyzeClips({
...config.llm,
transcript: await readFile(subtitle, 'utf8'),
- duration: media.duration
+ duration: media.duration,
+ focus,
+ minDuration: durationRange.min,
+ maxDuration: durationRange.max,
+ count
});
const path = join(stage.workdir, 'clip-candidates.json');
await writeFile(path, `${JSON.stringify({ candidates }, null, 2)}\n`);
- return { outputs: [{ kind: 'clip_candidates', status: 'completed', path, metadata: { candidates } }] };
+ const progress = {
+ phase: 'completed',
+ percent: 100,
+ completed: candidates.length,
+ failed: 0,
+ total: candidates.length,
+ message: `Found ${candidates.length} clip candidates`
+ };
+ stage.reportProgress(progress);
+ return {
+ outputs: [{
+ kind: 'clip_candidates',
+ status: 'completed',
+ path,
+ metadata: {
+ candidates,
+ focus,
+ duration: `${durationRange.min}-${durationRange.max}`,
+ clipCount: candidates.length
+ }
+ }],
+ progress
+ };
}
if (stage.stageRun.stageId === 'render') {
const source = stage.inputArtifacts.find(artifact => artifact.kind === 'source_video')?.path;
@@ -41,31 +80,135 @@ export function createClipExecutor(input: {
const candidates = parseClipCandidates(raw, duration);
const selectedIds = Array.isArray(stage.job.state.selectedCandidateIds)
? new Set(stage.job.state.selectedCandidateIds.filter(value => typeof value === 'string'))
- : new Set(candidates.map(candidate => candidate.id));
+ : new Set<string>();
const selected = candidates.filter(candidate => selectedIds.has(candidate.id));
if (selected.length === 0) throw new CreatorExecutorError('creator_clip_selection_missing', 'At least one clip must be selected');
- const output = join(stage.workdir, 'auto-clip.mp4');
- const videoFilters = selected.map((candidate, index) => (
- `[0:v]trim=start=${candidate.start}:end=${candidate.end},setpts=PTS-STARTPTS[v${index}]`
- ));
- const filter = sourceMedia.hasAudio
- ? videoFilters.concat(
- selected.map((candidate, index) => `[0:a]atrim=start=${candidate.start}:end=${candidate.end},asetpts=PTS-STARTPTS[a${index}]`),
- `${selected.map((_, index) => `[v${index}][a${index}]`).join('')}concat=n=${selected.length}:v=1:a=1[outv][outa]`
- ).join(';')
- : videoFilters.concat(`${selected.map((_, index) => `[v${index}]`).join('')}concat=n=${selected.length}:v=1:a=0[outv]`).join(';');
- await runProcess(input.ffmpegPath, [
- '-y', '-i', source, '-filter_complex', filter, '-map', '[outv]',
- ...(sourceMedia.hasAudio ? ['-map', '[outa]'] : ['-an']),
- output
- ], stage.signal);
- return { outputs: [{ kind: 'auto_clip_video', status: 'completed', path: output, metadata: await validateMediaFile(output, input.ffprobePath) }] };
+ const aspectRatio = readAspectRatio(stage.job.state.aspectRatio);
+ const outputs = [];
+ for (let index = 0; index < selected.length; index += 1) {
+ const candidate = selected[index]!;
+ const fileName = `${String(index + 1).padStart(2, '0')}-${safeFileName(candidate.title)}.mp4`;
+ const output = join(stage.workdir, fileName);
+ stage.reportProgress({
+ phase: 'rendering_clips',
+ percent: Math.round(index / selected.length * 100),
+ completed: index,
+ failed: 0,
+ total: selected.length,
+ message: `Rendering clip ${index + 1} of ${selected.length}`
+ });
+ await runProcess(input.ffmpegPath, buildClipArguments({
+ source,
+ output,
+ candidate,
+ aspectRatio,
+ hasAudio: sourceMedia.hasAudio
+ }), stage.signal);
+ outputs.push({
+ kind: 'auto_clip_video' as const,
+ status: 'completed' as const,
+ path: output,
+ sourceArtifactIds: [candidateArtifact.id, ...candidateArtifact.sourceArtifactIds],
+ metadata: {
+ ...await validateMediaFile(output, input.ffprobePath),
+ fileName,
+ candidateId: candidate.id,
+ title: candidate.title,
+ transcript: candidate.transcript,
+ start: candidate.start,
+ end: candidate.end,
+ duration: candidate.end - candidate.start,
+ aspectRatio,
+ candidateArtifactId: candidateArtifact.id
+ }
+ });
+ }
+ const progress = {
+ phase: 'completed',
+ percent: 100,
+ completed: outputs.length,
+ failed: 0,
+ total: outputs.length,
+ message: `Rendered ${outputs.length} clips`
+ };
+ stage.reportProgress(progress);
+ return { outputs, progress };
}
throw new CreatorExecutorError('creator_stage_not_supported', 'Unsupported clip stage');
}
};
}
+type ClipAspectRatio = 'source' | '16:9' | '9:16' | '1:1';
+
+function buildClipArguments(input: {
+ source: string;
+ output: string;
+ candidate: ReturnType<typeof parseClipCandidates>[number];
+ aspectRatio: ClipAspectRatio;
+ hasAudio: boolean;
+}): string[] {
+ const format = aspectRatioFilter(input.aspectRatio);
+ const videoFilter = [
+ `trim=start=${input.candidate.start}:end=${input.candidate.end}`,
+ 'setpts=PTS-STARTPTS',
+ ...format,
+ 'format=yuv420p'
+ ].join(',');
+ const filter = input.hasAudio
+ ? `[0:v]${videoFilter}[outv];[0:a]atrim=start=${input.candidate.start}:end=${input.candidate.end},asetpts=PTS-STARTPTS[outa]`
+ : `[0:v]${videoFilter}[outv]`;
+ return [
+ '-y',
+ '-i', input.source,
+ '-filter_complex', filter,
+ '-map', '[outv]',
+ ...(input.hasAudio ? ['-map', '[outa]', '-c:a', 'aac'] : ['-an']),
+ '-c:v', 'libx264',
+ '-preset', 'medium',
+ '-movflags', '+faststart',
+ input.output
+ ];
+}
+
+function aspectRatioFilter(value: ClipAspectRatio): string[] {
+ if (value === '16:9') return ['scale=1920:1080:force_original_aspect_ratio=increase', 'crop=1920:1080'];
+ if (value === '9:16') return ['scale=1080:1920:force_original_aspect_ratio=increase', 'crop=1080:1920'];
+ if (value === '1:1') return ['scale=1080:1080:force_original_aspect_ratio=increase', 'crop=1080:1080'];
+ return ['scale=trunc(iw/2)*2:trunc(ih/2)*2'];
+}
+
+function readFocus(value: unknown): 'balanced' | 'viral' | 'knowledge' {
+ return value === 'viral' || value === 'knowledge' ? value : 'balanced';
+}
+
+function readDurationRange(value: unknown): { min: number; max: number } {
+ if (value === '15-30') return { min: 15, max: 30 };
+ if (value === '60-90') return { min: 60, max: 90 };
+ return { min: 30, max: 60 };
+}
+
+function readClipCount(value: unknown): number {
+ return typeof value === 'number' && Number.isFinite(value)
+ ? Math.max(1, Math.min(20, Math.round(value)))
+ : 10;
+}
+
+function readAspectRatio(value: unknown): ClipAspectRatio {
+ return value === '16:9' || value === '9:16' || value === '1:1' ? value : 'source';
+}
+
+function safeFileName(value: string): string {
+ const normalized = value
+ .normalize('NFKC')
+ .replace(/[\\/:*?"<>|]/g, '-')
+ .replace(/\s+/g, '-')
+ .replace(/-+/g, '-')
+ .replace(/^-|-$/g, '')
+ .slice(0, 80);
+ return normalized || 'video-clip';
+}
+
function runProcess(binary: string, args: string[], signal: AbortSignal): Promise<void> {
return new Promise((resolve, reject) => {
const child = spawnCreatorProcess(binary, args, { stdio: ['ignore', 'ignore', 'pipe'] }, signal);
diff --git a/apps/daemon/src/creator/krillin/adapter.ts b/apps/daemon/src/creator/krillin/adapter.ts
index 96fd7e01..2e378ab2 100644
--- a/apps/daemon/src/creator/krillin/adapter.ts
+++ b/apps/daemon/src/creator/krillin/adapter.ts
@@ -39,11 +39,6 @@ export function createKrillinExecutor(input: {
async run(stage): Promise<CreatorExecutorResult> {
const configured = await input.configStore.read();
const preflight = preflightKrillinDependencies(input.resourceRoot, configured);
- await ensureKrillinTranscriptionDependency(
- input.dependencyLoader,
- preflight.config,
- stage
- );
const ffprobe = executablePath(input.resourceRoot, /(?:^|\/)ffprobe(?:\.exe)?$/i);
const materializedArtifacts = await writeArtifactIndex(input.jobsRoot, stage);
const options = buildKrillinStageOptions(stage);
@@ -51,11 +46,22 @@ export function createKrillinExecutor(input: {
try {
const attempts = createKrillinCliExecutionPlan(
resolveKrillinStageContract(stage).stageType,
+ {
+ sourceUrl: stringValue(options.sourceUrl),
+ mediaSource: resolveKrillinCliSource(materializedArtifacts, options)
+ },
options
);
let completed: KrillinResultArtifact[] | undefined;
for (const attempt of attempts) {
try {
+ if (requiresTranscriptionDependency(stage.stageRun.stageId, attempt.options)) {
+ await ensureKrillinTranscriptionDependency(
+ input.dependencyLoader,
+ preflight.config,
+ stage
+ );
+ }
completed = await runKrillinCli({
resourceRoot: input.resourceRoot,
jobsRoot: input.jobsRoot,
@@ -64,6 +70,7 @@ export function createKrillinExecutor(input: {
stage,
config: preflight.config,
artifacts: materializedArtifacts,
+ source: attempt.source,
options: attempt.options,
ytDlpRuntime: input.getYtDlpRuntime?.()
});
@@ -93,10 +100,14 @@ export function createKrillinExecutor(input: {
});
throw new CreatorExecutorError(normalized.code, normalized.message);
}
+ const relevantArtifacts = stage.job.templateId === 'auto-clip'
+ && stage.stageRun.stageId === 'subtitle'
+ ? artifacts.filter(artifact => artifact.kind === 'target_subtitle')
+ : artifacts;
const outputs = await validateResultArtifacts({
stage,
jobsRoot: input.jobsRoot,
- artifacts,
+ artifacts: relevantArtifacts,
ffprobe
});
return {
@@ -113,6 +124,13 @@ export function createKrillinExecutor(input: {
};
}
+function requiresTranscriptionDependency(
+ stageId: string,
+ options: Record<string, unknown>
+): boolean {
+ return stageId === 'subtitle' && options.captionSource !== 'platform';
+}
+
async function ensureKrillinTranscriptionDependency(
loader: KrillinDependencyLoader,
config: CreatorServicesConfig,
@@ -335,13 +353,21 @@ export function resolveKrillinStageContract(
requiredOutputKinds: ['bilingual_video']
};
}
+ if (input.job.templateId === 'auto-clip' && stageId === 'subtitle') {
+ return {
+ stageType: 'subtitle',
+ allowedOutputKinds: new Set(['target_subtitle']),
+ outputAliases: { target_subtitle: 'target_subtitle' },
+ requiredOutputKinds: ['target_subtitle']
+ };
+ }
if (stageId === 'subtitle' || stageId === 'tts' || stageId === 'render-horizontal' || stageId === 'render-vertical') {
const expected = expectedOutputKinds(stageId);
return {
stageType: stageId,
allowedOutputKinds: expected,
outputAliases: Object.fromEntries([...expected].map(kind => [kind, kind])),
- requiredOutputKinds: requiredOutputKinds(stageId)
+ requiredOutputKinds: requiredOutputKinds(stageId, input.job.templateId)
};
}
throw new CreatorExecutorError('creator_stage_not_supported', `Unsupported KrillinAI stage ${stageId}`);
@@ -375,7 +401,10 @@ function expectedOutputKinds(stageId: string): Set<string> {
return new Set();
}
-function requiredOutputKinds(stageId: string): string[] {
+function requiredOutputKinds(stageId: string, templateId?: string): string[] {
+ if (stageId === 'subtitle' && templateId === 'auto-clip') {
+ return ['target_subtitle'];
+ }
if (stageId === 'subtitle') {
return ['source_video', 'source_subtitle', 'target_subtitle', 'vertical_subtitle'];
}
@@ -394,6 +423,10 @@ function compactObject(value: Record<string, unknown>): Record<string, unknown>
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
}
+function stringValue(value: unknown): string | undefined {
+ return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
+}
+
function nonEmptyString(value: CreatorJson | undefined): string | undefined {
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
}
diff --git a/apps/daemon/src/creator/krillin/cli-runner.ts b/apps/daemon/src/creator/krillin/cli-runner.ts
index 8831bda5..90026cd1 100644
--- a/apps/daemon/src/creator/krillin/cli-runner.ts
+++ b/apps/daemon/src/creator/krillin/cli-runner.ts
@@ -79,6 +79,7 @@ type RunKrillinCliInput = {
stage: CreatorExecutorInput;
config: CreatorServicesConfig;
artifacts: MaterializedKrillinArtifact[];
+ source?: string;
options: Record<string, unknown>;
ytDlpRuntime?: YtDlpRuntime;
};
@@ -125,7 +126,13 @@ export async function runKrillinCli(input: RunKrillinCliInput): Promise<KrillinR
await writeInitialManifest(input.stage, input.options);
}
- const args = buildKrillinCliCommandArguments(input.stage, input.artifacts, input.options, stylePath);
+ const args = buildKrillinCliCommandArguments(
+ input.stage,
+ input.artifacts,
+ input.options,
+ stylePath,
+ input.source
+ );
input.stage.reportProgress({
krillinMode: 'cli',
providerStatus: 'running',
@@ -211,12 +218,13 @@ export function buildKrillinCliCommandArguments(
stage: CreatorExecutorInput,
artifacts: MaterializedKrillinArtifact[],
options: Record<string, unknown>,
- stylePath: string | undefined
+ stylePath: string | undefined,
+ sourceOverride?: string
): string[] {
const command = krillinCliStageId(stage.stageRun.stageId);
const common = ['--workdir', stage.workdir, '--task-id', stage.stageRun.id];
if (command === 'subtitle') {
- const source = resolveKrillinCliSource(artifacts, options);
+ const source = sourceOverride ?? resolveKrillinCliSource(artifacts, options);
if (!source) throw new CreatorExecutorError('creator_stage_input_missing', 'Subtitle input video or URL is required');
const sourceOnly = booleanOption(options, 'sourceOnly', false);
return [
diff --git a/apps/daemon/src/creator/krillin/execution-plan.ts b/apps/daemon/src/creator/krillin/execution-plan.ts
index bea40736..42b2b82c 100644
--- a/apps/daemon/src/creator/krillin/execution-plan.ts
+++ b/apps/daemon/src/creator/krillin/execution-plan.ts
@@ -1,17 +1,55 @@
export type KrillinCliExecutionAttempt = {
+ source?: string;
options: Record<string, unknown>;
continueOnErrorCode?: string;
};
+export type KrillinCliExecutionSources = {
+ sourceUrl?: string;
+ mediaSource?: string;
+};
+
export function createKrillinCliExecutionPlan(
stageId: string,
- options: Record<string, unknown>
+ sourcesOrOptions: KrillinCliExecutionSources | Record<string, unknown>,
+ maybeOptions?: Record<string, unknown>
): KrillinCliExecutionAttempt[] {
- return [{
- options: stageId === 'subtitle' && stringOption(options, 'captionSource') === undefined
- ? { ...options, captionSource: 'any' }
- : options
- }];
+ const sources = maybeOptions === undefined ? {} : sourcesOrOptions as KrillinCliExecutionSources;
+ const options = maybeOptions ?? sourcesOrOptions as Record<string, unknown>;
+ if (maybeOptions === undefined) {
+ return [{
+ options: stageId === 'subtitle' && stringOption(options, 'captionSource') === undefined
+ ? { ...options, captionSource: 'any' }
+ : options
+ }];
+ }
+ if (stageId !== 'subtitle') {
+ return [{ options }];
+ }
+
+ const captionSource = stringOption(options, 'captionSource') ?? 'any';
+ const mediaSource = sources.mediaSource ?? sources.sourceUrl;
+ if (!isYouTubeSource(sources.sourceUrl) || captionSource === 'whisper') {
+ return [{ ...(mediaSource === undefined ? {} : { source: mediaSource }), options }];
+ }
+ if (captionSource !== 'any') {
+ return [{
+ ...(sources.sourceUrl === undefined ? {} : { source: sources.sourceUrl }),
+ options
+ }];
+ }
+
+ return [
+ {
+ source: sources.sourceUrl,
+ options: { ...options, captionSource: 'platform' },
+ continueOnErrorCode: 'platform_caption_failed'
+ },
+ {
+ ...(mediaSource === undefined ? {} : { source: mediaSource }),
+ options: { ...options, captionSource: 'whisper' }
+ }
+ ];
}
export function isYouTubeSource(value: string | undefined): boolean {
diff --git a/apps/daemon/src/creator/service.ts b/apps/daemon/src/creator/service.ts
index 6095f315..e837eef0 100644
--- a/apps/daemon/src/creator/service.ts
+++ b/apps/daemon/src/creator/service.ts
@@ -138,10 +138,13 @@ export function createCreatorService(input: {
current.revision
);
}
- if (current.templateId !== 'video-translation') {
+ if (
+ current.templateId !== 'video-translation'
+ && current.templateId !== 'auto-clip'
+ ) {
throw new CreatorServiceError(
'creator_source_upload_unsupported',
- 'Local source upload is only supported for video translation jobs'
+ 'Local source upload is only supported for video translation or video clip jobs'
);
}
const duplicate = [...current.artifacts].reverse().find(artifact => (
@@ -694,7 +697,10 @@ export function createCreatorService(input: {
} else if (request.action === 'update-settings' || request.action === 'undo-action') {
const patch = readNonEmptyRecord(parsedInput.patch, 'patch');
nextState = { ...nextState, ...patch };
- if (current.templateId === 'video-translation' && nextState.sourceType === 'url') {
+ if (
+ (current.templateId === 'video-translation' || current.templateId === 'auto-clip')
+ && nextState.sourceType === 'url'
+ ) {
nextState.sourceArtifactId = null;
}
if (shouldClearTtsConfigurationRequest(current, nextState)) {
diff --git a/apps/daemon/src/creator/stage-runner.ts b/apps/daemon/src/creator/stage-runner.ts
index 8b2c8105..ac3c8721 100644
--- a/apps/daemon/src/creator/stage-runner.ts
+++ b/apps/daemon/src/creator/stage-runner.ts
@@ -1,7 +1,13 @@
import { createHash } from 'node:crypto';
import { mkdir, readFile } from 'node:fs/promises';
import { join } from 'node:path';
-import type { CreatorArtifact, CreatorJob, CreatorJson, CreatorStageRun } from '@opencreator/protocol';
+import {
+ readCreatorResultSnapshots,
+ type CreatorArtifact,
+ type CreatorJob,
+ type CreatorJson,
+ type CreatorStageRun
+} from '@opencreator/protocol';
import type { CreatorExecutor } from './executor.js';
import { CreatorExecutorError } from './executor.js';
import type { CreatorRepository } from './repository.js';
@@ -167,7 +173,7 @@ export function createCreatorStageRunner(input: {
const createsResultVersion = stage.resultVersionPolicy !== 'none';
const targetResultVersion = readPositiveInteger(stageRun!.progress.targetResultVersion);
const resultVersion = createsResultVersion
- ? targetResultVersion ?? nextCreatorResultVersion(beforeOutputs)
+ ? targetResultVersion ?? nextStageResultVersion(beforeOutputs, stageId)
: undefined;
const insertedArtifacts: CreatorArtifact[] = [];
const changedKinds = new Set(result.outputs.map(output => output.kind));
@@ -222,6 +228,9 @@ export function createCreatorStageRunner(input: {
...(job.templateId === 'cover'
? artifactRefsByKind(resolved.artifacts)
: {}),
+ ...(job.templateId === 'auto-clip' && stageId === 'analyze'
+ ? artifactRefsByKind(resolved.artifacts)
+ : {}),
...(job.templateId === 'video-translation'
? videoTranslationArtifactRefsPatch(job.state, stageId)
: {}),
@@ -618,6 +627,10 @@ function resultSnapshotDescription(stageId: string, templateId: string): string
if (stageId === 'article') return '撰写公众号文章';
if (stageId === 'images') return '生成文章配图';
}
+ if (templateId === 'auto-clip') {
+ if (stageId === 'analyze') return '识别视频高光片段';
+ if (stageId === 'render') return '导出视频切片';
+ }
if (stageId === 'subtitle') return '生成字幕';
if (stageId === 'tts') return '生成配音';
if (stageId === 'render-horizontal') return '合成横屏视频';
@@ -632,6 +645,16 @@ function resultSnapshotDescription(stageId: string, templateId: string): string
return `完成 ${stageId}`;
}
+function nextStageResultVersion(job: CreatorJob, stageId: string): number {
+ if (job.templateId !== 'auto-clip' || stageId !== 'analyze') {
+ return nextCreatorResultVersion(job);
+ }
+ const snapshotVersion = readCreatorResultSnapshots(job.state.resultSnapshots)
+ .reduce((highest, snapshot) => Math.max(highest, snapshot.version), 0);
+ const stateVersion = readPositiveInteger(job.state.latestResultVersion) ?? 0;
+ return Math.max(snapshotVersion, stateVersion) + 1;
+}
+
function creatorConfigurationInput(code: string, message: string): Record<string, CreatorJson> | null {
const section = code === 'creator_llm_config_missing'
? 'llm'
diff --git a/apps/daemon/src/creator/templates/auto-clip-actions.ts b/apps/daemon/src/creator/templates/auto-clip-actions.ts
new file mode 100644
index 00000000..e5c9800d
--- /dev/null
+++ b/apps/daemon/src/creator/templates/auto-clip-actions.ts
@@ -0,0 +1,76 @@
+import type { CreatorJob, CreatorStageRun } from '@opencreator/protocol';
+import type { CreatorCommandDispatcher } from '../command-dispatcher.js';
+import type { CreatorService } from '../service.js';
+
+export type AutoClipWorkflow = ReturnType<typeof createAutoClipWorkflow>;
+
+export function createAutoClipWorkflow(input: {
+ creator: CreatorService;
+ dispatcher: Pick<CreatorCommandDispatcher, 'dispatch'>;
+}) {
+ async function continueFrom(stage: CreatorStageRun): Promise<void> {
+ if (stage.status !== 'succeeded' || stage.progress.workflow !== true) return;
+ const job = input.creator.getJob(stage.jobId);
+ if (job === undefined || job.templateId !== 'auto-clip') return;
+ const nextStageId = nextWorkflowStage(stage.stageId);
+ if (nextStageId === undefined) return;
+ queueNextStage(job, stage, nextStageId, input.dispatcher);
+ }
+
+ return {
+ async handleStageChanged(stage: CreatorStageRun): Promise<void> {
+ await continueFrom(stage);
+ },
+ async recover(): Promise<void> {
+ for (const job of input.creator.listJobs()) {
+ if (job.templateId !== 'auto-clip') continue;
+ const completed = [...job.stages].reverse().find(stage => (
+ stage.status === 'succeeded'
+ && stage.progress.workflow === true
+ && nextWorkflowStage(stage.stageId) !== undefined
+ && !hasLaterWorkflowStage(job, stage)
+ ));
+ if (completed !== undefined) await continueFrom(completed);
+ }
+ }
+ };
+}
+
+function nextWorkflowStage(stageId: string): string | undefined {
+ if (stageId === 'probe') return 'download';
+ if (stageId === 'download') return 'subtitle';
+ if (stageId === 'subtitle') return 'analyze';
+ return undefined;
+}
+
+function queueNextStage(
+ job: CreatorJob,
+ completed: CreatorStageRun,
+ nextStageId: string,
+ dispatcher: Pick<CreatorCommandDispatcher, 'dispatch'>
+): void {
+ const alreadyQueued = job.stages.some(stage => (
+ stage.stageId === nextStageId
+ && stage.progress.workflowParentStageRunId === completed.id
+ ));
+ if (alreadyQueued) return;
+ dispatcher.dispatch(job.id, {
+ action: 'run-stage',
+ expectedRevision: job.revision,
+ idempotencyKey: `auto-clip:${completed.id}:${nextStageId}`,
+ input: {
+ stageId: nextStageId,
+ workflow: true,
+ workflowParentStageRunId: completed.id
+ }
+ }, 'system');
+}
+
+function hasLaterWorkflowStage(job: CreatorJob, completed: CreatorStageRun): boolean {
+ const nextStageId = nextWorkflowStage(completed.stageId);
+ if (nextStageId === undefined) return true;
+ return job.stages.some(stage => (
+ stage.stageId === nextStageId
+ && stage.progress.workflowParentStageRunId === completed.id
+ ));
+}
diff --git a/apps/daemon/src/creator/templates/auto-clip.ts b/apps/daemon/src/creator/templates/auto-clip.ts
index db3507a3..879d2b0f 100644
--- a/apps/daemon/src/creator/templates/auto-clip.ts
+++ b/apps/daemon/src/creator/templates/auto-clip.ts
@@ -1,7 +1,8 @@
import { z } from 'zod';
import type { CreatorTemplateDefinition } from './types.js';
const record = z.record(z.string(), z.unknown()) as never;
-export function createAutoClipTemplate(): CreatorTemplateDefinition {
+
+export function createLegacyAutoClipTemplate(): CreatorTemplateDefinition {
return {
id: 'auto-clip', version: 1, renderer: 'auto-clips',
inputSchema: z.object({
@@ -31,3 +32,93 @@ export function createAutoClipTemplate(): CreatorTemplateDefinition {
agentGuidance: '先分析并展示四维评分候选,用户选择后再渲染。'
};
}
+
+export function createAutoClipTemplate(): CreatorTemplateDefinition {
+ return {
+ id: 'auto-clip',
+ version: 2,
+ renderer: 'auto-clips',
+ inputSchema: z.object({
+ sourceType: z.enum(['url', 'file']).default('url'),
+ sourceUrl: z.string().default(''),
+ sourceArtifactId: z.string().nullable().default(null),
+ formatId: z.string().default('bestvideo+bestaudio/best'),
+ sourceLanguage: z.string().default('auto'),
+ targetLanguage: z.string().default('zh-CN'),
+ preferPlatformCaptions: z.boolean().default(true),
+ focus: z.enum(['balanced', 'viral', 'knowledge']).default('balanced'),
+ duration: z.enum(['15-30', '30-60', '60-90']).default('30-60'),
+ clipCount: z.number().int().min(1).max(20).default(10),
+ aspectRatio: z.enum(['source', '16:9', '9:16', '1:1']).default('9:16'),
+ selectedCandidateIds: z.array(z.string()).default([]),
+ currentStage: z.string().nullable().default(null)
+ }).passthrough() as never,
+ stages: [
+ {
+ id: 'probe',
+ executor: 'download',
+ completesJob: false,
+ resultVersionPolicy: 'none',
+ allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
+ inputArtifacts: [],
+ outputArtifacts: [{ kind: 'download_probe', status: 'completed' }]
+ },
+ {
+ id: 'download',
+ executor: 'download',
+ completesJob: false,
+ resultVersionPolicy: 'none',
+ dependsOn: ['probe'],
+ allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
+ inputArtifacts: [{ kind: 'download_probe', selector: 'latest-completed' }],
+ outputArtifacts: [{ kind: 'source_video', status: 'completed' }]
+ },
+ {
+ id: 'subtitle',
+ executor: 'krillinai',
+ completesJob: false,
+ resultVersionPolicy: 'none',
+ dependsOn: ['download'],
+ allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
+ inputArtifacts: [{ kind: 'source_video', selector: 'latest-completed' }],
+ outputArtifacts: [{ kind: 'target_subtitle', status: 'completed' }]
+ },
+ {
+ id: 'analyze',
+ executor: 'clip',
+ completesJob: false,
+ dependsOn: ['subtitle'],
+ allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
+ inputArtifacts: [
+ { kind: 'source_video', selector: 'latest-completed' },
+ { kind: 'target_subtitle', selector: 'latest-completed' }
+ ],
+ outputArtifacts: [{ kind: 'clip_candidates', status: 'completed' }]
+ },
+ {
+ id: 'render',
+ executor: 'clip',
+ resultVersionPolicy: 'none',
+ dependsOn: ['analyze'],
+ allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
+ inputArtifacts: [
+ { kind: 'source_video', selector: 'latest-completed' },
+ { kind: 'clip_candidates', selector: 'latest-completed' }
+ ],
+ outputArtifacts: [{ kind: 'auto_clip_video', status: 'completed' }]
+ }
+ ],
+ actions: [
+ { id: 'update-settings', inputSchema: record, allowedStages: ['probe', 'download', 'subtitle', 'analyze', 'render'] },
+ { id: 'run-stage', inputSchema: record, allowedStages: ['probe', 'download', 'subtitle', 'analyze', 'render'] },
+ { id: 'undo-action', inputSchema: record, allowedStages: ['probe', 'download', 'subtitle', 'analyze', 'render'] }
+ ],
+ outputs: [{ kind: 'auto_clip_video', required: true }],
+ agentGuidance: [
+ '这是视频切片模板。',
+ 'URL 来源从 probe 开始并设置 workflow=true,本地或导入视频从 subtitle 开始并设置 workflow=true。',
+ 'analyze 完成后先展示候选片段与评分,用户选择 selectedCandidateIds 后再运行 render。',
+ '不得把多个候选片段拼接成一个文件。'
+ ].join(' ')
+ };
+}
diff --git a/apps/daemon/src/creator/templates/registry.ts b/apps/daemon/src/creator/templates/registry.ts
index 9227b7a3..079a62aa 100644
--- a/apps/daemon/src/creator/templates/registry.ts
+++ b/apps/daemon/src/creator/templates/registry.ts
@@ -9,7 +9,7 @@ import {
createLegacyImageGenerationTemplate
} from './image-generation.js';
import { createVideoGenerationTemplate } from './video-generation.js';
-import { createAutoClipTemplate } from './auto-clip.js';
+import { createAutoClipTemplate, createLegacyAutoClipTemplate } from './auto-clip.js';
import { createStickmanVideoTemplate } from './stickman-video.js';
import { createSmartDubbingTemplate } from './smart-dubbing.js';
import { createXiaohongshuPostTemplate } from './xiaohongshu-post.js';
@@ -22,6 +22,7 @@ import type {
export {
createAutoClipTemplate,
+ createLegacyAutoClipTemplate,
createCoverTemplate,
createLegacyCoverTemplate,
createImageGenerationTemplate,
@@ -51,6 +52,7 @@ export function createDefaultCreatorTemplateRegistry(): CreatorTemplateRegistry
createVideoGenerationTemplate(),
createShortVideoScriptTemplate(),
createWechatArticleTemplate(),
+ createLegacyAutoClipTemplate(),
createAutoClipTemplate(),
createStickmanVideoTemplate()
]);
diff --git a/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts b/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts
new file mode 100644
index 00000000..59aa544b
--- /dev/null
+++ b/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts
@@ -0,0 +1,115 @@
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { afterEach, describe, expect, it } from 'vitest';
+import { createCreatorAgentRepository } from '../../src/creator/agent/repository.js';
+import { createCreatorCommandDispatcher } from '../../src/creator/command-dispatcher.js';
+import { createCreatorRepository } from '../../src/creator/repository.js';
+import { createCreatorService } from '../../src/creator/service.js';
+import { createAutoClipWorkflow } from '../../src/creator/templates/auto-clip-actions.js';
+import { createDefaultCreatorTemplateRegistry } from '../../src/creator/templates/registry.js';
+import { openRuntimeDatabase } from '../../src/storage/database.js';
+
+let tempDir = '';
+
+afterEach(() => {
+ if (tempDir) rmSync(tempDir, { recursive: true, force: true });
+ tempDir = '';
+});
+
+describe('auto clip workflow', () => {
+ it('queues URL preparation, transcription, and analysis in order', async () => {
+ const fixture = setup('url');
+ const probe = fixture.dispatcher.dispatch(fixture.jobId, {
+ action: 'run-stage',
+ expectedRevision: 0,
+ idempotencyKey: 'auto-clip-url',
+ input: { stageId: 'probe', workflow: true }
+ }, 'user').commandReceipt.stageRunId!;
+
+ const download = await succeedAndContinue(fixture, probe);
+ expect(download).toMatchObject({
+ stageId: 'download',
+ progress: { workflow: true, workflowParentStageRunId: probe }
+ });
+ const subtitle = await succeedAndContinue(fixture, download.id);
+ expect(subtitle.stageId).toBe('subtitle');
+ const analyze = await succeedAndContinue(fixture, subtitle.id);
+ expect(analyze.stageId).toBe('analyze');
+ await succeedAndContinue(fixture, analyze.id);
+
+ expect(fixture.service.getJob(fixture.jobId)?.stages.map(stage => stage.stageId))
+ .toEqual(['probe', 'download', 'subtitle', 'analyze']);
+ fixture.db.close();
+ });
+
+ it('starts imported and uploaded videos at transcription', async () => {
+ const fixture = setup('file');
+ const subtitle = fixture.dispatcher.dispatch(fixture.jobId, {
+ action: 'run-stage',
+ expectedRevision: 0,
+ idempotencyKey: 'auto-clip-file',
+ input: { stageId: 'subtitle', workflow: true }
+ }, 'user').commandReceipt.stageRunId!;
+
+ const analyze = await succeedAndContinue(fixture, subtitle);
+
+ expect(analyze).toMatchObject({
+ stageId: 'analyze',
+ progress: { workflow: true, workflowParentStageRunId: subtitle }
+ });
+ fixture.db.close();
+ });
+
+ it('recovers a completed workflow stage without queuing duplicates', async () => {
+ const fixture = setup('url');
+ const probe = fixture.dispatcher.dispatch(fixture.jobId, {
+ action: 'run-stage',
+ expectedRevision: 0,
+ idempotencyKey: 'auto-clip-recover',
+ input: { stageId: 'probe', workflow: true }
+ }, 'user').commandReceipt.stageRunId!;
+ fixture.repository.updateStageRun({ id: probe, status: 'succeeded' });
+
+ await fixture.workflow.recover();
+ await fixture.workflow.recover();
+
+ expect(fixture.service.getJob(fixture.jobId)?.stages.map(stage => stage.stageId))
+ .toEqual(['probe', 'download']);
+ fixture.db.close();
+ });
+});
+
+function setup(sourceType: 'url' | 'file') {
+ tempDir = mkdtempSync(join(tmpdir(), 'creator-auto-clip-workflow-'));
+ const db = openRuntimeDatabase(join(tempDir, 'runtime.sqlite'));
+ const repository = createCreatorRepository(db);
+ const service = createCreatorService({
+ repository,
+ templates: createDefaultCreatorTemplateRegistry()
+ });
+ const job = service.createJob({
+ projectId: 'project-auto-clip',
+ templateId: 'auto-clip',
+ state: {
+ sourceType,
+ sourceUrl: sourceType === 'url' ? 'https://www.youtube.com/watch?v=auto-clip' : ''
+ }
+ });
+ const dispatcher = createCreatorCommandDispatcher({
+ service,
+ repository,
+ receipts: createCreatorAgentRepository(db)
+ });
+ const workflow = createAutoClipWorkflow({ creator: service, dispatcher });
+ return { db, repository, service, dispatcher, workflow, jobId: job.id };
+}
+
+async function succeedAndContinue(
+ fixture: ReturnType<typeof setup>,
+ stageRunId: string
+) {
+ fixture.repository.updateStageRun({ id: stageRunId, status: 'succeeded' });
+ await fixture.workflow.handleStageChanged(fixture.repository.getStageRun(stageRunId)!);
+ return fixture.service.getJob(fixture.jobId)!.stages.at(-1)!;
+}
diff --git a/apps/daemon/test/unit/creator-clip-analyzer.test.ts b/apps/daemon/test/unit/creator-clip-analyzer.test.ts
new file mode 100644
index 00000000..c307b77e
--- /dev/null
+++ b/apps/daemon/test/unit/creator-clip-analyzer.test.ts
@@ -0,0 +1,67 @@
+import { describe, expect, it, vi } from 'vitest';
+import { analyzeClips, parseClipCandidates } from '../../src/creator/clip/analyzer.js';
+
+describe('clip analyzer', () => {
+ it('passes focus, duration, and candidate limits to the model prompt', async () => {
+ const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
+ const request = JSON.parse(String(init?.body)) as {
+ messages: Array<{ content: string }>;
+ };
+ expect(request.messages[0]!.content).toContain('优先寻找开头抓人');
+ expect(request.messages[0]!.content).toContain('最多 1 个片段');
+ expect(request.messages[0]!.content).toContain('30-60 秒');
+ return new Response(JSON.stringify({
+ choices: [{
+ message: {
+ content: JSON.stringify({
+ candidates: [
+ candidate('short', 0, 20),
+ candidate('selected', 25, 60),
+ candidate('extra', 65, 110)
+ ]
+ })
+ }
+ }]
+ }), { status: 200 });
+ });
+
+ const result = await analyzeClips({
+ apiKey: 'test-key',
+ baseUrl: 'https://api.openai.test/v1',
+ model: 'test-model',
+ transcript: '这是一段用于验证高光识别设置的字幕。',
+ duration: 120,
+ focus: 'viral',
+ minDuration: 30,
+ maxDuration: 60,
+ count: 1,
+ fetchImpl: fetchImpl as typeof fetch
+ });
+
+ expect(result.map(item => item.id)).toEqual(['selected']);
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
+ });
+
+ it('rejects duplicate candidate ids before rendering', () => {
+ expect(() => parseClipCandidates({
+ candidates: [candidate('duplicate', 0, 20), candidate('duplicate', 25, 50)]
+ }, 60)).toThrow(/duplicate_clip_id/);
+ });
+});
+
+function candidate(id: string, start: number, end: number) {
+ return {
+ id,
+ title: `片段 ${id}`,
+ start,
+ end,
+ transcript: `片段 ${id} 的完整字幕`,
+ reason: `片段 ${id} 可以独立传播`,
+ scores: {
+ hook: 92,
+ information: 88,
+ emotion: 84,
+ completeness: 90
+ }
+ };
+}
diff --git a/apps/daemon/test/unit/creator-krillin-adapter-dependency.test.ts b/apps/daemon/test/unit/creator-krillin-adapter-dependency.test.ts
index d8117d8f..48634025 100644
--- a/apps/daemon/test/unit/creator-krillin-adapter-dependency.test.ts
+++ b/apps/daemon/test/unit/creator-krillin-adapter-dependency.test.ts
@@ -1,52 +1,151 @@
import { createDefaultCreatorServicesConfig } from '@opencreator/protocol';
-import { describe, expect, it, vi } from 'vitest';
+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, relative } from 'node:path';
+import { afterEach, describe, expect, it, vi } from 'vitest';
const preflightKrillinDependencies = vi.hoisted(() => vi.fn());
+const runKrillinCli = vi.hoisted(() => vi.fn());
vi.mock('../../src/creator/krillin/dependency-preflight.js', () => ({
preflightKrillinDependencies
}));
+vi.mock('../../src/creator/krillin/cli-runner.js', async importOriginal => {
+ const actual = await importOriginal<typeof import('../../src/creator/krillin/cli-runner.js')>();
+ return { ...actual, runKrillinCli };
+});
+
import { createKrillinExecutor } from '../../src/creator/krillin/adapter.js';
+import { KrillinCliError } from '../../src/creator/krillin/cli-runner.js';
+
+let tempDir = '';
+
+afterEach(() => {
+ vi.clearAllMocks();
+ if (tempDir) rmSync(tempDir, { recursive: true, force: true });
+ tempDir = '';
+});
describe('KrillinAI configured transcription dependency', () => {
- it('prepares the selected local provider before applying YouTube caption logic', async () => {
- const config = createDefaultCreatorServicesConfig();
- config.transcription.provider = 'whisperkit';
- preflightKrillinDependencies.mockReturnValue({
- manifest: { resources: [] },
- config
+ it('uses the original YouTube URL without preparing transcription when platform captions succeed', async () => {
+ const fixture = setup();
+ runKrillinCli.mockImplementation(async input => [writeTargetSubtitle(input.jobsRoot)]);
+
+ const result = await fixture.executor.run(fixture.stage);
+
+ expect(result.outputs).toEqual([
+ expect.objectContaining({ kind: 'target_subtitle', status: 'completed' })
+ ]);
+ expect(fixture.ensure).not.toHaveBeenCalled();
+ expect(runKrillinCli).toHaveBeenCalledTimes(1);
+ expect(runKrillinCli.mock.calls[0]?.[0]).toMatchObject({
+ source: 'https://www.youtube.com/watch?v=demo',
+ options: { captionSource: 'platform' }
});
- const preparationStopped = new Error('preparation stopped');
- const ensure = vi.fn(async () => {
- throw preparationStopped;
+ });
+
+ it('prepares transcription only after platform captions fail and uses the local video', async () => {
+ const fixture = setup();
+ runKrillinCli
+ .mockRejectedValueOnce(new KrillinCliError(
+ 'platform_caption_failed',
+ 'No platform captions are available'
+ ))
+ .mockImplementationOnce(async input => [writeTargetSubtitle(input.jobsRoot)]);
+
+ await fixture.executor.run(fixture.stage);
+
+ expect(fixture.ensure).toHaveBeenCalledTimes(1);
+ expect(runKrillinCli).toHaveBeenCalledTimes(2);
+ expect(runKrillinCli.mock.calls[0]?.[0]).toMatchObject({
+ source: 'https://www.youtube.com/watch?v=demo',
+ options: { captionSource: 'platform' }
});
- const executor = createKrillinExecutor({
- resourceRoot: '/tmp/opencreator-krillin-runtime',
- jobsRoot: '/tmp/opencreator-jobs',
- configStore: {
- read: vi.fn(async () => config)
- } as never,
- dependencyLoader: {
- root: '/tmp/opencreator-krillin-dependencies',
- capabilities: vi.fn(),
- ensure
- }
+ expect(runKrillinCli.mock.calls[1]?.[0]).toMatchObject({
+ source: expect.stringMatching(/^local:/),
+ options: { captionSource: 'whisper' }
});
-
- await expect(executor.run({
- signal: new AbortController().signal,
- stageRun: {
- stageId: 'subtitle',
- progress: {}
- },
- options: {
- source: 'https://www.youtube.com/watch?v=demo',
- captionSource: 'any'
- },
- reportProgress: vi.fn()
- } as never)).rejects.toBe(preparationStopped);
-
- expect(ensure).toHaveBeenCalledWith(expect.objectContaining({ config }));
});
});
+
+function setup() {
+ tempDir = realpathSync(mkdtempSync(join(tmpdir(), 'creator-krillin-caption-plan-')));
+ const resourceRoot = join(tempDir, 'runtime');
+ const jobsRoot = join(tempDir, 'jobs');
+ const sourcePath = join(jobsRoot, 'auto-clip-job', 'inputs', 'source.mp4');
+ const ffprobePath = join(resourceRoot, 'bin', 'ffprobe');
+ mkdirSync(join(resourceRoot, 'bin'), { recursive: true });
+ mkdirSync(join(jobsRoot, 'auto-clip-job', 'inputs'), { recursive: true });
+ writeFileSync(sourcePath, 'video');
+ writeFileSync(ffprobePath, 'ffprobe');
+ writeFileSync(join(resourceRoot, 'manifest.json'), JSON.stringify({
+ version: 1,
+ platform: process.platform,
+ arch: process.arch,
+ resources: [{
+ path: 'bin/ffprobe',
+ sha256: 'a'.repeat(64),
+ kind: 'executable'
+ }]
+ }));
+
+ const config = createDefaultCreatorServicesConfig();
+ config.transcription.provider = 'whisperkit';
+ preflightKrillinDependencies.mockReturnValue({
+ manifest: { resources: [] },
+ config
+ });
+ const ensure = vi.fn(async () => undefined);
+ const executor = createKrillinExecutor({
+ resourceRoot,
+ jobsRoot,
+ configStore: {
+ read: vi.fn(async () => config)
+ } as never,
+ dependencyLoader: {
+ root: join(tempDir, 'dependencies'),
+ capabilities: vi.fn(),
+ ensure
+ }
+ });
+ const stage = {
+ signal: new AbortController().signal,
+ stageRun: {
+ id: 'subtitle-stage',
+ stageId: 'subtitle',
+ progress: {}
+ },
+ job: {
+ id: 'auto-clip-job',
+ templateId: 'auto-clip',
+ state: {
+ sourceUrl: 'https://www.youtube.com/watch?v=demo',
+ sourceLanguage: 'auto',
+ targetLanguage: 'zh-CN',
+ preferPlatformCaptions: true
+ }
+ },
+ inputArtifacts: [{
+ id: 'source-video',
+ kind: 'source_video',
+ path: sourcePath
+ }],
+ workdir: join(jobsRoot, 'auto-clip-job', 'subtitle-stage'),
+ reportProgress: vi.fn()
+ } as never;
+ return { ensure, executor, stage };
+}
+
+function writeTargetSubtitle(jobsRoot: string) {
+ const outputDir = join(jobsRoot, 'auto-clip-job', 'outputs');
+ const path = join(outputDir, 'target.srt');
+ mkdirSync(outputDir, { recursive: true });
+ writeFileSync(path, '1\n00:00:00,000 --> 00:00:01,000\n字幕内容\n');
+ return {
+ kind: 'target_subtitle',
+ relativePath: relative(jobsRoot, path).replaceAll('\\', '/'),
+ size: 48,
+ sha256: 'b'.repeat(64)
+ };
+}
diff --git a/apps/daemon/test/unit/creator-runtime-advanced.test.ts b/apps/daemon/test/unit/creator-runtime-advanced.test.ts
index 8139a67e..9291a883 100644
--- a/apps/daemon/test/unit/creator-runtime-advanced.test.ts
+++ b/apps/daemon/test/unit/creator-runtime-advanced.test.ts
@@ -441,6 +441,78 @@ describe('creator runtime advanced contracts', () => {
db.close();
});
+ it('creates a new video clip result snapshot for every completed analysis', async () => {
+ const { db, repository, service, templates } = setup();
+ let analysis = 0;
+ const runner = createCreatorStageRunner({
+ repository,
+ templates,
+ executors: [{
+ id: 'clip',
+ async run() {
+ analysis += 1;
+ return {
+ outputs: [{
+ kind: 'clip_candidates',
+ status: 'completed' as const,
+ path: join(tempDir, `clip-candidates-v${analysis}.json`),
+ metadata: { candidates: [{ id: `clip-${analysis}` }] }
+ }]
+ };
+ }
+ }],
+ workRoot: join(tempDir, 'work')
+ });
+ const job = service.createJob({ projectId: 'p1', templateId: 'auto-clip' });
+ const source = repository.insertArtifact({
+ jobId: job.id,
+ kind: 'source_video',
+ status: 'completed',
+ path: join(tempDir, 'source.mp4'),
+ sourceArtifactIds: [],
+ metadata: {}
+ });
+ const subtitle = repository.insertArtifact({
+ jobId: job.id,
+ kind: 'target_subtitle',
+ status: 'completed',
+ path: join(tempDir, 'subtitle.srt'),
+ sourceArtifactIds: [source.id],
+ metadata: {}
+ });
+
+ await runner.run(job.id, 'analyze');
+ await runner.run(job.id, 'analyze');
+
+ const completed = service.getJob(job.id)!;
+ expect(completed.state).toMatchObject({
+ resultVersion: 2,
+ latestResultVersion: 2
+ });
+ expect(completed.state.resultSnapshots).toMatchObject([
+ {
+ version: 1,
+ description: '识别视频高光片段',
+ artifactRefs: {
+ source_video: [source.id],
+ target_subtitle: [subtitle.id],
+ clip_candidates: [expect.any(String)]
+ }
+ },
+ {
+ version: 2,
+ description: '识别视频高光片段',
+ artifactRefs: {
+ source_video: [source.id],
+ target_subtitle: [subtitle.id],
+ clip_candidates: [expect.any(String)]
+ }
+ }
+ ]);
+ await runner.close();
+ db.close();
+ });
+
it('keeps a video download job in draft after the non-final probe stage', async () => {
const { db, repository, service, templates } = setup();
const probePath = join(tempDir, 'probe.json');
@@ -1156,8 +1228,9 @@ describe('creator runtime advanced contracts', () => {
});
expect(probe).toMatchObject({ platform: 'bilibili', formats: [{ id: '1080', hasVideo: true, hasAudio: false }] });
expect(() => parseClipCandidates({ candidates: [{
- id: 'bad', start: 8, end: 13, reason: '越界',
- scores: { hook: 8, information: 8, emotion: 8, completeness: 8 }
+ id: 'bad', title: '越界片段', start: 8, end: 13,
+ transcript: '这个片段超过了视频总时长。', reason: '越界',
+ scores: { hook: 80, information: 80, emotion: 80, completeness: 80 }
}] }, 12)).toThrow(/invalid_clip_range/);
});
diff --git a/apps/desktop/e2e/creator-packaged-app.spec.ts b/apps/desktop/e2e/creator-packaged-app.spec.ts
index b2e77f82..1f201932 100644
--- a/apps/desktop/e2e/creator-packaged-app.spec.ts
+++ b/apps/desktop/e2e/creator-packaged-app.spec.ts
@@ -291,6 +291,36 @@ test('实际 Desktop 包创建并重启恢复 Creator Job,且使用内嵌 Runt
await expect(currentApp.page.getByRole('heading', { name: '图像生成' })).toBeVisible();
await expect(currentApp.page.getByRole('textbox', { name: '提示词' })).toBeVisible();
+ await currentApp.page.getByRole('button', { name: '工作台' }).click();
+ await expect(currentApp.page.getByRole('heading', { name: '工作台' })).toBeVisible();
+ await currentApp.page.getByRole('button', { name: /^视频切片/ }).click();
+ const clipWorkspace = currentApp.page.getByRole('region', { name: '视频切片 操作区' });
+ await expect(clipWorkspace.getByRole('textbox', { name: '视频链接' })).toBeVisible();
+ await clipWorkspace.getByRole('textbox', { name: '视频链接' })
+ .fill('https://example.com/watch/packaged-auto-clip');
+ await clipWorkspace.getByRole('button', { name: '下一步:切片设置' }).click();
+ await clipWorkspace.getByRole('combobox', { name: '内容重点' }).selectOption('knowledge');
+ await clipWorkspace.getByRole('combobox', { name: '目标时长' }).selectOption('30-60');
+ await clipWorkspace.getByRole('spinbutton', { name: '候选数量' }).fill('8');
+ await clipWorkspace.getByRole('combobox', { name: '输出画幅' }).selectOption('9:16');
+ const clipJobId = new URL(currentApp.page.url()).hash.match(/jobId=([^&]+)/)?.[1];
+ expect(clipJobId).toBeTruthy();
+ await expect.poll(async () => (
+ await runtimeRequest<{
+ job: { state: Record<string, unknown> };
+ }>(
+ currentApp.page,
+ 'GET',
+ `/creator/jobs/${decodeURIComponent(clipJobId!)}`
+ )
+ ).body.job.state).toMatchObject({
+ sourceUrl: 'https://example.com/watch/packaged-auto-clip',
+ focus: 'knowledge',
+ duration: '30-60',
+ clipCount: 8,
+ aspectRatio: '9:16'
+ });
+
const createdJob = await runtimeRequest<{
job: { id: string; revision: number; state: Record<string, unknown> };
}>(currentApp.page, 'POST', '/creator/jobs', {
diff --git a/apps/web/e2e/web-desktop-parity.spec.ts b/apps/web/e2e/web-desktop-parity.spec.ts
index 101b6e74..7bb7da66 100644
--- a/apps/web/e2e/web-desktop-parity.spec.ts
+++ b/apps/web/e2e/web-desktop-parity.spec.ts
@@ -659,6 +659,124 @@ test('短视频脚本在 Browser/Desktop Bridge 下保持相同界面、请求
expect(results[1]!.state).toEqual(results[0]!.state);
});
+test('视频切片在 Browser/Desktop Bridge 下保持相同界面、请求和持久状态', async ({
+ browser,
+ runtime
+}, testInfo) => {
+ test.skip(
+ testInfo.project.name !== 'chromium-desktop',
+ '一致性规格内部固定创建 Browser/Desktop Chromium 上下文'
+ );
+
+ const results: Array<{
+ text: string;
+ boxes: Record<string, { x: number; y: number; width: number; height: number }>;
+ requests: string[];
+ state: Record<string, unknown>;
+ }> = [];
+
+ for (const platform of ['browser', 'desktop'] as const) {
+ const created = await runtime.api<{
+ job: { id: string };
+ }>('POST', '/creator/jobs', {
+ projectId: runtime.projectId,
+ templateId: 'auto-clip',
+ state: {
+ sourceUrl: 'https://example.com/watch/opencreator-parity'
+ }
+ });
+ const context = await browser.newContext({
+ viewport: { width: 1280, height: 800 },
+ deviceScaleFactor: 1,
+ colorScheme: 'dark',
+ reducedMotion: 'reduce'
+ });
+ const page = await context.newPage();
+ if (platform === 'desktop') await installDesktopBridge(page);
+
+ try {
+ await runtime.openApp(page);
+ const requests: string[] = [];
+ page.on('request', request => {
+ const url = new URL(request.url());
+ if (!url.pathname.includes('/creator/')) return;
+ requests.push(
+ `${request.method()} ${url.pathname
+ .replace('/.opencreator/runtime', '')
+ .replace(encodeURIComponent(created.job.id), ':jobId')}`
+ );
+ });
+ await page.goto(
+ `${runtime.origin}/#/workbench?tool=auto-clips`
+ + `&jobId=${encodeURIComponent(created.job.id)}`
+ );
+
+ const workspace = page.getByRole('region', { name: '视频切片 操作区' });
+ const panel = page.getByRole('complementary', { name: 'OpenCreator' });
+ await expect(workspace.getByRole('button', { name: '下一步:切片设置' }))
+ .toBeEnabled();
+ await workspace.getByRole('button', { name: '下一步:切片设置' }).click();
+ await workspace.getByRole('combobox', { name: '内容重点' }).selectOption('viral');
+ await workspace.getByRole('combobox', { name: '目标时长' }).selectOption('30-60');
+ await workspace.getByRole('spinbutton', { name: '候选数量' }).fill('6');
+ await workspace.getByRole('combobox', { name: '输出画幅' }).selectOption('1:1');
+ await expect(workspace.getByLabel('任务摘要')).toContainText('传播潜力优先');
+ await expect(workspace.getByLabel('任务摘要')).toContainText('候选片段6');
+
+ await expect.poll(async () => (
+ await runtime.api<{
+ job: { state: Record<string, unknown> };
+ }>('GET', `/creator/jobs/${encodeURIComponent(created.job.id)}`)
+ ).job.state).toMatchObject({
+ sourceUrl: 'https://example.com/watch/opencreator-parity',
+ focus: 'viral',
+ duration: '30-60',
+ clipCount: 6,
+ aspectRatio: '1:1'
+ });
+
+ const boxes: Record<
+ string,
+ { x: number; y: number; width: number; height: number }
+ > = {};
+ for (const [name, locator] of [
+ ['workspace', workspace],
+ ['panel', panel],
+ ['focus', workspace.getByRole('combobox', { name: '内容重点' })],
+ ['aspect-ratio', workspace.getByRole('combobox', { name: '输出画幅' })]
+ ] as const) {
+ const box = await locator.boundingBox();
+ expect(box, `${platform} 缺少 ${name} 尺寸目标`).not.toBeNull();
+ boxes[name] = {
+ x: Math.round(box!.x),
+ y: Math.round(box!.y),
+ width: Math.round(box!.width),
+ height: Math.round(box!.height)
+ };
+ }
+ const saved = await runtime.api<{
+ job: { state: Record<string, unknown> };
+ }>('GET', `/creator/jobs/${encodeURIComponent(created.job.id)}`);
+ results.push({
+ text: normalizeParityText(
+ `${await workspace.innerText()}\n${await panel.innerText()}`
+ ),
+ boxes,
+ requests,
+ state: saved.job.state
+ });
+ } finally {
+ await context.close();
+ }
+ }
+
+ expect(results[1]!.text).toBe(results[0]!.text);
+ expect(results[1]!.boxes).toEqual(results[0]!.boxes);
+ expect(results[1]!.requests).toEqual(results[0]!.requests);
+ expect(results[1]!.state).toEqual(results[0]!.state);
+ expect(results[0]!.requests).toContain('POST /creator/jobs/:jobId/actions');
+});
+
test('第三方组件设置在 Browser/Desktop Bridge 下保持相同状态、尺寸和 Runtime 请求', async ({
browser,
runtime
diff --git a/apps/web/src/features/conversation/CreatorDashboard.tsx b/apps/web/src/features/conversation/CreatorDashboard.tsx
index eb01dbad..ae214400 100644
--- a/apps/web/src/features/conversation/CreatorDashboard.tsx
+++ b/apps/web/src/features/conversation/CreatorDashboard.tsx
@@ -98,7 +98,7 @@ const creatorSkillsByCategory: Record<CreatorSkillCategory, CreatorSkill[]> = {
},
{
id: 'intelligent-clipping',
- title: '智能剪辑',
+ title: '视频切片',
category: '视频剪辑',
image: '/dashboard/templates/intelligent-clipping-cover.png',
interaction: { type: 'workspace', workspace: 'auto-clips' },
@@ -398,7 +398,7 @@ const englishCreatorLabels: Record<string, string> = {
数字人口播: 'Digital Avatar',
火柴人动画: 'Stick Figure Animation',
动画生成: 'Animation',
- 智能剪辑: 'Intelligent Curation',
+ 视频切片: 'Video Clips',
视频剪辑: 'Video Editing',
封面生成: 'Cover Generation',
创意短片策划: 'Creative Short Planning',
diff --git a/apps/web/src/features/dashboard/AutoClipWorkspace.tsx b/apps/web/src/features/dashboard/AutoClipWorkspace.tsx
index 1bc4eca9..62c6711f 100644
--- a/apps/web/src/features/dashboard/AutoClipWorkspace.tsx
+++ b/apps/web/src/features/dashboard/AutoClipWorkspace.tsx
@@ -1,74 +1,62 @@
+import {
+ readCreatorResultSnapshots,
+ type CreatorArtifact,
+ type CreatorJson,
+ type CreatorStageRun
+} from '@opencreator/protocol';
import { useEffect, useMemo, useRef, useState } from 'react';
-import { Captions, Check, Download, FileVideo, LayoutGrid, List, ListVideo, Play, Scissors, Settings2, SlidersHorizontal, Sparkles } from 'lucide-react';
-import CreatorToolShell from './CreatorToolShell.js';
+import {
+ Captions,
+ Check,
+ Download,
+ FileVideo,
+ LayoutGrid,
+ List,
+ ListVideo,
+ LoaderCircle,
+ Play,
+ Scissors,
+ Settings2,
+ SlidersHorizontal,
+ Sparkles
+} from 'lucide-react';
+import { useLocalizedCopy } from '../../i18n/useLocalizedCopy.js';
+import type { VideoMetadataService } from '../../services/video-metadata-service.js';
import CreatorResultVersionMenu from './CreatorResultVersionMenu.js';
import CreatorTaskSummary from './CreatorTaskSummary.js';
-import { useLocalizedCopy } from '../../i18n/useLocalizedCopy.js';
+import CreatorToolShell from './CreatorToolShell.js';
import { useOptionalCreatorSession } from './creator-session-store.js';
-import type { VideoMetadataService } from '../../services/video-metadata-service.js';
import VideoSourceInput from './VideoSourceInput.js';
-type ClipCandidate = {
- id: number;
- title: string;
- time: string;
- duration: string;
- subtitle: string;
- scores: { hook: number; semantic: number; emotion: number; viral: number };
-};
type AutoClipStep = 0 | 1 | 2;
type AutoClipResultTab = 'candidates' | 'details' | 'export' | 'settings';
type AutoClipLayout = 'grid' | 'list';
type VideoOrientation = 'landscape' | 'portrait';
type AnalysisFocus = 'balanced' | 'viral' | 'knowledge';
type ClipDuration = '15-30' | '30-60' | '60-90';
+type ClipAspectRatio = 'source' | '16:9' | '9:16' | '1:1';
+type ClipScoreKey = 'hook' | 'information' | 'emotion' | 'completeness';
+
+type ClipCandidate = {
+ id: string;
+ title: string;
+ start: number;
+ end: number;
+ transcript: string;
+ reason: string;
+ scores: Record<ClipScoreKey, number>;
+};
+
type AutoClipResultVersion = {
value: number;
description: string;
- signature: string;
- videoUrl: string;
- videoFile: File | null;
- focus: AnalysisFocus;
- duration: ClipDuration;
- clipCount: number;
- sourceOrientation: VideoOrientation;
- selectedIds: number[];
+ state: Record<string, CreatorJson>;
+ artifact: CreatorArtifact;
+ sourceArtifact?: CreatorArtifact;
+ candidates: ClipCandidate[];
};
-const clips: ClipCandidate[] = [
- { id: 1, title: '创作者最容易忽略的第一步', time: '00:01:12 - 00:01:47', duration: '35s', subtitle: '很多人一开始就急着使用工具,但真正影响结果的是你有没有先定义清楚受众和目标。', scores: { hook: 94, semantic: 92, emotion: 86, viral: 91 } },
- { id: 2, title: '一个判断内容价值的方法', time: '00:03:08 - 00:03:44', duration: '36s', subtitle: '判断一个选题是否值得做,可以问自己:用户看完以后,会不会立刻改变一个动作?', scores: { hook: 91, semantic: 95, emotion: 82, viral: 90 } },
- { id: 3, title: '为什么短视频开头不能解释背景', time: '00:05:21 - 00:06:02', duration: '41s', subtitle: '开头先讲背景通常会损失观众。先抛出结果,再补充原因,信息会更容易被留下。', scores: { hook: 96, semantic: 89, emotion: 84, viral: 94 } },
- { id: 4, title: '从长内容找到高光片段', time: '00:08:15 - 00:08:58', duration: '43s', subtitle: '高光不一定是声音最大的位置,而是观点发生转折、答案突然变得清楚的那一刻。', scores: { hook: 88, semantic: 94, emotion: 89, viral: 87 } },
- { id: 5, title: '让观点更容易被记住', time: '00:11:04 - 00:11:39', duration: '35s', subtitle: '把抽象观点换成一个具体对比,观众不需要记住你的解释,也会记住那个差异。', scores: { hook: 87, semantic: 93, emotion: 80, viral: 86 } },
- { id: 6, title: '内容节奏的三个层次', time: '00:14:27 - 00:15:12', duration: '45s', subtitle: '节奏不是单纯加快语速,而是问题、答案和证据之间有没有持续推进。', scores: { hook: 85, semantic: 91, emotion: 83, viral: 84 } },
- { id: 7, title: '字幕为什么需要按语义断句', time: '00:18:09 - 00:18:46', duration: '37s', subtitle: '字幕跟着字数切会打断理解。按照语义停顿来切,观众能更快抓住每句话的重点。', scores: { hook: 84, semantic: 96, emotion: 78, viral: 83 } },
- { id: 8, title: '一个反直觉的剪辑建议', time: '00:21:31 - 00:22:03', duration: '32s', subtitle: '不是所有停顿都要删掉。关键观点前的一小段停顿,反而会让观众更注意接下来的内容。', scores: { hook: 92, semantic: 88, emotion: 87, viral: 90 } },
- { id: 9, title: '如何判断片段能够独立传播', time: '00:25:18 - 00:25:59', duration: '41s', subtitle: '把片段单独拿出来,如果观众不需要知道前文也能理解问题和结论,它才适合独立发布。', scores: { hook: 86, semantic: 97, emotion: 79, viral: 88 } },
- { id: 10, title: '最后给创作者的行动建议', time: '00:29:42 - 00:30:20', duration: '38s', subtitle: '先发布一个足够清楚的版本,再根据真实反馈调整,不要在没有观众的时候追求完美。', scores: { hook: 89, semantic: 92, emotion: 91, viral: 89 } }
-];
-
-const englishClips: Record<number, { title: string; subtitle: string }> = {
- 1: { title: 'The first step creators often miss', subtitle: 'Many people rush to use tools, but defining the audience and goal first has the greatest impact on the result.' },
- 2: { title: 'A way to judge content value', subtitle: 'Ask whether viewers will immediately change an action after watching to decide whether a topic is worth making.' },
- 3: { title: 'Why short videos should not start with background', subtitle: 'Starting with background loses viewers. Lead with the result, then explain why.' },
- 4: { title: 'Finding highlights in long content', subtitle: 'A highlight is not always the loudest moment. It is where the point turns and the answer suddenly becomes clear.' },
- 5: { title: 'Make an idea easier to remember', subtitle: 'Turn an abstract point into a concrete comparison so viewers remember the difference without memorizing the explanation.' },
- 6: { title: 'Three layers of content pacing', subtitle: 'Pacing is not just speaking faster. It is whether questions, answers, and evidence keep moving forward.' },
- 7: { title: 'Why subtitles need semantic line breaks', subtitle: 'Breaking subtitles by character count interrupts understanding. Semantic pauses help viewers grasp each sentence.' },
- 8: { title: 'A counterintuitive editing tip', subtitle: 'Not every pause should be removed. A brief pause before a key point can focus attention.' },
- 9: { title: 'Can a clip stand on its own?', subtitle: 'A clip is ready to publish independently when viewers can understand the question and conclusion without prior context.' },
- 10: { title: 'A final action for creators', subtitle: 'Publish a clear-enough version, then adjust from real feedback instead of chasing perfection before you have an audience.' }
-};
-
-function totalScore(clip: ClipCandidate) {
- const values = Object.values(clip.scores);
- return Math.round(values.reduce((sum, score) => sum + score, 0) / values.length);
-}
-
-function isValidUrl(value: string) {
- try { return ['http:', 'https:'].includes(new URL(value.trim()).protocol); } catch { return false; }
-}
+const analysisStageIds = new Set(['probe', 'download', 'subtitle', 'analyze']);
export default function AutoClipWorkspace(props: {
onBack(): void;
@@ -78,84 +66,189 @@ export default function AutoClipWorkspace(props: {
const l = useLocalizedCopy();
const session = useOptionalCreatorSession();
const draftInitializedRef = useRef(false);
- const [videoUrl, setVideoUrl] = useState(() => typeof session?.state.sourceUrl === 'string' ? session.state.sourceUrl : '');
+ const initializedSelectionVersionRef = useRef<number>();
+ const [videoUrl, setVideoUrl] = useState(() => readString(session?.state.sourceUrl));
const [videoFile, setVideoFile] = useState<File | null>(null);
- const [sourceArtifactId, setSourceArtifactId] = useState(
- () => typeof session?.state.sourceArtifactId === 'string'
- ? session.state.sourceArtifactId
- : ''
- );
- const [focus, setFocus] = useState<AnalysisFocus>(() => session?.state.focus === 'viral' || session?.state.focus === 'knowledge' ? session.state.focus : 'balanced');
- const [duration, setDuration] = useState<ClipDuration>(() => session?.state.duration === '15-30' || session?.state.duration === '60-90' ? session.state.duration : '30-60');
- const [clipCount, setClipCount] = useState(() => typeof session?.state.clipCount === 'number' ? session.state.clipCount : 10);
- const [sourceOrientation, setSourceOrientation] = useState<VideoOrientation>(() => session?.state.sourceOrientation === 'portrait' ? 'portrait' : 'landscape');
- const [activeClip, setActiveClip] = useState(1);
- const [selected, setSelected] = useState<number[]>([1, 2, 3]);
+ const [sourceArtifactId, setSourceArtifactId] = useState(() => readString(session?.state.sourceArtifactId));
+ const [focus, setFocus] = useState<AnalysisFocus>(() => readFocus(session?.state.focus));
+ const [duration, setDuration] = useState<ClipDuration>(() => readDuration(session?.state.duration));
+ const [clipCount, setClipCount] = useState(() => readClipCount(session?.state.clipCount));
+ const [aspectRatio, setAspectRatio] = useState<ClipAspectRatio>(() => readAspectRatio(session?.state.aspectRatio));
+ const [sourceOrientation, setSourceOrientation] = useState<VideoOrientation>('landscape');
+ const [activeClipId, setActiveClipId] = useState('');
+ const [selected, setSelected] = useState<string[]>(() => readStringArray(session?.state.selectedCandidateIds));
const [sort, setSort] = useState<'score' | 'time'>('score');
const [clipLayout, setClipLayout] = useState<AutoClipLayout>('grid');
const [notice, setNotice] = useState('');
+ const [error, setError] = useState('');
const [currentStep, setCurrentStep] = useState<AutoClipStep>(0);
const [furthestStep, setFurthestStep] = useState<AutoClipStep>(0);
const [resultTab, setResultTab] = useState<AutoClipResultTab>('candidates');
- const [resultVersion, setResultVersion] = useState(0);
- const [resultVersions, setResultVersions] = useState<AutoClipResultVersion[]>([]);
- const importedSourceArtifact = session?.job.artifacts.find(artifact => (
- artifact.id === sourceArtifactId
- && artifact.kind === 'source_video'
- && artifact.status === 'completed'
- ));
- const importedSourceName = importedSourceArtifact === undefined
- ? ''
- : typeof importedSourceArtifact.metadata.fileName === 'string'
- ? importedSourceArtifact.metadata.fileName
- : l('项目视频', 'Project video');
+ const [resultVersion, setResultVersion] = useState<number>();
+ const [sourcePreviewUrl, setSourcePreviewUrl] = useState('');
+ const [exportUrls, setExportUrls] = useState<Record<string, string>>({});
+ const resultVersions = useMemo(
+ () => createAutoClipResultVersions(
+ session?.job.artifacts ?? [],
+ session?.state.resultSnapshots
+ ),
+ [session?.job.artifacts, session?.state.resultSnapshots]
+ );
+ const latestVersion = resultVersions.at(-1)?.value;
+ const selectedResult = resultVersions.find(version => version.value === resultVersion)
+ ?? resultVersions.at(-1);
+ const candidates = selectedResult?.candidates ?? [];
+ const orderedClips = useMemo(() => [...candidates].sort(sort === 'score'
+ ? (left, right) => totalScore(right) - totalScore(left)
+ : (left, right) => left.start - right.start), [candidates, sort]);
+ const currentClip = candidates.find(clip => clip.id === activeClipId) ?? candidates[0];
+ const importedSourceArtifact = findArtifact(
+ session?.job.artifacts ?? [],
+ sourceArtifactId,
+ 'source_video'
+ );
+ const currentSourceArtifact = selectedResult?.sourceArtifact
+ ?? importedSourceArtifact
+ ?? latestCompletedArtifact(session?.job.artifacts ?? [], 'source_video');
+ const importedSourceName = artifactFileName(currentSourceArtifact)
+ || l('项目视频', 'Project video');
const hasSource = importedSourceArtifact !== undefined
|| videoFile !== null
|| isValidUrl(videoUrl);
- const selectedResult = resultVersions.find(version => version.value === resultVersion);
- const resultClips = useMemo(
- () => clips.slice(0, selectedResult?.clipCount ?? clipCount),
- [clipCount, selectedResult?.clipCount]
+ const latestAnalysisStage = latestStage(session?.job.stages ?? [], analysisStageIds);
+ const latestRenderStage = latestStage(session?.job.stages ?? [], new Set(['render']));
+ const analyzing = latestAnalysisStage?.status === 'queued' || latestAnalysisStage?.status === 'running';
+ const exporting = latestRenderStage?.status === 'queued' || latestRenderStage?.status === 'running';
+ const runtimeError = latestFailedStage(session?.job.stages ?? []);
+ const visibleError = error || formatClipError(runtimeError ?? session?.error, l);
+ const exportedArtifacts = useMemo(
+ () => selectedResult === undefined
+ ? []
+ : latestExportsForCandidateArtifact(
+ session?.job.artifacts ?? [],
+ selectedResult.artifact.id
+ ),
+ [selectedResult?.artifact.id, session?.job.artifacts]
);
- const orderedClips = useMemo(() => [...resultClips].sort(sort === 'score' ? (left, right) => totalScore(right) - totalScore(left) : (left, right) => left.id - right.id), [resultClips, sort]);
- const currentClip = resultClips.find(clip => clip.id === activeClip) ?? resultClips[0] ?? clips[0]!;
- const signature = createAnalysisSignature({
- videoUrl,
- videoFile,
- sourceArtifactId,
- focus,
- duration,
- clipCount,
- sourceOrientation
- });
- const hasPendingChanges = selectedResult !== undefined && selectedResult.signature !== signature;
- const nextVersion = resultVersions.reduce((highest, version) => Math.max(highest, version.value), 0) + 1;
+ const currentOrientation = readOrientation(currentSourceArtifact) ?? sourceOrientation;
+
+ useEffect(() => {
+ if (latestVersion !== undefined) setResultVersion(latestVersion);
+ }, [latestVersion]);
+
+ useEffect(() => {
+ if (resultVersions.length === 0) return;
+ setCurrentStep(2);
+ setFurthestStep(2);
+ }, [resultVersions.length]);
+
+ useEffect(() => {
+ if (selectedResult === undefined) return;
+ if (initializedSelectionVersionRef.current === selectedResult.value) return;
+ initializedSelectionVersionRef.current = selectedResult.value;
+ const saved = readStringArray(session?.state.selectedCandidateIds)
+ .filter(id => selectedResult.candidates.some(candidate => candidate.id === id));
+ const next = saved.length > 0
+ ? saved
+ : [...selectedResult.candidates]
+ .sort((left, right) => totalScore(right) - totalScore(left))
+ .slice(0, Math.min(3, selectedResult.candidates.length))
+ .map(candidate => candidate.id);
+ setSelected(next);
+ setActiveClipId(next[0] ?? selectedResult.candidates[0]?.id ?? '');
+ session?.updateDraft({ selectedCandidateIds: next });
+ }, [selectedResult?.value, session?.state.selectedCandidateIds, session?.updateDraft]);
useEffect(() => {
if (session === null) return;
session.updateDraft({
sourceUrl: videoUrl,
- sourceType: sourceArtifactId ? 'file' : videoFile ? 'file' : 'url',
+ sourceType: sourceArtifactId || videoFile ? 'file' : 'url',
sourceArtifactId: sourceArtifactId || null,
focus,
duration,
clipCount,
- sourceOrientation,
- selectedCandidateIds: selected.map(String)
+ aspectRatio,
+ selectedCandidateIds: selected
}, { persist: draftInitializedRef.current });
draftInitializedRef.current = true;
- }, [clipCount, duration, focus, selected, session?.updateDraft, sourceArtifactId, sourceOrientation, videoFile, videoUrl]);
+ }, [aspectRatio, clipCount, duration, focus, selected, session?.updateDraft, sourceArtifactId, videoFile, videoUrl]);
- const steps = [l('添加视频', 'Add video'), l('分析设置', 'Analysis settings'), l('选择与导出', 'Select and export')];
+ useEffect(() => {
+ if (currentSourceArtifact === undefined || session === null) {
+ setSourcePreviewUrl('');
+ return undefined;
+ }
+ let active = true;
+ let objectUrl = '';
+ void session.openArtifact(currentSourceArtifact.id)
+ .then(async response => {
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
+ objectUrl = URL.createObjectURL(await response.blob());
+ if (active) setSourcePreviewUrl(objectUrl);
+ })
+ .catch(() => {
+ if (active) setSourcePreviewUrl('');
+ });
+ return () => {
+ active = false;
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
+ };
+ }, [currentSourceArtifact?.id, session?.openArtifact]);
+
+ useEffect(() => {
+ if (exportedArtifacts.length === 0 || session === null) {
+ setExportUrls({});
+ return undefined;
+ }
+ let active = true;
+ const objectUrls: string[] = [];
+ void Promise.all(exportedArtifacts.map(async artifact => {
+ const response = await session.openArtifact(artifact.id);
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
+ const objectUrl = URL.createObjectURL(await response.blob());
+ objectUrls.push(objectUrl);
+ return [artifact.id, objectUrl] as const;
+ })).then(entries => {
+ if (active) setExportUrls(Object.fromEntries(entries));
+ }).catch(cause => {
+ if (active) setError(formatClipError(cause, l));
+ });
+ return () => {
+ active = false;
+ objectUrls.forEach(url => URL.revokeObjectURL(url));
+ };
+ }, [exportedArtifacts, l, session?.openArtifact]);
+
+ useEffect(() => {
+ if (latestRenderStage?.status === 'succeeded' && exportedArtifacts.length > 0) {
+ setNotice(l(
+ `已生成 ${exportedArtifacts.length} 个独立视频切片`,
+ `${exportedArtifacts.length} standalone video clips are ready`
+ ));
+ setResultTab('export');
+ }
+ }, [exportedArtifacts.length, l, latestRenderStage?.id, latestRenderStage?.status]);
+
+ const steps = [
+ l('添加视频', 'Add video'),
+ l('切片设置', 'Clip settings'),
+ l('选择与导出', 'Select and export')
+ ];
+
+ function openStep(step: AutoClipStep) {
+ setCurrentStep(step);
+ setFurthestStep(previous => Math.max(previous, step) as AutoClipStep);
+ }
function continueToSettings() {
if (!hasSource) {
- setNotice(l('请先上传视频或填写公开视频链接', 'Upload a video or enter a public video link first'));
+ setError(l('请先上传视频或填写公开视频链接', 'Upload a video or enter a public video link first'));
return;
}
- setCurrentStep(1);
- setFurthestStep(current => Math.max(current, 1) as AutoClipStep);
+ setError('');
setNotice('');
+ openStep(1);
}
function chooseVideo(file: File | null) {
@@ -165,6 +258,7 @@ export default function AutoClipWorkspace(props: {
setSourceArtifactId('');
}
setSourceOrientation('landscape');
+ setError('');
setNotice('');
}
@@ -173,154 +267,222 @@ export default function AutoClipWorkspace(props: {
setVideoUrl('');
setSourceArtifactId('');
setSourceOrientation('landscape');
+ setError('');
setNotice('');
}
- function updateSourceOrientation(width: number, height: number) {
- setSourceOrientation(height > width ? 'portrait' : 'landscape');
- }
-
- function analyze(sourceOverride?: { url: string; file: File | null }) {
- const nextUrl = sourceOverride?.url ?? videoUrl;
- const nextFile = sourceOverride?.file ?? videoFile;
- if (
- nextFile === null
- && !isValidUrl(nextUrl)
- && importedSourceArtifact === undefined
- ) {
+ async function analyze() {
+ if (analyzing || session === null) return;
+ if (!hasSource) {
setCurrentStep(0);
- setNotice(l('请先上传视频或填写公开视频链接', 'Upload a video or enter a public video link first'));
- return false;
- }
- const nextSignature = createAnalysisSignature({
- videoUrl: nextUrl,
- videoFile: nextFile,
- sourceArtifactId,
- focus,
- duration,
- clipCount,
- sourceOrientation
- });
- if (session !== null) {
- void session.applyAction({ actor: 'user', action: 'run-stage', input: { stageId: 'analyze' } });
+ setError(l('请先上传视频或填写公开视频链接', 'Upload a video or enter a public video link first'));
+ return;
}
- if (selectedResult?.signature === nextSignature) {
- setCurrentStep(2);
- setFurthestStep(2);
+ setError('');
+ setNotice(l('正在准备视频并识别高光片段', 'Preparing the video and finding highlights'));
+ setSelected([]);
+ try {
+ session.updateDraft({
+ sourceUrl: videoUrl,
+ sourceType: sourceArtifactId || videoFile ? 'file' : 'url',
+ sourceArtifactId: sourceArtifactId || null,
+ focus,
+ duration,
+ clipCount,
+ aspectRatio,
+ selectedCandidateIds: []
+ }, { semantic: true });
+ await session.flush();
+ let stageId: 'probe' | 'subtitle' | 'analyze';
+ if (videoFile !== null) {
+ await session.uploadSourceVideo(videoFile);
+ stageId = 'subtitle';
+ setVideoFile(null);
+ } else {
+ const source = matchingSourceArtifact(
+ session.job.artifacts,
+ sourceArtifactId,
+ videoUrl
+ );
+ const subtitle = source === undefined
+ ? undefined
+ : matchingSubtitleArtifact(session.job.artifacts, source);
+ stageId = subtitle !== undefined ? 'analyze' : source !== undefined ? 'subtitle' : 'probe';
+ }
+ const updatedJob = await session.applyAction({
+ actor: 'user',
+ action: 'run-stage',
+ input: {
+ stageId,
+ ...(stageId === 'analyze' ? {} : { workflow: true })
+ }
+ });
setResultTab('candidates');
- setNotice(l(`设置没有变化,继续查看 V${resultVersion},未创建新版本。`, `Nothing changed. Continuing with V${resultVersion}; no new version was created.`));
- return true;
+ const completedInResponse = updatedJob.artifacts.some(artifact => (
+ artifact.kind === 'clip_candidates' && artifact.status === 'completed'
+ ));
+ const nextStep: AutoClipStep = completedInResponse ? 2 : 1;
+ setCurrentStep(nextStep);
+ setFurthestStep(previous => Math.max(previous, nextStep) as AutoClipStep);
+ } catch (cause) {
+ setError(formatClipError(cause, l));
}
- const version = nextVersion;
- const initialSelection = clips.slice(0, Math.min(3, clipCount)).map(clip => clip.id);
- const nextResult: AutoClipResultVersion = {
- value: version,
- description: version === 1 ? l('初次分析', 'Initial analysis') : l(`基于 V${resultVersion} 调整`, `Adjusted from V${resultVersion}`),
- signature: nextSignature,
- videoUrl: nextUrl,
- videoFile: nextFile,
- focus,
- duration,
- clipCount,
- sourceOrientation,
- selectedIds: initialSelection
- };
- setResultVersions(current => [...current, nextResult]);
- setResultVersion(version);
- setSelected(initialSelection);
- setActiveClip(1);
- setSort('score');
- setResultTab('candidates');
- setCurrentStep(2);
- setFurthestStep(2);
- setNotice(version === 1 ? l(`已识别字幕语义并生成 ${clipCount} 个候选片段,V1 已完成`, `Analyzed subtitle semantics and generated ${clipCount} candidates. V1 is ready.`) : l(`V${version} 分析完成,之前的版本仍可查看`, `V${version} analysis is ready. Previous versions remain available.`));
- return true;
}
- function toggleClip(id: number) {
- setSelected(current => {
- const next = current.includes(id) ? current.filter(item => item !== id) : [...current, id];
- setResultVersions(versions => versions.map(version => version.value === resultVersion ? { ...version, selectedIds: next } : version));
- return next;
- });
+ function toggleClip(id: string) {
+ setSelected(current => current.includes(id)
+ ? current.filter(item => item !== id)
+ : [...current, id]);
+ setNotice('');
+ }
+
+ function selectTopClips() {
+ const next = [...candidates]
+ .sort((left, right) => totalScore(right) - totalScore(left))
+ .slice(0, Math.min(3, candidates.length))
+ .map(candidate => candidate.id);
+ setSelected(next);
+ setSort('score');
+ setResultTab('candidates');
+ setNotice(l('已选择综合评分最高的 3 个片段', 'Selected the top 3 clips by overall score'));
}
function selectVersion(version: number) {
const result = resultVersions.find(item => item.value === version);
- if (!result) return;
- setResultVersion(result.value);
- setVideoUrl(result.videoUrl);
- setVideoFile(result.videoFile);
- setFocus(result.focus);
- setDuration(result.duration);
- setClipCount(result.clipCount);
- setSourceOrientation(result.sourceOrientation);
- setSelected(result.selectedIds);
- setActiveClip(result.selectedIds[0] ?? 1);
+ if (result === undefined) return;
+ setResultVersion(version);
+ setFocus(readFocus(result.state.focus));
+ setDuration(readDuration(result.state.duration));
+ setClipCount(readClipCount(result.state.clipCount));
+ setAspectRatio(readAspectRatio(result.state.aspectRatio));
+ setVideoUrl(readString(result.state.sourceUrl));
+ setVideoFile(null);
+ setSourceArtifactId(result.sourceArtifact?.id ?? '');
+ setResultTab('candidates');
setCurrentStep(2);
setFurthestStep(2);
- setResultTab('candidates');
- setNotice(l(`正在查看 V${result.value}`, `Viewing V${result.value}`));
+ initializedSelectionVersionRef.current = undefined;
}
- function exportSelected() {
+ async function exportSelected() {
if (selected.length === 0) {
- setNotice(l('请至少选择一个片段', 'Select at least one clip'));
- return false;
+ setError(l('请至少选择一个片段', 'Select at least one clip'));
+ return;
}
+ if (exporting || session === null || selectedResult === undefined) return;
+ setError('');
+ setNotice(l(
+ `正在生成 ${selected.length} 个独立视频切片`,
+ `Rendering ${selected.length} standalone video clips`
+ ));
setResultTab('export');
- if (session !== null) {
- void session.applyAction({ actor: 'user', action: 'run-stage', input: { stageId: 'render' } });
+ try {
+ session.updateDraft({ selectedCandidateIds: selected, aspectRatio }, { semantic: true });
+ await session.flush();
+ await session.applyAction({
+ actor: 'user',
+ action: 'run-stage',
+ input: {
+ stageId: 'render',
+ inputResultVersion: selectedResult.value
+ }
+ });
+ } catch (cause) {
+ setError(formatClipError(cause, l));
}
- setNotice(l(`${selected.length} 个片段已加入导出队列`, `${selected.length} clips were added to the export queue`));
- return true;
}
- function handleCommand(command: string) {
- const foundUrl = command.match(/https?:\/\/[^\s,,。;;]+/i)?.[0];
- if (foundUrl) {
- setVideoUrl(foundUrl);
- setVideoFile(null);
- setCurrentStep(0);
- setFurthestStep(resultVersions.length ? 2 : 0);
- if (/分析|剪辑|片段|analyze|clip|edit/i.test(command)) {
- analyze({ url: foundUrl, file: null });
- return l(`视频分析完成。我根据字幕语义、观点完整度和传播潜力找到了 ${clipCount} 个片段。`, `Video analysis is complete. I found ${clipCount} clips based on subtitle meaning, idea completeness, and sharing potential.`);
- }
- return l('视频链接已同步到第一步。你可以确认分析设置后开始提取。', 'The video link is synchronized to step one. Review the analysis settings, then start extracting clips.');
- }
- if (/分析|识别|自动剪辑|analyze|auto.?clip/i.test(command)) return analyze() ? l('分析完成,候选片段和四维评分已经同步到结果页。', 'Analysis complete. Candidate clips and four scoring dimensions are now in the results.') : l('请先添加要分析的视频。', 'Add a video to analyze first.');
- if (/最高|前三|top\s*3/i.test(command)) {
- const next = [...resultClips].sort((a, b) => totalScore(b) - totalScore(a)).slice(0, 3).map(clip => clip.id);
- setSelected(next);
- setSort('score');
- setResultTab('candidates');
- setCurrentStep(2);
- setResultVersions(versions => versions.map(version => version.value === resultVersion ? { ...version, selectedIds: next } : version));
- return l('已选中综合评分最高的 3 个片段。', 'Selected the top 3 clips by overall score.');
- }
- if (/导出|下载|export|download/i.test(command)) {
- if (!selectedResult || selected.length === 0) return l('请先分析视频并至少选择一个片段。', 'Analyze the video and select at least one clip first.');
- exportSelected();
- return l(`已开始导出 ${selected.length} 个片段。`, `Started exporting ${selected.length} clips.`);
- }
- return l('你可以发送视频链接,让我分析高光片段、选择评分最高的片段或导出已选内容。', 'Send a video link and ask me to find highlights, select the highest-scoring clips, or export your selection.');
+ function downloadArtifact(artifact: CreatorArtifact) {
+ const url = exportUrls[artifact.id];
+ if (!url) return;
+ const link = document.createElement('a');
+ link.href = url;
+ link.download = artifactFileName(artifact) || `OpenCreator-video-clip-${artifact.version}.mp4`;
+ link.click();
+ setNotice(l('视频切片已开始下载', 'The video clip download has started'));
}
+ const quickActions = selectedResult === undefined
+ ? [{
+ id: 'analyze-video-clips',
+ label: l('开始识别高光', 'Find highlights'),
+ kind: 'action' as const,
+ onAction: () => void analyze(),
+ disabled: !hasSource || analyzing
+ }]
+ : [
+ {
+ id: 'select-top-clips',
+ label: l('选择评分最高的 3 个', 'Select top 3 clips'),
+ kind: 'action' as const,
+ onAction: selectTopClips,
+ disabled: candidates.length === 0
+ },
+ {
+ id: 'export-video-clips',
+ label: l('导出已选切片', 'Export selected clips'),
+ kind: 'action' as const,
+ onAction: () => void exportSelected(),
+ disabled: selected.length === 0 || exporting
+ }
+ ];
+
return (
<CreatorToolShell
- title={l('自动剪辑', 'Auto Clips')}
- subtitle={l('理解字幕语义,从长视频提取可独立传播的片段', 'Understand subtitle semantics and extract standalone clips from long videos')}
- context={selectedResult ? l(`V${resultVersion},${selectedResult.clipCount} 个候选,已选 ${selected.length} 个`, `V${resultVersion}, ${selectedResult.clipCount} candidates, ${selected.length} selected`) : l('等待分析长视频', 'Waiting to analyze a long video')}
- initialMessage={l('上传长视频或发送链接,我会先确认分析目标和片段数量,再提取候选片段,每条都提供四维评分和完整字幕。', 'Upload a long video or send a link. I will confirm the analysis goal and clip count, then extract candidates with four scores and full transcripts.')}
- suggestions={selectedResult ? [l('选择评分最高的 3 个', 'Select the top 3 clips'), l('导出已选片段', 'Export selected clips')] : [l('开始分析', 'Start analysis')]}
- placeholder={props.promptHint ?? l('发送视频链接或描述剪辑要求', 'Send a video link or describe your editing requirements')}
+ title={l('视频切片', 'Video Clips')}
+ subtitle={l(
+ '自动识别长视频中的高光时刻,选择后生成独立短视频',
+ 'Find the strongest moments in long videos and turn them into standalone clips'
+ )}
+ context={selectedResult
+ ? l(
+ `V${selectedResult.value},${candidates.length} 个候选,已选 ${selected.length} 个`,
+ `V${selectedResult.value}, ${candidates.length} candidates, ${selected.length} selected`
+ )
+ : analyzing
+ ? l('正在识别视频高光', 'Finding video highlights')
+ : l('等待添加长视频', 'Waiting for a long video')}
+ suggestions={[]}
+ quickActions={quickActions}
+ placeholder={props.promptHint ?? l(
+ '询问切片进度,或描述内容重点、时长和画幅要求',
+ 'Ask about progress or describe the focus, duration, and format you need'
+ )}
+ stepLabel={exporting
+ ? l('导出视频切片', 'Exporting video clips')
+ : analyzing
+ ? l('识别视频高光', 'Finding video highlights')
+ : currentStep === 2
+ ? l('选择与导出', 'Select and export')
+ : steps[currentStep]!}
+ currentIssue={visibleError || undefined}
+ onCancelTask={analyzing || exporting
+ ? () => void session?.cancelJob().catch(cause => setError(formatClipError(cause, l)))
+ : undefined}
+ onResumeTask={session?.job.status === 'canceled'
+ ? () => void session.resumeJob().catch(cause => setError(formatClipError(cause, l)))
+ : undefined}
onBack={props.onBack}
- onCommand={handleCommand}
>
<div className="creator-tool-stack">
- <nav className="video-translation-steps creator-tool-steps" aria-label={l('自动剪辑流程', 'Auto clip workflow')}>
- <ol>{steps.map((step, index) => { const active = index === currentStep; const completed = index < currentStep; return <li key={step} data-active={active} data-completed={completed}><button type="button" disabled={index > furthestStep} aria-current={active ? 'step' : undefined} onClick={() => setCurrentStep(index as AutoClipStep)}><span>{completed ? <Check size={13} strokeWidth={2.2} aria-hidden="true" /> : index + 1}</span><strong>{step}</strong></button></li>; })}</ol>
+ <nav className="video-translation-steps creator-tool-steps" aria-label={l('视频切片流程', 'Video clip workflow')}>
+ <ol>{steps.map((step, index) => {
+ const active = index === currentStep;
+ const completed = index < currentStep;
+ return (
+ <li key={step} data-active={active} data-completed={completed}>
+ <button
+ type="button"
+ disabled={index > furthestStep || analyzing || exporting}
+ aria-current={active ? 'step' : undefined}
+ onClick={() => openStep(index as AutoClipStep)}
+ >
+ <span>{completed ? <Check size={13} strokeWidth={2.2} aria-hidden="true" /> : index + 1}</span>
+ <strong>{step}</strong>
+ </button>
+ </li>
+ );
+ })}</ol>
</nav>
{currentStep === 0 ? (
@@ -338,164 +500,565 @@ export default function AutoClipWorkspace(props: {
setVideoFile(null);
setSourceArtifactId('');
setSourceOrientation('landscape');
+ setError('');
setNotice('');
}}
onClear={clearCurrentSource}
- onDimensions={updateSourceOrientation}
+ onDimensions={(width, height) => setSourceOrientation(height > width ? 'portrait' : 'landscape')}
/>
) : (
- <section className="creator-tool-panel" aria-labelledby="auto-clip-imported-source-title">
+ <section className="creator-tool-panel" aria-labelledby="video-clips-imported-source-title">
<div className="creator-tool-panel-heading">
<div>
- <h2 id="auto-clip-imported-source-title">{l('项目视频', 'Project video')}</h2>
- <p>{l('已从视频下载任务导入,无需重新访问源网站', 'Imported from a video download job without fetching the source website again')}</p>
+ <h2 id="video-clips-imported-source-title">{l('项目视频', 'Project video')}</h2>
+ <p>{l('已从项目产出导入,无需重新下载', 'Imported from a project output without downloading it again')}</p>
</div>
</div>
<div className="video-result-file-row">
<span><FileVideo size={18} strokeWidth={1.7} /></span>
<div>
<strong>{importedSourceName}</strong>
- <small>{l('已关联到当前自动剪辑任务', 'Attached to this auto clip job')}</small>
+ <small>{l('已关联到当前视频切片任务', 'Attached to this video clip job')}</small>
</div>
- <button type="button" onClick={clearCurrentSource}>
- {l('更换', 'Change')}
- </button>
+ <button type="button" onClick={clearCurrentSource}>{l('更换', 'Change')}</button>
</div>
</section>
)}
- <div className="creator-tool-actions"><button className="creator-tool-primary" type="button" disabled={!hasSource} onClick={continueToSettings}>{l('下一步:分析设置', 'Next: Analysis settings')}</button></div>
+ <div className="creator-tool-actions">
+ <button className="creator-tool-primary" type="button" disabled={!hasSource} onClick={continueToSettings}>
+ {l('下一步:切片设置', 'Next: Clip settings')}
+ </button>
+ </div>
</>
) : null}
{currentStep === 1 ? (
<div className="creator-task-final-grid">
- <section className="creator-tool-panel" aria-labelledby="auto-clip-settings-title">
- <div className="creator-tool-panel-heading"><div><h2 id="auto-clip-settings-title">{l('设置分析目标', 'Set the analysis goal')}</h2><p>{l('先确定内容偏好、片段时长和数量,再开始识别字幕语义', 'Choose a content focus, clip length, and count before analyzing subtitle meaning')}</p></div></div>
+ <section className="creator-tool-panel" aria-labelledby="video-clips-settings-title">
+ <div className="creator-tool-panel-heading">
+ <div>
+ <h2 id="video-clips-settings-title">{l('设置切片目标', 'Set clip goals')}</h2>
+ <p>{l('AI 会根据内容重点、目标时长和传播完整度寻找最佳片段', 'AI finds the best moments using your focus, duration, and standalone clarity')}</p>
+ </div>
+ </div>
<div className="creator-tool-form-row auto-clip-settings-grid">
- <label className="creator-tool-field"><span>{l('内容偏好', 'Content focus')}</span><select aria-label={l('内容偏好', 'Content focus')} value={focus} onChange={event => setFocus(event.target.value as AnalysisFocus)}><option value="balanced">{l('综合表现', 'Balanced')}</option><option value="viral">{l('传播潜力优先', 'Shareability first')}</option><option value="knowledge">{l('知识完整度优先', 'Knowledge completeness')}</option></select></label>
- <label className="creator-tool-field"><span>{l('目标时长', 'Target duration')}</span><select aria-label={l('目标时长', 'Target duration')} value={duration} onChange={event => setDuration(event.target.value as ClipDuration)}><option value="15-30">15-30 {l('秒', 'sec')}</option><option value="30-60">30-60 {l('秒', 'sec')}</option><option value="60-90">60-90 {l('秒', 'sec')}</option></select></label>
- <label className="creator-tool-field"><span>{l('片段数量', 'Number of clips')}</span><input type="number" min="1" max={clips.length} step="1" aria-label={l('片段数量', 'Number of clips')} value={clipCount} onChange={event => setClipCount(clampClipCount(Number(event.target.value)))} /></label>
+ <label className="creator-tool-field">
+ <span>{l('内容重点', 'Content focus')}</span>
+ <select aria-label={l('内容重点', 'Content focus')} value={focus} onChange={event => setFocus(event.target.value as AnalysisFocus)}>
+ <option value="balanced">{l('综合表现', 'Balanced')}</option>
+ <option value="viral">{l('传播潜力优先', 'Shareability first')}</option>
+ <option value="knowledge">{l('知识完整度优先', 'Knowledge completeness')}</option>
+ </select>
+ </label>
+ <label className="creator-tool-field">
+ <span>{l('目标时长', 'Target duration')}</span>
+ <select aria-label={l('目标时长', 'Target duration')} value={duration} onChange={event => setDuration(event.target.value as ClipDuration)}>
+ <option value="15-30">15-30 {l('秒', 'sec')}</option>
+ <option value="30-60">30-60 {l('秒', 'sec')}</option>
+ <option value="60-90">60-90 {l('秒', 'sec')}</option>
+ </select>
+ </label>
+ <label className="creator-tool-field">
+ <span>{l('候选数量', 'Number of clips')}</span>
+ <input type="number" min="1" max="20" step="1" aria-label={l('候选数量', 'Number of clips')} value={clipCount} onChange={event => setClipCount(clampClipCount(Number(event.target.value)))} />
+ </label>
+ <label className="creator-tool-field">
+ <span>{l('输出画幅', 'Output format')}</span>
+ <select aria-label={l('输出画幅', 'Output format')} value={aspectRatio} onChange={event => setAspectRatio(event.target.value as ClipAspectRatio)}>
+ <option value="9:16">{l('竖屏', 'Portrait')} 9:16</option>
+ <option value="1:1">{l('方形', 'Square')} 1:1</option>
+ <option value="16:9">{l('横屏', 'Landscape')} 16:9</option>
+ <option value="source">{l('跟随原视频', 'Match source')}</option>
+ </select>
+ </label>
+ </div>
+ <div className="auto-clip-analysis-note">
+ <Sparkles size={18} strokeWidth={1.7} />
+ <div>
+ <strong>{l(`最多生成 ${clipCount} 个候选片段`, `Up to ${clipCount} candidate clips`)}</strong>
+ <p>{l('每条包含完整字幕、推荐理由、开头吸引力、信息价值、情绪强度和观点完整度评分', 'Each clip includes a transcript, rationale, and scores for hook, information, emotion, and completeness')}</p>
+ </div>
+ </div>
+ <div className="creator-tool-actions">
+ <button className="creator-tool-primary" type="button" disabled={analyzing} onClick={() => void analyze()}>
+ {analyzing ? <LoaderCircle className="smart-dubbing-spinner" size={16} /> : <Sparkles size={16} />}
+ {analyzing
+ ? l('正在识别高光', 'Finding highlights')
+ : selectedResult
+ ? l('重新识别并生成新版本', 'Reanalyze as a new version')
+ : l('识别高光片段', 'Find highlight clips')}
+ </button>
</div>
- <div className="auto-clip-analysis-note"><Sparkles size={18} strokeWidth={1.7} /><div><strong>{l(`将生成 ${clipCount} 个候选片段`, `${clipCount} candidate clips will be generated`)}</strong><p>{l('每条包含完整字幕、开头吸引力、语义完整度、情绪强度和传播潜力评分', 'Each includes a full transcript plus hook, completeness, emotion, and shareability scores')}</p></div></div>
- <div className="creator-tool-actions"><button className="creator-tool-primary" type="button" onClick={() => analyze()}><Sparkles size={16} />{selectedResult && hasPendingChanges ? l(`重新分析并生成 V${nextVersion}`, `Reanalyze as V${nextVersion}`) : l('识别语义并提取片段', 'Analyze and extract clips')}</button></div>
</section>
<CreatorTaskSummary
sourceIcon={FileVideo}
sourceLabel={l('视频来源', 'Video source')}
sourceValue={videoFile?.name ?? (importedSourceName || videoUrl)}
items={[
- { label: l('内容偏好', 'Content focus'), value: focusLabel(focus, l) },
+ { label: l('内容重点', 'Content focus'), value: focusLabel(focus, l) },
{ label: l('目标时长', 'Target duration'), value: `${duration} ${l('秒', 'sec')}` },
{ label: l('候选片段', 'Candidates'), value: String(clipCount) },
- { label: l('输出画幅', 'Output frame'), value: orientationLabel(sourceOrientation, l) }
+ { label: l('输出画幅', 'Output format'), value: aspectRatioLabel(aspectRatio, l) }
]}
/>
</div>
) : null}
{currentStep === 2 && selectedResult ? (
- <section className="video-result-workspace auto-clip-result-workspace" aria-label={l('自动剪辑项目产出', 'Auto clip project outputs')}>
+ <section className="video-result-workspace auto-clip-result-workspace" aria-label={l('视频切片项目产出', 'Video clip project outputs')}>
<div className="video-result-toolbar">
- <div className="video-result-tabs" role="tablist" aria-label={l('自动剪辑结果类型', 'Auto clip result types')}>
+ <div className="video-result-tabs" role="tablist" aria-label={l('视频切片结果类型', 'Video clip result types')}>
<button type="button" role="tab" aria-selected={resultTab === 'candidates'} onClick={() => setResultTab('candidates')}><ListVideo size={15} strokeWidth={1.8} />{l('候选片段', 'Candidates')}</button>
<button type="button" role="tab" aria-selected={resultTab === 'details'} onClick={() => setResultTab('details')}><Captions size={15} strokeWidth={1.8} />{l('字幕与评分', 'Transcript and scores')}</button>
<button type="button" role="tab" aria-selected={resultTab === 'export'} onClick={() => setResultTab('export')}><Download size={15} strokeWidth={1.8} />{l('导出内容', 'Exports')}</button>
<button type="button" role="tab" aria-selected={resultTab === 'settings'} onClick={() => setResultTab('settings')}><Settings2 size={15} strokeWidth={1.8} />{l('任务设置', 'Task settings')}</button>
</div>
- <CreatorResultVersionMenu version={resultVersion} versions={resultVersions.map(({ value, description }) => ({ value, description }))} onVersionChange={selectVersion} />
+ <CreatorResultVersionMenu
+ version={selectedResult.value}
+ versions={resultVersions.map(version => ({ value: version.value, description: version.description }))}
+ onVersionChange={selectVersion}
+ />
</div>
- {hasPendingChanges ? <div className="stickman-version-draft" role="status"><div><strong>{l(`正在基于 V${resultVersion} 调整`, `Adjusting from V${resultVersion}`)}</strong><span>{l('原版本的候选片段、字幕与评分仍可查看', 'The original candidates, transcripts, and scores remain available')}</span></div><button type="button" onClick={() => setCurrentStep(1)}>{l('继续设置', 'Continue settings')}</button></div> : null}
<div className="auto-clip-result-content">
+ {resultTab === 'candidates' ? (
+ <div className="video-result-pane">
+ <header className="video-result-pane-heading">
+ <div>
+ <h2>{l(`已找到 ${candidates.length} 个候选片段`, `Found ${candidates.length} candidate clips`)}</h2>
+ <p>{l(`V${selectedResult.value},已选 ${selected.length} 个`, `V${selectedResult.value}, ${selected.length} selected`)}</p>
+ </div>
+ <div className="auto-clip-result-actions">
+ <div className="auto-clip-layout-switch" role="group" aria-label={l('候选片段布局', 'Candidate clip layout')}>
+ <button type="button" aria-pressed={clipLayout === 'grid'} aria-label={l('网格视图', 'Grid view')} title={l('网格视图', 'Grid view')} onClick={() => setClipLayout('grid')}><LayoutGrid size={16} strokeWidth={1.8} /></button>
+ <button type="button" aria-pressed={clipLayout === 'list'} aria-label={l('列表视图', 'List view')} title={l('列表视图', 'List view')} onClick={() => setClipLayout('list')}><List size={16} strokeWidth={1.8} /></button>
+ </div>
+ <label>{l('排序', 'Sort')}
+ <select value={sort} onChange={event => setSort(event.target.value as typeof sort)}>
+ <option value="score">{l('综合评分', 'Overall score')}</option>
+ <option value="time">{l('原片顺序', 'Source order')}</option>
+ </select>
+ </label>
+ <button type="button" disabled={selected.length === 0 || exporting} onClick={() => void exportSelected()}>
+ {exporting ? <LoaderCircle className="smart-dubbing-spinner" size={15} /> : <Download size={15} />}
+ {l('导出已选', 'Export selected')} ({selected.length})
+ </button>
+ </div>
+ </header>
+ {clipLayout === 'grid' ? (
+ <section className="auto-clip-candidate-grid" data-orientation={currentOrientation} aria-label={l('候选片段网格', 'Candidate clip grid')}>
+ {orderedClips.map(clip => (
+ <article key={clip.id} data-selected={selected.includes(clip.id)}>
+ <div className="auto-clip-card-media">
+ {sourcePreviewUrl ? <video src={mediaFragment(sourcePreviewUrl, clip)} muted playsInline preload="metadata" aria-hidden="true" /> : <span className="auto-clip-media-placeholder"><FileVideo size={24} /></span>}
+ <span className="auto-clip-card-duration">{formatDuration(clip.end - clip.start)}</span>
+ <label><input type="checkbox" checked={selected.includes(clip.id)} onChange={() => toggleClip(clip.id)} aria-label={`${l('选择片段', 'Select clip')} ${clip.title}`} /></label>
+ <button type="button" onClick={() => { setActiveClipId(clip.id); setResultTab('details'); }} aria-label={`${l('播放片段', 'Play clip')} ${clip.title}`}><Play size={18} fill="currentColor" /></button>
+ </div>
+ <div className="auto-clip-card-copy"><strong>{clip.title}</strong><span>{formatTimeRange(clip)}</span></div>
+ <footer><span>{l('综合评分', 'Score')} <b>{totalScore(clip)}</b></span><div><button type="button" onClick={() => { setActiveClipId(clip.id); setResultTab('details'); }} aria-label={`${l('查看片段', 'View clip')} ${clip.title}`} title={l('查看详情', 'View details')}><Captions size={15} /></button></div></footer>
+ </article>
+ ))}
+ </section>
+ ) : (
+ <section className="auto-clip-candidate-detailed-list" data-orientation={currentOrientation} aria-label={l('候选片段列表', 'Candidate clip list')}>
+ {orderedClips.map(clip => (
+ <article key={clip.id} data-selected={selected.includes(clip.id)}>
+ <label className="auto-clip-list-select"><input type="checkbox" checked={selected.includes(clip.id)} onChange={() => toggleClip(clip.id)} aria-label={`${l('选择片段', 'Select clip')} ${clip.title}`} /></label>
+ <button className="auto-clip-list-preview" type="button" onClick={() => { setActiveClipId(clip.id); setResultTab('details'); }} aria-label={`${l('播放片段', 'Play clip')} ${clip.title}`}>
+ {sourcePreviewUrl ? <video src={mediaFragment(sourcePreviewUrl, clip)} muted playsInline preload="metadata" aria-hidden="true" /> : <span className="auto-clip-media-placeholder"><FileVideo size={24} /></span>}
+ <span>{formatDuration(clip.end - clip.start)}</span><Play size={18} fill="currentColor" />
+ </button>
+ <div className="auto-clip-list-content">
+ <header><div><strong>{clip.title}</strong><span>{formatTimeRange(clip)}</span></div><b>{totalScore(clip)}</b></header>
+ <p>{clip.transcript}</p>
+ <dl>{Object.entries(clip.scores).map(([key, score]) => <div key={key}><dt>{scoreLabel(key as ClipScoreKey, l)}</dt><dd>{score}</dd></div>)}</dl>
+ </div>
+ <div className="auto-clip-list-actions"><button type="button" onClick={() => { setActiveClipId(clip.id); setResultTab('details'); }} aria-label={`${l('查看片段', 'View clip')} ${clip.title}`}><Captions size={15} />{l('查看详情', 'View details')}</button></div>
+ </article>
+ ))}
+ </section>
+ )}
+ </div>
+ ) : null}
- {resultTab === 'candidates' ? (
- <div className="video-result-pane">
- <header className="video-result-pane-heading"><div><h2>{l(`已找到 ${selectedResult.clipCount} 个候选片段`, `Found ${selectedResult.clipCount} candidate clips`)}</h2><p>{l(`V${resultVersion},已选 ${selected.length} 个`, `V${resultVersion}, ${selected.length} selected`)}</p></div><div className="auto-clip-result-actions"><div className="auto-clip-layout-switch" role="group" aria-label={l('候选片段布局', 'Candidate clip layout')}><button type="button" aria-pressed={clipLayout === 'grid'} aria-label={l('网格视图', 'Grid view')} title={l('网格视图', 'Grid view')} onClick={() => setClipLayout('grid')}><LayoutGrid size={16} strokeWidth={1.8} /></button><button type="button" aria-pressed={clipLayout === 'list'} aria-label={l('列表视图', 'List view')} title={l('列表视图', 'List view')} onClick={() => setClipLayout('list')}><List size={16} strokeWidth={1.8} /></button></div><label>{l('排序', 'Sort')}<select value={sort} onChange={event => setSort(event.target.value as typeof sort)}><option value="score">{l('综合评分', 'Overall score')}</option><option value="time">{l('原片顺序', 'Source order')}</option></select></label><button type="button" disabled={selected.length === 0} onClick={exportSelected}><Download size={15} />{l('导出已选', 'Export selected')} ({selected.length})</button></div></header>
- {clipLayout === 'grid' ? (
- <section className="auto-clip-candidate-grid" data-orientation={selectedResult.sourceOrientation} aria-label={l('候选片段网格', 'Candidate clip grid')}>
- {orderedClips.map(clip => (
- <article key={clip.id} data-selected={selected.includes(clip.id)}>
- <div className="auto-clip-card-media">
- <img src="/dashboard/templates/video-translation-example.png" alt="" />
- <span className="auto-clip-card-duration">{clip.duration}</span>
- <label><input type="checkbox" checked={selected.includes(clip.id)} onChange={() => toggleClip(clip.id)} aria-label={`${l('选择片段', 'Select clip')} ${clip.id}`} /></label>
- <button type="button" onClick={() => { setActiveClip(clip.id); setResultTab('details'); }} aria-label={`${l('播放片段', 'Play clip')} ${clip.id}`}><Play size={18} fill="currentColor" /></button>
- </div>
- <div className="auto-clip-card-copy"><strong>{localizedClip(clip, l).title}</strong><span>{clip.time}</span></div>
- <footer><span>{l('综合评分', 'Score')} <b>{totalScore(clip)}</b></span><div><button type="button" onClick={() => { setActiveClip(clip.id); setResultTab('details'); }} aria-label={`${l('查看片段', 'View clip')} ${clip.id} ${localizedClip(clip, l).title}`} title={l('查看详情', 'View details')}><Captions size={15} /></button><button type="button" onClick={() => setNotice(l(`片段 ${clip.id} 已加入导出队列`, `Clip ${clip.id} was added to the export queue`))} aria-label={`${l('下载片段', 'Download clip')} ${clip.id}`} title={l('下载片段', 'Download clip')}><Download size={15} /></button></div></footer>
- </article>
- ))}
- </section>
- ) : (
- <section className="auto-clip-candidate-detailed-list" data-orientation={selectedResult.sourceOrientation} aria-label={l('候选片段列表', 'Candidate clip list')}>
- {orderedClips.map(clip => (
- <article key={clip.id} data-selected={selected.includes(clip.id)}>
- <label className="auto-clip-list-select"><input type="checkbox" checked={selected.includes(clip.id)} onChange={() => toggleClip(clip.id)} aria-label={`${l('选择片段', 'Select clip')} ${clip.id}`} /></label>
- <button className="auto-clip-list-preview" type="button" onClick={() => { setActiveClip(clip.id); setResultTab('details'); }} aria-label={`${l('播放片段', 'Play clip')} ${clip.id}`}><img src="/dashboard/templates/video-translation-example.png" alt="" /><span>{clip.duration}</span><Play size={18} fill="currentColor" /></button>
- <div className="auto-clip-list-content"><header><div><strong>{localizedClip(clip, l).title}</strong><span>{clip.time}</span></div><b>{totalScore(clip)}</b></header><p>{localizedClip(clip, l).subtitle}</p><dl>{Object.entries(clip.scores).map(([key, score]) => <div key={key}><dt>{scoreLabel(key as keyof ClipCandidate['scores'], l)}</dt><dd>{score}</dd></div>)}</dl></div>
- <div className="auto-clip-list-actions"><button type="button" onClick={() => { setActiveClip(clip.id); setResultTab('details'); }} aria-label={`${l('查看片段', 'View clip')} ${clip.id} ${localizedClip(clip, l).title}`}><Captions size={15} />{l('查看详情', 'View details')}</button><button type="button" onClick={() => setNotice(l(`片段 ${clip.id} 已加入导出队列`, `Clip ${clip.id} was added to the export queue`))} aria-label={`${l('下载片段', 'Download clip')} ${clip.id}`}><Download size={15} />{l('下载', 'Download')}</button></div>
- </article>
- ))}
- </section>
- )}
- </div>
- ) : null}
-
- {resultTab === 'details' ? (
- <div className="video-result-pane">
- <header className="video-result-pane-heading"><div><h2>{l('字幕与四维评分', 'Transcript and four scores')}</h2><p>{l('检查片段是否能够脱离原视频独立传播', 'Check whether this clip can stand on its own')}</p></div><button type="button" onClick={() => setResultTab('candidates')}>{l('返回候选片段', 'Back to candidates')}</button></header>
- <aside className="auto-clip-detail auto-clip-detail-result" data-orientation={selectedResult.sourceOrientation} aria-label={`${l('片段', 'Clip')} ${currentClip.id} ${l('详情', 'details')}`}><div className="auto-clip-player"><img src="/dashboard/templates/video-translation-example.png" alt={l('片段预览', 'Clip preview')} /><span><Play size={22} fill="currentColor" /></span></div><header><div><small>{l('片段', 'Clip')} {currentClip.id}</small><h2>{localizedClip(currentClip, l).title}</h2><p>{currentClip.time} · {currentClip.duration}</p></div><strong>{totalScore(currentClip)}</strong></header><dl className="auto-clip-scores"><div><dt>{l('开头吸引力', 'Hook')}</dt><dd>{currentClip.scores.hook}</dd></div><div><dt>{l('语义完整度', 'Completeness')}</dt><dd>{currentClip.scores.semantic}</dd></div><div><dt>{l('情绪强度', 'Emotion')}</dt><dd>{currentClip.scores.emotion}</dd></div><div><dt>{l('传播潜力', 'Shareability')}</dt><dd>{currentClip.scores.viral}</dd></div></dl><section className="auto-clip-subtitle"><h3>{l('片段字幕', 'Clip transcript')}</h3><p>{localizedClip(currentClip, l).subtitle}</p></section><button type="button" onClick={() => toggleClip(currentClip.id)}>{selected.includes(currentClip.id) ? <><Check size={15} />{l('已选择', 'Selected')}</> : l('选择此片段', 'Select this clip')}</button></aside>
- </div>
- ) : null}
+ {resultTab === 'details' && currentClip ? (
+ <div className="video-result-pane">
+ <header className="video-result-pane-heading"><div><h2>{l('字幕与四维评分', 'Transcript and four scores')}</h2><p>{l('检查片段是否能够脱离原视频独立传播', 'Check whether this clip can stand on its own')}</p></div><button type="button" onClick={() => setResultTab('candidates')}>{l('返回候选片段', 'Back to candidates')}</button></header>
+ <aside className="auto-clip-detail auto-clip-detail-result" data-orientation={currentOrientation} aria-label={`${l('片段详情', 'Clip details')} ${currentClip.title}`}>
+ <div className="auto-clip-player">
+ {sourcePreviewUrl ? <video controls playsInline preload="metadata" src={mediaFragment(sourcePreviewUrl, currentClip)} aria-label={l('片段预览', 'Clip preview')} /> : <span className="auto-clip-media-placeholder"><FileVideo size={28} /></span>}
+ </div>
+ <header><div><small>{formatTimeRange(currentClip)}</small><h2>{currentClip.title}</h2><p>{currentClip.reason}</p></div><strong>{totalScore(currentClip)}</strong></header>
+ <dl className="auto-clip-scores">
+ <div><dt>{l('开头吸引力', 'Hook')}</dt><dd>{currentClip.scores.hook}</dd></div>
+ <div><dt>{l('信息价值', 'Information')}</dt><dd>{currentClip.scores.information}</dd></div>
+ <div><dt>{l('情绪强度', 'Emotion')}</dt><dd>{currentClip.scores.emotion}</dd></div>
+ <div><dt>{l('观点完整度', 'Completeness')}</dt><dd>{currentClip.scores.completeness}</dd></div>
+ </dl>
+ <section className="auto-clip-subtitle"><h3>{l('片段字幕', 'Clip transcript')}</h3><p>{currentClip.transcript}</p></section>
+ <button type="button" onClick={() => toggleClip(currentClip.id)}>{selected.includes(currentClip.id) ? <><Check size={15} />{l('已选择', 'Selected')}</> : l('选择此片段', 'Select this clip')}</button>
+ </aside>
+ </div>
+ ) : null}
- {resultTab === 'export' ? (
- <div className="video-result-pane">
- <header className="video-result-pane-heading"><div><h2>{l('导出内容', 'Export selection')}</h2><p>{l('选择片段不会创建新版本,重新分析才会保留为新版本', 'Selecting clips does not create a version. Reanalysis does.')}</p></div><button type="button" disabled={selected.length === 0} onClick={exportSelected}><Download size={15} />{l('导出全部已选', 'Export selected')}</button></header>
- {selected.length ? <div className="auto-clip-export-list">{selected.map(id => { const clip = clips.find(item => item.id === id)!; return <div className="video-result-file-row" key={id}><span><Scissors size={18} strokeWidth={1.7} /></span><div><strong>{String(id).padStart(2, '0')}-{localizedClip(clip, l).title}.mp4</strong><small>{clip.time} · {clip.duration} · {l('综合评分', 'Score')} {totalScore(clip)}</small></div><button type="button" onClick={() => setNotice(l(`片段 ${id} 已加入导出队列`, `Clip ${id} was added to the export queue`))} aria-label={`${l('导出片段', 'Export clip')} ${id}`}><Download size={16} /></button></div>; })}</div> : <div className="video-result-empty"><Scissors size={26} strokeWidth={1.5} /><strong>{l('还没有选择片段', 'No clips selected')}</strong><button type="button" onClick={() => setResultTab('candidates')}>{l('返回选择片段', 'Choose clips')}</button></div>}
- </div>
- ) : null}
+ {resultTab === 'export' ? (
+ <div className="video-result-pane">
+ <header className="video-result-pane-heading">
+ <div><h2>{l('独立视频切片', 'Standalone video clips')}</h2><p>{l('每个已选片段会生成单独的 MP4 文件', 'Every selected moment is rendered as its own MP4 file')}</p></div>
+ <button type="button" disabled={selected.length === 0 || exporting} onClick={() => void exportSelected()}>{exporting ? <LoaderCircle className="smart-dubbing-spinner" size={15} /> : <Scissors size={15} />}{exportedArtifacts.length ? l('重新导出', 'Export again') : l('生成切片', 'Render clips')}</button>
+ </header>
+ {exporting ? (
+ <div className="video-result-empty" role="status"><LoaderCircle className="smart-dubbing-spinner" size={26} /><strong>{l('正在生成视频切片', 'Rendering video clips')}</strong><span>{readProgressText(latestRenderStage, l)}</span></div>
+ ) : exportedArtifacts.length > 0 ? (
+ <div className="auto-clip-export-grid">
+ {exportedArtifacts.map(artifact => (
+ <article className="auto-clip-export-card" key={artifact.id}>
+ {exportUrls[artifact.id] ? <video controls playsInline preload="metadata" src={exportUrls[artifact.id]} /> : <div className="auto-clip-export-loading"><LoaderCircle className="smart-dubbing-spinner" size={22} /></div>}
+ <footer>
+ <div><strong>{artifactFileName(artifact)}</strong><span>{aspectRatioLabel(readAspectRatio(artifact.metadata.aspectRatio), l)} · {formatDuration(readNumber(artifact.metadata.duration))}</span></div>
+ <button type="button" disabled={!exportUrls[artifact.id]} onClick={() => downloadArtifact(artifact)} aria-label={`${l('下载视频切片', 'Download video clip')} ${artifactFileName(artifact)}`}><Download size={16} /></button>
+ </footer>
+ </article>
+ ))}
+ </div>
+ ) : (
+ <div className="video-result-empty"><Scissors size={26} strokeWidth={1.5} /><strong>{l('还没有生成视频切片', 'No video clips rendered yet')}</strong><span>{l(`已选择 ${selected.length} 个候选片段`, `${selected.length} candidates selected`)}</span><button type="button" onClick={() => setResultTab('candidates')}>{l('返回选择片段', 'Choose clips')}</button></div>
+ )}
+ </div>
+ ) : null}
- {resultTab === 'settings' ? (
- <div className="video-result-pane">
- <header className="video-result-pane-heading"><div><h2>{l('当前版本设置', 'Current version settings')}</h2><p>{l('调整视频或分析目标后重新分析,会生成新版本', 'Changing the source or analysis goal and reanalyzing creates a new version')}</p></div><div className="video-result-pane-actions"><button type="button" onClick={() => setCurrentStep(0)}><FileVideo size={15} />{l('更换视频', 'Change video')}</button><button type="button" onClick={() => setCurrentStep(1)}><SlidersHorizontal size={15} />{l('调整分析设置', 'Adjust analysis')}</button></div></header>
- <dl className="video-result-settings"><div><dt>{l('视频来源', 'Video source')}</dt><dd>{selectedResult.videoFile?.name ?? selectedResult.videoUrl}</dd></div><div><dt>{l('候选数量', 'Candidates')}</dt><dd>{selectedResult.clipCount}</dd></div><div><dt>{l('输出画幅', 'Output frame')}</dt><dd>{orientationLabel(selectedResult.sourceOrientation, l)}</dd></div><div><dt>{l('内容偏好', 'Content focus')}</dt><dd>{focusLabel(selectedResult.focus, l)}</dd></div><div><dt>{l('目标时长', 'Target duration')}</dt><dd>{selectedResult.duration} {l('秒', 'sec')}</dd></div></dl>
- </div>
- ) : null}
+ {resultTab === 'settings' ? (
+ <div className="video-result-pane">
+ <header className="video-result-pane-heading"><div><h2>{l('当前版本设置', 'Current version settings')}</h2><p>{l('调整内容重点、时长或数量后重新识别,会保留为新版本', 'Reanalyzing after changing focus, duration, or count creates a new version')}</p></div><div className="video-result-pane-actions"><button type="button" onClick={() => openStep(0)}><FileVideo size={15} />{l('更换视频', 'Change video')}</button><button type="button" onClick={() => openStep(1)}><SlidersHorizontal size={15} />{l('调整切片设置', 'Adjust clip settings')}</button></div></header>
+ <dl className="video-result-settings">
+ <div><dt>{l('视频来源', 'Video source')}</dt><dd>{artifactFileName(selectedResult.sourceArtifact) || readString(selectedResult.state.sourceUrl)}</dd></div>
+ <div><dt>{l('候选数量', 'Candidates')}</dt><dd>{selectedResult.candidates.length}</dd></div>
+ <div><dt>{l('输出画幅', 'Output format')}</dt><dd>{aspectRatioLabel(readAspectRatio(selectedResult.state.aspectRatio), l)}</dd></div>
+ <div><dt>{l('内容重点', 'Content focus')}</dt><dd>{focusLabel(readFocus(selectedResult.state.focus), l)}</dd></div>
+ <div><dt>{l('目标时长', 'Target duration')}</dt><dd>{readDuration(selectedResult.state.duration)} {l('秒', 'sec')}</dd></div>
+ </dl>
+ </div>
+ ) : null}
</div>
</section>
) : null}
- {notice ? <p className="creator-tool-notice" role="status">{notice}</p> : null}
+
+ {analyzing && currentStep !== 2 ? (
+ <p className="creator-tool-notice" role="status"><LoaderCircle className="smart-dubbing-spinner" size={14} />{readProgressText(latestAnalysisStage, l)}</p>
+ ) : notice ? <p className="creator-tool-notice" role="status">{notice}</p> : null}
+ {visibleError ? <p className="creator-tool-error" role="alert">{visibleError}</p> : null}
</div>
</CreatorToolShell>
);
}
-function localizedClip(clip: ClipCandidate, l: ReturnType<typeof useLocalizedCopy>) {
- const english = englishClips[clip.id];
- return { title: l(clip.title, english?.title ?? clip.title), subtitle: l(clip.subtitle, english?.subtitle ?? clip.subtitle) };
+function createAutoClipResultVersions(
+ artifacts: CreatorArtifact[],
+ resultSnapshots: CreatorJson | undefined
+): AutoClipResultVersion[] {
+ const byId = new Map(artifacts.map(artifact => [artifact.id, artifact]));
+ const versions = readCreatorResultSnapshots(resultSnapshots).flatMap(snapshot => {
+ const artifact = (snapshot.artifactRefs.clip_candidates ?? [])
+ .map(id => byId.get(id))
+ .find((candidate): candidate is CreatorArtifact => candidate !== undefined);
+ if (artifact === undefined) return [];
+ const candidates = readCandidates(artifact.metadata.candidates);
+ if (candidates.length === 0) return [];
+ const sourceArtifact = (snapshot.artifactRefs.source_video ?? [])
+ .map(id => byId.get(id))
+ .find((candidate): candidate is CreatorArtifact => candidate !== undefined);
+ return [{
+ value: snapshot.version,
+ description: snapshot.description,
+ state: snapshot.state,
+ artifact,
+ ...(sourceArtifact === undefined ? {} : { sourceArtifact }),
+ candidates
+ }];
+ });
+ if (versions.length > 0) return versions.sort((left, right) => left.value - right.value);
+ return artifacts
+ .filter(artifact => artifact.kind === 'clip_candidates')
+ .flatMap(artifact => {
+ const candidates = readCandidates(artifact.metadata.candidates);
+ if (candidates.length === 0) return [];
+ return [{
+ value: readPositiveInteger(artifact.metadata.resultVersion) ?? artifact.version,
+ description: '识别视频高光片段',
+ state: {},
+ artifact,
+ sourceArtifact: artifacts.find(candidate => (
+ candidate.kind === 'source_video'
+ && artifact.sourceArtifactIds.includes(candidate.id)
+ )),
+ candidates
+ }];
+ })
+ .sort((left, right) => left.value - right.value);
+}
+
+function readCandidates(value: CreatorJson | undefined): ClipCandidate[] {
+ if (!Array.isArray(value)) return [];
+ return value.flatMap(item => {
+ if (!isRecord(item)) return [];
+ const scores = isRecord(item.scores) ? item.scores : undefined;
+ const id = readString(item.id);
+ const title = readString(item.title);
+ const transcript = readString(item.transcript);
+ const reason = readString(item.reason);
+ const start = readNumber(item.start);
+ const end = readNumber(item.end);
+ if (!id || !title || !transcript || !reason || end <= start || scores === undefined) return [];
+ return [{
+ id,
+ title,
+ transcript,
+ reason,
+ start,
+ end,
+ scores: {
+ hook: scoreValue(scores.hook),
+ information: scoreValue(scores.information),
+ emotion: scoreValue(scores.emotion),
+ completeness: scoreValue(scores.completeness)
+ }
+ }];
+ });
+}
+
+function totalScore(clip: ClipCandidate): number {
+ const values = Object.values(clip.scores);
+ return Math.round(values.reduce((sum, score) => sum + score, 0) / values.length);
+}
+
+function scoreValue(value: CreatorJson | undefined): number {
+ return Math.max(0, Math.min(100, Math.round(readNumber(value))));
+}
+
+function formatTimeRange(clip: ClipCandidate): string {
+ return `${formatTimestamp(clip.start)} - ${formatTimestamp(clip.end)}`;
+}
+
+function formatTimestamp(seconds: number): string {
+ const total = Math.max(0, Math.round(seconds));
+ const hours = Math.floor(total / 3600);
+ const minutes = Math.floor(total % 3600 / 60);
+ const remaining = total % 60;
+ return hours > 0
+ ? [hours, minutes, remaining].map(value => String(value).padStart(2, '0')).join(':')
+ : [minutes, remaining].map(value => String(value).padStart(2, '0')).join(':');
+}
+
+function formatDuration(seconds: number): string {
+ const value = Math.max(0, Math.round(seconds));
+ return value >= 60
+ ? `${Math.floor(value / 60)}:${String(value % 60).padStart(2, '0')}`
+ : `${value}s`;
+}
+
+function mediaFragment(url: string, clip: ClipCandidate): string {
+ return `${url}#t=${clip.start},${clip.end}`;
}
-function focusLabel(value: AnalysisFocus, l: ReturnType<typeof useLocalizedCopy>) {
+function focusLabel(value: AnalysisFocus, l: ReturnType<typeof useLocalizedCopy>): string {
if (value === 'viral') return l('传播潜力优先', 'Shareability first');
if (value === 'knowledge') return l('知识完整度优先', 'Knowledge completeness');
return l('综合表现', 'Balanced');
}
-function scoreLabel(value: keyof ClipCandidate['scores'], l: ReturnType<typeof useLocalizedCopy>) {
+function aspectRatioLabel(value: ClipAspectRatio, l: ReturnType<typeof useLocalizedCopy>): string {
+ if (value === '16:9') return l('横屏 16:9', 'Landscape 16:9');
+ if (value === '9:16') return l('竖屏 9:16', 'Portrait 9:16');
+ if (value === '1:1') return l('方形 1:1', 'Square 1:1');
+ return l('跟随原视频', 'Match source');
+}
+
+function scoreLabel(value: ClipScoreKey, l: ReturnType<typeof useLocalizedCopy>): string {
if (value === 'hook') return l('开头', 'Hook');
- if (value === 'semantic') return l('语义', 'Meaning');
+ if (value === 'information') return l('信息', 'Information');
if (value === 'emotion') return l('情绪', 'Emotion');
- return l('传播', 'Sharing');
+ return l('完整度', 'Completeness');
+}
+
+function readProgressText(
+ stage: CreatorStageRun | undefined,
+ l: ReturnType<typeof useLocalizedCopy>
+): string {
+ if (stage?.stageId === 'probe') return l('正在读取视频信息', 'Reading video information');
+ if (stage?.stageId === 'download') return l('正在下载源视频', 'Downloading the source video');
+ if (stage?.stageId === 'subtitle') return l('正在生成视频字幕', 'Generating the transcript');
+ if (stage?.stageId === 'analyze') return l('正在识别最适合独立传播的高光片段', 'Finding the strongest standalone moments');
+ if (stage?.stageId === 'render') {
+ const completed = readNumber(stage.progress.completed);
+ const total = readNumber(stage.progress.total);
+ return total > 0
+ ? l(`正在生成切片 ${completed}/${total}`, `Rendering clips ${completed}/${total}`)
+ : l('正在生成视频切片', 'Rendering video clips');
+ }
+ return l('正在准备任务', 'Preparing the task');
+}
+
+function readFocus(value: CreatorJson | undefined): AnalysisFocus {
+ return value === 'viral' || value === 'knowledge' ? value : 'balanced';
+}
+
+function readDuration(value: CreatorJson | undefined): ClipDuration {
+ return value === '15-30' || value === '60-90' ? value : '30-60';
+}
+
+function readAspectRatio(value: CreatorJson | undefined): ClipAspectRatio {
+ return value === 'source' || value === '16:9' || value === '1:1' ? value : '9:16';
}
-function orientationLabel(value: VideoOrientation, l: ReturnType<typeof useLocalizedCopy>) {
- return value === 'portrait' ? l('竖屏', 'Portrait') : l('横屏', 'Landscape');
+function readClipCount(value: CreatorJson | undefined): number {
+ return typeof value === 'number' ? clampClipCount(value) : 10;
}
-function clampClipCount(value: number) {
+function clampClipCount(value: number): number {
if (!Number.isFinite(value)) return 1;
- return Math.min(clips.length, Math.max(1, Math.round(value)));
+ return Math.min(20, Math.max(1, Math.round(value)));
+}
+
+function readString(value: CreatorJson | undefined): string {
+ return typeof value === 'string' ? value.trim() : '';
+}
+
+function readStringArray(value: CreatorJson | undefined): string[] {
+ return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : [];
+}
+
+function readNumber(value: CreatorJson | undefined): number {
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0;
+}
+
+function readPositiveInteger(value: CreatorJson | undefined): number | undefined {
+ return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;
+}
+
+function isRecord(value: CreatorJson | undefined): value is Record<string, CreatorJson> {
+ return value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
+}
+
+function isValidUrl(value: string): boolean {
+ try {
+ const url = new URL(value.trim());
+ return url.protocol === 'https:' || url.protocol === 'http:';
+ } catch {
+ return false;
+ }
+}
+
+function findArtifact(
+ artifacts: CreatorArtifact[],
+ artifactId: string,
+ kind: string
+): CreatorArtifact | undefined {
+ return artifacts.find(artifact => (
+ artifact.id === artifactId
+ && artifact.kind === kind
+ && artifact.status === 'completed'
+ ));
+}
+
+function latestCompletedArtifact(
+ artifacts: CreatorArtifact[],
+ kind: string
+): CreatorArtifact | undefined {
+ return [...artifacts].reverse().find(artifact => (
+ artifact.kind === kind && artifact.status === 'completed'
+ ));
+}
+
+function matchingSourceArtifact(
+ artifacts: CreatorArtifact[],
+ artifactId: string,
+ sourceUrl: string
+): CreatorArtifact | undefined {
+ const selected = findArtifact(artifacts, artifactId, 'source_video');
+ if (selected !== undefined) return selected;
+ const normalizedUrl = sourceUrl.trim();
+ return [...artifacts].reverse().find(artifact => (
+ artifact.kind === 'source_video'
+ && artifact.status === 'completed'
+ && normalizedUrl.length > 0
+ && [artifact.metadata.sourceUrl, artifact.metadata.requestedUrl, artifact.metadata.webpageUrl]
+ .some(value => typeof value === 'string' && value.trim() === normalizedUrl)
+ ));
+}
+
+function matchingSubtitleArtifact(
+ artifacts: CreatorArtifact[],
+ source: CreatorArtifact
+): CreatorArtifact | undefined {
+ return [...artifacts].reverse().find(artifact => (
+ artifact.kind === 'target_subtitle'
+ && artifact.status === 'completed'
+ && artifact.sourceArtifactIds.includes(source.id)
+ ));
+}
+
+function latestStage(stages: CreatorStageRun[], stageIds: Set<string>): CreatorStageRun | undefined {
+ return [...stages].reverse().find(stage => stageIds.has(stage.stageId));
+}
+
+function latestFailedStage(stages: CreatorStageRun[]): CreatorStageRun | undefined {
+ return [...stages].reverse().find(stage => stage.status === 'failed');
+}
+
+function latestExportsForCandidateArtifact(
+ artifacts: CreatorArtifact[],
+ candidateArtifactId: string
+): CreatorArtifact[] {
+ const latestByCandidate = new Map<string, CreatorArtifact>();
+ for (const artifact of artifacts) {
+ if (
+ artifact.kind !== 'auto_clip_video'
+ || artifact.status !== 'completed'
+ || artifact.metadata.candidateArtifactId !== candidateArtifactId
+ ) continue;
+ const candidateId = readString(artifact.metadata.candidateId) || artifact.id;
+ latestByCandidate.set(candidateId, artifact);
+ }
+ return [...latestByCandidate.values()].sort((left, right) => (
+ readNumber(left.metadata.start) - readNumber(right.metadata.start)
+ ));
+}
+
+function artifactFileName(artifact: CreatorArtifact | undefined): string {
+ if (artifact === undefined) return '';
+ const value = artifact.metadata.fileName;
+ return typeof value === 'string' && value.trim() ? value.trim() : '';
+}
+
+function readOrientation(artifact: CreatorArtifact | undefined): VideoOrientation | undefined {
+ const width = readNumber(artifact?.metadata.width);
+ const height = readNumber(artifact?.metadata.height);
+ if (width <= 0 || height <= 0) return undefined;
+ return height > width ? 'portrait' : 'landscape';
}
-function createAnalysisSignature(input: { videoUrl: string; videoFile: File | null; sourceArtifactId: string; focus: AnalysisFocus; duration: ClipDuration; clipCount: number; sourceOrientation: VideoOrientation }) {
- return JSON.stringify({ url: input.videoUrl.trim(), sourceArtifactId: input.sourceArtifactId, file: input.videoFile ? { name: input.videoFile.name, size: input.videoFile.size, type: input.videoFile.type, lastModified: input.videoFile.lastModified } : null, focus: input.focus, duration: input.duration, clipCount: input.clipCount, sourceOrientation: input.sourceOrientation });
+function formatClipError(
+ error: unknown,
+ l: (zh: string, en: string) => string
+): string {
+ if (error === null || error === undefined) return '';
+ const candidate = error as { code?: unknown; errorCode?: unknown; message?: unknown; errorMessage?: unknown };
+ const code = typeof candidate.code === 'string'
+ ? candidate.code
+ : typeof candidate.errorCode === 'string'
+ ? candidate.errorCode
+ : '';
+ if (code === 'creator_llm_config_missing') return l('请先在设置中配置文本模型', 'Configure the text model in Settings first');
+ if (code === 'creator_transcription_config_missing') return l('请先在设置中配置视频转录服务', 'Configure video transcription in Settings first');
+ if (code === 'unsupported_source') return l('目前仅支持公开视频链接或本地视频文件', 'Use a supported public video URL or a local video file');
+ if (code === 'creator_clip_selection_missing') return l('请至少选择一个候选片段', 'Select at least one candidate clip');
+ if (code === 'creator_stage_canceled') return l('视频切片任务已取消', 'The video clip task was canceled');
+ const message = typeof candidate.message === 'string'
+ ? candidate.message
+ : typeof candidate.errorMessage === 'string'
+ ? candidate.errorMessage
+ : error instanceof Error
+ ? error.message
+ : '';
+ return message || l('视频切片失败,请稍后重试', 'Video clipping failed. Try again later.');
}
diff --git a/apps/web/src/features/dashboard/DashboardPage.tsx b/apps/web/src/features/dashboard/DashboardPage.tsx
index d3e33f43..a4e9cf57 100644
--- a/apps/web/src/features/dashboard/DashboardPage.tsx
+++ b/apps/web/src/features/dashboard/DashboardPage.tsx
@@ -126,9 +126,9 @@ const creatorTools: DashboardEntry[] = [
workspace: 'video-download'
},
{
- title: '自动剪辑',
- description: '语义识别与高光切片',
- prompt: '帮我剪辑这些视频素材,请梳理叙事节奏,给出剪辑方案并生成成片。',
+ title: '视频切片',
+ description: 'AI 识别长视频高光片段',
+ prompt: '帮我从这段长视频中识别适合独立传播的高光片段,并生成多个短视频切片。',
category: '视频编辑',
icon: Clapperboard,
workspace: 'auto-clips'
@@ -885,6 +885,8 @@ const englishDashboardLabels: Record<string, string> = {
语义识别与高光切片: 'Semantic detection and highlight clips',
短视频脚本: 'Short Video Script',
生成分段口播与画面建议: 'Generate timed narration and visual suggestions',
+ 视频切片: 'Video Clips',
+ 'AI 识别长视频高光片段': 'Find the strongest moments in long videos with AI',
智能配音: 'AI Dubbing',
小红书帖子: 'Xiaohongshu Posts',
从主题和素材生成完整帖子: 'Turn a topic or source material into a complete post',
diff --git a/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx b/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx
index b662e826..82afc3a5 100644
--- a/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx
+++ b/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx
@@ -130,7 +130,7 @@ describe('VideoDownloadWorkspace', () => {
name: '发送到视频翻译 Creator Download.mp4'
})).not.toBeInTheDocument();
expect(screen.queryByRole('button', {
- name: '发送到自动剪辑 Creator Download.mp4'
+ name: '发送到视频切片 Creator Download.mp4'
})).not.toBeInTheDocument();
});
diff --git a/apps/web/src/features/dashboard/creator-panel-adapters.ts b/apps/web/src/features/dashboard/creator-panel-adapters.ts
index 0c17a01a..ece6734c 100644
--- a/apps/web/src/features/dashboard/creator-panel-adapters.ts
+++ b/apps/web/src/features/dashboard/creator-panel-adapters.ts
@@ -311,6 +311,72 @@ export const videoDownloadPanelAdapter: CreatorPanelAdapter = {
}
};
+export const autoClipPanelAdapter: CreatorPanelAdapter = {
+ id: 'auto-clip',
+ composerPlaceholder: l => l(
+ '询问分析或导出状态,或调整内容重点、片段时长和输出画幅',
+ 'Ask about analysis or export progress, or adjust the focus, clip length, and output format'
+ ),
+ stageLabel(stageId, l) {
+ if (stageId === 'probe') return l('读取视频信息', 'Read video information');
+ if (stageId === 'download') return l('下载源视频', 'Download source video');
+ if (stageId === 'subtitle') return l('生成视频字幕', 'Generate video transcript');
+ if (stageId === 'analyze') return l('识别高光片段', 'Find highlight clips');
+ if (stageId === 'render') return l('导出视频切片', 'Export video clips');
+ return l('视频切片任务', 'Video clips task');
+ },
+ phaseLabel(phase, l) {
+ const labels: Record<string, string> = {
+ validating: l('检查视频与切片设置', 'Checking the video and clip settings'),
+ probing_source: l('读取视频信息', 'Reading video information'),
+ preparing_download: l('准备下载源视频', 'Preparing the source video download'),
+ downloading: l('下载源视频', 'Downloading the source video'),
+ merging_media: l('合并视频与音频', 'Merging video and audio'),
+ normalizing_media: l('转换视频格式', 'Converting the video format'),
+ preparing_source: l('准备视频内容', 'Preparing the video content'),
+ reading_platform_captions: l('获取平台字幕', 'Fetching platform captions'),
+ processing_platform_captions: l('解析平台字幕', 'Processing platform captions'),
+ transcribing_audio: l('转录视频语音', 'Transcribing the video audio'),
+ collecting_subtitles: l('整理视频字幕', 'Collecting the video transcript'),
+ analyzing_clips: l('分析高光与传播潜力', 'Analyzing highlights and social potential'),
+ rendering_clips: l('生成独立视频切片', 'Rendering individual video clips'),
+ completed: l('视频切片已完成', 'Video clips completed')
+ };
+ return labels[phase] ?? genericPhaseLabel(phase, l);
+ },
+ activityStageId: readActivityStageId,
+ normalizeActivity(activity, l) {
+ if (activity.action === 'run-stage') {
+ const stageId = readActivityStageId(activity);
+ return {
+ label: stageId === null
+ ? l('开始视频切片任务', 'Started the video clips task')
+ : l(
+ `开始${autoClipPanelAdapter.stageLabel(stageId, l)}`,
+ `Started ${autoClipPanelAdapter.stageLabel(stageId, l)}`
+ ),
+ fields: []
+ };
+ }
+ return normalizeCommonActivity(activity, l, autoClipPanelAdapter, {}, autoClipFieldLabel);
+ },
+ readStageProgress: readStandardProgress,
+ runningProgressText(_stage, progress, l) {
+ if (progress.total !== null && progress.total > 0 && progress.completed !== null && progress.phase === 'rendering_clips') {
+ return l(`正在导出视频切片 ${progress.completed}/${progress.total}`, `Exporting video clips ${progress.completed}/${progress.total}`);
+ }
+ return progress.phase === null ? null : autoClipPanelAdapter.phaseLabel(progress.phase, l);
+ },
+ succeededProgressText(stage, l) {
+ if (stage.stageId === 'probe') return l('视频信息已读取', 'Video information read');
+ if (stage.stageId === 'download') return l('源视频已下载', 'Source video downloaded');
+ if (stage.stageId === 'subtitle') return l('视频字幕已生成', 'Video transcript generated');
+ if (stage.stageId === 'analyze') return l('高光片段已识别', 'Highlight clips found');
+ if (stage.stageId === 'render') return l('视频切片已导出', 'Video clips exported');
+ return null;
+ }
+};
+
export const stickmanVideoPanelAdapter: CreatorPanelAdapter = {
id: 'stickman-video',
composerPlaceholder: l => l(
@@ -773,6 +839,7 @@ export const videoGenerationPanelAdapter: CreatorPanelAdapter = {
export function creatorPanelAdapterFor(templateId: string): CreatorPanelAdapter {
if (templateId === 'video-translation') return videoTranslationPanelAdapter;
if (templateId === 'video-download') return videoDownloadPanelAdapter;
+ if (templateId === 'auto-clip') return autoClipPanelAdapter;
if (templateId === 'smart-dubbing') return smartDubbingPanelAdapter;
if (templateId === 'xiaohongshu-post') return xiaohongshuPostPanelAdapter;
if (templateId === 'short-video-script') return shortVideoScriptPanelAdapter;
@@ -995,6 +1062,19 @@ function shortVideoScriptFieldLabel(
return labels[field] ?? null;
}
+function autoClipFieldLabel(field: string, l: CreatorPanelLocalize): string | null {
+ const labels: Record<string, string> = {
+ sourceType: l('视频来源', 'Video source'),
+ sourceUrl: l('视频链接', 'Video URL'),
+ sourceArtifactId: l('项目视频', 'Project video'),
+ focus: l('内容重点', 'Content focus'),
+ duration: l('目标时长', 'Target duration'),
+ clipCount: l('候选数量', 'Candidate count'),
+ aspectRatio: l('输出画幅', 'Output format')
+ };
+ return labels[field] ?? null;
+}
+
function videoGenerationFieldLabel(
field: string,
l: CreatorPanelLocalize
diff --git a/apps/web/src/features/dashboard/creator-workspace.ts b/apps/web/src/features/dashboard/creator-workspace.ts
index 5c6f2faf..8e137cd4 100644
--- a/apps/web/src/features/dashboard/creator-workspace.ts
+++ b/apps/web/src/features/dashboard/creator-workspace.ts
@@ -31,6 +31,7 @@ export const visibleCreatorWorkspaces = [
'video-translation',
'video-download',
'stickman-video',
+ 'auto-clips',
'smart-dubbing',
'xiaohongshu-post',
'short-video-script',
diff --git a/apps/web/src/features/dashboard/dashboard.css b/apps/web/src/features/dashboard/dashboard.css
index ece0cd22..16922054 100644
--- a/apps/web/src/features/dashboard/dashboard.css
+++ b/apps/web/src/features/dashboard/dashboard.css
@@ -9046,7 +9046,8 @@
}
.stickman-video-result img,
-.auto-clip-player img {
+.auto-clip-player img,
+.auto-clip-player video {
width: 100%;
height: 100%;
display: block;
@@ -9422,7 +9423,8 @@
aspect-ratio: 16 / 9;
}
-.auto-clip-card-media > img {
+.auto-clip-card-media > img,
+.auto-clip-card-media > video {
width: 100%;
height: 100%;
display: block;
@@ -9586,7 +9588,8 @@
aspect-ratio: 16 / 9;
}
-.auto-clip-list-preview img {
+.auto-clip-list-preview img,
+.auto-clip-list-preview video {
width: 100%;
height: 100%;
display: block;
@@ -9735,6 +9738,83 @@
aspect-ratio: 9 / 16;
}
+.auto-clip-media-placeholder {
+ width: 100%;
+ height: 100%;
+ display: grid;
+ place-items: center;
+ background: var(--surface-2);
+ color: var(--subtle);
+}
+
+.auto-clip-export-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
+ align-items: start;
+ gap: 12px;
+}
+
+.auto-clip-export-card {
+ min-width: 0;
+ overflow: hidden;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: var(--surface);
+}
+
+.auto-clip-export-card video,
+.auto-clip-export-loading {
+ width: 100%;
+ aspect-ratio: 9 / 16;
+ display: grid;
+ place-items: center;
+ background: #09090b;
+ color: #fff;
+ object-fit: contain;
+}
+
+.auto-clip-export-card footer {
+ min-width: 0;
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto;
+ align-items: center;
+ gap: 10px;
+ padding: 10px;
+}
+
+.auto-clip-export-card footer > div {
+ min-width: 0;
+ display: grid;
+ gap: 3px;
+}
+
+.auto-clip-export-card footer strong,
+.auto-clip-export-card footer span {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.auto-clip-export-card footer strong {
+ font-size: 12px;
+}
+
+.auto-clip-export-card footer span {
+ color: var(--muted);
+ font-size: 10px;
+}
+
+.auto-clip-export-card footer button {
+ width: 32px;
+ height: 32px;
+ display: grid;
+ place-items: center;
+ padding: 0;
+ border: 1px solid var(--border);
+ border-radius: 7px;
+ color: var(--text);
+}
+
.auto-clip-export-list,
.cover-reference-results {
display: grid;
diff --git a/apps/web/src/features/projects/ProjectsPage.tsx b/apps/web/src/features/projects/ProjectsPage.tsx
index 3cd74b30..b52979a2 100644
--- a/apps/web/src/features/projects/ProjectsPage.tsx
+++ b/apps/web/src/features/projects/ProjectsPage.tsx
@@ -516,12 +516,19 @@ function creatorDraftDefaults(templateId: string): Record<string, unknown[]> {
}
if (templateId === 'auto-clip') {
return {
+ sourceType: ['url'],
sourceUrl: [''],
+ sourceArtifactId: [null],
+ formatId: ['bestvideo+bestaudio/best'],
+ sourceLanguage: ['auto'],
+ targetLanguage: ['zh-CN'],
+ preferPlatformCaptions: [true],
focus: ['balanced'],
duration: ['30-60'],
clipCount: [10],
- sourceOrientation: ['landscape'],
- selectedCandidateIds: [['1', '2', '3']]
+ aspectRatio: ['9:16'],
+ selectedCandidateIds: [[]],
+ currentStage: [null]
};
}
if (templateId === 'xiaohongshu-post') {
@@ -646,7 +653,7 @@ function shorten(value: string, limit: number): string {
function templateLabel(templateId: string, l: LocalizeCopy): string | undefined {
if (templateId === 'video-translation') return l('视频翻译', 'Video translation');
if (templateId === 'video-download') return l('视频下载', 'Video download');
- if (templateId === 'auto-clip') return l('自动剪辑', 'Auto clips');
+ if (templateId === 'auto-clip') return l('视频切片', 'Video clips');
if (templateId === 'cover') return l('封面生成', 'Thumbnail generation');
if (templateId === 'image-generation') return l('图像生成', 'Image generation');
if (templateId === 'video-generation') return l('视频生成', 'Video generation');
@@ -761,7 +768,7 @@ function projectCover(templateId: string): string {
if (templateId === 'image-generation') return '/dashboard/templates/image-generation-project-cover.png';
if (templateId === 'video-generation') return '/dashboard/templates/animated-story.jpg';
if (templateId === 'stickman-video') return '/dashboard/templates/ai-video-insane.jpg';
- if (templateId === 'auto-clip') return '/dashboard/templates/animated-story.jpg';
+ if (templateId === 'auto-clip') return '/dashboard/templates/intelligent-clipping-cover.png';
if (templateId === 'xiaohongshu-post') return '/dashboard/templates/digital-presenter.jpg';
if (templateId === 'short-video-script') return '/skill-market/examples/gpt-image-2-info-poster.png';
return '/dashboard/templates/digital-presenter.jpg';