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.

Merge subtitle style consistency fix into master

Leggett7bda6252d643
diff --cc apps/daemon/src/api/routes.creator.ts
index 648ca89d,5658a761..f7139793
--- a/apps/daemon/src/api/routes.creator.ts
+++ b/apps/daemon/src/api/routes.creator.ts
@@@ -111,11 -109,40 +113,42 @@@ export async function registerCreatorRo
stageRunner?: Pick<CreatorStageRunner, 'cancel' | 'cancelJob'>;
presets?: CreatorPresetRegistry;
presetCatalogRoot?: string;
+ readServicesConfig?(): Promise<CreatorServicesConfig>;
+ codexImageRuntime?: CodexNativeImageRuntime;
issueService?: CreatorIssueService;
+ subtitlePreviewService?: SubtitlePreviewService;
}
): Promise<void> {
+ server.get('/creator/subtitle-preview', async (request, reply) => {
+ try {
+ const query = readObject(request.query);
+ const input = z.object({
+ width: z.number().int().min(32).max(1920),
+ height: z.number().int().min(32).max(1920),
+ subtitleStyle: creatorSubtitleStyleSchema,
+ bilingual: z.boolean(),
+ subtitlePosition: z.enum(['top', 'bottom']),
+ translationText: z.string().min(1).max(128).regex(/^[^\r\n{}\\]+$/u),
+ originalText: z.string().min(1).max(128).regex(/^[^\r\n{}\\]+$/u)
+ }).strict().parse(JSON.parse(readString(query.options, 'options')));
+ if (options.subtitlePreviewService === undefined) {
+ return reply.code(503).send(apiError('creator_subtitle_style_unsupported', 'Subtitle renderer is unavailable'));
+ }
+ const controller = new AbortController();
+ const cancel = () => { if (!reply.raw.writableEnded) controller.abort(); };
+ reply.raw.once('close', cancel);
+ try {
+ const png = await options.subtitlePreviewService.render(input, controller.signal);
+ return reply.type('image/png').header('Cache-Control', 'no-store').send(png);
+ } finally {
+ reply.raw.removeListener('close', cancel);
+ }
+ } catch (error) {
+ if (error instanceof SyntaxError) return reply.code(400).send(apiError('VALIDATION_FAILED', 'Invalid preview options'));
+ if (error instanceof ZodError || error instanceof TypeError) return sendCreatorError(reply, error);
+ return reply.code(503).send(apiError('creator_subtitle_style_unsupported', error instanceof Error ? error.message : 'Subtitle preview failed'));
+ }
+ });
if (options.stickmanVisualAssets !== undefined) {
server.get('/creator/visual-assets', async (request, reply) => {
try {
diff --cc apps/daemon/src/api/server.ts
index 9fd839bc,78656470..b8a0917b
--- a/apps/daemon/src/api/server.ts
+++ b/apps/daemon/src/api/server.ts
@@@ -1575,10 -1461,14 +1576,16 @@@ export async function buildServer(input
stageRunner: creatorStageRunner,
presets: creatorPresetRegistry,
presetCatalogRoot: creatorPresetCatalogRoot,
+ readServicesConfig: () => creatorServicesConfigStore.read(),
+ codexImageRuntime,
preflight: creatorPreflight,
- issueService: creatorIssueService
+ issueService: creatorIssueService,
+ subtitlePreviewService: createSubtitlePreviewService({
+ resourceRoot: creatorRuntimeRoot,
+ workRoot: join(creatorJobsRoot, '.previews'),
+ ensureRuntimeReady: () => ensureKrillinRuntimeReady(),
+ getYtDlpRuntime: () => getCreatorYtDlpRuntime?.()
+ })
});
await registerAttachmentRoutes(server, attachmentService, {
maxSizeBytes: input.attachmentMaxSizeBytes
diff --cc apps/daemon/test/unit/creator-krillin-cli-protocol.test.ts
index c0a2ff10,454b7586..9dea8ef1
--- a/apps/daemon/test/unit/creator-krillin-cli-protocol.test.ts
+++ b/apps/daemon/test/unit/creator-krillin-cli-protocol.test.ts
@@@ -10,13 -10,37 +10,41 @@@ import
resolveKrillinCliSource
} from '../../src/creator/krillin/cli-runner.js';
import { createKrillinConfigToml } from '../../src/creator/krillin/config-bridge.js';
-import { buildKrillinStageOptions } from '../../src/creator/krillin/adapter.js';
+import { buildKrillinStageOptions, normalizeKrillinFailure } from '../../src/creator/krillin/adapter.js';
describe('KrillinAI CLI protocol', () => {
+ it.each(['audio_no_speech', 'audio_transcription_empty', 'audio_transcription_invalid_response', 'audio_transcription_timestamps_missing', 'audio_transcription_api_failed'])('preserves %s through usage-error normalization', code => {
+ const message = 'OpenAI transcription response was classified by the runtime';
+ expect(normalizeKrillinFailure({ code, kind: 'usage', message })).toEqual({ code, message });
+ });
+ it.each(['top', 'bottom'])('passes semantic subtitle ordering to the render command with translation on %s', subtitlePosition => {
+ const stage = { job: { templateId: 'video-translation', state: { bilingual: true, subtitlePosition } }, stageRun: { stageId: 'render-horizontal', id: 'render' }, workdir: '/job/render' };
+ const args = buildKrillinCliCommandArguments(stage as never, [
+ { id: 'source', kind: 'source_video', path: '/job/video.mp4' },
+ { id: 'target', kind: 'target_subtitle', path: '/job/target.srt' },
+ { id: 'bilingual', kind: 'bilingual_subtitle', path: '/job/bilingual.srt' }
+ ], buildKrillinStageOptions(stage as never), '/job/style.json');
+ expect(args[args.indexOf('--line-mode') + 1]).toBe(`bilingual-target-${subtitlePosition}`);
+ expect(args).toContain('--subtitle-style-file');
+ });
+
+ it('passes saved legacy styles instead of silently using runtime defaults', () => {
+ const stage = { job: { templateId: 'video-translation', state: { subtitleFont: 'rounded', subtitleSize: 'large', subtitleColor: '#123456', subtitleShadowOffsetX: -4, subtitleShadowOffsetY: 6, subtitleShadowBlur: 2 } }, stageRun: { stageId: 'render-horizontal' } };
+ expect(buildKrillinStageOptions(stage as never).subtitleStyle).toMatchObject({ horizontal: { major: { font_name: 'OpenCreator Rounded Bold', font_size: 18, primary_color: '#123456', override_tags: '\\xshad-4\\yshad6\\blur2' } } });
+ });
+
+ it.each([true, false])('keeps edited vertical subtitles and renders the requested bilingual=%s mode', bilingual => {
+ const stage = { job: { templateId: 'video-translation', state: { bilingual, subtitlePosition: 'bottom' } }, stageRun: { stageId: 'render-vertical', id: 'render' }, workdir: '/job/render' };
+ const args = buildKrillinCliCommandArguments(stage as never, [
+ { id: 'source', kind: 'source_video', path: '/job/video.mp4' },
+ { id: 'target', kind: 'target_subtitle', path: '/job/target.srt' },
+ { id: 'vertical', kind: 'vertical_subtitle', path: '/job/edited-vertical.srt' }
+ ], buildKrillinStageOptions(stage as never), undefined);
+ expect(args[args.indexOf('--subtitle') + 1]).toBe('/job/edited-vertical.srt');
+ expect(args[args.indexOf('--mixed-target-subtitle') + 1]).toBe('/job/target.srt');
+ expect(args[args.indexOf('--line-mode') + 1]).toBe('bilingual-target-bottom');
+ expect(args.includes('--target-only')).toBe(!bilingual);
+ });
it.each([true, false])('never prepares video in the translation subtitle stage, even when composeVideo=%s', composeVideo => {
const stage = { job: { templateId: 'video-translation', state: { sourceUrl: 'https://youtu.be/demo', sourceLanguage: 'en', targetLanguage: 'zh_cn', composeVideo } }, stageRun: { stageId: 'subtitle', id: 'stage' }, workdir: '/job/stage' };
const options = buildKrillinStageOptions(stage as never);
diff --cc apps/web/e2e/video-translation-style-preview.spec.ts
index b9d93e9d,33bc391e..656c9a6e
--- a/apps/web/e2e/video-translation-style-preview.spec.ts
+++ b/apps/web/e2e/video-translation-style-preview.spec.ts
@@@ -68,9 -90,15 +92,12 @@@ test('字幕样式预览显示视频封
return container !== null && element.getBoundingClientRect().width <= container.getBoundingClientRect().width;
})).toBe(true);
- await page.getByRole('button', { name: '继续' }).click();
- await page.getByRole('switch', { name: '合成字幕视频' }).click();
- await page.getByRole('radio', { name: /9:16/ }).click();
- await page.getByRole('navigation', { name: '翻译流程' }).getByRole('button', { name: /字幕样式$/ }).click();
+ await page.getByRole('combobox', { name: '输出画幅' }).selectOption('vertical');
await expect(preview).toHaveAttribute('data-ratio', '9:16');
await expect(preview).toHaveAttribute('data-converted', 'true');
+ await expect(subtitles).toBeVisible();
+ await expect.poll(() => subtitles.evaluate(element => (element as HTMLImageElement).naturalWidth)).toBe(540);
+ await expect.poll(() => subtitles.evaluate(element => (element as HTMLImageElement).naturalHeight)).toBe(960);
const verticalBox = await frame.boundingBox();
expect(verticalBox).not.toBeNull();
expect(verticalBox!.width / verticalBox!.height).toBeCloseTo(9 / 16, 1);
diff --cc apps/web/src/features/dashboard/VideoTranslationWorkspace.control.test.tsx
index 9d649a74,32521384..821db1d7
--- a/apps/web/src/features/dashboard/VideoTranslationWorkspace.control.test.tsx
+++ b/apps/web/src/features/dashboard/VideoTranslationWorkspace.control.test.tsx
@@@ -395,33 -267,6 +395,40 @@@ describe('VideoTranslationWorkspace tas
expect(screen.getByRole('button', { name: '#7EE7FF' })).toHaveAttribute('aria-pressed', 'true');
});
- it('validates HEX colors, updates the preview, and closes the palette with Escape or an outside click', () => {
++ it('validates HEX colors, updates the preview, and closes the palette with Escape or an outside click', async () => {
++ const openSubtitlePreview = vi.fn(() => new Promise<Response>(() => {}));
+ render(<LanguageProvider initialPreference="zh-CN">
+ <CreatorSessionProvider initialJob={job({ status: 'draft', revision: 0, stages: [], state: {
+ currentStep: 2, furthestStep: 2, composeVideo: true
- } })} service={{ applyAction: vi.fn(), runAgentTurn: vi.fn() } as never}>
++ } })} service={{ applyAction: vi.fn(), runAgentTurn: vi.fn(), openSubtitlePreview } as never}>
+ <VideoTranslationWorkspace onBack={vi.fn()} />
+ </CreatorSessionProvider>
+ </LanguageProvider>);
+ const trigger = screen.getByRole('button', { name: '选择译文颜色' });
+ expect(screen.queryByRole('dialog', { name: '译文颜色色板' })).not.toBeInTheDocument();
+ fireEvent.click(trigger);
+ const hex = screen.getByRole('textbox', { name: '译文颜色 HEX' });
- const frame = screen.getByRole('region', { name: '字幕样式预览' }).querySelector(':scope > div');
++ await waitFor(() => expect(openSubtitlePreview).toHaveBeenCalledWith(
++ expect.objectContaining({ subtitleStyle: expect.objectContaining({ primaryColor: '#FFFFFF' }) }),
++ expect.objectContaining({ signal: expect.any(AbortSignal) })
++ ));
+ fireEvent.change(hex, { target: { value: '#12' } });
- expect(frame).toHaveStyle({ '--subtitle-preview-color': '#FFFFFF' });
++ expect(trigger).toHaveTextContent('#FFFFFF');
+ fireEvent.change(hex, { target: { value: '123abc' } });
- expect(frame).toHaveStyle({ '--subtitle-preview-color': '#123ABC' });
++ await waitFor(() => expect(openSubtitlePreview).toHaveBeenLastCalledWith(
++ expect.objectContaining({ subtitleStyle: expect.objectContaining({ primaryColor: '#123ABC' }) }),
++ expect.objectContaining({ signal: expect.any(AbortSignal) })
++ ));
+ expect(trigger).toHaveTextContent('#123ABC');
+ fireEvent.keyDown(hex, { key: 'Escape' });
+ expect(trigger).toHaveFocus();
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
+ fireEvent.click(trigger);
+ expect(screen.getByRole('textbox', { name: '译文颜色 HEX' })).toHaveValue('#123ABC');
+ fireEvent.pointerDown(screen.getByRole('combobox', { name: '输出画幅' }));
+ expect(screen.queryByRole('dialog', { name: '译文颜色色板' })).not.toBeInTheDocument();
+ });
+
it('uses the same preset and custom color controls for original, outline, and shadow', () => {
render(
<LanguageProvider initialPreference="zh-CN">
diff --cc apps/web/src/features/dashboard/VideoTranslationWorkspace.tsx
index 2f6cba90,41e39beb..d18cd60d
--- a/apps/web/src/features/dashboard/VideoTranslationWorkspace.tsx
+++ b/apps/web/src/features/dashboard/VideoTranslationWorkspace.tsx
@@@ -3428,317 -3189,324 +3418,326 @@@ export default function VideoTranslatio
) : null}
{workspacePhase === 'configure' && currentStep === 2 ? (
- <section className="video-translation-step-panel video-translation-subtitle-style" aria-labelledby="subtitle-style-title">
- <div className="video-translation-step-heading">
- <h2 id="subtitle-style-title">{l('设置字幕样式', 'Set subtitle style')}</h2>
- <p>{l('调整字幕字体、大小和颜色,并实时预览显示效果', 'Choose the subtitle font, size, and color with a live preview')}</p>
- </div>
-
- <div className="video-translation-subtitle-style-layout">
- <div className="video-translation-subtitle-controls">
- <label className="video-translation-field">
- <span>{l('字幕字体', 'Subtitle font')}</span>
- <div className="video-translation-select-wrap">
- <select
- aria-label={l('字幕字体', 'Subtitle font')}
- value={subtitleFont}
- onChange={event => setSubtitleFont(event.target.value as SubtitleFont)}
- >
- <option value="system">{l('系统默认', 'System default')}</option>
- <option value="sans">{l('无衬线', 'Sans serif')}</option>
- <option value="serif">{l('衬线', 'Serif')}</option>
- <option value="rounded">{l('圆体', 'Rounded')}</option>
- </select>
- <ChevronDown size={15} strokeWidth={1.8} aria-hidden="true" />
- </div>
- </label>
-
- <div className="video-translation-style-control">
- <span>{l('字重', 'Font weight')}</span>
- <div className="video-translation-size-options" role="radiogroup" aria-label={l('字幕字重', 'Subtitle font weight')}>
- {(['regular', 'medium', 'bold'] as const).map(weight => (
- <button
- type="button"
- role="radio"
- aria-checked={subtitleWeight === weight}
- key={weight}
- onClick={() => setSubtitleWeight(weight)}
- >
- {subtitleWeightLabel(weight, l)}
- </button>
- ))}
- </div>
- </div>
-
- <div className="video-translation-style-control">
- <span>{l('字幕大小', 'Subtitle size')}</span>
- <div className="video-translation-size-options" role="radiogroup" aria-label={l('字幕大小', 'Subtitle size')}>
- {(['small', 'medium', 'large'] as const).map(size => (
- <button
- type="button"
- role="radio"
- aria-checked={subtitleSize === size}
- key={size}
- onClick={() => setSubtitleSize(size)}
- >
- {subtitleSizeLabel(size, l)}
- </button>
- ))}
- </div>
- </div>
+ <div className="video-translation-output-settings">
+ <section className="video-translation-step-panel video-translation-subtitle-style" aria-labelledby="subtitle-style-title">
+ <div className="video-translation-step-heading">
+ <h2 id="subtitle-style-title">{l('视频与字幕', 'Video & subtitles')}</h2>
+ </div>
- <SubtitleColorControl
- label={l('译文颜色', 'Translation color')}
- inputLabel={l('自定义译文颜色', 'Custom translation color')}
- customLabel={l('自定义', 'Custom')}
- value={subtitleColor}
- onChange={setSubtitleColor}
- />
-
- <SubtitleColorControl
- label={l('原文颜色', 'Original color')}
- inputLabel={l('原文颜色', 'Original color')}
- customLabel={l('自定义', 'Custom')}
- value={subtitleSecondaryColor}
- onChange={setSubtitleSecondaryColor}
- prefixPresetLabel
- />
-
- <div className="video-translation-outline-fields">
- <SubtitleColorControl
- label={l('描边颜色', 'Outline color')}
- inputLabel={l('描边颜色', 'Outline color')}
- customLabel={l('自定义', 'Custom')}
- value={subtitleOutlineColor}
- onChange={setSubtitleOutlineColor}
- prefixPresetLabel
+ <div className="video-translation-option-block" data-agent-focus={agentFocus === 'output'}>
+ <div className="video-translation-option-title">
+ <span className="video-translation-option-icon"><MonitorPlay size={17} strokeWidth={1.8} /></span>
+ <Switch
+ checked={composeVideo}
+ label={l('合成字幕视频', 'Render subtitled video')}
+ description={l('将字幕直接嵌入成片', 'Embed subtitles directly in the final video')}
+ onChange={setComposeVideo}
/>
+ </div>
+ </div>
+ {composeVideo ? (
+ <div className="video-translation-output-format-settings">
<label className="video-translation-field">
- <span>{l('描边宽度', 'Outline width')}</span>
- <input
- type="number"
- min="0"
- max="8"
- step="0.5"
- value={subtitleOutlineWidth}
- onChange={event => setSubtitleOutlineWidth(Number(event.target.value))}
- />
+ <span>{l('输出画幅', 'Output format')}</span>
+ <div className="video-translation-select-wrap">
+ <select
+ aria-label={l('输出画幅', 'Output format')}
+ value={videoFormat}
+ onChange={event => setVideoFormat(event.target.value as VideoFormat)}
+ >
+ {([
+ ['horizontal', '16:9', '横屏'],
+ ['vertical', '9:16', '竖屏'],
+ ['all', '双画幅', '全部']
+ ] as const).map(([value, ratio, label]) => (
+ <option
+ value={value}
+ disabled={sourceOrientation === 'portrait' && value !== 'vertical'}
+ title={sourceOrientation === 'portrait' && value !== 'vertical'
+ ? l('竖屏源视频仅支持竖屏输出', 'Portrait source videos only support portrait output')
+ : undefined}
+ key={value}
+ >
+ {value === 'all' ? l('双画幅', '16:9 + 9:16') : ratio} {localizeFormatLabel(label, l)}
+ </option>
+ ))}
+ </select>
+ <ChevronDown size={15} strokeWidth={1.8} aria-hidden="true" />
+ </div>
</label>
+ {videoFormat === 'vertical' || videoFormat === 'all' ? (
+ <div className="video-translation-title-fields">
+ <label className="video-translation-field">
+ <span>{l('竖屏主标题', 'Vertical video title')} <small>{l('选填', 'Optional')}</small></span>
+ <input value={verticalTitle} onChange={event => setVerticalTitle(event.target.value)} placeholder={l('留空将自动生成', 'Leave blank to generate automatically')} />
+ </label>
+ <label className="video-translation-field">
+ <span>{l('竖屏副标题', 'Vertical video subtitle')} <small>{l('选填', 'Optional')}</small></span>
+ <input value={verticalSubtitle} onChange={event => setVerticalSubtitle(event.target.value)} placeholder={l('留空将自动生成', 'Leave blank to generate automatically')} />
+ </label>
+ </div>
+ ) : null}
</div>
+ ) : null}
- <div className="video-translation-shadow-settings">
- <Switch
- checked={subtitleShadowEnabled}
- label={l('字幕阴影', 'Subtitle shadow')}
- description={l('为字幕增加可控阴影,提高复杂画面上的可读性', 'Add a controlled shadow for readability on detailed footage')}
- onChange={setSubtitleShadowEnabled}
- />
- {subtitleShadowEnabled ? (
- <>
- <SubtitleColorControl
- label={l('阴影颜色', 'Shadow color')}
- inputLabel={l('阴影颜色', 'Shadow color')}
- customLabel={l('自定义', 'Custom')}
- value={subtitleShadowColor}
- onChange={setSubtitleShadowColor}
- prefixPresetLabel
- />
- <div className="video-translation-style-fields">
- <label className="video-translation-field">
- <span>{l('不透明度', 'Opacity')}</span>
- <input
- type="number"
- min="0"
- max="1"
- step="0.05"
- value={subtitleShadowOpacity}
- onChange={event => setSubtitleShadowOpacity(Number(event.target.value))}
+ {composeVideo ? (
+ <>
+ <div className="video-translation-subtitle-style-layout">
+ <div
+ className="video-translation-subtitle-preview"
+ data-ratio={aspectRatioLabel(previewWidth, previewHeight)}
+ data-orientation={previewHeight > previewWidth ? 'portrait' : 'landscape'}
+ data-converted={convertedToVertical}
+ role="region"
+ aria-label={l('字幕样式预览', 'Subtitle style preview')}
+ >
+ <span>{l('字幕样式预览', 'Subtitle style preview')}</span>
+ <div
+ style={{
+ '--subtitle-preview-aspect-ratio': `${previewWidth} / ${previewHeight}`,
- '--subtitle-preview-color': subtitleColor,
- '--subtitle-preview-secondary-color': subtitleSecondaryColor,
- '--subtitle-preview-outline-color': subtitleOutlineColor,
- '--subtitle-preview-outline-width': `${subtitleOutlineWidth}px`,
- '--subtitle-preview-shadow': subtitleShadowEnabled
- ? `${subtitleShadowOffsetX}px ${subtitleShadowOffsetY}px ${subtitleShadowBlur}px color-mix(in srgb, ${subtitleShadowColor} ${Math.round(subtitleShadowOpacity * 100)}%, transparent)`
- : 'none',
- '--subtitle-preview-font-size': ({ small: '14px', medium: '16px', large: '18px' } as const)[subtitleSize],
- '--subtitle-preview-font-family': subtitleFontFamily(subtitleFont, subtitleWeight),
- '--subtitle-preview-font-weight': ({ regular: 400, medium: 500, bold: 700 } as const)[subtitleWeight]
+ } as CSSProperties}
+ >
+ {previewPosterUrl ? (
+ <img
+ className="video-translation-subtitle-preview-media"
+ src={previewPosterUrl}
+ alt=""
+ aria-hidden="true"
+ onError={event => { event.currentTarget.hidden = true; }}
/>
- </label>
+ ) : null}
+ {previewVideoSrc ? (
+ <SubtitlePreviewVideo key={previewVideoSrc} src={previewVideoSrc} onDimensions={updateSourceOrientation} />
+ ) : null}
+ {previewVerticalOutput && (verticalTitle.trim() || verticalSubtitle.trim()) ? (
+ <div className="video-translation-subtitle-preview-titles">
+ {verticalTitle.trim() ? <div data-title-kind="major">{verticalTitle}</div> : null}
+ {verticalSubtitle.trim() ? <div data-title-kind="minor">{verticalSubtitle}</div> : null}
+ </div>
+ ) : null}
- <div className="video-translation-subtitle-preview-cues">
- {bilingual && subtitlePosition === 'bottom' ? (
- <small data-subtitle-kind="original">{l('这是一段原文字幕', 'This is an original subtitle')}</small>
- ) : null}
- <strong data-subtitle-kind="translation">{l('这是一段译文字幕', 'This is a translated subtitle')}</strong>
- {bilingual && subtitlePosition === 'top' ? (
- <small data-subtitle-kind="original">{l('这是一段原文字幕', 'This is an original subtitle')}</small>
- ) : null}
- </div>
++ <VideoTranslationStylePreview
++ render={creatorSession?.openSubtitlePreview}
++ input={{
++ width: Math.max(32, Math.round(960 * previewWidth / Math.max(previewWidth, previewHeight))),
++ height: Math.max(32, Math.round(960 * previewHeight / Math.max(previewWidth, previewHeight))),
++ bilingual,
++ subtitlePosition,
++ translationText: l('这是一段译文字幕', 'This is a translated subtitle'),
++ originalText: l('这是一段原文字幕', 'This is an original subtitle'),
++ subtitleStyle: {
++ fontPreset: subtitleFont,
++ fontWeight: subtitleWeight,
++ fontSize: subtitleSize,
++ primaryColor: subtitleColor,
++ secondaryColor: subtitleSecondaryColor,
++ outlineColor: subtitleOutlineColor,
++ outlineWidth: subtitleOutlineWidth,
++ shadow: {
++ enabled: subtitleShadowEnabled,
++ color: subtitleShadowColor,
++ opacity: subtitleShadowOpacity,
++ offsetX: subtitleShadowOffsetX,
++ offsetY: subtitleShadowOffsetY,
++ blur: subtitleShadowBlur
++ }
++ }
++ }}
++ />
+ </div>
+ </div>
+ <div className="video-translation-subtitle-controls">
+ <h3 className="video-translation-subtitle-style-title">{l('字幕样式', 'Subtitle style')}</h3>
+ <div className="video-translation-typography-fields">
<label className="video-translation-field">
- <span>{l('水平偏移', 'Horizontal offset')}</span>
- <input
- type="number"
- min="-20"
- max="20"
- step="1"
- value={subtitleShadowOffsetX}
- onChange={event => setSubtitleShadowOffsetX(Number(event.target.value))}
- />
+ <span>{l('字幕字体', 'Subtitle font')}</span>
+ <div className="video-translation-select-wrap">
+ <select
+ aria-label={l('字幕字体', 'Subtitle font')}
+ value={subtitleFont}
+ onChange={event => setSubtitleFont(event.target.value as SubtitleFont)}
+ >
+ <option value="system">{l('系统默认', 'System default')}</option>
+ <option value="sans">{l('无衬线', 'Sans serif')}</option>
+ <option value="serif">{l('衬线', 'Serif')}</option>
+ <option value="rounded">{l('圆体', 'Rounded')}</option>
+ </select>
+ <ChevronDown size={15} strokeWidth={1.8} aria-hidden="true" />
+ </div>
</label>
+
<label className="video-translation-field">
- <span>{l('垂直偏移', 'Vertical offset')}</span>
- <input
- type="number"
- min="-20"
- max="20"
- step="1"
- value={subtitleShadowOffsetY}
- onChange={event => setSubtitleShadowOffsetY(Number(event.target.value))}
- />
+ <span>{l('字重', 'Font weight')}</span>
+ <div className="video-translation-select-wrap">
+ <select
+ aria-label={l('字幕字重', 'Subtitle font weight')}
+ value={subtitleWeight}
+ onChange={event => setSubtitleWeight(event.target.value as SubtitleWeight)}
+ >
+ {(['regular', 'medium', 'bold'] as const).map(weight => (
+ <option key={weight} value={weight}>{subtitleWeightLabel(weight, l)}</option>
+ ))}
+ </select>
+ <ChevronDown size={15} strokeWidth={1.8} aria-hidden="true" />
+ </div>
</label>
+
<label className="video-translation-field">
- <span>{l('模糊', 'Blur')}</span>
- <input
- type="number"
- min="0"
- max="10"
- step="0.5"
- value={subtitleShadowBlur}
- onChange={event => setSubtitleShadowBlur(Number(event.target.value))}
- />
+ <span>{l('字幕大小', 'Subtitle size')}</span>
+ <div className="video-translation-select-wrap">
+ <select
+ aria-label={l('字幕大小', 'Subtitle size')}
+ value={subtitleSize}
+ onChange={event => setSubtitleSize(event.target.value as SubtitleSize)}
+ >
+ {(['small', 'medium', 'large'] as const).map(size => (
+ <option key={size} value={size}>{subtitleSizeLabel(size, l)}</option>
+ ))}
+ </select>
+ <ChevronDown size={15} strokeWidth={1.8} aria-hidden="true" />
+ </div>
</label>
</div>
- </>
- ) : null}
- </div>
- </div>
-
- <div
- className="video-translation-subtitle-preview"
- data-ratio={aspectRatioLabel(previewWidth, previewHeight)}
- data-orientation={previewHeight > previewWidth ? 'portrait' : 'landscape'}
- data-converted={convertedToVertical}
- role="region"
- aria-label={l('字幕样式预览', 'Subtitle style preview')}
- >
- <span>{l('字幕样式预览', 'Subtitle style preview')}</span>
- <div
- style={{
- '--subtitle-preview-aspect-ratio': `${previewWidth} / ${previewHeight}`,
- } as CSSProperties}
- >
- {previewPosterUrl ? (
- <img
- className="video-translation-subtitle-preview-media"
- src={previewPosterUrl}
- alt=""
- aria-hidden="true"
- onError={event => { event.currentTarget.hidden = true; }}
- />
- ) : null}
- {previewVideoSrc ? (
- <SubtitlePreviewVideo key={previewVideoSrc} src={previewVideoSrc} onDimensions={updateSourceOrientation} />
- ) : null}
- <VideoTranslationStylePreview
- render={creatorSession?.openSubtitlePreview}
- input={{
- width: Math.max(32, Math.round(960 * previewWidth / Math.max(previewWidth, previewHeight))),
- height: Math.max(32, Math.round(960 * previewHeight / Math.max(previewWidth, previewHeight))),
- bilingual,
- subtitlePosition,
- translationText: l('这是一段译文字幕', 'This is a translated subtitle'),
- originalText: l('这是一段原文字幕', 'This is an original subtitle'),
- subtitleStyle: {
- fontPreset: subtitleFont,
- fontWeight: subtitleWeight,
- fontSize: subtitleSize,
- primaryColor: subtitleColor,
- secondaryColor: subtitleSecondaryColor,
- outlineColor: subtitleOutlineColor,
- outlineWidth: subtitleOutlineWidth,
- shadow: {
- enabled: subtitleShadowEnabled,
- color: subtitleShadowColor,
- opacity: subtitleShadowOpacity,
- offsetX: subtitleShadowOffsetX,
- offsetY: subtitleShadowOffsetY,
- blur: subtitleShadowBlur
- }
- }
- }}
- />
- </div>
- </div>
- </div>
- </section>
- ) : null}
- {workspacePhase === 'configure' && currentStep === 3 ? (
- <div className="video-translation-final-grid">
- <section className="video-translation-step-panel video-translation-final-settings" aria-labelledby="output-settings-title">
- <div className="video-translation-step-heading">
- <h2 id="output-settings-title">{l('选择输出内容', 'Choose output')}</h2>
- <p>{l('按需生成配音和多画幅成片', 'Generate dubbing and videos in the formats you need')}</p>
- </div>
+ <div className="video-translation-style-fields">
+ <SubtitleColorControl
+ label={l('译文颜色', 'Translation color')}
+ value={subtitleColor}
+ onChange={setSubtitleColor}
+ />
+
+ {bilingual ? <SubtitleColorControl
+ label={l('原文颜色', 'Original color')}
+ value={subtitleSecondaryColor}
+ onChange={setSubtitleSecondaryColor}
+ prefixPresetLabel
+ /> : null}
+ </div>
- <div className="video-translation-option-block" data-agent-focus={agentFocus === 'dubbing'}>
- <div className="video-translation-option-title">
- <span className="video-translation-option-icon"><Mic2 size={17} strokeWidth={1.8} /></span>
- <Switch
- checked={dubbing}
- label={l('生成目标语言配音', 'Generate target-language dubbing')}
- description={l('匹配翻译后的语速与停顿', 'Match the translated pacing and pauses')}
- onChange={value => {
- setDubbing(value);
- }}
- />
- </div>
- {dubbing ? (
- <div className="video-translation-option-content">
- <div className="video-translation-voice-source">
- <strong>{ttsProviderLabel(ttsProvider, l)}</strong>
- <small>{ttsModel || l('本地语音服务', 'Local speech service')}</small>
+ <details className="video-translation-advanced-style">
+ <summary>
+ {l('更多样式', 'More styles')}
+ <ChevronDown size={15} strokeWidth={1.8} aria-hidden="true" />
+ </summary>
+ <div className="video-translation-advanced-style-content">
+ <div className="video-translation-outline-fields">
+ <SubtitleColorControl
+ label={l('描边颜色', 'Outline color')}
+ value={subtitleOutlineColor}
+ onChange={setSubtitleOutlineColor}
+ prefixPresetLabel
+ />
+ <label className="video-translation-field">
+ <span>{l('描边宽度', 'Outline width')}</span>
+ <input
+ type="number"
+ min="0"
+ max="8"
+ step="0.5"
+ value={subtitleOutlineWidth}
+ onChange={event => setSubtitleOutlineWidth(Number(event.target.value))}
+ />
+ </label>
+ </div>
+
+ <div className="video-translation-shadow-settings">
+ <Switch
+ checked={subtitleShadowEnabled}
+ label={l('字幕阴影', 'Subtitle shadow')}
+ description={l('为字幕增加可控阴影,提高复杂画面上的可读性', 'Add a controlled shadow for readability on detailed footage')}
+ onChange={setSubtitleShadowEnabled}
+ />
+ {subtitleShadowEnabled ? (
+ <>
+ <SubtitleColorControl
+ label={l('阴影颜色', 'Shadow color')}
+ value={subtitleShadowColor}
+ onChange={setSubtitleShadowColor}
+ prefixPresetLabel
+ />
+ <div className="video-translation-style-fields">
+ <label className="video-translation-field">
+ <span>{l('不透明度', 'Opacity')}</span>
+ <input
+ type="number"
+ min="0"
+ max="1"
+ step="0.05"
+ value={subtitleShadowOpacity}
+ onChange={event => setSubtitleShadowOpacity(Number(event.target.value))}
+ />
+ </label>
+ <label className="video-translation-field">
+ <span>{l('水平偏移', 'Horizontal offset')}</span>
+ <input
+ type="number"
+ min="-20"
+ max="20"
+ step="1"
+ value={subtitleShadowOffsetX}
+ onChange={event => setSubtitleShadowOffsetX(Number(event.target.value))}
+ />
+ </label>
+ <label className="video-translation-field">
+ <span>{l('垂直偏移', 'Vertical offset')}</span>
+ <input
+ type="number"
+ min="-20"
+ max="20"
+ step="1"
+ value={subtitleShadowOffsetY}
+ onChange={event => setSubtitleShadowOffsetY(Number(event.target.value))}
+ />
+ </label>
+ <label className="video-translation-field">
+ <span>{l('模糊', 'Blur')}</span>
+ <input
+ type="number"
+ min="0"
+ max="10"
+ step="0.5"
+ value={subtitleShadowBlur}
+ onChange={event => setSubtitleShadowBlur(Number(event.target.value))}
+ />
+ </label>
+ </div>
+ </>
+ ) : null}
+ </div>
+ </div>
+ </details>
</div>
- <TtsVoicePicker
- id="video-translation-voice"
- provider={ttsProvider}
- model={ttsModel}
- value={voiceCode}
- service={props.creatorServicesService ?? null}
- label={l('配音音色', 'Dubbing voice')}
- onChange={(voiceId, voice) => {
- setVoiceCode(voiceId);
- setVoiceName(voice?.name ?? voiceId);
- }}
- onVoiceResolved={voice => setVoiceName(voice.name)}
- />
</div>
- ) : null}
- </div>
-
- <div className="video-translation-option-block" data-agent-focus={agentFocus === 'output'}>
- <div className="video-translation-option-title">
- <span className="video-translation-option-icon"><MonitorPlay size={17} strokeWidth={1.8} /></span>
- <Switch
- checked={composeVideo}
- label={l('合成字幕视频', 'Render subtitled video')}
- description={l('将字幕直接嵌入成片', 'Embed subtitles directly in the final video')}
- onChange={value => {
- setComposeVideo(value);
- }}
- />
- </div>
- {composeVideo ? (
- <div className="video-translation-option-content">
- <div className="video-translation-format" role="radiogroup" aria-label={l('输出画幅', 'Output format')}>
- {([
- ['horizontal', '16:9', '横屏'],
- ['vertical', '9:16', '竖屏'],
- ['all', '双画幅', '全部']
- ] as const).map(([value, ratio, label]) => (
- <button
- type="button"
- role="radio"
- aria-checked={videoFormat === value}
- disabled={sourceOrientation === 'portrait' && value !== 'vertical'}
- title={sourceOrientation === 'portrait' && value !== 'vertical'
- ? l('竖屏源视频仅支持竖屏输出', 'Portrait source videos only support portrait output')
- : undefined}
- key={value}
- onClick={() => {
- setVideoFormat(value);
- }}
- >
- <span>{value === 'all' ? l('双画幅', '16:9 + 9:16') : ratio}</span>
- <small>{localizeFormatLabel(label, l)}</small>
- {videoFormat === value ? <Check size={14} strokeWidth={2} aria-hidden="true" /> : null}
- </button>
- ))}
+ <div className="video-translation-option-block video-translation-dubbing-settings" data-agent-focus={agentFocus === 'dubbing'}>
+ <div className="video-translation-option-title">
+ <span className="video-translation-option-icon"><Mic2 size={17} strokeWidth={1.8} /></span>
+ <Switch
+ checked={dubbing}
+ label={l('生成目标语言配音', 'Generate target-language dubbing')}
+ description={l('匹配翻译后的语速与停顿', 'Match the translated pacing and pauses')}
+ onChange={value => {
+ setDubbing(value);
+ }}
+ />
</div>
- {videoFormat === 'vertical' || videoFormat === 'all' ? (
- <div className="video-translation-title-fields">
- <label className="video-translation-field">
- <span>{l('竖屏主标题', 'Vertical video title')} <small>{l('选填', 'Optional')}</small></span>
- <input value={verticalTitle} onChange={event => setVerticalTitle(event.target.value)} placeholder={l('留空将自动生成', 'Leave blank to generate automatically')} />
- </label>
- <label className="video-translation-field">
- <span>{l('竖屏副标题', 'Vertical video subtitle')} <small>{l('选填', 'Optional')}</small></span>
- <input value={verticalSubtitle} onChange={event => setVerticalSubtitle(event.target.value)} placeholder={l('留空将自动生成', 'Leave blank to generate automatically')} />
- </label>
+ {dubbing ? (
+ <div className="video-translation-option-content">
+ {officialSpeech.official ? <OfficialModelField label={l('语音合成模型', 'Speech model')} service={officialSpeech} /> : <div className="video-translation-voice-source">
+ <strong>{ttsProviderLabel(ttsProvider, l)}</strong>
+ <small>{ttsModel || l('本地语音服务', 'Local speech service')}</small>
+ </div>}
+ <TtsVoicePicker
+ id="video-translation-voice"
+ provider={ttsProvider}
+ model={ttsModel}
+ value={voiceCode}
+ service={props.creatorServicesService ?? null}
+ label={l('配音音色', 'Dubbing voice')}
+ onChange={(voiceId, voice) => {
+ setVoiceCode(voiceId);
+ setVoiceName(voice?.name ?? voiceId);
+ }}
+ onVoiceResolved={voice => setVoiceName(voice.name)}
+ />
</div>
) : null}
</div>
diff --cc apps/web/src/features/dashboard/dashboard.css
index 28d29958,8dbbfdd4..9da92acf
--- a/apps/web/src/features/dashboard/dashboard.css
+++ b/apps/web/src/features/dashboard/dashboard.css
@@@ -1456,64 -1311,6 +1474,42 @@@
justify-self: center;
}
+.video-translation-subtitle-preview-titles {
+ position: absolute;
+ z-index: 2;
+ inset: 0 0 auto;
+ height: 19.53125%;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ gap: 3px;
+ padding: 0 8px;
+ box-sizing: border-box;
+ overflow: hidden;
+ background: #000;
+ color: #ffff00;
+ font-family: "OpenCreator Sans Bold", system-ui, sans-serif;
+ line-height: 1.2;
+}
+
+.video-translation-subtitle-preview-titles > div {
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ overflow: hidden;
+ overflow-wrap: anywhere;
+}
+
+.video-translation-subtitle-preview-titles [data-title-kind="major"] {
+ font-size: 11px;
+ font-weight: 700;
+}
+
+.video-translation-subtitle-preview-titles [data-title-kind="minor"] {
+ font-size: 9px;
+ font-weight: 400;
+}
+
- .video-translation-subtitle-preview small,
- .video-translation-subtitle-preview strong {
- max-width: 100%;
- line-height: 1.35;
- overflow-wrap: anywhere;
- -webkit-text-stroke: var(--subtitle-preview-outline-width) var(--subtitle-preview-outline-color);
- paint-order: stroke fill;
- text-shadow: var(--subtitle-preview-shadow);
- }
-
- .video-translation-subtitle-preview small {
- color: var(--subtitle-preview-secondary-color);
- font-size: 13px;
- font-weight: var(--subtitle-preview-font-weight);
- }
-
- .video-translation-subtitle-preview strong {
- color: var(--subtitle-preview-color);
- font-size: var(--subtitle-preview-font-size);
- font-weight: var(--subtitle-preview-font-weight);
- }
-
.video-translation-summary {
position: sticky;
top: 24px;