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: optimize automatic video clipping workflow

Joshuaca5fde89d306
diff --git a/apps/daemon/src/creator/clip/analyzer.ts b/apps/daemon/src/creator/clip/analyzer.ts
index 161d1ed0..f7b5d640 100644
--- a/apps/daemon/src/creator/clip/analyzer.ts
+++ b/apps/daemon/src/creator/clip/analyzer.ts
@@ -17,6 +17,7 @@ const candidateSchema = z.object({
const responseSchema = z.object({ candidates: z.array(candidateSchema) }).strict();
export type ClipCandidate = z.infer<typeof candidateSchema>;
+export type ClipGenre = 'auto' | 'talk' | 'podcast' | 'tutorial' | 'interview' | 'entertainment' | 'sports' | 'gaming' | 'news';
export function parseClipCandidates(value: unknown, duration: number): ClipCandidate[] {
const parsed = responseSchema.parse(value);
@@ -42,6 +43,7 @@ export async function analyzeClips(input: {
minDuration: number;
maxDuration: number;
count: number;
+ genre?: ClipGenre;
fetchImpl?: typeof fetch;
}): Promise<ClipCandidate[]> {
const response = await (input.fetchImpl ?? fetch)(`${input.baseUrl.replace(/\/$/, '') || 'https://api.openai.com/v1'}/chat/completions`, {
@@ -77,15 +79,18 @@ function buildClipAnalysisPrompt(input: {
minDuration: number;
maxDuration: number;
count: number;
+ genre?: ClipGenre;
}): string {
const focus = input.focus === 'viral'
? '优先寻找开头抓人、情绪明确、适合社交平台独立传播的片段'
: input.focus === 'knowledge'
? '优先寻找观点完整、信息密度高、无需上下文也能理解的知识片段'
: '平衡开头吸引力、信息价值、情绪强度和观点完整度';
+ const genre = genreInstruction(input.genre ?? 'auto');
return [
'你是短视频剪辑分析器。请从字幕中选择互不重叠、脱离原视频也能独立成立的高光片段。',
`分析偏好:${focus}。`,
+ `内容类型:${genre}。`,
`返回最多 ${input.count} 个片段,每个片段时长必须在 ${input.minDuration}-${input.maxDuration} 秒之间。`,
'标题要简洁具体;transcript 必须是该时间范围内可直接展示给用户的完整字幕;reason 解释它为什么适合作为短视频。',
'四项评分均使用 0-100 的整数:hook 开头吸引力,information 信息价值,emotion 情绪强度,completeness 观点完整度。',
@@ -95,3 +100,15 @@ function buildClipAnalysisPrompt(input: {
`字幕:\n${input.transcript}`
].join('\n');
}
+
+function genreInstruction(value: ClipGenre): string {
+ if (value === 'talk') return '演讲或观点表达';
+ if (value === 'podcast') return '播客对谈';
+ if (value === 'tutorial') return '教程或知识讲解';
+ if (value === 'interview') return '人物访谈';
+ if (value === 'entertainment') return '娱乐内容';
+ if (value === 'sports') return '体育内容';
+ if (value === 'gaming') return '游戏内容';
+ if (value === 'news') return '新闻或时事内容';
+ return '自动判断,不预设内容类型';
+}
diff --git a/apps/daemon/src/creator/clip/executor.ts b/apps/daemon/src/creator/clip/executor.ts
index 84791993..0988f226 100644
--- a/apps/daemon/src/creator/clip/executor.ts
+++ b/apps/daemon/src/creator/clip/executor.ts
@@ -5,12 +5,13 @@ import type { CreatorExecutor } from '../executor.js';
import { CreatorExecutorError } from '../executor.js';
import { spawnCreatorProcess } from '../process-tree.js';
import { validateMediaFile } from '../validators/media.js';
-import { analyzeClips, parseClipCandidates } from './analyzer.js';
+import { analyzeClips, parseClipCandidates, type ClipGenre } from './analyzer.js';
export function createClipExecutor(input: {
configStore: Pick<CreatorServicesConfigStore, 'read'>;
ffmpegPath: string;
ffprobePath: string;
+ preferHardwareEncoding?: boolean;
}): CreatorExecutor {
return {
id: 'clip',
@@ -30,6 +31,7 @@ export function createClipExecutor(input: {
const durationRange = readDurationRange(stage.job.state.duration);
const focus = readFocus(stage.job.state.focus);
const count = readClipCount(stage.job.state.clipCount);
+ const genre = readGenre(stage.job.state.genre);
stage.reportProgress({
phase: 'analyzing_clips',
percent: 30,
@@ -42,7 +44,8 @@ export function createClipExecutor(input: {
focus,
minDuration: durationRange.min,
maxDuration: durationRange.max,
- count
+ count,
+ genre
});
const path = join(stage.workdir, 'clip-candidates.json');
await writeFile(path, `${JSON.stringify({ candidates }, null, 2)}\n`);
@@ -63,6 +66,7 @@ export function createClipExecutor(input: {
metadata: {
candidates,
focus,
+ genre,
duration: `${durationRange.min}-${durationRange.max}`,
clipCount: candidates.length
}
@@ -78,32 +82,74 @@ export function createClipExecutor(input: {
const sourceMedia = await validateMediaFile(source, input.ffprobePath);
const duration = sourceMedia.duration;
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<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');
+ if (candidates.length === 0) throw new CreatorExecutorError('creator_clip_candidates_missing', 'No clips are available to render');
const aspectRatio = readAspectRatio(stage.job.state.aspectRatio);
const outputs = [];
- for (let index = 0; index < selected.length; index += 1) {
- const candidate = selected[index]!;
+ let videoEncoder: ClipVideoEncoder = (input.preferHardwareEncoding ?? process.platform === 'darwin')
+ ? 'h264_videotoolbox'
+ : 'libx264';
+ for (let index = 0; index < candidates.length; index += 1) {
+ const candidate = candidates[index]!;
+ const clipDuration = candidate.end - candidate.start;
const fileName = `${String(index + 1).padStart(2, '0')}-${safeFileName(candidate.title)}.mp4`;
const output = join(stage.workdir, fileName);
+ let lastReportedPercent = Math.round(index / candidates.length * 100);
stage.reportProgress({
phase: 'rendering_clips',
- percent: Math.round(index / selected.length * 100),
+ percent: lastReportedPercent,
completed: index,
failed: 0,
- total: selected.length,
- message: `Rendering clip ${index + 1} of ${selected.length}`
+ total: candidates.length,
+ message: `Rendering clip ${index + 1} of ${candidates.length}`
});
- await runProcess(input.ffmpegPath, buildClipArguments({
+ const renderInput = {
source,
output,
candidate,
aspectRatio,
- hasAudio: sourceMedia.hasAudio
- }), stage.signal);
+ hasAudio: sourceMedia.hasAudio,
+ videoEncoder
+ };
+ const reportRenderProgress = (renderedSeconds: number) => {
+ const clipProgress = Math.max(0, Math.min(1, renderedSeconds / clipDuration));
+ const percent = Math.min(99, Math.round((index + clipProgress) / candidates.length * 100));
+ if (percent <= lastReportedPercent) return;
+ lastReportedPercent = percent;
+ stage.reportProgress({
+ phase: 'rendering_clips',
+ percent,
+ completed: index,
+ failed: 0,
+ total: candidates.length,
+ message: `Rendering clip ${index + 1} of ${candidates.length}`
+ });
+ };
+ try {
+ await runProcess(
+ input.ffmpegPath,
+ buildClipArguments(renderInput),
+ stage.signal,
+ reportRenderProgress
+ );
+ } catch (error) {
+ if (videoEncoder !== 'h264_videotoolbox' || stage.signal.aborted) throw error;
+ videoEncoder = 'libx264';
+ renderInput.videoEncoder = videoEncoder;
+ stage.reportProgress({
+ phase: 'rendering_clips',
+ percent: lastReportedPercent,
+ completed: index,
+ failed: 0,
+ total: candidates.length,
+ message: 'Hardware encoding unavailable; retrying with software encoding'
+ });
+ await runProcess(
+ input.ffmpegPath,
+ buildClipArguments(renderInput),
+ stage.signal,
+ reportRenderProgress
+ );
+ }
outputs.push({
kind: 'auto_clip_video' as const,
status: 'completed' as const,
@@ -140,6 +186,7 @@ export function createClipExecutor(input: {
}
type ClipAspectRatio = 'source' | '16:9' | '9:16' | '1:1';
+type ClipVideoEncoder = 'libx264' | 'h264_videotoolbox';
function buildClipArguments(input: {
source: string;
@@ -147,41 +194,67 @@ function buildClipArguments(input: {
candidate: ReturnType<typeof parseClipCandidates>[number];
aspectRatio: ClipAspectRatio;
hasAudio: boolean;
+ videoEncoder: ClipVideoEncoder;
}): 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];[0:a]asetpts=PTS-STARTPTS[outa]`
: `[0:v]${videoFilter}[outv]`;
return [
'-y',
+ '-ss', formatFfmpegTime(input.candidate.start),
'-i', input.source,
+ '-t', formatFfmpegTime(input.candidate.end - input.candidate.start),
'-filter_complex', filter,
'-map', '[outv]',
...(input.hasAudio ? ['-map', '[outa]', '-c:a', 'aac'] : ['-an']),
- '-c:v', 'libx264',
- '-preset', 'medium',
+ ...videoEncoderArguments(input.videoEncoder),
'-movflags', '+faststart',
+ '-progress', 'pipe:2',
+ '-nostats',
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'];
+ if (value === '16:9') return ["crop='min(iw,ih*16/9)':'min(ih,iw*9/16)'", 'scale=1920:1080:flags=bilinear'];
+ if (value === '9:16') return ["crop='min(iw,ih*9/16)':'min(ih,iw*16/9)'", 'scale=1080:1920:flags=bilinear'];
+ if (value === '1:1') return ["crop='min(iw,ih)':'min(iw,ih)'", 'scale=1080:1080:flags=bilinear'];
return ['scale=trunc(iw/2)*2:trunc(ih/2)*2'];
}
+function videoEncoderArguments(value: ClipVideoEncoder): string[] {
+ return value === 'h264_videotoolbox'
+ ? ['-c:v', value, '-q:v', '65', '-realtime', 'true', '-prio_speed', 'true']
+ : ['-c:v', value, '-preset', 'veryfast'];
+}
+
+function formatFfmpegTime(value: number): string {
+ return String(Math.max(0, Number(value.toFixed(3))));
+}
+
function readFocus(value: unknown): 'balanced' | 'viral' | 'knowledge' {
return value === 'viral' || value === 'knowledge' ? value : 'balanced';
}
+function readGenre(value: unknown): ClipGenre {
+ return value === 'talk'
+ || value === 'podcast'
+ || value === 'tutorial'
+ || value === 'interview'
+ || value === 'entertainment'
+ || value === 'sports'
+ || value === 'gaming'
+ || value === 'news'
+ ? value
+ : 'auto';
+}
+
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 };
@@ -209,12 +282,35 @@ function safeFileName(value: string): string {
return normalized || 'video-clip';
}
-function runProcess(binary: string, args: string[], signal: AbortSignal): Promise<void> {
+function runProcess(
+ binary: string,
+ args: string[],
+ signal: AbortSignal,
+ onProgress?: (seconds: number) => void
+): Promise<void> {
return new Promise((resolve, reject) => {
const child = spawnCreatorProcess(binary, args, { stdio: ['ignore', 'ignore', 'pipe'] }, signal);
let stderr = '';
- child.stderr?.on('data', chunk => { stderr += String(chunk); });
+ let progressBuffer = '';
+ child.stderr?.on('data', chunk => {
+ const text = String(chunk);
+ stderr = `${stderr}${text}`.slice(-4000);
+ progressBuffer += text;
+ const lines = progressBuffer.split(/\r?\n/);
+ progressBuffer = lines.pop() ?? '';
+ for (const line of lines) {
+ const seconds = parseFfmpegProgressTime(line);
+ if (seconds !== null) onProgress?.(seconds);
+ }
+ });
child.once('error', reject);
child.once('exit', code => code === 0 ? resolve() : reject(new Error(stderr.slice(-2000))));
});
}
+
+function parseFfmpegProgressTime(line: string): number | null {
+ const match = /^out_time=(\d+):(\d{2}):(\d{2}(?:\.\d+)?)$/.exec(line.trim());
+ if (!match) return null;
+ const seconds = Number(match[1]) * 3600 + Number(match[2]) * 60 + Number(match[3]);
+ return Number.isFinite(seconds) ? seconds : null;
+}
diff --git a/apps/daemon/src/creator/download/executor.ts b/apps/daemon/src/creator/download/executor.ts
index 3128c940..6ef83a37 100644
--- a/apps/daemon/src/creator/download/executor.ts
+++ b/apps/daemon/src/creator/download/executor.ts
@@ -448,6 +448,7 @@ async function downloadLegacy(
path,
metadata: {
...media,
+ ...sourceMetadata(probe),
fileName: basename(path),
size: info.size,
bytes: info.size,
@@ -602,19 +603,12 @@ async function outputMetadata(
]);
return {
...media,
+ ...sourceMetadata(probe),
fileName: playback.fileName,
size: info.size,
bytes: info.size,
sha256,
mimeType: mimeTypeFor(path),
- source: 'video-download',
- sourceUrl: probe.url || probe.requestedUrl,
- requestedUrl: probe.requestedUrl,
- platform: probe.platform,
- sourceId: probe.id,
- title: probe.title,
- uploader: probe.uploader,
- thumbnailUrl: probe.thumbnailUrl,
optionId: option.id,
mediaType: option.mediaType,
container: option.container,
@@ -639,6 +633,19 @@ async function outputMetadata(
};
}
+function sourceMetadata(probe: DownloadProbe): Record<string, CreatorJson> {
+ return {
+ source: 'video-download',
+ sourceUrl: probe.url || probe.requestedUrl,
+ requestedUrl: probe.requestedUrl,
+ platform: probe.platform,
+ sourceId: probe.id,
+ title: probe.title,
+ uploader: probe.uploader,
+ thumbnailUrl: probe.thumbnailUrl
+ };
+}
+
async function normalizeVideoForPlayback(
path: string,
input: DownloadExecutorOptions,
diff --git a/apps/daemon/src/creator/krillin/adapter.ts b/apps/daemon/src/creator/krillin/adapter.ts
index 2e378ab2..66d2dba6 100644
--- a/apps/daemon/src/creator/krillin/adapter.ts
+++ b/apps/daemon/src/creator/krillin/adapter.ts
@@ -53,6 +53,7 @@ export function createKrillinExecutor(input: {
options
);
let completed: KrillinResultArtifact[] | undefined;
+ let deferredFailure: KrillinCliError | undefined;
for (const attempt of attempts) {
try {
if (requiresTranscriptionDependency(stage.stageRun.stageId, attempt.options)) {
@@ -80,8 +81,12 @@ export function createKrillinExecutor(input: {
error instanceof KrillinCliError
&& error.code === attempt.continueOnErrorCode
) {
+ deferredFailure = error;
continue;
}
+ if (deferredFailure !== undefined) {
+ throw combineKrillinFallbackFailures(deferredFailure, error);
+ }
throw error;
}
}
@@ -168,8 +173,12 @@ export function buildKrillinStageOptions(input: CreatorExecutorInput): Record<st
const state = input.job.state;
return compactObject({
sourceUrl: typeof state.sourceUrl === 'string' ? state.sourceUrl : undefined,
- originLanguage: typeof state.sourceLanguage === 'string' ? state.sourceLanguage : undefined,
- targetLanguage: typeof state.targetLanguage === 'string' ? state.targetLanguage : undefined,
+ originLanguage: normalizeKrillinLanguage(
+ typeof state.sourceLanguage === 'string' ? state.sourceLanguage : undefined
+ ),
+ targetLanguage: normalizeKrillinLanguage(
+ typeof state.targetLanguage === 'string' ? state.targetLanguage : undefined
+ ),
captionSource: state.preferPlatformCaptions === false ? 'whisper' : 'any',
sourceOnly: input.job.templateId === 'stickman-video'
&& input.stageRun.stageId === 'source-transcript',
@@ -185,6 +194,35 @@ export function buildKrillinStageOptions(input: CreatorExecutorInput): Record<st
});
}
+export function normalizeKrillinLanguage(value: string | undefined): string | undefined {
+ const normalized = value?.trim().toLowerCase().replaceAll('_', '-');
+ if (!normalized) return undefined;
+ if (normalized === 'auto') return 'auto';
+ if (['zh-tw', 'zh-hant', 'zh-hk', 'zh-mo'].includes(normalized)) return 'zh_tw';
+ if (['zh', 'zh-cn', 'zh-hans', 'zh-sg'].includes(normalized)) return 'zh_cn';
+ if (normalized === 'iw') return 'he';
+ return normalized.split('-', 1)[0];
+}
+
+function combineKrillinFallbackFailures(platformFailure: KrillinCliError, fallbackFailure: unknown): Error {
+ const fallbackMessage = fallbackFailure instanceof Error
+ ? fallbackFailure.message
+ : 'Unknown audio transcription failure';
+ const message = `Platform captions failed: ${platformFailure.message}; audio transcription fallback failed: ${fallbackMessage}`;
+ if (fallbackFailure instanceof KrillinCliError) {
+ return new KrillinCliError(
+ fallbackFailure.code,
+ message,
+ fallbackFailure.kind,
+ fallbackFailure.retryable
+ );
+ }
+ if (fallbackFailure instanceof CreatorExecutorError) {
+ return new CreatorExecutorError(fallbackFailure.code, message);
+ }
+ return new CreatorExecutorError('krillin_stage_failed', message);
+}
+
export function buildKrillinSubtitleStyle(value: CreatorJson | undefined): Record<string, unknown> | undefined {
if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;
const style = value as Record<string, CreatorJson>;
diff --git a/apps/daemon/src/creator/templates/auto-clip-actions.ts b/apps/daemon/src/creator/templates/auto-clip-actions.ts
index e5c9800d..61e4d42d 100644
--- a/apps/daemon/src/creator/templates/auto-clip-actions.ts
+++ b/apps/daemon/src/creator/templates/auto-clip-actions.ts
@@ -9,7 +9,10 @@ export function createAutoClipWorkflow(input: {
dispatcher: Pick<CreatorCommandDispatcher, 'dispatch'>;
}) {
async function continueFrom(stage: CreatorStageRun): Promise<void> {
- if (stage.status !== 'succeeded' || stage.progress.workflow !== true) return;
+ if (
+ stage.status !== 'succeeded'
+ || (stage.progress.workflow !== true && stage.stageId !== 'analyze')
+ ) return;
const job = input.creator.getJob(stage.jobId);
if (job === undefined || job.templateId !== 'auto-clip') return;
const nextStageId = nextWorkflowStage(stage.stageId);
@@ -26,7 +29,7 @@ export function createAutoClipWorkflow(input: {
if (job.templateId !== 'auto-clip') continue;
const completed = [...job.stages].reverse().find(stage => (
stage.status === 'succeeded'
- && stage.progress.workflow === true
+ && (stage.progress.workflow === true || stage.stageId === 'analyze')
&& nextWorkflowStage(stage.stageId) !== undefined
&& !hasLaterWorkflowStage(job, stage)
));
@@ -40,6 +43,7 @@ function nextWorkflowStage(stageId: string): string | undefined {
if (stageId === 'probe') return 'download';
if (stageId === 'download') return 'subtitle';
if (stageId === 'subtitle') return 'analyze';
+ if (stageId === 'analyze') return 'render';
return undefined;
}
diff --git a/apps/daemon/src/creator/templates/auto-clip.ts b/apps/daemon/src/creator/templates/auto-clip.ts
index 879d2b0f..6b60099b 100644
--- a/apps/daemon/src/creator/templates/auto-clip.ts
+++ b/apps/daemon/src/creator/templates/auto-clip.ts
@@ -13,7 +13,6 @@ export function createLegacyAutoClipTemplate(): CreatorTemplateDefinition {
sourceLanguage: z.string().default('auto'),
targetLanguage: z.string().default('zh-CN'),
preferPlatformCaptions: z.boolean().default(true),
- selectedCandidateIds: z.array(z.string()).default([]),
currentStage: z.string().nullable().default(null)
}).passthrough() as never,
stages: [
@@ -29,7 +28,7 @@ export function createLegacyAutoClipTemplate(): CreatorTemplateDefinition {
{ id: 'undo-action', inputSchema: record, allowedStages: ['probe', 'download', 'subtitle', 'analyze', 'render'] }
],
outputs: [{ kind: 'auto_clip_video', required: true }],
- agentGuidance: '先分析并展示四维评分候选,用户选择后再渲染。'
+ agentGuidance: '分析高光片段后自动将全部片段分别渲染为独立视频文件。'
};
}
@@ -47,10 +46,10 @@ export function createAutoClipTemplate(): CreatorTemplateDefinition {
targetLanguage: z.string().default('zh-CN'),
preferPlatformCaptions: z.boolean().default(true),
focus: z.enum(['balanced', 'viral', 'knowledge']).default('balanced'),
+ genre: z.enum(['auto', 'talk', 'podcast', 'tutorial', 'interview', 'entertainment', 'sports', 'gaming', 'news']).default('auto'),
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: [
@@ -117,7 +116,7 @@ export function createAutoClipTemplate(): CreatorTemplateDefinition {
agentGuidance: [
'这是视频切片模板。',
'URL 来源从 probe 开始并设置 workflow=true,本地或导入视频从 subtitle 开始并设置 workflow=true。',
- 'analyze 完成后先展示候选片段与评分,用户选择 selectedCandidateIds 后再运行 render。',
+ '工作流必须从 analyze 自动继续到 render,将本次分析出的全部片段直接生成视频。',
'不得把多个候选片段拼接成一个文件。'
].join(' ')
};
diff --git a/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts b/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts
index 59aa544b..e38fff91 100644
--- a/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts
+++ b/apps/daemon/test/unit/creator-auto-clip-workflow.test.ts
@@ -18,7 +18,7 @@ afterEach(() => {
});
describe('auto clip workflow', () => {
- it('queues URL preparation, transcription, and analysis in order', async () => {
+ it('queues URL preparation, transcription, analysis, and rendering in order', async () => {
const fixture = setup('url');
const probe = fixture.dispatcher.dispatch(fixture.jobId, {
action: 'run-stage',
@@ -36,10 +36,15 @@ describe('auto clip workflow', () => {
expect(subtitle.stageId).toBe('subtitle');
const analyze = await succeedAndContinue(fixture, subtitle.id);
expect(analyze.stageId).toBe('analyze');
- await succeedAndContinue(fixture, analyze.id);
+ const render = await succeedAndContinue(fixture, analyze.id);
+ expect(render).toMatchObject({
+ stageId: 'render',
+ progress: { workflow: true, workflowParentStageRunId: analyze.id }
+ });
+ await succeedAndContinue(fixture, render.id);
expect(fixture.service.getJob(fixture.jobId)?.stages.map(stage => stage.stageId))
- .toEqual(['probe', 'download', 'subtitle', 'analyze']);
+ .toEqual(['probe', 'download', 'subtitle', 'analyze', 'render']);
fixture.db.close();
});
@@ -58,6 +63,29 @@ describe('auto clip workflow', () => {
stageId: 'analyze',
progress: { workflow: true, workflowParentStageRunId: subtitle }
});
+ const render = await succeedAndContinue(fixture, analyze.id);
+ expect(render).toMatchObject({
+ stageId: 'render',
+ progress: { workflow: true, workflowParentStageRunId: analyze.id }
+ });
+ fixture.db.close();
+ });
+
+ it('renders after a directly requested analysis without requiring a selection', async () => {
+ const fixture = setup('file');
+ const analyze = fixture.dispatcher.dispatch(fixture.jobId, {
+ action: 'run-stage',
+ expectedRevision: 0,
+ idempotencyKey: 'auto-clip-direct-analysis',
+ input: { stageId: 'analyze' }
+ }, 'user').commandReceipt.stageRunId!;
+
+ const render = await succeedAndContinue(fixture, analyze);
+
+ expect(render).toMatchObject({
+ stageId: 'render',
+ progress: { workflow: true, workflowParentStageRunId: analyze }
+ });
fixture.db.close();
});
diff --git a/apps/daemon/test/unit/creator-clip-analyzer.test.ts b/apps/daemon/test/unit/creator-clip-analyzer.test.ts
index c307b77e..6394002a 100644
--- a/apps/daemon/test/unit/creator-clip-analyzer.test.ts
+++ b/apps/daemon/test/unit/creator-clip-analyzer.test.ts
@@ -2,7 +2,7 @@ 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 () => {
+ it('passes content settings 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 }>;
@@ -10,6 +10,7 @@ describe('clip analyzer', () => {
expect(request.messages[0]!.content).toContain('优先寻找开头抓人');
expect(request.messages[0]!.content).toContain('最多 1 个片段');
expect(request.messages[0]!.content).toContain('30-60 秒');
+ expect(request.messages[0]!.content).toContain('内容类型:教程或知识讲解');
return new Response(JSON.stringify({
choices: [{
message: {
@@ -32,6 +33,7 @@ describe('clip analyzer', () => {
transcript: '这是一段用于验证高光识别设置的字幕。',
duration: 120,
focus: 'viral',
+ genre: 'tutorial',
minDuration: 30,
maxDuration: 60,
count: 1,
diff --git a/apps/daemon/test/unit/creator-clip-executor.test.ts b/apps/daemon/test/unit/creator-clip-executor.test.ts
new file mode 100644
index 00000000..2efeffc6
--- /dev/null
+++ b/apps/daemon/test/unit/creator-clip-executor.test.ts
@@ -0,0 +1,264 @@
+import { chmodSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import {
+ createDefaultCreatorServicesConfig,
+ type CreatorArtifact,
+ type CreatorJob,
+ type CreatorStageRun
+} from '@opencreator/protocol';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { createClipExecutor } from '../../src/creator/clip/executor.js';
+
+let tempDir = '';
+
+afterEach(() => {
+ if (tempDir) rmSync(tempDir, { recursive: true, force: true });
+ tempDir = '';
+ vi.unstubAllGlobals();
+});
+
+describe('clip executor', () => {
+ it('uses the saved content settings during analysis', async () => {
+ tempDir = mkdtempSync(join(tmpdir(), 'creator-clip-executor-'));
+ const workdir = join(tempDir, 'work');
+ mkdirSync(workdir);
+ const sourcePath = join(tempDir, 'source.mp4');
+ const subtitlePath = join(tempDir, 'subtitle.srt');
+ const ffprobePath = join(tempDir, 'ffprobe');
+ writeFileSync(sourcePath, 'source-video');
+ writeFileSync(subtitlePath, '1\n00:01:05,000 --> 00:01:40,000\nProduct pricing and customer feedback\n');
+ writeExecutable(ffprobePath, `#!/bin/sh\nprintf '%s\\n' '{"format":{"duration":"180"},"streams":[{"codec_type":"video","width":1920,"height":1080},{"codec_type":"audio"}]}'\n`);
+ 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('内容类型:播客对谈');
+ return new Response(JSON.stringify({
+ choices: [{ message: { content: JSON.stringify({
+ candidates: [candidate('clip-1', 'Pricing insight', 65, 100)]
+ }) } }]
+ }), { status: 200 });
+ });
+ vi.stubGlobal('fetch', fetchImpl);
+ const config = createDefaultCreatorServicesConfig();
+ config.llm.apiKey = 'test-key';
+ config.llm.baseUrl = 'https://api.openai.test/v1';
+ config.llm.model = 'test-model';
+ const executor = createClipExecutor({
+ configStore: { read: async () => config },
+ ffmpegPath: join(tempDir, 'unused-ffmpeg'),
+ ffprobePath
+ });
+
+ const currentJob = job();
+ currentJob.state = {
+ ...currentJob.state,
+ focus: 'knowledge',
+ genre: 'podcast',
+ duration: '30-60',
+ clipCount: 4
+ };
+ const result = await executor.run({
+ stageRun: stageRun('analyze'),
+ job: currentJob,
+ inputArtifacts: [
+ artifact('source', 'source_video', sourcePath),
+ artifact('subtitle', 'target_subtitle', subtitlePath)
+ ],
+ workdir,
+ signal: new AbortController().signal,
+ reportProgress: vi.fn()
+ });
+
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
+ expect(result.outputs[0]?.metadata).toMatchObject({
+ genre: 'podcast',
+ duration: '30-60',
+ clipCount: 1
+ });
+ });
+
+ it('renders every analyzed clip as a separate file without a selection', async () => {
+ tempDir = mkdtempSync(join(tmpdir(), 'creator-clip-executor-'));
+ const workdir = join(tempDir, 'work');
+ mkdirSync(workdir);
+ const sourcePath = join(tempDir, 'source.mp4');
+ const candidatesPath = join(tempDir, 'clip-candidates.json');
+ const ffprobePath = join(tempDir, 'ffprobe');
+ const ffmpegPath = join(tempDir, 'ffmpeg');
+ const ffmpegLogPath = join(tempDir, 'ffmpeg.log');
+ writeFileSync(sourcePath, 'source-video');
+ writeFileSync(candidatesPath, JSON.stringify({ candidates: [
+ candidate('clip-1', 'First clip', 0, 30),
+ candidate('clip-2', 'Second clip', 40, 75)
+ ] }));
+ writeExecutable(ffprobePath, `#!/bin/sh\nprintf '%s\\n' '{"format":{"duration":"120"},"streams":[{"codec_type":"video","width":1920,"height":1080},{"codec_type":"audio"}]}'\n`);
+ writeExecutable(ffmpegPath, `#!/bin/sh\nlast=''\nfor arg in "$@"; do\n last="$arg"\n printf '%s\\n' "$arg" >> '${ffmpegLogPath}'\ndone\nprintf '%s\\n' '---' >> '${ffmpegLogPath}'\nprintf '%s\\n' 'out_time=00:00:15.000000' >&2\nprintf '%s\\n' 'progress=continue' >&2\nprintf 'rendered-video' > "$last"\n`);
+
+ const sourceArtifact = artifact('source', 'source_video', sourcePath);
+ const candidateArtifact = artifact('candidates', 'clip_candidates', candidatesPath);
+ const executor = createClipExecutor({
+ configStore: { read: vi.fn() } as never,
+ ffmpegPath,
+ ffprobePath,
+ preferHardwareEncoding: false
+ });
+ const reportProgress = vi.fn();
+ const result = await executor.run({
+ stageRun: stageRun(),
+ job: job(),
+ inputArtifacts: [sourceArtifact, candidateArtifact],
+ workdir,
+ signal: new AbortController().signal,
+ reportProgress
+ });
+
+ const invocations = readFileSync(ffmpegLogPath, 'utf8').trim().split('\n---\n')
+ .map(entry => entry.split('\n'));
+ const firstArgs = invocations[0]!;
+ const firstFilter = firstArgs[firstArgs.indexOf('-filter_complex') + 1]!;
+ expect(firstArgs.slice(firstArgs.indexOf('-ss'), firstArgs.indexOf('-ss') + 2)).toEqual(['-ss', '0']);
+ expect(firstArgs.indexOf('-ss')).toBeLessThan(firstArgs.indexOf('-i'));
+ expect(firstArgs.slice(firstArgs.indexOf('-t'), firstArgs.indexOf('-t') + 2)).toEqual(['-t', '30']);
+ expect(firstFilter).not.toContain('trim=');
+ expect(firstFilter.indexOf('crop=')).toBeLessThan(firstFilter.indexOf('scale='));
+ expect(firstArgs.slice(firstArgs.indexOf('-preset'), firstArgs.indexOf('-preset') + 2)).toEqual(['-preset', 'veryfast']);
+ expect(firstArgs.slice(firstArgs.indexOf('-progress'), firstArgs.indexOf('-progress') + 2)).toEqual(['-progress', 'pipe:2']);
+ expect(firstArgs).toContain('-nostats');
+ expect(invocations[1]!.slice(invocations[1]!.indexOf('-ss'), invocations[1]!.indexOf('-ss') + 2)).toEqual(['-ss', '40']);
+ expect(invocations[1]!.slice(invocations[1]!.indexOf('-t'), invocations[1]!.indexOf('-t') + 2)).toEqual(['-t', '35']);
+ expect(reportProgress.mock.calls.map(([progress]) => progress).some(progress => (
+ progress.phase === 'rendering_clips'
+ && progress.completed === 0
+ && progress.percent > 0
+ && progress.percent < 50
+ ))).toBe(true);
+ expect(result.outputs.map(output => output.metadata?.candidateId))
+ .toEqual(['clip-1', 'clip-2']);
+ expect(result.outputs.map(output => output.path && readFileSync(output.path, 'utf8')))
+ .toEqual(['rendered-video', 'rendered-video']);
+ expect(invocations).toHaveLength(2);
+ expect(result.progress).toMatchObject({ completed: 2, failed: 0, total: 2 });
+ });
+
+ it('falls back to software encoding when VideoToolbox is unavailable', async () => {
+ tempDir = mkdtempSync(join(tmpdir(), 'creator-clip-executor-'));
+ const workdir = join(tempDir, 'work');
+ mkdirSync(workdir);
+ const sourcePath = join(tempDir, 'source.mp4');
+ const candidatesPath = join(tempDir, 'clip-candidates.json');
+ const ffprobePath = join(tempDir, 'ffprobe');
+ const ffmpegPath = join(tempDir, 'ffmpeg');
+ const ffmpegLogPath = join(tempDir, 'ffmpeg.log');
+ writeFileSync(sourcePath, 'source-video');
+ writeFileSync(candidatesPath, JSON.stringify({
+ candidates: [candidate('clip-1', 'First clip', 10, 30)]
+ }));
+ writeExecutable(ffprobePath, `#!/bin/sh\nprintf '%s\\n' '{"format":{"duration":"120"},"streams":[{"codec_type":"video","width":1920,"height":1080},{"codec_type":"audio"}]}'\n`);
+ writeExecutable(ffmpegPath, `#!/bin/sh\nlast=''\nhardware='false'\nfor arg in "$@"; do\n last="$arg"\n if [ "$arg" = 'h264_videotoolbox' ]; then hardware='true'; fi\n printf '%s\\n' "$arg" >> '${ffmpegLogPath}'\ndone\nprintf '%s\\n' '---' >> '${ffmpegLogPath}'\nif [ "$hardware" = 'true' ]; then\n printf '%s\\n' 'VideoToolbox is unavailable' >&2\n exit 1\nfi\nprintf 'rendered-video' > "$last"\n`);
+
+ const executor = createClipExecutor({
+ configStore: { read: vi.fn() } as never,
+ ffmpegPath,
+ ffprobePath,
+ preferHardwareEncoding: true
+ });
+ const reportProgress = vi.fn();
+ const result = await executor.run({
+ stageRun: stageRun(),
+ job: job(),
+ inputArtifacts: [
+ artifact('source', 'source_video', sourcePath),
+ artifact('candidates', 'clip_candidates', candidatesPath)
+ ],
+ workdir,
+ signal: new AbortController().signal,
+ reportProgress
+ });
+
+ const invocations = readFileSync(ffmpegLogPath, 'utf8').trim().split('\n---\n')
+ .map(entry => entry.split('\n'));
+ expect(invocations).toHaveLength(2);
+ expect(invocations[0]).toContain('h264_videotoolbox');
+ expect(invocations[0]).toEqual(expect.arrayContaining(['-q:v', '65', '-realtime', 'true', '-prio_speed']));
+ expect(invocations[1]).toContain('libx264');
+ expect(invocations[1]).toEqual(expect.arrayContaining(['-preset', 'veryfast']));
+ expect(reportProgress).toHaveBeenCalledWith(expect.objectContaining({
+ message: 'Hardware encoding unavailable; retrying with software encoding'
+ }));
+ expect(result.outputs).toHaveLength(1);
+ expect(result.outputs[0]?.path && readFileSync(result.outputs[0].path!, 'utf8')).toBe('rendered-video');
+ });
+});
+
+function candidate(id: string, title: string, start: number, end: number) {
+ return {
+ id,
+ title,
+ start,
+ end,
+ transcript: `${title} transcript`,
+ reason: `${title} reason`,
+ scores: { hook: 90, information: 88, emotion: 80, completeness: 92 }
+ };
+}
+
+function artifact(id: string, kind: string, path: string): CreatorArtifact {
+ return {
+ id,
+ jobId: 'auto-clip-job',
+ kind,
+ version: 1,
+ status: 'completed',
+ path,
+ sourceArtifactIds: [],
+ metadata: {},
+ createdAt: new Date().toISOString()
+ };
+}
+
+function job(): CreatorJob {
+ const now = new Date().toISOString();
+ return {
+ id: 'auto-clip-job',
+ projectId: 'project-1',
+ templateId: 'auto-clip',
+ templateVersion: 2,
+ status: 'running',
+ revision: 0,
+ state: {
+ aspectRatio: '9:16',
+ selectedCandidateIds: ['clip-1']
+ },
+ agentThreadId: null,
+ stages: [],
+ artifacts: [],
+ activities: [],
+ createdAt: now,
+ updatedAt: now
+ };
+}
+
+function stageRun(stageId: 'analyze' | 'render' = 'render'): CreatorStageRun {
+ return {
+ id: `${stageId}-stage`,
+ jobId: 'auto-clip-job',
+ stageId,
+ executor: 'clip',
+ status: 'running',
+ dispatchStatus: 'claimed',
+ claimOwner: 'test',
+ claimExpiresAt: null,
+ attempt: 1,
+ idempotencyKey: null,
+ progress: {},
+ errorCode: null,
+ errorMessage: null,
+ startedAt: new Date().toISOString(),
+ finishedAt: null
+ };
+}
+
+function writeExecutable(path: string, contents: string): void {
+ writeFileSync(path, contents);
+ chmodSync(path, 0o755);
+}
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 48634025..3985bd5c 100644
--- a/apps/daemon/test/unit/creator-krillin-adapter-dependency.test.ts
+++ b/apps/daemon/test/unit/creator-krillin-adapter-dependency.test.ts
@@ -41,7 +41,11 @@ describe('KrillinAI configured transcription dependency', () => {
expect(runKrillinCli).toHaveBeenCalledTimes(1);
expect(runKrillinCli.mock.calls[0]?.[0]).toMatchObject({
source: 'https://www.youtube.com/watch?v=demo',
- options: { captionSource: 'platform' }
+ options: {
+ captionSource: 'platform',
+ originLanguage: 'auto',
+ targetLanguage: 'zh_cn'
+ }
});
});
@@ -64,7 +68,29 @@ describe('KrillinAI configured transcription dependency', () => {
});
expect(runKrillinCli.mock.calls[1]?.[0]).toMatchObject({
source: expect.stringMatching(/^local:/),
- options: { captionSource: 'whisper' }
+ options: {
+ captionSource: 'whisper',
+ originLanguage: 'auto',
+ targetLanguage: 'zh_cn'
+ }
+ });
+ });
+
+ it('preserves platform caption diagnostics when transcription fallback also fails', async () => {
+ const fixture = setup();
+ runKrillinCli
+ .mockRejectedValueOnce(new KrillinCliError(
+ 'platform_caption_failed',
+ 'No original YouTube captions are available'
+ ))
+ .mockRejectedValueOnce(new KrillinCliError(
+ 'audio_transcription_failed',
+ 'whisperkit-cli rejected the language option'
+ ));
+
+ await expect(fixture.executor.run(fixture.stage)).rejects.toMatchObject({
+ code: 'audio_transcription_failed',
+ message: expect.stringMatching(/No original YouTube captions.*whisperkit-cli rejected/)
});
});
});
diff --git a/apps/web/e2e/web-desktop-parity.spec.ts b/apps/web/e2e/web-desktop-parity.spec.ts
index 7bb7da66..00feacaf 100644
--- a/apps/web/e2e/web-desktop-parity.spec.ts
+++ b/apps/web/e2e/web-desktop-parity.spec.ts
@@ -718,10 +718,10 @@ test('视频切片在 Browser/Desktop Bridge 下保持相同界面、请求和
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('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(workspace.getByLabel('任务摘要')).toContainText('切片数量6');
await expect.poll(async () => (
await runtime.api<{
diff --git a/apps/web/src/features/dashboard/AutoClipWorkspace.tsx b/apps/web/src/features/dashboard/AutoClipWorkspace.tsx
index 62c6711f..85e56a12 100644
--- a/apps/web/src/features/dashboard/AutoClipWorkspace.tsx
+++ b/apps/web/src/features/dashboard/AutoClipWorkspace.tsx
@@ -6,18 +6,13 @@ import {
} from '@opencreator/protocol';
import { useEffect, useMemo, useRef, useState } from 'react';
import {
- Captions,
Check,
Download,
FileVideo,
- LayoutGrid,
- List,
- ListVideo,
+ Grid2X2,
+ List as ListIcon,
LoaderCircle,
- Play,
Scissors,
- Settings2,
- SlidersHorizontal,
Sparkles
} from 'lucide-react';
import { useLocalizedCopy } from '../../i18n/useLocalizedCopy.js';
@@ -29,13 +24,13 @@ import { useOptionalCreatorSession } from './creator-session-store.js';
import VideoSourceInput from './VideoSourceInput.js';
type AutoClipStep = 0 | 1 | 2;
-type AutoClipResultTab = 'candidates' | 'details' | 'export' | 'settings';
-type AutoClipLayout = 'grid' | 'list';
-type VideoOrientation = 'landscape' | 'portrait';
+type VideoOrientation = 'landscape' | 'portrait' | 'square';
type AnalysisFocus = 'balanced' | 'viral' | 'knowledge';
+type ClipGenre = 'auto' | 'talk' | 'podcast' | 'tutorial' | 'interview' | 'entertainment' | 'sports' | 'gaming' | 'news';
type ClipDuration = '15-30' | '30-60' | '60-90';
type ClipAspectRatio = 'source' | '16:9' | '9:16' | '1:1';
type ClipScoreKey = 'hook' | 'information' | 'emotion' | 'completeness';
+type AutoClipResultView = 'list' | 'grid';
type ClipCandidate = {
id: string;
@@ -47,12 +42,20 @@ type ClipCandidate = {
scores: Record<ClipScoreKey, number>;
};
+type ClipSubtitleCue = {
+ id: string;
+ start: number;
+ end: number;
+ text: string;
+};
+
type AutoClipResultVersion = {
value: number;
description: string;
state: Record<string, CreatorJson>;
artifact: CreatorArtifact;
sourceArtifact?: CreatorArtifact;
+ subtitleArtifact?: CreatorArtifact;
candidates: ClipCandidate[];
};
@@ -66,26 +69,21 @@ export default function AutoClipWorkspace(props: {
const l = useLocalizedCopy();
const session = useOptionalCreatorSession();
const draftInitializedRef = useRef(false);
- const initializedSelectionVersionRef = useRef<number>();
const [videoUrl, setVideoUrl] = useState(() => readString(session?.state.sourceUrl));
const [videoFile, setVideoFile] = useState<File | null>(null);
const [sourceArtifactId, setSourceArtifactId] = useState(() => readString(session?.state.sourceArtifactId));
+ const [sourceLanguage, setSourceLanguage] = useState(() => readSourceLanguage(session?.state.sourceLanguage));
+ const [genre, setGenre] = useState<ClipGenre>(() => readGenre(session?.state.genre));
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<number>();
- const [sourcePreviewUrl, setSourcePreviewUrl] = useState('');
+ const [resultView, setResultView] = useState<AutoClipResultView>('list');
const [exportUrls, setExportUrls] = useState<Record<string, string>>({});
const resultVersions = useMemo(
() => createAutoClipResultVersions(
@@ -98,10 +96,6 @@ export default function AutoClipWorkspace(props: {
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,
@@ -110,18 +104,30 @@ export default function AutoClipWorkspace(props: {
const currentSourceArtifact = selectedResult?.sourceArtifact
?? importedSourceArtifact
?? latestCompletedArtifact(session?.job.artifacts ?? [], 'source_video');
+ const currentProbeArtifact = relatedArtifact(
+ session?.job.artifacts ?? [],
+ currentSourceArtifact,
+ 'download_probe'
+ );
const importedSourceName = artifactFileName(currentSourceArtifact)
|| l('项目视频', 'Project video');
+ const sourceDisplayName = videoFile?.name
+ ?? (sourceArtifactId
+ ? importedSourceName
+ : readString(currentSourceArtifact?.metadata.title)
+ || readString(currentProbeArtifact?.metadata.title)
+ || videoUrl
+ || importedSourceName);
const hasSource = importedSourceArtifact !== undefined
|| videoFile !== null
|| isValidUrl(videoUrl);
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 rendering = latestRenderStage?.status === 'queued' || latestRenderStage?.status === 'running';
const runtimeError = latestFailedStage(session?.job.stages ?? []);
const visibleError = error || formatClipError(runtimeError ?? session?.error, l);
- const exportedArtifacts = useMemo(
+ const renderedArtifacts = useMemo(
() => selectedResult === undefined
? []
: latestExportsForCandidateArtifact(
@@ -130,7 +136,11 @@ export default function AutoClipWorkspace(props: {
),
[selectedResult?.artifact.id, session?.job.artifacts]
);
- const currentOrientation = readOrientation(currentSourceArtifact) ?? sourceOrientation;
+ const renderedClipItems = renderedArtifacts.flatMap(artifact => {
+ const candidateId = readString(artifact.metadata.candidateId);
+ const clip = candidates.find(candidate => candidate.id === candidateId);
+ return clip === undefined ? [] : [{ artifact, clip }];
+ });
useEffect(() => {
if (latestVersion !== undefined) setResultVersion(latestVersion);
@@ -142,68 +152,42 @@ export default function AutoClipWorkspace(props: {
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 || videoFile ? 'file' : 'url',
sourceArtifactId: sourceArtifactId || null,
+ sourceLanguage,
+ preferPlatformCaptions: true,
+ genre,
focus,
duration,
clipCount,
- aspectRatio,
- selectedCandidateIds: selected
+ aspectRatio
}, { persist: draftInitializedRef.current });
draftInitializedRef.current = true;
- }, [aspectRatio, clipCount, duration, focus, selected, session?.updateDraft, sourceArtifactId, videoFile, videoUrl]);
-
- 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]);
+ }, [
+ aspectRatio,
+ clipCount,
+ duration,
+ focus,
+ genre,
+ session?.updateDraft,
+ sourceArtifactId,
+ sourceLanguage,
+ videoFile,
+ videoUrl
+ ]);
useEffect(() => {
- if (exportedArtifacts.length === 0 || session === null) {
+ if (renderedArtifacts.length === 0 || session === null) {
setExportUrls({});
return undefined;
}
let active = true;
const objectUrls: string[] = [];
- void Promise.all(exportedArtifacts.map(async artifact => {
+ void Promise.all(renderedArtifacts.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());
@@ -218,22 +202,21 @@ export default function AutoClipWorkspace(props: {
active = false;
objectUrls.forEach(url => URL.revokeObjectURL(url));
};
- }, [exportedArtifacts, l, session?.openArtifact]);
+ }, [renderedArtifacts, l, session?.openArtifact]);
useEffect(() => {
- if (latestRenderStage?.status === 'succeeded' && exportedArtifacts.length > 0) {
+ if (latestRenderStage?.status === 'succeeded' && renderedArtifacts.length > 0) {
setNotice(l(
- `已生成 ${exportedArtifacts.length} 个独立视频切片`,
- `${exportedArtifacts.length} standalone video clips are ready`
+ `已自动生成 ${renderedArtifacts.length} 个独立视频切片`,
+ `${renderedArtifacts.length} standalone video clips were generated automatically`
));
- setResultTab('export');
}
- }, [exportedArtifacts.length, l, latestRenderStage?.id, latestRenderStage?.status]);
+ }, [renderedArtifacts.length, l, latestRenderStage?.id, latestRenderStage?.status]);
const steps = [
l('添加视频', 'Add video'),
l('切片设置', 'Clip settings'),
- l('选择与导出', 'Select and export')
+ l('切片结果', 'Clip results')
];
function openStep(step: AutoClipStep) {
@@ -257,7 +240,6 @@ export default function AutoClipWorkspace(props: {
setVideoUrl('');
setSourceArtifactId('');
}
- setSourceOrientation('landscape');
setError('');
setNotice('');
}
@@ -266,31 +248,31 @@ export default function AutoClipWorkspace(props: {
setVideoFile(null);
setVideoUrl('');
setSourceArtifactId('');
- setSourceOrientation('landscape');
setError('');
setNotice('');
}
async function analyze() {
- if (analyzing || session === null) return;
+ if (analyzing || rendering || session === null) return;
if (!hasSource) {
setCurrentStep(0);
setError(l('请先上传视频或填写公开视频链接', 'Upload a video or enter a public video link first'));
return;
}
setError('');
- setNotice(l('正在准备视频并识别高光片段', 'Preparing the video and finding highlights'));
- setSelected([]);
+ setNotice(l('正在分析视频并自动生成切片', 'Analyzing the video and rendering clips automatically'));
try {
session.updateDraft({
sourceUrl: videoUrl,
sourceType: sourceArtifactId || videoFile ? 'file' : 'url',
sourceArtifactId: sourceArtifactId || null,
+ sourceLanguage,
+ preferPlatformCaptions: true,
+ genre,
focus,
duration,
clipCount,
- aspectRatio,
- selectedCandidateIds: []
+ aspectRatio
}, { semantic: true });
await session.flush();
let stageId: 'probe' | 'subtitle' | 'analyze';
@@ -307,17 +289,22 @@ export default function AutoClipWorkspace(props: {
const subtitle = source === undefined
? undefined
: matchingSubtitleArtifact(session.job.artifacts, source);
- stageId = subtitle !== undefined ? 'analyze' : source !== undefined ? 'subtitle' : 'probe';
+ const sourceLanguageChanged = selectedResult !== undefined
+ && readSourceLanguage(selectedResult.state.sourceLanguage) !== sourceLanguage;
+ stageId = subtitle !== undefined && !sourceLanguageChanged
+ ? 'analyze'
+ : source !== undefined
+ ? 'subtitle'
+ : 'probe';
}
const updatedJob = await session.applyAction({
actor: 'user',
action: 'run-stage',
input: {
stageId,
- ...(stageId === 'analyze' ? {} : { workflow: true })
+ workflow: true
}
});
- setResultTab('candidates');
const completedInResponse = updatedJob.artifacts.some(artifact => (
artifact.kind === 'clip_candidates' && artifact.status === 'completed'
));
@@ -329,28 +316,12 @@ export default function AutoClipWorkspace(props: {
}
}
- 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 === undefined) return;
setResultVersion(version);
+ setSourceLanguage(readSourceLanguage(result.state.sourceLanguage));
+ setGenre(readGenre(result.state.genre));
setFocus(readFocus(result.state.focus));
setDuration(readDuration(result.state.duration));
setClipCount(readClipCount(result.state.clipCount));
@@ -358,38 +329,8 @@ export default function AutoClipWorkspace(props: {
setVideoUrl(readString(result.state.sourceUrl));
setVideoFile(null);
setSourceArtifactId(result.sourceArtifact?.id ?? '');
- setResultTab('candidates');
setCurrentStep(2);
setFurthestStep(2);
- initializedSelectionVersionRef.current = undefined;
- }
-
- async function exportSelected() {
- if (selected.length === 0) {
- 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');
- 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));
- }
}
function downloadArtifact(artifact: CreatorArtifact) {
@@ -405,39 +346,24 @@ export default function AutoClipWorkspace(props: {
const quickActions = selectedResult === undefined
? [{
id: 'analyze-video-clips',
- label: l('开始识别高光', 'Find highlights'),
+ label: l('一键自动切片', 'Auto-clip now'),
kind: 'action' as const,
onAction: () => void analyze(),
- disabled: !hasSource || analyzing
+ disabled: !hasSource || analyzing || rendering
}]
- : [
- {
- 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('视频切片', 'Video Clips')}
subtitle={l(
- '自动识别长视频中的高光时刻,选择后生成独立短视频',
- 'Find the strongest moments in long videos and turn them into standalone clips'
+ '自动识别长视频中的高光时刻,并直接生成独立短视频',
+ 'Find the strongest moments in long videos and automatically render standalone clips'
)}
context={selectedResult
? l(
- `V${selectedResult.value},${candidates.length} 个候选,已选 ${selected.length} 个`,
- `V${selectedResult.value}, ${candidates.length} candidates, ${selected.length} selected`
+ `V${selectedResult.value},${candidates.length} 个视频切片`,
+ `V${selectedResult.value}, ${candidates.length} video clips`
)
: analyzing
? l('正在识别视频高光', 'Finding video highlights')
@@ -448,15 +374,15 @@ export default function AutoClipWorkspace(props: {
'询问切片进度,或描述内容重点、时长和画幅要求',
'Ask about progress or describe the focus, duration, and format you need'
)}
- stepLabel={exporting
- ? l('导出视频切片', 'Exporting video clips')
+ stepLabel={rendering
+ ? l('生成视频切片', 'Rendering video clips')
: analyzing
? l('识别视频高光', 'Finding video highlights')
: currentStep === 2
- ? l('选择与导出', 'Select and export')
+ ? l('切片结果', 'Clip results')
: steps[currentStep]!}
currentIssue={visibleError || undefined}
- onCancelTask={analyzing || exporting
+ onCancelTask={analyzing || rendering
? () => void session?.cancelJob().catch(cause => setError(formatClipError(cause, l)))
: undefined}
onResumeTask={session?.job.status === 'canceled'
@@ -473,7 +399,7 @@ export default function AutoClipWorkspace(props: {
<li key={step} data-active={active} data-completed={completed}>
<button
type="button"
- disabled={index > furthestStep || analyzing || exporting}
+ disabled={index > furthestStep || analyzing || rendering}
aria-current={active ? 'step' : undefined}
onClick={() => openStep(index as AutoClipStep)}
>
@@ -499,12 +425,10 @@ export default function AutoClipWorkspace(props: {
setVideoUrl(url);
setVideoFile(null);
setSourceArtifactId('');
- setSourceOrientation('landscape');
setError('');
setNotice('');
}}
onClear={clearCurrentSource}
- onDimensions={(width, height) => setSourceOrientation(height > width ? 'portrait' : 'landscape')}
/>
) : (
<section className="creator-tool-panel" aria-labelledby="video-clips-imported-source-title">
@@ -541,63 +465,112 @@ export default function AutoClipWorkspace(props: {
<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="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 className="auto-clip-setting-sections">
+ <section className="auto-clip-setting-section" aria-labelledby="auto-clip-content-settings-title">
+ <header>
+ <h3 id="auto-clip-content-settings-title">{l('内容识别', 'Content analysis')}</h3>
+ </header>
+ <div className="creator-tool-form-row auto-clip-settings-grid">
+ <label className="creator-tool-field">
+ <span>{l('原视频语言', 'Source language')}</span>
+ <select aria-label={l('原视频语言', 'Source language')} value={sourceLanguage} onChange={event => setSourceLanguage(event.target.value)}>
+ <option value="auto">{l('自动检测(优先平台字幕)', 'Auto detect (prefer platform captions)')}</option>
+ <option value="zh_cn">{l('简体中文', 'Simplified Chinese')}</option>
+ <option value="zh_tw">{l('繁體中文', 'Traditional Chinese')}</option>
+ <option value="en">English</option>
+ <option value="ja">日本語</option>
+ <option value="ko">한국어</option>
+ <option value="es">Español</option>
+ <option value="fr">Français</option>
+ <option value="de">Deutsch</option>
+ <option value="pt">Português</option>
+ <option value="ru">Русский</option>
+ </select>
+ </label>
+ <label className="creator-tool-field">
+ <span>{l('内容类型', 'Content type')}</span>
+ <select aria-label={l('内容类型', 'Content type')} value={genre} onChange={event => setGenre(event.target.value as ClipGenre)}>
+ <option value="auto">{l('自动判断', 'Auto detect')}</option>
+ <option value="talk">{l('演讲 / 观点', 'Talk / commentary')}</option>
+ <option value="podcast">{l('播客对谈', 'Podcast')}</option>
+ <option value="tutorial">{l('教程 / 知识', 'Tutorial / education')}</option>
+ <option value="interview">{l('人物访谈', 'Interview')}</option>
+ <option value="entertainment">{l('娱乐内容', 'Entertainment')}</option>
+ <option value="sports">{l('体育内容', 'Sports')}</option>
+ <option value="gaming">{l('游戏内容', 'Gaming')}</option>
+ <option value="news">{l('新闻 / 时事', 'News / current affairs')}</option>
+ </select>
+ </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>
+ </div>
+ </section>
+
+ <section className="auto-clip-setting-section" aria-labelledby="auto-clip-output-settings-title">
+ <header>
+ <h3 id="auto-clip-output-settings-title">{l('切片输出', 'Clip output')}</h3>
+ </header>
+ <div className="creator-tool-form-row auto-clip-settings-grid">
+ <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>
+ </section>
</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>
+ <strong>{l(`自动生成最多 ${clipCount} 个独立视频切片`, `Automatically render up to ${clipCount} standalone video clips`)}</strong>
+ <p>{l('分析完成后直接生成全部片段,每条包含完整字幕、推荐理由和四维评分', 'Every analyzed moment is rendered automatically with its transcript, rationale, and four scores')}</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} />}
+ <button className="creator-tool-primary" type="button" disabled={analyzing || rendering} onClick={() => void analyze()}>
+ {analyzing || rendering ? <LoaderCircle className="smart-dubbing-spinner" size={16} /> : <Sparkles size={16} />}
{analyzing
? l('正在识别高光', 'Finding highlights')
+ : rendering
+ ? l('正在生成切片', 'Rendering clips')
: selectedResult
- ? l('重新识别并生成新版本', 'Reanalyze as a new version')
- : l('识别高光片段', 'Find highlight clips')}
+ ? l('重新分析并自动生成新版本', 'Reanalyze and render a new version')
+ : l('开始自动切片', 'Start automatic clipping')}
</button>
</div>
</section>
<CreatorTaskSummary
sourceIcon={FileVideo}
sourceLabel={l('视频来源', 'Video source')}
- sourceValue={videoFile?.name ?? (importedSourceName || videoUrl)}
+ sourceValue={sourceDisplayName}
items={[
+ { label: l('原视频语言', 'Source language'), value: sourceLanguageLabel(sourceLanguage, l) },
+ { label: l('内容类型', 'Content type'), value: genreLabel(genre, 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('切片数量', 'Clip count'), value: String(clipCount) },
{ label: l('输出画幅', 'Output format'), value: aspectRatioLabel(aspectRatio, l) }
]}
/>
@@ -607,138 +580,76 @@ export default function AutoClipWorkspace(props: {
{currentStep === 2 && selectedResult ? (
<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('视频切片结果类型', '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 className="auto-clip-result-heading">
+ <h2>{l('切片结果', 'Clip results')}</h2>
+ <span>{l(`${renderedClipItems.length} 个切片`, `${renderedClipItems.length} clips`)}</span>
+ </div>
+ <div className="auto-clip-result-controls">
+ <div className="auto-clip-view-switch" role="group" aria-label={l('结果视图', 'Result view')}>
+ <button
+ type="button"
+ aria-label={l('列表视图', 'List view')}
+ aria-pressed={resultView === 'list'}
+ title={l('列表视图', 'List view')}
+ onClick={() => setResultView('list')}
+ >
+ <ListIcon size={15} />
+ </button>
+ <button
+ type="button"
+ aria-label={l('网格视图', 'Grid view')}
+ aria-pressed={resultView === 'grid'}
+ title={l('网格视图', 'Grid view')}
+ onClick={() => setResultView('grid')}
+ >
+ <Grid2X2 size={15} />
+ </button>
+ </div>
+ <CreatorResultVersionMenu
+ version={selectedResult.value}
+ versions={resultVersions.map(version => ({ value: version.value, description: version.description }))}
+ onVersionChange={selectVersion}
+ />
</div>
- <CreatorResultVersionMenu
- version={selectedResult.value}
- versions={resultVersions.map(version => ({ value: version.value, description: version.description }))}
- onVersionChange={selectVersion}
- />
</div>
<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>
+ <div className="video-result-pane" data-view={resultView}>
+ {rendering ? (
+ <div className="video-result-empty" role="status"><LoaderCircle className="smart-dubbing-spinner" size={26} /><strong>{l('正在自动生成视频切片', 'Rendering video clips automatically')}</strong><span>{readProgressText(latestRenderStage, l)}</span></div>
+ ) : renderedClipItems.length > 0 ? (
+ resultView === 'grid' ? (
+ <section className="auto-clip-grid" aria-label={l('视频切片网格', 'Video clip grid')}>
+ {renderedClipItems.map(({ artifact, clip }, index) => (
+ <AutoClipGridItem
+ key={artifact.id}
+ index={index}
+ clip={clip}
+ artifact={artifact}
+ videoUrl={exportUrls[artifact.id] ?? ''}
+ onDownload={() => downloadArtifact(artifact)}
+ />
))}
</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 className="auto-clip-compact-list" aria-label={l('视频切片列表', 'Video clip list')}>
+ {renderedClipItems.map(({ artifact, clip }, index) => (
+ <AutoClipResultItem
+ key={artifact.id}
+ index={index}
+ clip={clip}
+ artifact={artifact}
+ videoUrl={exportUrls[artifact.id] ?? ''}
+ subtitleCues={selectedResult.subtitleArtifact?.metadata.cues}
+ onDownload={() => downloadArtifact(artifact)}
+ />
))}
</section>
- )}
- </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}
+ )
+ ) : (
+ <div className="video-result-empty"><Scissors size={26} strokeWidth={1.5} /><strong>{l('视频切片尚未生成', 'Video clips are not ready yet')}</strong><span>{l('分析完成后会自动生成全部片段', 'All analyzed moments will be rendered automatically')}</span></div>
+ )}
+ </div>
- {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('调整内容重点、时长或数量后重新识别,会保留为新版本', '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}
@@ -752,6 +663,181 @@ export default function AutoClipWorkspace(props: {
);
}
+function AutoClipGridItem(props: {
+ index: number;
+ clip: ClipCandidate;
+ artifact: CreatorArtifact;
+ videoUrl: string;
+ onDownload(): void;
+}) {
+ const l = useLocalizedCopy();
+ const orientation = readOrientation(props.artifact)
+ ?? aspectRatioOrientation(readAspectRatio(props.artifact.metadata.aspectRatio))
+ ?? 'landscape';
+ const sequence = String(props.index + 1).padStart(2, '0');
+ return (
+ <article className="auto-clip-grid-item" aria-label={`${l('网格切片', 'Grid clip')} ${props.index + 1}: ${props.clip.title}`}>
+ <div className="auto-clip-grid-preview" data-orientation={orientation}>
+ {props.videoUrl ? (
+ <video
+ controls
+ playsInline
+ preload="metadata"
+ src={props.videoUrl}
+ aria-label={`${l('网格切片预览', 'Grid clip preview')} ${props.index + 1}`}
+ />
+ ) : <div className="auto-clip-export-loading"><LoaderCircle className="smart-dubbing-spinner" size={22} /></div>}
+ </div>
+ <div className="auto-clip-grid-meta">
+ <div>
+ <strong>{totalScore(props.clip)}<small>/100</small></strong>
+ <span>#{sequence}</span>
+ <button
+ type="button"
+ disabled={!props.videoUrl}
+ onClick={props.onDownload}
+ title={l('下载切片', 'Download clip')}
+ aria-label={`${l('下载视频切片', 'Download video clip')} ${props.clip.title}`}
+ >
+ <Download size={15} />
+ </button>
+ </div>
+ <h3>{props.clip.title}</h3>
+ <p>{formatTimeRange(props.clip)} · {formatDuration(props.clip.end - props.clip.start)}</p>
+ </div>
+ </article>
+ );
+}
+
+function AutoClipResultItem(props: {
+ index: number;
+ clip: ClipCandidate;
+ artifact: CreatorArtifact;
+ videoUrl: string;
+ subtitleCues: CreatorJson | undefined;
+ onDownload(): void;
+}) {
+ const l = useLocalizedCopy();
+ const videoRef = useRef<HTMLVideoElement>(null);
+ const transcriptScrollRef = useRef<HTMLDivElement>(null);
+ const cueRefs = useRef(new Map<string, HTMLElement>());
+ const [playbackTime, setPlaybackTime] = useState(0);
+ const cues = useMemo(
+ () => readClipSubtitleCues(props.subtitleCues, props.clip),
+ [props.clip, props.subtitleCues]
+ );
+ const absoluteTime = props.clip.start + playbackTime;
+ const activeCueIds = new Set(cues
+ .filter(cue => absoluteTime >= cue.start && absoluteTime < cue.end)
+ .map(cue => cue.id));
+ const activeCueKey = [...activeCueIds].join('|');
+ const orientation = readOrientation(props.artifact)
+ ?? aspectRatioOrientation(readAspectRatio(props.artifact.metadata.aspectRatio))
+ ?? 'landscape';
+
+ useEffect(() => {
+ setPlaybackTime(0);
+ }, [props.clip.id, props.videoUrl]);
+
+ useEffect(() => {
+ const activeCueId = activeCueIds.values().next().value;
+ if (typeof activeCueId !== 'string') return;
+ const container = transcriptScrollRef.current;
+ const cue = cueRefs.current.get(activeCueId);
+ if (container === null || cue === undefined) return;
+ const containerRect = container.getBoundingClientRect();
+ const cueRect = cue.getBoundingClientRect();
+ if (cueRect.top < containerRect.top) {
+ container.scrollTop -= containerRect.top - cueRect.top;
+ } else if (cueRect.bottom > containerRect.bottom) {
+ container.scrollTop += cueRect.bottom - containerRect.bottom;
+ }
+ }, [activeCueKey]);
+
+ function seekToCue(cue: ClipSubtitleCue) {
+ const targetTime = Math.max(0, cue.start - props.clip.start);
+ if (videoRef.current !== null) videoRef.current.currentTime = targetTime;
+ setPlaybackTime(targetTime);
+ }
+
+ const sequence = String(props.index + 1).padStart(2, '0');
+ return (
+ <article className="auto-clip-compact-item" aria-label={`${l('切片', 'Clip')} ${props.index + 1}: ${props.clip.title}`}>
+ <header className="auto-clip-compact-header">
+ <span>#{sequence}</span>
+ <div>
+ <h3>{props.clip.title}</h3>
+ <small>{formatTimeRange(props.clip)} · {formatDuration(props.clip.end - props.clip.start)}</small>
+ </div>
+ <button
+ type="button"
+ disabled={!props.videoUrl}
+ onClick={props.onDownload}
+ title={l('下载切片', 'Download clip')}
+ aria-label={`${l('下载视频切片', 'Download video clip')} ${props.clip.title}`}
+ >
+ <Download size={16} />
+ </button>
+ </header>
+ <div className="auto-clip-compact-body">
+ <section className="auto-clip-compact-score" aria-label={`${l('切片评分', 'Clip score')} ${props.index + 1}`}>
+ <span>{l('综合评分', 'Score')}</span>
+ <strong>{totalScore(props.clip)}<small>/100</small></strong>
+ <dl>
+ {Object.entries(props.clip.scores).map(([key, score]) => (
+ <div key={key}><dt>{scoreLabel(key as ClipScoreKey, l)}</dt><dd>{score}</dd></div>
+ ))}
+ </dl>
+ </section>
+ <div className="auto-clip-compact-preview" data-orientation={orientation}>
+ {props.videoUrl ? (
+ <video
+ ref={videoRef}
+ controls
+ playsInline
+ preload="metadata"
+ src={props.videoUrl}
+ onLoadedMetadata={event => setPlaybackTime(event.currentTarget.currentTime)}
+ onSeeked={event => setPlaybackTime(event.currentTarget.currentTime)}
+ onTimeUpdate={event => setPlaybackTime(event.currentTarget.currentTime)}
+ aria-label={`${l('切片预览', 'Clip preview')} ${props.index + 1}`}
+ />
+ ) : <div className="auto-clip-export-loading"><LoaderCircle className="smart-dubbing-spinner" size={22} /></div>}
+ </div>
+ <section className="auto-clip-compact-transcript" aria-label={`${l('切片字幕', 'Clip transcript')} ${props.index + 1}`}>
+ <header><h4>{l('字幕', 'Transcript')}</h4><span>{cues.length} {l('条', 'lines')}</span></header>
+ <div ref={transcriptScrollRef}>
+ {cues.map((cue, cueIndex) => {
+ const active = activeCueIds.has(cue.id);
+ return (
+ <button
+ type="button"
+ key={cue.id}
+ ref={node => {
+ if (node === null) cueRefs.current.delete(cue.id);
+ else cueRefs.current.set(cue.id, node);
+ }}
+ data-active={active}
+ data-subtitle-cue="true"
+ aria-current={active ? 'true' : undefined}
+ aria-label={l(
+ `跳转到切片 ${props.index + 1} 字幕 ${cueIndex + 1},${formatTimestamp(cue.start - props.clip.start)}`,
+ `Jump to clip ${props.index + 1} transcript ${cueIndex + 1}, ${formatTimestamp(cue.start - props.clip.start)}`
+ )}
+ onClick={() => seekToCue(cue)}
+ >
+ <span>{formatTimestamp(cue.start - props.clip.start)}</span>
+ <strong>{cue.text}</strong>
+ </button>
+ );
+ })}
+ </div>
+ </section>
+ </div>
+ </article>
+ );
+}
+
function createAutoClipResultVersions(
artifacts: CreatorArtifact[],
resultSnapshots: CreatorJson | undefined
@@ -767,12 +853,16 @@ function createAutoClipResultVersions(
const sourceArtifact = (snapshot.artifactRefs.source_video ?? [])
.map(id => byId.get(id))
.find((candidate): candidate is CreatorArtifact => candidate !== undefined);
+ const subtitleArtifact = (snapshot.artifactRefs.target_subtitle ?? [])
+ .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 }),
+ ...(subtitleArtifact === undefined ? {} : { subtitleArtifact }),
candidates
}];
});
@@ -791,6 +881,9 @@ function createAutoClipResultVersions(
candidate.kind === 'source_video'
&& artifact.sourceArtifactIds.includes(candidate.id)
)),
+ subtitleArtifact: artifact.sourceArtifactIds
+ .map(id => byId.get(id))
+ .find(candidate => candidate?.kind === 'target_subtitle'),
candidates
}];
})
@@ -826,6 +919,64 @@ function readCandidates(value: CreatorJson | undefined): ClipCandidate[] {
});
}
+function readClipSubtitleCues(
+ value: CreatorJson | undefined,
+ clip: ClipCandidate
+): ClipSubtitleCue[] {
+ const cues = Array.isArray(value)
+ ? value.flatMap((item, index) => {
+ if (!isRecord(item)) return [];
+ const start = subtitleTimestampSeconds(item.start);
+ const end = subtitleTimestampSeconds(item.end);
+ const text = readString(item.text);
+ if (!text || !Number.isFinite(start) || !Number.isFinite(end) || end <= start) return [];
+ const clippedStart = Math.max(clip.start, start);
+ const clippedEnd = Math.min(clip.end, end);
+ if (clippedEnd <= clippedStart) return [];
+ const rawId = typeof item.id === 'string' || typeof item.id === 'number'
+ ? String(item.id)
+ : String(index + 1);
+ return [{
+ id: `${rawId}-${index}`,
+ start: clippedStart,
+ end: clippedEnd,
+ text
+ }];
+ })
+ : [];
+ return cues.length > 0 ? cues : approximateSubtitleCues(clip);
+}
+
+function approximateSubtitleCues(clip: ClipCandidate): ClipSubtitleCue[] {
+ const segments = clip.transcript
+ .match(/[^。!?!?;;\n.]+[。!?!?;;.]?/g)
+ ?.map(text => text.trim())
+ .filter(Boolean) ?? [];
+ if (segments.length === 0) return [];
+ const totalWeight = segments.reduce((total, text) => total + text.length, 0);
+ const duration = clip.end - clip.start;
+ let cursor = clip.start;
+ return segments.map((text, index) => {
+ const start = cursor;
+ const end = index === segments.length - 1
+ ? clip.end
+ : Math.min(clip.end, start + duration * text.length / totalWeight);
+ cursor = end;
+ return { id: `approximate-${index}`, start, end, text };
+ });
+}
+
+function subtitleTimestampSeconds(value: CreatorJson | undefined): number {
+ if (typeof value === 'number') return value;
+ if (typeof value !== 'string') return Number.NaN;
+ const match = /^(\d+):(\d{2}):(\d{2})(?:[,.](\d{1,3}))?$/.exec(value.trim());
+ if (match === null) return Number.NaN;
+ return Number(match[1]) * 3600
+ + Number(match[2]) * 60
+ + Number(match[3])
+ + Number((match[4] ?? '').padEnd(3, '0')) / 1000;
+}
+
function totalScore(clip: ClipCandidate): number {
const values = Object.values(clip.scores);
return Math.round(values.reduce((sum, score) => sum + score, 0) / values.length);
@@ -856,16 +1007,38 @@ function formatDuration(seconds: number): string {
: `${value}s`;
}
-function mediaFragment(url: string, clip: ClipCandidate): string {
- return `${url}#t=${clip.start},${clip.end}`;
-}
-
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 genreLabel(value: ClipGenre, l: ReturnType<typeof useLocalizedCopy>): string {
+ if (value === 'talk') return l('演讲 / 观点', 'Talk / commentary');
+ if (value === 'podcast') return l('播客对谈', 'Podcast');
+ if (value === 'tutorial') return l('教程 / 知识', 'Tutorial / education');
+ if (value === 'interview') return l('人物访谈', 'Interview');
+ if (value === 'entertainment') return l('娱乐内容', 'Entertainment');
+ if (value === 'sports') return l('体育内容', 'Sports');
+ if (value === 'gaming') return l('游戏内容', 'Gaming');
+ if (value === 'news') return l('新闻 / 时事', 'News / current affairs');
+ return l('自动判断', 'Auto detect');
+}
+
+function sourceLanguageLabel(value: string, l: ReturnType<typeof useLocalizedCopy>): string {
+ if (value === 'zh_cn') return l('简体中文', 'Simplified Chinese');
+ if (value === 'zh_tw') return l('繁體中文', 'Traditional Chinese');
+ if (value === 'ja') return '日本語';
+ if (value === 'ko') return '한국어';
+ if (value === 'es') return 'Español';
+ if (value === 'fr') return 'Français';
+ if (value === 'de') return 'Deutsch';
+ if (value === 'pt') return 'Português';
+ if (value === 'ru') return 'Русский';
+ if (value === 'en') return 'English';
+ return l('自动检测', 'Auto detect');
+}
+
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');
@@ -902,6 +1075,35 @@ function readFocus(value: CreatorJson | undefined): AnalysisFocus {
return value === 'viral' || value === 'knowledge' ? value : 'balanced';
}
+function readGenre(value: CreatorJson | undefined): ClipGenre {
+ return value === 'talk'
+ || value === 'podcast'
+ || value === 'tutorial'
+ || value === 'interview'
+ || value === 'entertainment'
+ || value === 'sports'
+ || value === 'gaming'
+ || value === 'news'
+ ? value
+ : 'auto';
+}
+
+function readSourceLanguage(value: CreatorJson | undefined): string {
+ return typeof value === 'string' && [
+ 'auto',
+ 'zh_cn',
+ 'zh_tw',
+ 'en',
+ 'ja',
+ 'ko',
+ 'es',
+ 'fr',
+ 'de',
+ 'pt',
+ 'ru'
+ ].includes(value) ? value : 'auto';
+}
+
function readDuration(value: CreatorJson | undefined): ClipDuration {
return value === '15-30' || value === '60-90' ? value : '30-60';
}
@@ -910,6 +1112,13 @@ function readAspectRatio(value: CreatorJson | undefined): ClipAspectRatio {
return value === 'source' || value === '16:9' || value === '1:1' ? value : '9:16';
}
+function aspectRatioOrientation(value: ClipAspectRatio): VideoOrientation | undefined {
+ if (value === '9:16') return 'portrait';
+ if (value === '16:9') return 'landscape';
+ if (value === '1:1') return 'square';
+ return undefined;
+}
+
function readClipCount(value: CreatorJson | undefined): number {
return typeof value === 'number' ? clampClipCount(value) : 10;
}
@@ -923,10 +1132,6 @@ 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;
}
@@ -977,13 +1182,21 @@ function matchingSourceArtifact(
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)
- ));
+ return [...artifacts].reverse().find(artifact => {
+ if (
+ artifact.kind !== 'source_video'
+ || artifact.status !== 'completed'
+ || normalizedUrl.length === 0
+ ) return false;
+ const probe = relatedArtifact(artifacts, artifact, 'download_probe');
+ return [
+ artifact.metadata.sourceUrl,
+ artifact.metadata.requestedUrl,
+ artifact.metadata.webpageUrl,
+ probe?.metadata.url,
+ probe?.metadata.requestedUrl
+ ].some(value => typeof value === 'string' && value.trim() === normalizedUrl);
+ });
}
function matchingSubtitleArtifact(
@@ -1030,10 +1243,21 @@ function artifactFileName(artifact: CreatorArtifact | undefined): string {
return typeof value === 'string' && value.trim() ? value.trim() : '';
}
+function relatedArtifact(
+ artifacts: CreatorArtifact[],
+ artifact: CreatorArtifact | undefined,
+ kind: string
+): CreatorArtifact | undefined {
+ if (artifact === undefined) return undefined;
+ const sourceIds = new Set(artifact.sourceArtifactIds);
+ return artifacts.find(candidate => candidate.kind === kind && sourceIds.has(candidate.id));
+}
+
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;
+ if (Math.abs(width - height) / Math.max(width, height) < 0.02) return 'square';
return height > width ? 'portrait' : 'landscape';
}
@@ -1051,7 +1275,7 @@ function formatClipError(
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_clip_candidates_missing') return l('没有可生成的视频片段,请重新分析', 'No clips are available. Run the analysis again.');
if (code === 'creator_stage_canceled') return l('视频切片任务已取消', 'The video clip task was canceled');
const message = typeof candidate.message === 'string'
? candidate.message
diff --git a/apps/web/src/features/dashboard/dashboard.css b/apps/web/src/features/dashboard/dashboard.css
index 16922054..84274729 100644
--- a/apps/web/src/features/dashboard/dashboard.css
+++ b/apps/web/src/features/dashboard/dashboard.css
@@ -1718,6 +1718,44 @@
grid-template-columns: repeat(3, minmax(0, 1fr));
}
+.auto-clip-setting-sections {
+ display: grid;
+ gap: 20px;
+}
+
+.auto-clip-setting-section {
+ min-width: 0;
+}
+
+.auto-clip-setting-section + .auto-clip-setting-section {
+ padding-top: 18px;
+ border-top: 1px solid var(--border-hairline);
+}
+
+.auto-clip-setting-section > header {
+ min-height: 20px;
+ display: flex;
+ align-items: baseline;
+ justify-content: space-between;
+ gap: 12px;
+}
+
+.auto-clip-setting-section > header h3 {
+ margin: 0;
+ font-size: 13px;
+ font-weight: 650;
+ letter-spacing: 0;
+}
+
+.auto-clip-setting-section > header span {
+ color: var(--muted);
+ font-size: 11px;
+}
+
+.auto-clip-setting-section .creator-tool-form-row {
+ margin-top: 10px;
+}
+
.creator-tool-actions {
display: flex;
justify-content: flex-end;
@@ -9220,18 +9258,18 @@
padding: 14px;
}
-.auto-clip-detail > header {
+.auto-clip-detail-copy {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
- margin-top: 14px;
}
-.auto-clip-detail > header small { color: var(--accent); font-size: 10px; font-weight: 650; }
-.auto-clip-detail > header h2 { margin: 4px 0; font-size: 15px; }
-.auto-clip-detail > header p { margin: 0; color: var(--muted); font-size: 11px; }
-.auto-clip-detail > header > strong { color: var(--accent); font-size: 26px; }
+.auto-clip-detail-copy > div { min-width: 0; }
+.auto-clip-detail-copy small { color: var(--accent); font-size: 10px; font-weight: 650; }
+.auto-clip-detail-copy h2 { margin: 4px 0; font-size: 15px; }
+.auto-clip-detail-copy p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
+.auto-clip-detail-copy > strong { flex: 0 0 auto; color: var(--accent); font-size: 26px; }
.auto-clip-scores {
display: grid;
@@ -9254,27 +9292,74 @@
.auto-clip-scores dd { margin: 0; color: var(--text); font-size: 13px; font-weight: 650; }
.auto-clip-subtitle {
- padding: 11px;
+ overflow: hidden;
border: 1px solid var(--border-hairline);
border-radius: 7px;
background: var(--conversation-bg);
}
-.auto-clip-subtitle h3 { margin: 0 0 7px; font-size: 12px; }
-.auto-clip-subtitle p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
-
-.auto-clip-detail > button {
- width: 100%;
- height: 34px;
+.auto-clip-subtitle > header {
display: flex;
align-items: center;
- justify-content: center;
- gap: 6px;
- margin-top: 12px;
- border: 1px solid var(--border);
- border-radius: 7px;
+ justify-content: space-between;
+ gap: 8px;
+ padding: 10px 12px;
+ border-bottom: 1px solid var(--border-hairline);
+}
+
+.auto-clip-subtitle h3 { margin: 0; font-size: 12px; }
+.auto-clip-subtitle > header span { color: var(--muted); font-size: 10px; }
+
+.auto-clip-subtitle-list {
+ max-height: min(340px, 42vh);
+ overflow-y: auto;
+ scrollbar-gutter: stable;
+}
+
+.auto-clip-subtitle-list > button {
+ width: 100%;
+ min-width: 0;
+ display: grid;
+ grid-template-columns: 42px minmax(0, 1fr);
+ align-items: start;
+ gap: 9px;
+ padding: 10px 11px 10px 8px;
+ border: 0;
+ border-left: 3px solid transparent;
+ border-radius: 0;
+ color: var(--muted);
+ text-align: left;
+ transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
+}
+
+.auto-clip-subtitle-list > button + button {
+ border-top: 1px solid var(--border-hairline);
+}
+
+.auto-clip-subtitle-list > button:hover {
+ background: var(--surface-2);
+ color: var(--text);
+}
+
+.auto-clip-subtitle-list > button[data-active="true"] {
+ border-left-color: var(--accent);
+ background: color-mix(in srgb, var(--accent) 8%, var(--surface));
color: var(--text);
+}
+
+.auto-clip-subtitle-list > button > span {
+ color: var(--subtle);
+ font-size: 10px;
+ font-variant-numeric: tabular-nums;
+ line-height: 1.55;
+}
+
+.auto-clip-subtitle-list > button > strong {
+ min-width: 0;
font-size: 12px;
+ font-weight: 500;
+ line-height: 1.55;
+ overflow-wrap: anywhere;
}
.auto-clip-analysis-note {
@@ -9314,68 +9399,52 @@
.auto-clip-result-workspace {
height: auto;
min-height: 560px;
+ container: auto-clip-result / inline-size;
}
-.cover-result-workspace {
- height: 100%;
- min-height: 0;
+.auto-clip-result-heading {
+ min-width: 0;
+ display: flex;
+ align-items: baseline;
+ gap: 9px;
}
-.auto-clip-result-actions {
- display: flex;
- align-items: center;
- gap: 8px;
+.auto-clip-result-heading h2 {
+ margin: 0;
+ color: var(--text);
+ font-size: 15px;
+ font-weight: 650;
+ letter-spacing: 0;
}
-.auto-clip-result-actions label {
- display: inline-flex;
- align-items: center;
- gap: 7px;
+.auto-clip-result-heading span {
color: var(--muted);
font-size: 11px;
}
-.auto-clip-result-actions select,
-.auto-clip-result-actions button {
- height: 34px;
- padding: 0 9px;
- border: 1px solid var(--border);
- border-radius: 7px;
- background: var(--surface);
- color: var(--text);
- font-size: 12px;
-}
-
-.auto-clip-result-actions button {
- display: inline-flex;
+.auto-clip-result-controls,
+.auto-clip-view-switch {
+ display: flex;
align-items: center;
- gap: 6px;
- border-color: var(--accent);
- background: var(--accent);
- color: var(--on-accent);
- white-space: nowrap;
}
-.auto-clip-result-actions button:disabled {
- border-color: var(--border);
- background: var(--surface-2);
- color: var(--subtle);
+.auto-clip-result-controls {
+ gap: 8px;
}
-.auto-clip-layout-switch {
- height: 34px;
- display: inline-flex;
- align-items: center;
+.auto-clip-view-switch {
+ gap: 2px;
padding: 3px;
border: 1px solid var(--border);
border-radius: 7px;
background: var(--surface-2);
- box-sizing: border-box;
}
-.auto-clip-result-actions .auto-clip-layout-switch button {
+.auto-clip-view-switch > button {
width: 28px;
- height: 26px;
+ height: 28px;
+ display: grid;
+ place-items: center;
padding: 0;
border: 0;
border-radius: 5px;
@@ -9383,133 +9452,682 @@
color: var(--muted);
}
-.auto-clip-result-actions .auto-clip-layout-switch button[aria-pressed="true"] {
+.auto-clip-view-switch > button:hover {
+ color: var(--text);
+}
+
+.auto-clip-view-switch > button[aria-pressed="true"] {
background: var(--surface);
color: var(--text);
- box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 10%, transparent);
+ box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 9%, transparent);
}
-.auto-clip-candidate-grid {
- display: grid;
- grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
- align-items: start;
- gap: 14px;
+.auto-clip-view-switch > button:active {
+ transform: translateY(1px);
}
-.auto-clip-candidate-grid[data-orientation="landscape"] {
- grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
+.auto-clip-result-content {
+ min-height: 0;
}
-.auto-clip-candidate-grid > article {
+.auto-clip-result-workspace .video-result-pane {
+ padding: 0;
+}
+
+.auto-clip-result-workspace .video-result-pane[data-view="grid"] {
+ padding: 24px;
+}
+
+.auto-clip-grid {
min-width: 0;
- overflow: hidden;
- border: 1px solid var(--border);
- border-radius: 8px;
- background: var(--surface);
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
+ align-items: start;
+ gap: 36px 24px;
}
-.auto-clip-candidate-grid > article[data-selected="true"] {
- border-color: color-mix(in srgb, var(--accent) 58%, var(--border));
+.auto-clip-grid-item {
+ min-width: 0;
}
-.auto-clip-card-media {
+.auto-clip-grid-preview {
position: relative;
- aspect-ratio: 9 / 16;
+ width: 100%;
overflow: hidden;
+ border-radius: 6px;
background: #09090b;
}
-.auto-clip-candidate-grid[data-orientation="landscape"] .auto-clip-card-media {
+.auto-clip-grid-preview[data-orientation="portrait"] {
+ aspect-ratio: 9 / 16;
+}
+
+.auto-clip-grid-preview[data-orientation="landscape"] {
aspect-ratio: 16 / 9;
}
-.auto-clip-card-media > img,
-.auto-clip-card-media > video {
+.auto-clip-grid-preview[data-orientation="square"] {
+ aspect-ratio: 1;
+}
+
+.auto-clip-grid-preview video,
+.auto-clip-grid-preview .auto-clip-export-loading {
width: 100%;
height: 100%;
display: block;
- object-fit: cover;
-}
-
-.auto-clip-card-duration {
- position: absolute;
- top: 8px;
- right: 8px;
- padding: 4px 7px;
- border-radius: 5px;
- background: rgba(9, 9, 11, 0.78);
- color: #fff;
- font-size: 10px;
- font-weight: 600;
+ aspect-ratio: auto;
+ background: #09090b;
+ object-fit: contain;
}
-.auto-clip-card-media > label {
- position: absolute;
- top: 8px;
- left: 8px;
- width: 28px;
- height: 28px;
+.auto-clip-grid-preview .auto-clip-export-loading {
display: grid;
place-items: center;
- border-radius: 6px;
- background: rgba(9, 9, 11, 0.78);
-}
-
-.auto-clip-card-media > label input,
-.auto-clip-list-select input {
- width: 15px;
- height: 15px;
- margin: 0;
- accent-color: var(--accent);
}
-.auto-clip-card-media > button {
- position: absolute;
- inset: 50% auto auto 50%;
- width: 38px;
- height: 38px;
+.auto-clip-grid-meta {
+ min-width: 0;
display: grid;
- place-items: center;
- padding: 0;
- border: 1px solid rgba(255, 255, 255, 0.24);
- border-radius: 50%;
- background: rgba(9, 9, 11, 0.72);
- color: #fff;
- transform: translate(-50%, -50%);
+ gap: 7px;
+ padding-top: 12px;
}
-.auto-clip-card-copy {
+.auto-clip-grid-meta > div {
min-width: 0;
display: grid;
- gap: 6px;
- padding: 11px 11px 9px;
+ grid-template-columns: auto minmax(0, 1fr) 30px;
+ align-items: center;
+ gap: 10px;
}
-.auto-clip-card-copy strong {
- min-height: 36px;
- overflow: hidden;
- display: -webkit-box;
- color: var(--text);
- font-size: 12px;
- line-height: 1.5;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
+.auto-clip-grid-meta > div > strong {
+ color: var(--accent);
+ font-size: 24px;
+ font-variant-numeric: tabular-nums;
+ line-height: 1;
}
-.auto-clip-card-copy span {
- overflow: hidden;
+.auto-clip-grid-meta > div > strong small {
+ margin-left: 2px;
+ color: var(--subtle);
+ font-size: 9px;
+ font-weight: 500;
+}
+
+.auto-clip-grid-meta > div > span {
color: var(--subtle);
font-size: 10px;
- text-overflow: ellipsis;
- white-space: nowrap;
+ font-weight: 650;
+ font-variant-numeric: tabular-nums;
}
-.auto-clip-candidate-grid footer {
- min-height: 38px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 8px;
+.auto-clip-grid-meta button {
+ width: 30px;
+ height: 30px;
+ display: grid;
+ place-items: center;
+ padding: 0;
+ border: 1px solid var(--border);
+ border-radius: 6px;
+ background: var(--surface);
+ color: var(--text);
+}
+
+.auto-clip-grid-meta button:hover:not(:disabled) {
+ border-color: var(--border-strong);
+ color: var(--accent);
+}
+
+.auto-clip-grid-meta button:active:not(:disabled) {
+ transform: translateY(1px);
+}
+
+.auto-clip-grid-meta button:disabled {
+ color: var(--subtle);
+ cursor: not-allowed;
+}
+
+.auto-clip-grid-meta h3 {
+ min-height: 38px;
+ overflow: hidden;
+ display: -webkit-box;
+ margin: 0;
+ color: var(--text);
+ font-size: 13px;
+ font-weight: 600;
+ letter-spacing: 0;
+ line-height: 1.45;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+}
+
+.auto-clip-grid-meta p {
+ overflow: hidden;
+ margin: 0;
+ color: var(--subtle);
+ font-size: 10px;
+ font-variant-numeric: tabular-nums;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.auto-clip-compact-list {
+ min-width: 0;
+}
+
+.auto-clip-compact-item {
+ min-width: 0;
+ background: var(--surface);
+}
+
+.auto-clip-compact-item + .auto-clip-compact-item {
+ border-top: 1px solid var(--border);
+}
+
+.auto-clip-compact-header {
+ min-width: 0;
+ display: grid;
+ grid-template-columns: 38px minmax(0, 1fr) 32px;
+ align-items: center;
+ gap: 10px;
+ min-height: 54px;
+ padding: 9px 12px;
+ border-bottom: 1px solid var(--border-hairline);
+ background: var(--conversation-bg);
+ box-sizing: border-box;
+}
+
+.auto-clip-compact-header > span {
+ color: var(--accent);
+ font-size: 12px;
+ font-weight: 700;
+ font-variant-numeric: tabular-nums;
+}
+
+.auto-clip-compact-header > div {
+ min-width: 0;
+}
+
+.auto-clip-compact-header h3 {
+ overflow: hidden;
+ margin: 0;
+ color: var(--text);
+ font-size: 13px;
+ font-weight: 650;
+ letter-spacing: 0;
+ line-height: 1.35;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.auto-clip-compact-header small {
+ display: block;
+ margin-top: 2px;
+ color: var(--subtle);
+ font-size: 10px;
+ font-variant-numeric: tabular-nums;
+}
+
+.auto-clip-compact-header > button {
+ width: 32px;
+ height: 32px;
+ display: grid;
+ place-items: center;
+ padding: 0;
+ border: 1px solid var(--border);
+ border-radius: 6px;
+ background: var(--surface);
+ color: var(--text);
+}
+
+.auto-clip-compact-header > button:hover:not(:disabled) {
+ border-color: var(--border-strong);
+ color: var(--accent);
+}
+
+.auto-clip-compact-header > button:active:not(:disabled) {
+ transform: translateY(1px);
+}
+
+.auto-clip-compact-header > button:disabled {
+ color: var(--subtle);
+ cursor: not-allowed;
+}
+
+.auto-clip-compact-body {
+ min-width: 0;
+ display: grid;
+ grid-template-columns: 108px 216px minmax(260px, 1fr);
+ align-items: stretch;
+ gap: 18px;
+ padding: 20px 18px;
+}
+
+.auto-clip-compact-score {
+ min-width: 0;
+ display: grid;
+ align-content: start;
+ gap: 3px;
+}
+
+.auto-clip-compact-score > span {
+ color: var(--muted);
+ font-size: 10px;
+}
+
+.auto-clip-compact-score > strong {
+ color: var(--accent);
+ font-size: 27px;
+ font-variant-numeric: tabular-nums;
+ line-height: 1.15;
+}
+
+.auto-clip-compact-score > strong small {
+ margin-left: 2px;
+ color: var(--subtle);
+ font-size: 10px;
+ font-weight: 500;
+}
+
+.auto-clip-compact-score dl {
+ display: grid;
+ gap: 5px;
+ margin: 11px 0 0;
+}
+
+.auto-clip-compact-score dl > div {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 6px;
+}
+
+.auto-clip-compact-score dt {
+ overflow: hidden;
+ color: var(--muted);
+ font-size: 10px;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.auto-clip-compact-score dd {
+ margin: 0;
+ color: var(--text);
+ font-size: 11px;
+ font-weight: 650;
+ font-variant-numeric: tabular-nums;
+}
+
+.auto-clip-compact-preview {
+ width: 100%;
+ height: 320px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ align-self: center;
+ overflow: hidden;
+ border-radius: 6px;
+ background: #09090b;
+}
+
+.auto-clip-compact-preview video {
+ max-width: 100%;
+ max-height: 100%;
+ display: block;
+ background: #09090b;
+ object-fit: contain;
+}
+
+.auto-clip-compact-preview[data-orientation="landscape"] video {
+ width: 100%;
+ aspect-ratio: 16 / 9;
+}
+
+.auto-clip-compact-preview[data-orientation="portrait"] video {
+ height: 100%;
+ aspect-ratio: 9 / 16;
+}
+
+.auto-clip-compact-preview[data-orientation="square"] video {
+ height: 100%;
+ aspect-ratio: 1;
+}
+
+.auto-clip-compact-preview .auto-clip-export-loading {
+ width: 100%;
+ height: 100%;
+ aspect-ratio: auto;
+}
+
+.auto-clip-compact-transcript {
+ min-width: 0;
+ height: 320px;
+ display: grid;
+ grid-template-rows: auto minmax(0, 1fr);
+ border-left: 1px solid var(--border-hairline);
+ padding-left: 16px;
+ box-sizing: border-box;
+}
+
+.auto-clip-compact-transcript > header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 10px;
+ min-height: 27px;
+ padding: 0 8px 6px;
+}
+
+.auto-clip-compact-transcript h4 {
+ margin: 0;
+ color: var(--text);
+ font-size: 11px;
+ font-weight: 650;
+ letter-spacing: 0;
+}
+
+.auto-clip-compact-transcript > header span {
+ color: var(--subtle);
+ font-size: 10px;
+}
+
+.auto-clip-compact-transcript > div {
+ min-height: 0;
+ overflow-y: auto;
+ scrollbar-gutter: stable;
+}
+
+.auto-clip-compact-transcript > div > button {
+ width: 100%;
+ min-width: 0;
+ display: grid;
+ grid-template-columns: 42px minmax(0, 1fr);
+ align-items: start;
+ gap: 9px;
+ padding: 8px 8px 8px 6px;
+ border: 0;
+ border-left: 2px solid transparent;
+ border-radius: 0;
+ color: var(--muted);
+ text-align: left;
+ transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
+}
+
+.auto-clip-compact-transcript > div > button + button {
+ border-top: 1px solid var(--border-hairline);
+}
+
+.auto-clip-compact-transcript > div > button:hover {
+ background: var(--surface-2);
+ color: var(--text);
+}
+
+.auto-clip-compact-transcript > div > button[data-active="true"] {
+ border-left-color: var(--accent);
+ background: color-mix(in srgb, var(--accent) 8%, var(--surface));
+ color: var(--text);
+}
+
+.auto-clip-compact-transcript > div > button > span {
+ color: var(--subtle);
+ font-size: 10px;
+ font-variant-numeric: tabular-nums;
+ line-height: 1.5;
+}
+
+.auto-clip-compact-transcript > div > button > strong {
+ min-width: 0;
+ font-size: 11px;
+ font-weight: 500;
+ line-height: 1.5;
+ overflow-wrap: anywhere;
+}
+
+@container auto-clip-result (max-width: 720px) {
+ .auto-clip-result-workspace .video-result-pane[data-view="grid"] {
+ padding: 16px;
+ }
+
+ .auto-clip-grid {
+ grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
+ gap: 28px 18px;
+ }
+
+ .auto-clip-compact-body {
+ grid-template-columns: 82px 150px minmax(190px, 1fr);
+ gap: 12px;
+ padding: 12px;
+ }
+
+ .auto-clip-compact-preview,
+ .auto-clip-compact-transcript {
+ height: 260px;
+ }
+
+ .auto-clip-compact-transcript {
+ padding-left: 12px;
+ }
+}
+
+@container auto-clip-result (max-width: 480px) {
+ .auto-clip-grid {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 24px 14px;
+ }
+
+ .auto-clip-compact-header {
+ grid-template-columns: 34px minmax(0, 1fr) 32px;
+ gap: 7px;
+ padding-right: 9px;
+ padding-left: 9px;
+ }
+
+ .auto-clip-compact-body {
+ grid-template-columns: minmax(0, 1fr);
+ gap: 12px;
+ }
+
+ .auto-clip-compact-score {
+ grid-template-columns: 68px minmax(0, 1fr);
+ align-items: center;
+ }
+
+ .auto-clip-compact-score > span,
+ .auto-clip-compact-score > strong {
+ grid-column: 1;
+ }
+
+ .auto-clip-compact-score dl {
+ grid-column: 2;
+ grid-row: 1 / span 2;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ margin: 0;
+ }
+
+ .auto-clip-compact-preview {
+ width: 100%;
+ height: 240px;
+ }
+
+ .auto-clip-compact-transcript {
+ height: 210px;
+ border-top: 1px solid var(--border-hairline);
+ border-left: 0;
+ padding-top: 10px;
+ padding-left: 0;
+ }
+}
+
+.cover-result-workspace {
+ height: 100%;
+ min-height: 0;
+}
+
+.auto-clip-result-actions {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.auto-clip-result-actions label {
+ display: inline-flex;
+ align-items: center;
+ gap: 7px;
+ color: var(--muted);
+ font-size: 11px;
+}
+
+.auto-clip-result-actions select,
+.auto-clip-result-actions button {
+ height: 34px;
+ padding: 0 9px;
+ border: 1px solid var(--border);
+ border-radius: 7px;
+ background: var(--surface);
+ color: var(--text);
+ font-size: 12px;
+}
+
+.auto-clip-result-actions button {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ border-color: var(--accent);
+ background: var(--accent);
+ color: var(--on-accent);
+ white-space: nowrap;
+}
+
+.auto-clip-result-actions button:disabled {
+ border-color: var(--border);
+ background: var(--surface-2);
+ color: var(--subtle);
+}
+
+.auto-clip-layout-switch {
+ height: 34px;
+ display: inline-flex;
+ align-items: center;
+ padding: 3px;
+ border: 1px solid var(--border);
+ border-radius: 7px;
+ background: var(--surface-2);
+ box-sizing: border-box;
+}
+
+.auto-clip-result-actions .auto-clip-layout-switch button {
+ width: 28px;
+ height: 26px;
+ padding: 0;
+ border: 0;
+ border-radius: 5px;
+ background: transparent;
+ color: var(--muted);
+}
+
+.auto-clip-result-actions .auto-clip-layout-switch button[aria-pressed="true"] {
+ background: var(--surface);
+ color: var(--text);
+ box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 10%, transparent);
+}
+
+.auto-clip-candidate-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
+ align-items: start;
+ gap: 14px;
+}
+
+.auto-clip-candidate-grid[data-orientation="landscape"] {
+ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
+}
+
+.auto-clip-candidate-grid > article {
+ min-width: 0;
+ overflow: hidden;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: var(--surface);
+}
+
+.auto-clip-card-media {
+ position: relative;
+ aspect-ratio: 9 / 16;
+ overflow: hidden;
+ background: #09090b;
+}
+
+.auto-clip-candidate-grid[data-orientation="landscape"] .auto-clip-card-media {
+ aspect-ratio: 16 / 9;
+}
+
+.auto-clip-card-media > img,
+.auto-clip-card-media > video {
+ width: 100%;
+ height: 100%;
+ display: block;
+ object-fit: cover;
+}
+
+.auto-clip-card-duration {
+ position: absolute;
+ top: 8px;
+ right: 8px;
+ padding: 4px 7px;
+ border-radius: 5px;
+ background: rgba(9, 9, 11, 0.78);
+ color: #fff;
+ font-size: 10px;
+ font-weight: 600;
+}
+
+.auto-clip-card-media > button {
+ position: absolute;
+ inset: 50% auto auto 50%;
+ width: 38px;
+ height: 38px;
+ display: grid;
+ place-items: center;
+ padding: 0;
+ border: 1px solid rgba(255, 255, 255, 0.24);
+ border-radius: 50%;
+ background: rgba(9, 9, 11, 0.72);
+ color: #fff;
+ transform: translate(-50%, -50%);
+}
+
+.auto-clip-card-copy {
+ min-width: 0;
+ display: grid;
+ gap: 6px;
+ padding: 11px 11px 9px;
+}
+
+.auto-clip-card-copy strong {
+ min-height: 36px;
+ overflow: hidden;
+ display: -webkit-box;
+ color: var(--text);
+ font-size: 12px;
+ line-height: 1.5;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+}
+
+.auto-clip-card-copy span {
+ overflow: hidden;
+ color: var(--subtle);
+ font-size: 10px;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.auto-clip-candidate-grid footer {
+ min-height: 38px;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
padding: 7px 8px 7px 11px;
border-top: 1px solid var(--border-hairline);
}
@@ -9551,7 +10169,7 @@
.auto-clip-candidate-detailed-list > article {
min-width: 0;
display: grid;
- grid-template-columns: 24px 132px minmax(0, 1fr) 106px;
+ grid-template-columns: 132px minmax(0, 1fr) 106px;
align-items: center;
gap: 14px;
padding: 12px;
@@ -9561,16 +10179,7 @@
}
.auto-clip-candidate-detailed-list[data-orientation="landscape"] > article {
- grid-template-columns: 24px 220px minmax(0, 1fr) 106px;
-}
-
-.auto-clip-candidate-detailed-list > article[data-selected="true"] {
- border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
-}
-
-.auto-clip-list-select {
- align-self: start;
- padding-top: 4px;
+ grid-template-columns: 220px minmax(0, 1fr) 106px;
}
.auto-clip-list-preview {
@@ -9727,13 +10336,40 @@
}
.auto-clip-detail-result {
- width: min(620px, 100%);
+ width: min(1040px, 100%);
margin: 0 auto;
box-sizing: border-box;
}
+.auto-clip-detail-layout {
+ display: grid;
+ grid-template-columns: minmax(280px, 1.1fr) minmax(320px, .9fr);
+ align-items: start;
+ gap: 18px;
+}
+
+.auto-clip-detail-media,
+.auto-clip-detail-sidebar {
+ min-width: 0;
+}
+
+.auto-clip-detail-media {
+ position: sticky;
+ top: 0;
+}
+
+.auto-clip-detail-sidebar {
+ display: grid;
+ align-content: start;
+ gap: 14px;
+}
+
+.auto-clip-detail-sidebar .auto-clip-scores {
+ margin: 0;
+}
+
.auto-clip-detail-result[data-orientation="portrait"] .auto-clip-player {
- width: min(260px, 100%);
+ width: min(320px, 100%);
margin: 0 auto;
aspect-ratio: 9 / 16;
}
@@ -11150,21 +11786,39 @@
grid-template-columns: minmax(0, 1fr);
}
+ .auto-clip-setting-section > header {
+ display: grid;
+ justify-content: stretch;
+ gap: 3px;
+ }
+
+ .auto-clip-detail-layout {
+ grid-template-columns: minmax(0, 1fr);
+ }
+
+ .auto-clip-detail-media {
+ position: static;
+ }
+
+ .auto-clip-subtitle-list {
+ max-height: 320px;
+ }
+
.auto-clip-result-actions {
flex-wrap: wrap;
justify-content: flex-end;
}
.auto-clip-candidate-detailed-list > article {
- grid-template-columns: 24px 112px minmax(0, 1fr);
+ grid-template-columns: 112px minmax(0, 1fr);
}
.auto-clip-candidate-detailed-list[data-orientation="landscape"] > article {
- grid-template-columns: 24px 160px minmax(0, 1fr);
+ grid-template-columns: 160px minmax(0, 1fr);
}
.auto-clip-list-actions {
- grid-column: 3;
+ grid-column: 2;
flex-direction: row;
justify-content: flex-start;
}
@@ -11220,14 +11874,14 @@
@container video-translation-workspace (max-width: 480px) {
.auto-clip-candidate-detailed-list > article {
- grid-template-columns: 24px minmax(0, 1fr);
+ grid-template-columns: minmax(0, 1fr);
align-items: start;
}
.auto-clip-list-preview,
.auto-clip-list-content,
.auto-clip-list-actions {
- grid-column: 2;
+ grid-column: 1;
}
.auto-clip-list-preview {
diff --git a/apps/web/src/features/projects/ProjectsPage.tsx b/apps/web/src/features/projects/ProjectsPage.tsx
index b52979a2..fc6a3d43 100644
--- a/apps/web/src/features/projects/ProjectsPage.tsx
+++ b/apps/web/src/features/projects/ProjectsPage.tsx
@@ -527,7 +527,6 @@ function creatorDraftDefaults(templateId: string): Record<string, unknown[]> {
duration: ['30-60'],
clipCount: [10],
aspectRatio: ['9:16'],
- selectedCandidateIds: [[]],
currentStage: [null]
};
}
diff --git a/runtime/krillinai/internal/pipeline/subtitle.go b/runtime/krillinai/internal/pipeline/subtitle.go
index a7ca4375..72c3efa3 100644
--- a/runtime/krillinai/internal/pipeline/subtitle.go
+++ b/runtime/krillinai/internal/pipeline/subtitle.go
@@ -74,6 +74,7 @@ func GenerateSubtitles(ctx context.Context, svc StageService, req SubtitleReques
_, err = svc.ProcessYouTubeSubtitle(ctx, youtubeReq)
}
if err == nil {
+ manifest.OriginLanguage = youtubeReq.OriginLanguage
manifest.CaptionSource = "youtube_vtt"
if !req.SourceOnly || req.PrepareVideo {
reportSubtitleProgress(req, "preparing_original_media", 76, "正在补齐原始视频")
@@ -113,6 +114,13 @@ func GenerateSubtitles(ctx context.Context, svc StageService, req SubtitleReques
stepParam.TaskPtr.SetProgressReporter(audioSubtitleProgressReporter(req))
reportSubtitleProgress(req, "transcribing_audio", 30, "正在转录并翻译音频字幕")
if err := svc.GenerateSubtitlesFromAudio(ctx, stepParam); err != nil {
+ if platformCaptionErr != nil {
+ err = fmt.Errorf(
+ "platform caption attempt failed: %v; audio transcription fallback failed: %w",
+ platformCaptionErr,
+ err,
+ )
+ }
return failSubtitleStage(req, manifest, ErrorKindRetryable, "audio_transcription_failed", err)
}
manifest.CaptionSource = string(CaptionSourceWhisper)
diff --git a/runtime/krillinai/internal/pipeline/subtitle_test.go b/runtime/krillinai/internal/pipeline/subtitle_test.go
index 1f83d855..462d9ba7 100644
--- a/runtime/krillinai/internal/pipeline/subtitle_test.go
+++ b/runtime/krillinai/internal/pipeline/subtitle_test.go
@@ -9,6 +9,7 @@ import (
pkgimage "krillin-ai/pkg/image"
"os"
"path/filepath"
+ "strings"
"testing"
)
@@ -27,6 +28,7 @@ type fakeStageService struct {
preparedVideoPath string
preparedAudioPath string
audioProgress []uint8
+ audioErr error
omitPreparedVideo bool
}
@@ -57,7 +59,7 @@ func (f *fakeStageService) GenerateSubtitlesFromAudio(_ context.Context, p *type
for _, percent := range f.audioProgress {
p.TaskPtr.SetProgress(percent)
}
- return nil
+ return f.audioErr
}
func (f *fakeStageService) GenerateSpeechFromSRT(_ context.Context, p *types.SubtitleTaskStepParam) error {
@@ -129,6 +131,33 @@ func TestGenerateSubtitlesFallsBackToAudioWhenAnySourceFails(t *testing.T) {
}
}
+func TestGenerateSubtitlesPreservesPlatformAndAudioFallbackErrors(t *testing.T) {
+ fake := &fakeStageService{
+ downloadErr: errors.New("no original YouTube captions"),
+ audioErr: errors.New("whisperkit-cli exited with status 64"),
+ }
+ req := SubtitleRequest{
+ Input: "https://www.youtube.com/watch?v=abc",
+ Workdir: t.TempDir(),
+ TaskID: "demo",
+ OriginLang: "auto",
+ TargetLang: "zh_cn",
+ CaptionSource: CaptionSourceAny,
+ }
+
+ resp, err := GenerateSubtitles(context.Background(), fake, req)
+ if err == nil {
+ t.Fatal("GenerateSubtitles() error = nil, want fallback error")
+ }
+ if !strings.Contains(err.Error(), "no original YouTube captions") ||
+ !strings.Contains(err.Error(), "whisperkit-cli exited with status 64") {
+ t.Fatalf("GenerateSubtitles() error = %q, want both failure reasons", err)
+ }
+ if resp.Error == nil || resp.Error.Code != "audio_transcription_failed" {
+ t.Fatalf("response error = %+v", resp.Error)
+ }
+}
+
func TestGenerateSubtitlesPassesSubtitleStyleToStepParam(t *testing.T) {
dir := t.TempDir()
fake := &fakeStageService{}
diff --git a/runtime/krillinai/internal/storage/bin.go b/runtime/krillinai/internal/storage/bin.go
index a205a456..2599e73a 100644
--- a/runtime/krillinai/internal/storage/bin.go
+++ b/runtime/krillinai/internal/storage/bin.go
@@ -1,6 +1,9 @@
package storage
-import "os/exec"
+import (
+ "context"
+ "os/exec"
+)
var (
FfmpegPath string
@@ -19,3 +22,8 @@ func YtdlpCommand(args ...string) *exec.Cmd {
commandArgs := append(append([]string{}, YtdlpPrefixArgs...), args...)
return exec.Command(YtdlpPath, commandArgs...)
}
+
+func YtdlpCommandContext(ctx context.Context, args ...string) *exec.Cmd {
+ commandArgs := append(append([]string{}, YtdlpPrefixArgs...), args...)
+ return exec.CommandContext(ctx, YtdlpPath, commandArgs...)
+}
diff --git a/runtime/krillinai/pkg/util/language.go b/runtime/krillinai/pkg/util/language.go
index c95bef77..e489a711 100644
--- a/runtime/krillinai/pkg/util/language.go
+++ b/runtime/krillinai/pkg/util/language.go
@@ -1,5 +1,7 @@
package util
+import "strings"
+
// 将内部语言代码映射为YouTube字幕语言代码
func MapLanguageForYouTube(language string) string {
languageMap := map[string]string{
@@ -104,3 +106,25 @@ func MapLanguageForYouTube(language string) string {
return language
}
+
+// MapLanguageFromYouTube converts YouTube/BCP-47 subtitle track identifiers
+// back to the compact language codes used by KrillinAI.
+func MapLanguageFromYouTube(language string) string {
+ normalized := strings.ToLower(strings.TrimSpace(language))
+ normalized = strings.TrimSuffix(normalized, "-orig")
+ normalized = strings.ReplaceAll(normalized, "_", "-")
+
+ switch normalized {
+ case "zh-hant", "zh-tw", "zh-hk", "zh-mo":
+ return "zh_tw"
+ case "zh", "zh-hans", "zh-cn", "zh-sg":
+ return "zh_cn"
+ case "iw":
+ return "he"
+ }
+
+ if separator := strings.IndexByte(normalized, '-'); separator >= 0 {
+ return normalized[:separator]
+ }
+ return normalized
+}
diff --git a/runtime/krillinai/pkg/whisperkit/transcription.go b/runtime/krillinai/pkg/whisperkit/transcription.go
index 94b1472a..fbde04c4 100644
--- a/runtime/krillinai/pkg/whisperkit/transcription.go
+++ b/runtime/krillinai/pkg/whisperkit/transcription.go
@@ -3,6 +3,7 @@ package whisperkit
import (
"bytes"
"encoding/json"
+ "fmt"
"krillin-ai/internal/storage"
"krillin-ai/internal/types"
"krillin-ai/log"
@@ -25,21 +26,7 @@ func (c *WhisperKitProcessor) TranscriptionWithProgress(
audioFile, language, workDir string,
reportProgress func(percent int),
) (*types.TranscriptionData, error) {
- cmdArgs := []string{
- "transcribe",
- "--model-path", "./models/whisperkit/openai_whisper-large-v2",
- "--audio-encoder-compute-units", "all",
- "--text-decoder-compute-units", "all",
- "--language", language,
- "--report",
- "--report-path", workDir,
- "--word-timestamps",
- "--skip-special-tokens",
- "--audio-path", audioFile,
- }
- if reportProgress != nil {
- cmdArgs = append(cmdArgs, "--verbose")
- }
+ cmdArgs := whisperKitCommandArguments(audioFile, language, workDir, reportProgress != nil)
cmd := exec.Command(storage.WhisperKitPath, cmdArgs...)
log.GetLogger().Info("WhisperKitProcessor转录开始", zap.String("cmd", cmd.String()))
output := newProgressOutput(reportProgress)
@@ -48,7 +35,7 @@ func (c *WhisperKitProcessor) TranscriptionWithProgress(
err := cmd.Run()
if err != nil {
log.GetLogger().Error("WhisperKitProcessor cmd 执行失败", zap.String("output", output.String()), zap.Error(err))
- return nil, err
+ return nil, whisperKitCommandError(err, output.String())
}
log.GetLogger().Info("WhisperKitProcessor转录json生成完毕", zap.String("audio file", audioFile))
@@ -66,8 +53,10 @@ func (c *WhisperKitProcessor) TranscriptionWithProgress(
}
var (
- transcriptionData types.TranscriptionData
- num int
+ transcriptionData = types.TranscriptionData{
+ Language: util.MapLanguageFromYouTube(result.Language),
+ }
+ num int
)
for _, segment := range result.Segments {
transcriptionData.Text += strings.ReplaceAll(segment.Text, "—", " ") // 连字符处理,因为模型存在很多错误添加到连字符
@@ -106,6 +95,39 @@ func (c *WhisperKitProcessor) TranscriptionWithProgress(
return &transcriptionData, nil
}
+func whisperKitCommandArguments(audioFile, language, workDir string, verbose bool) []string {
+ cmdArgs := []string{
+ "transcribe",
+ "--model-path", "./models/whisperkit/openai_whisper-large-v2",
+ "--audio-encoder-compute-units", "all",
+ "--text-decoder-compute-units", "all",
+ "--report",
+ "--report-path", workDir,
+ "--word-timestamps",
+ "--skip-special-tokens",
+ "--audio-path", audioFile,
+ }
+ if normalizedLanguage := strings.TrimSpace(language); normalizedLanguage != "" && !strings.EqualFold(normalizedLanguage, "auto") {
+ cmdArgs = append(cmdArgs, "--language", normalizedLanguage)
+ }
+ if verbose {
+ cmdArgs = append(cmdArgs, "--verbose")
+ }
+ return cmdArgs
+}
+
+func whisperKitCommandError(err error, output string) error {
+ details := strings.Join(strings.Fields(output), " ")
+ const maxDetailsLength = 1000
+ if len(details) > maxDetailsLength {
+ details = details[len(details)-maxDetailsLength:]
+ }
+ if details == "" {
+ return fmt.Errorf("whisperkit-cli transcribe failed: %w", err)
+ }
+ return fmt.Errorf("whisperkit-cli transcribe failed: %w: %s", err, details)
+}
+
var whisperKitProgressPattern = regexp.MustCompile(`\]\s*([0-9]{1,3})%\s*\|`)
type progressOutput struct {
diff --git a/runtime/krillinai/pkg/whisperkit/transcription_test.go b/runtime/krillinai/pkg/whisperkit/transcription_test.go
index 8171e0b2..2a4c8516 100644
--- a/runtime/krillinai/pkg/whisperkit/transcription_test.go
+++ b/runtime/krillinai/pkg/whisperkit/transcription_test.go
@@ -1,10 +1,33 @@
package whisperkit
import (
+ "errors"
"fmt"
+ "slices"
+ "strings"
"testing"
)
+func TestWhisperKitCommandArgumentsOmitAutoLanguage(t *testing.T) {
+ args := whisperKitCommandArguments("audio.wav", "auto", t.TempDir(), false)
+ if slices.Contains(args, "--language") || slices.Contains(args, "auto") {
+ t.Fatalf("command args = %v, auto detection must omit --language", args)
+ }
+
+ explicitArgs := whisperKitCommandArguments("audio.wav", "en", t.TempDir(), false)
+ languageIndex := slices.Index(explicitArgs, "--language")
+ if languageIndex < 0 || languageIndex+1 >= len(explicitArgs) || explicitArgs[languageIndex+1] != "en" {
+ t.Fatalf("command args = %v, want --language en", explicitArgs)
+ }
+}
+
+func TestWhisperKitCommandErrorIncludesCapturedOutput(t *testing.T) {
+ err := whisperKitCommandError(errors.New("exit status 64"), "Error: Invalid language code \"auto\"\n")
+ if !strings.Contains(err.Error(), "exit status 64") || !strings.Contains(err.Error(), "Invalid language code") {
+ t.Fatalf("error = %q, want exit status and command output", err)
+ }
+}
+
func TestProgressOutputReportsMonotonicFragmentedPercentages(t *testing.T) {
var reported []int
output := newProgressOutput(func(percent int) {