迁移时间线合成页签:片段卡/字幕/混音设置/音轨/版本表;Field 支持 title、新增 FilePick 原语
parent
f382b0113e
commit
733f2e9fe5
|
|
@ -55,12 +55,16 @@ const WIDTHS: Record<FieldWidth, string> = {
|
|||
full: 'basis-full grow shrink'
|
||||
}
|
||||
|
||||
/** 行内标签字段:`<Field label="类型">…</Field>`;stack 场景交给 <FormRow stack> 统一翻向 */
|
||||
export function Field({ label, required, children, width = 'default', className, hint }: {
|
||||
/**
|
||||
* 行内标签字段:`<Field label="类型">…</Field>`;stack 场景交给 <FormRow stack> 统一翻向。
|
||||
* title 挂在外层 label 上:整块(标签 + 控件)都是悬停热区,和旧站 .fld[title] 一致。
|
||||
*/
|
||||
export function Field({ label, required, children, width = 'default', className, hint, title }: {
|
||||
label?: ReactNode; required?: boolean; children: ReactNode; width?: FieldWidth; className?: string; hint?: ReactNode
|
||||
title?: string
|
||||
}) {
|
||||
return (
|
||||
<label className={cn(LABEL, FIELD_INNER, WIDTHS[width], 'min-w-0', className)}>
|
||||
<label title={title} className={cn(LABEL, FIELD_INNER, WIDTHS[width], 'min-w-0', className)}>
|
||||
{label && <span className="flex-none">{label}{required && <Req />}</span>}
|
||||
{children}
|
||||
{hint}
|
||||
|
|
@ -193,3 +197,24 @@ export function Check({ checked, onChange, children, disabled, className, title
|
|||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件选择(.upload):整块标签就是按钮,点哪里都能开文件对话框。
|
||||
*
|
||||
* 旧站把 <input type=file> 塞进 label 里 display:none,外壳用 padding 自己撑高度,
|
||||
* 结果同一行里 chip 31px、上传 26px、按钮 38px 三种高度混在一起;
|
||||
* 这里并进 --ctl-h 体系,容器决定档位,页面不再调 padding。
|
||||
*/
|
||||
export function FilePick({ label, accept, multiple, onFiles, className }: {
|
||||
label: ReactNode; accept?: string; multiple?: boolean; onFiles: (files: File[]) => void; className?: string
|
||||
}) {
|
||||
return (
|
||||
<label className={cn('inline-flex h-(--ctl-h) flex-row items-center justify-center gap-[5px] m-0 cursor-pointer '
|
||||
+ 'rounded-chip border border-line-strong bg-hover px-[9px] text-tiny leading-[1.2] text-ink-2 '
|
||||
+ 'whitespace-nowrap shrink-0 hover:bg-raise hover:text-ink', className)}>
|
||||
{label}
|
||||
<input type="file" className="hidden" accept={accept} multiple={multiple}
|
||||
onChange={(e) => onFiles(Array.from(e.currentTarget.files || []))} />
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,857 @@
|
|||
/** 待迁移:时间线合成(占位,见 .local/vue-ref/src/views/tabs/TimelineTab.vue) */
|
||||
export default function Timeline() {
|
||||
return <div className="p-[26px] text-center text-faint text-body">时间线合成 迁移中…</div>
|
||||
/**
|
||||
* 长视频合成引擎 · 时间线(图1 模块 04 / 图2 节点 ⑫ compose 前置)
|
||||
* 片段裁剪与转场 → 配音/字幕对齐 → 音轨混音 → 响度归一化 → 交付预检
|
||||
*/
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { FocusEvent } from 'react'
|
||||
import * as api from '../../api/client'
|
||||
import { fmtMs, fmtTime, opt, statusLabel } from '../../lib/format'
|
||||
import { normalize, type MediaItem } from '../../lib/media'
|
||||
import { useAutoRefresh } from '../../hooks'
|
||||
import { cn } from '../../lib/cn'
|
||||
import { Select } from '../../components/forms'
|
||||
import { AudioPlay } from '../../components/media/AudioPlay'
|
||||
import { MediaThumb } from '../../components/media/MediaThumb'
|
||||
import { refresh, useProjectStore } from '../../stores/project'
|
||||
import { useSystemStore } from '../../stores/system'
|
||||
import { notify } from '../../stores/notice'
|
||||
import { openPreview } from '../../stores/preview'
|
||||
import {
|
||||
Actions, Between, Button, Check, Chip, ChipBar, Ctlbar, Divider, Empty, ErrorText, ExtLink, Field,
|
||||
FieldBlock, FilePick, FormRow, Grid, IssueRow, Layout, LineHint, MONO, MUTED, MUTED_MONO, Mono, Panel,
|
||||
PanelHead, Row, SectionTitle, Spinner, TabStack, Table, TableBox, Tag, Value, cellCenter, cellRight
|
||||
} from '../../components/ui'
|
||||
|
||||
const SUBTITLE_MODES = [
|
||||
{ value: 'embed', label: '内嵌软字幕轨(播放器可开关,画质无损 · 推荐)' },
|
||||
{ value: 'burn', label: '烧录进画面(硬字幕,任何播放器都看得到)' },
|
||||
{ value: 'both', label: '烧录 + 内嵌(交付最稳,自动开字幕的播放器可能看着像双份)' },
|
||||
{ value: 'sidecar', label: '只出外挂 SRT 文件(成片内无字幕)' },
|
||||
{ value: 'off', label: '不输出字幕' }
|
||||
]
|
||||
const subtitleModeLabel = (m: string) => SUBTITLE_MODES.find((x) => x.value === m)?.label || m || '—'
|
||||
|
||||
/** 编排设置的初值:key 顺序同时是脏值比对的基准(resolveSettings 必须按同一顺序产出) */
|
||||
const SETTING_INIT = {
|
||||
subtitle_mode: 'embed', burn_subtitle: true, voice_gain_db: 0, bgm_gain_db: -17, duck_bgm: true,
|
||||
target_lufs: -16, tail_padding_ms: 350, lead_padding_ms: 160, hold_last_frame: true,
|
||||
sub_size: 0, sub_margin: 0, sub_outline: 0, keep_shot_audio: true, shot_audio_gain_db: -2,
|
||||
voice_source: 'native', native_audio_policy: 'auto'
|
||||
}
|
||||
type SettingValues = typeof SETTING_INIT
|
||||
|
||||
/**
|
||||
* 后端 settings → 表单值(纯函数:加载与「放弃修改」都走它,两处语义不会跑偏)。
|
||||
*/
|
||||
function resolveSettings(s: any): SettingValues {
|
||||
const mode = SUBTITLE_MODES.some((x) => x.value === s?.subtitle_mode)
|
||||
? s.subtitle_mode : (s?.burn_subtitle === false ? 'sidecar' : 'burn')
|
||||
const style = s?.subtitle_style || {}
|
||||
return {
|
||||
...SETTING_INIT,
|
||||
subtitle_mode: mode,
|
||||
burn_subtitle: ['burn', 'both'].includes(mode),
|
||||
voice_gain_db: Number(s?.voice_gain_db ?? 0),
|
||||
bgm_gain_db: Number(s?.bgm_gain_db ?? -17),
|
||||
duck_bgm: s?.duck_bgm !== false,
|
||||
target_lufs: Number(s?.target_lufs ?? -16),
|
||||
tail_padding_ms: Number(s?.tail_padding_ms ?? 350),
|
||||
lead_padding_ms: Number(s?.lead_padding_ms ?? 160),
|
||||
hold_last_frame: s?.hold_last_frame !== false,
|
||||
sub_size: Number(style.size ?? 0),
|
||||
sub_margin: Number(style.margin ?? 0),
|
||||
sub_outline: Number(style.outline ?? 0),
|
||||
// 后端没存过时沿用后端默认(native = 台词由视频模型直出),别让前端把项目拽回「必须 TTS」的旧语义
|
||||
keep_shot_audio: s?.keep_shot_audio !== false,
|
||||
shot_audio_gain_db: Number(s?.shot_audio_gain_db ?? -2),
|
||||
voice_source: ['auto', 'native', 'dub'].includes(s?.voice_source) ? s.voice_source : 'native',
|
||||
native_audio_policy: ['auto', 'dialogue_only', 'off'].includes(s?.native_audio_policy)
|
||||
? s.native_audio_policy : (s?.native_audio_policy || 'auto')
|
||||
}
|
||||
}
|
||||
|
||||
const BUILD_INIT = { name: '', only_approved: true, shot_ids: [] as number[] }
|
||||
const CUE_INIT = {
|
||||
cue_id: null as number | null, shot_id: '', text: '', speaker: '',
|
||||
start_ms: null as number | null, end_ms: null as number | null
|
||||
}
|
||||
const AUDIO_INIT = {
|
||||
kind: 'bgm', label: '', shot_id: '' as string, start_ms: 0, duration_ms: 0, gain_db: 0,
|
||||
loop: true, ducking: false, source_path: '', file: null as File | null
|
||||
}
|
||||
|
||||
/** 音轨类型(后端只认这三个码) */
|
||||
const AUDIO_KINDS = [
|
||||
{ value: 'bgm', label: '背景音乐' },
|
||||
{ value: 'sfx', label: '音效' },
|
||||
{ value: 'voiceover', label: '配音' }
|
||||
]
|
||||
|
||||
/** 字幕 / 音轨行(.subline):定列栅格,窄屏折成一列 */
|
||||
const SUBLINE = 'grid items-center gap-2 border-b border-line-soft py-[7px] text-caption [&>*]:min-w-0'
|
||||
|
||||
/** 数字输入框解析:清空时按 0 处理,避免 Number('') 之外的 NaN 渗进请求体 */
|
||||
const numOf = (v: string) => (v === '' ? 0 : Number(v))
|
||||
|
||||
export default function Timeline() {
|
||||
const projectId = useProjectStore((s) => s.id)
|
||||
const stats = useProjectStore((s) => s.stats)
|
||||
const meta = useSystemStore((s) => s.meta)
|
||||
const health = useSystemStore((s) => s.health)
|
||||
|
||||
const [error, setError] = useState('')
|
||||
const [busy, setBusy] = useState('')
|
||||
const [timeline, setTimeline] = useState<any>(null)
|
||||
const [report, setReport] = useState<any>(null)
|
||||
const [versions, setVersions] = useState<any[]>([])
|
||||
const [shots, setShots] = useState<any[]>([])
|
||||
const [assets, setAssets] = useState<any[]>([])
|
||||
const [viewVersion, setViewVersion] = useState<number | null>(null)
|
||||
const [expanded, setExpanded] = useState<Set<number>>(() => new Set())
|
||||
const [build, setBuild] = useState(BUILD_INIT)
|
||||
const [cue, setCue] = useState(CUE_INIT)
|
||||
const [audio, setAudio] = useState(AUDIO_INIT)
|
||||
const [setting, setSetting] = useState<SettingValues>(SETTING_INIT)
|
||||
/** 已保存设置的快照(用 ref:它变了不该重渲染,重渲染都来自 setting 本身) */
|
||||
const [synced, setSynced] = useState('')
|
||||
|
||||
const segments: any[] = timeline?.segments || []
|
||||
const subtitles: any[] = timeline?.subtitles || []
|
||||
const clips: any[] = timeline?.audio_clips || []
|
||||
const transitions: any[] = (meta as any)?.options?.transition || []
|
||||
const subtitleBurn = (health as any)?.ffmpeg_capabilities?.subtitle_burn !== false
|
||||
const subtitleEmbed = (health as any)?.ffmpeg_capabilities?.subtitle_embed !== false
|
||||
const needsBurn = setting.subtitle_mode === 'burn' || setting.subtitle_mode === 'both'
|
||||
const shotMap = useMemo(() => {
|
||||
const map: Record<number, any> = {}
|
||||
shots.forEach((s) => { map[s.id] = s })
|
||||
return map
|
||||
}, [shots])
|
||||
const buildable = useMemo(() => shots.filter((s: any) => s.output_exists), [shots])
|
||||
const audioAssets = useMemo(
|
||||
() => assets.filter((a: any) => /\.(wav|mp3|m4a|aac|ogg|flac)$/i.test(a.path || a.name || '')),
|
||||
[assets]
|
||||
)
|
||||
// 只有「有台词却没有配音轨」的片段才算缺配音,无台词镜头不该提示补配音
|
||||
const missingVoice = useMemo(() => segments.filter((s: any) => {
|
||||
const shot = shotMap[s.shot_id]
|
||||
if (!(shot?.dialogue || shot?.subtitle_text)) return false
|
||||
return !(timeline?.audio_clips || []).some((c: any) => c.shot_id === s.shot_id && c.kind === 'voiceover')
|
||||
}), [segments, shotMap, timeline])
|
||||
/** 片段缩略图统一走预览层:用对应镜头的关键帧当 poster,避免整排灰块 */
|
||||
const segmentItems = useMemo<MediaItem[]>(() => segments.map((seg: any) => {
|
||||
const shot = shotMap[seg.shot_id]
|
||||
return normalize({
|
||||
url: seg.source_url, kind: 'output', id: `seg-${seg.id}`,
|
||||
name: `${String(seg.order_index).padStart(2, '0')} · ${seg.label || '片段'}`,
|
||||
duration_ms: seg.duration_ms
|
||||
}, { poster: shot?.keyframe_url || '', group: `segment#${seg.id}` })
|
||||
}).filter(Boolean) as MediaItem[], [segments, shotMap])
|
||||
const selectedVersion = versions.find((v: any) => v.id === viewVersion) || null
|
||||
/** 编排设置是本地改完再保存的:改过没保存时暂停自动刷新,否则轮询会把用户刚填的覆盖掉 */
|
||||
const settingsDirty = !!synced && JSON.stringify(setting) !== synced
|
||||
const versionOptions = useMemo(() => [
|
||||
{ value: '', label: '当前时间线' },
|
||||
...versions.map((v: any) => ({
|
||||
value: v.id,
|
||||
label: `v${v.version} · ${v.name}(${v.segments} 段)${v.is_current ? ' · 生效中' : ''}`
|
||||
}))
|
||||
], [versions])
|
||||
const shotOptions = useMemo(() => shots.map((s: any) => ({
|
||||
value: String(s.id), label: `#${s.order_index} ${String(s.title || '').slice(0, 14)}`
|
||||
})), [shots])
|
||||
|
||||
/**
|
||||
* viewVersion 要同步可读:Vue 时代 ref 赋值立刻生效,紧接着的 load() 就能拿到新值;
|
||||
* React 的 setState 是异步的,所以额外留一份 ref,切换版本时两边一起改。
|
||||
*/
|
||||
const viewRef = useRef<number | null>(null)
|
||||
viewRef.current = viewVersion
|
||||
const showVersion = (id: number | null) => { viewRef.current = id; setViewVersion(id) }
|
||||
|
||||
const load = useCallback(async (silent = true, vid?: number | null) => {
|
||||
if (!projectId) return
|
||||
if (!silent) setBusy('读取时间线')
|
||||
const want = vid === undefined ? viewRef.current : vid
|
||||
try {
|
||||
const params = want ? { timeline_id: want } : null
|
||||
// 首次进入时 GET /timeline 会 404(尚未建立时间线),不能让它的失败连带
|
||||
// 拖垮镜头列表——否则「构建时间线」按钮永远没有可选项,页面自锁。
|
||||
const [tl, vers, sh, as] = await Promise.all([
|
||||
api.get(`/api/projects/${projectId}/timeline`, params)
|
||||
.then((d: any) => ({ ok: true as const, data: d, error: null as unknown }))
|
||||
.catch((exc: unknown) => ({ ok: false as const, data: null as any, error: exc })),
|
||||
api.get(`/api/projects/${projectId}/timelines`).catch(() => ({ timelines: [] })),
|
||||
api.get(`/api/projects/${projectId}/shots`).catch(() => ({ shots: [] })),
|
||||
api.get(`/api/projects/${projectId}/assets`).catch(() => ({ assets: [] }))
|
||||
])
|
||||
if (tl.ok) {
|
||||
setTimeline(tl.data.timeline)
|
||||
setReport(tl.data.report)
|
||||
setError('')
|
||||
} else {
|
||||
setTimeline(null)
|
||||
setReport(null)
|
||||
// 「尚未建立时间线」属正常初始状态,其余 404(项目/时间线不存在)仍要提示
|
||||
const msg = String((tl.error as any)?.message || '')
|
||||
setError(/尚未建立时间线/.test(msg) ? '' : msg)
|
||||
}
|
||||
setVersions(vers.timelines || [])
|
||||
setShots(sh.shots || [])
|
||||
setAssets(as.assets || [])
|
||||
if (tl.ok && tl.data.timeline) {
|
||||
const next = resolveSettings(tl.data.timeline.settings || {})
|
||||
setSetting(next)
|
||||
setSynced(JSON.stringify(next))
|
||||
}
|
||||
} catch (exc: any) {
|
||||
setTimeline(null)
|
||||
setReport(null)
|
||||
setError(exc?.message || String(exc))
|
||||
} finally { setBusy('') }
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [projectId])
|
||||
// 挂载拉首屏;load 只依赖 projectId,切项目时重新拉一次
|
||||
useEffect(() => { void load(false) }, [load]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
/** 所有写操作的公共流程:占用忙态 → 提示结果 → 重新拉时间线与项目概览 */
|
||||
async function run(label: string, fn: () => Promise<any>, message?: (res: any) => string) {
|
||||
setBusy(label)
|
||||
setError('')
|
||||
try {
|
||||
const res = await fn()
|
||||
const text = message ? message(res) : ''
|
||||
if (text) notify(text)
|
||||
await Promise.all([load(), refresh()])
|
||||
return res
|
||||
} catch (exc: any) { setError(exc?.message || String(exc)); return null }
|
||||
finally { setBusy('') }
|
||||
}
|
||||
|
||||
/** 构建 / 重建时间线(节点⑫ compose 的第一步:把审核合格片段拼成时间线) */
|
||||
const buildTimeline = () => run('构建时间线', () => api.post(`/api/projects/${projectId}/timeline`, {
|
||||
name: build.name.trim(), only_approved: build.only_approved,
|
||||
shot_ids: build.shot_ids.length ? build.shot_ids : null, settings: {}
|
||||
}), (r) => {
|
||||
const missing = r?.missing_voiceover?.length ?? 0
|
||||
return `时间线 v${r?.version ?? '?'} 已生成:${r?.segments ?? 0} 段 / ${fmtMs(r?.total_duration_ms)}`
|
||||
+ (missing ? `,缺配音 ${missing} 段` : '')
|
||||
})
|
||||
|
||||
async function patchSegment(seg: any, body: any, label = '更新片段') {
|
||||
await run(label, async () => {
|
||||
const res = await api.patch(`/api/projects/${projectId}/timeline/segments/${seg.id}`, body)
|
||||
if (res?.timeline) setTimeline(res.timeline)
|
||||
return res
|
||||
})
|
||||
}
|
||||
|
||||
function toggleSeg(id: number) {
|
||||
setExpanded((cur) => {
|
||||
const next = new Set(cur)
|
||||
if (next.has(id)) next.delete(id)
|
||||
else next.add(id)
|
||||
return next
|
||||
})
|
||||
}
|
||||
const openSegment = (i: number) => openPreview(segmentItems, i)
|
||||
|
||||
/** 片段排序:接口收全量 shot_ids 顺序,所以整表交换两位再提交 */
|
||||
async function move(idx: number, delta: number) {
|
||||
const ids = segments.map((s: any) => s.shot_id)
|
||||
const to = idx + delta
|
||||
if (to < 0 || to >= ids.length) return
|
||||
const copy = ids.slice()
|
||||
const tmp = copy[idx]
|
||||
copy[idx] = copy[to]
|
||||
copy[to] = tmp
|
||||
await run('调整片段顺序', () => api.post(`/api/projects/${projectId}/timeline/reorder`, { shot_ids: copy }))
|
||||
}
|
||||
|
||||
/** 字幕:点「编辑」回填表单,cue_id 决定这是改_existing 还是新增 */
|
||||
function editSubtitle(c: any) {
|
||||
setCue({
|
||||
cue_id: c.id, shot_id: c.shot_id ? String(c.shot_id) : '', text: c.text,
|
||||
speaker: c.speaker || '', start_ms: c.start_ms, end_ms: c.end_ms
|
||||
})
|
||||
}
|
||||
const saveSubtitle = () => run('保存字幕', () => api.post(`/api/projects/${projectId}/timeline/subtitles`, {
|
||||
cue_id: cue.cue_id,
|
||||
shot_id: cue.shot_id ? Number(cue.shot_id) : null, text: cue.text,
|
||||
speaker: cue.speaker, start_ms: cue.start_ms, end_ms: cue.end_ms
|
||||
}), () => (cue.cue_id ? '字幕已更新' : (cue.text.trim() ? '字幕已新增' : '字幕已删除')))
|
||||
|
||||
const addAudio = () => run('追加音轨', () => {
|
||||
const form = api.formData({
|
||||
kind: audio.kind, label: audio.label, start_ms: audio.start_ms, duration_ms: audio.duration_ms,
|
||||
gain_db: audio.gain_db, loop: audio.loop, ducking: audio.ducking,
|
||||
shot_id: audio.shot_id ? Number(audio.shot_id) : null, source_path: audio.source_path
|
||||
}, audio.file)
|
||||
return api.upload(`/api/projects/${projectId}/timeline/audio`, form)
|
||||
}, () => '音轨已追加到时间线')
|
||||
|
||||
function useAsset(path: string) {
|
||||
setAudio((f) => ({ ...f, source_path: path, label: f.label || path.split('/').pop() || '' }))
|
||||
}
|
||||
|
||||
/** 时间线设置(字幕烧录 / 响度 / 留白) */
|
||||
const saveSettings = () => run('保存时间线设置', async () => {
|
||||
const res = await api.patch(`/api/projects/${projectId}/timeline/settings`, {
|
||||
settings: {
|
||||
subtitle_mode: setting.subtitle_mode,
|
||||
burn_subtitle: ['burn', 'both'].includes(setting.subtitle_mode),
|
||||
voice_gain_db: setting.voice_gain_db,
|
||||
bgm_gain_db: setting.bgm_gain_db, duck_bgm: setting.duck_bgm, target_lufs: setting.target_lufs,
|
||||
tail_padding_ms: setting.tail_padding_ms, lead_padding_ms: setting.lead_padding_ms,
|
||||
hold_last_frame: setting.hold_last_frame,
|
||||
keep_shot_audio: setting.keep_shot_audio, shot_audio_gain_db: setting.shot_audio_gain_db,
|
||||
voice_source: setting.voice_source,
|
||||
native_audio_policy: setting.native_audio_policy,
|
||||
subtitle_style: { size: setting.sub_size, margin: setting.sub_margin, outline: setting.sub_outline }
|
||||
}
|
||||
})
|
||||
if (res?.timeline) setTimeline(res.timeline)
|
||||
return res
|
||||
}, () => '设置已保存并重排时间线')
|
||||
|
||||
const makeVoiceover = () => run('补齐配音任务', () => api.post(`/api/projects/${projectId}/voiceover`, {
|
||||
shot_ids: null, only_missing: true, priority: 4
|
||||
}), (r) => `已创建 ${r?.count ?? 0} 条配音任务,请回到调度中心派发`)
|
||||
|
||||
/** 版本管理:把历史版本设为当前(导出、预检、审核默认都走当前版本) */
|
||||
async function activateVersion() {
|
||||
if (!viewVersion) { notify('请先在左侧下拉里选择一个历史版本'); return }
|
||||
const row = selectedVersion
|
||||
if (row?.is_current) { notify(`v${row.version} 已经是当前时间线`); return }
|
||||
await run('设为当前', () => api.post(`/api/projects/${projectId}/timelines/${viewVersion}/activate`),
|
||||
(r) => `已切换到 v${r?.version}「${r?.name || row?.name || ''}」,导出与预检默认走这一版`)
|
||||
}
|
||||
|
||||
/** 版本管理:删除历史版本(只删编排记录,成片与镜头产物保留) */
|
||||
async function removeVersion() {
|
||||
if (!viewVersion) { notify('请先在左侧下拉里选择一个历史版本'); return }
|
||||
const row = selectedVersion
|
||||
if (versions.length <= 1) { notify('只剩一个时间线版本,不能删除;可先构建新版本'); return }
|
||||
const label = row ? `v${row.version}「${row.name}」` : `#${viewVersion}`
|
||||
if (!window.confirm(`删除时间线版本 ${label}?
|
||||
只删除编排记录(片段/字幕/音轨),已导出的成片与镜头产物不受影响。`)) return
|
||||
const id = viewVersion
|
||||
await run('删除版本', () => api.del(`/api/projects/${projectId}/timelines/${id}`), (r) => {
|
||||
const back = r?.current_version ? `,已自动切换到 v${r.current_version}` : ''
|
||||
showVersion(null)
|
||||
return `已删除 ${label}${back}`
|
||||
})
|
||||
}
|
||||
|
||||
async function activateOne(row: any) {
|
||||
await run('设为当前', () => api.post(`/api/projects/${projectId}/timelines/${row.id}/activate`),
|
||||
() => `已切换到 v${row.version}「${row.name}」,导出与预检默认走这一版`)
|
||||
}
|
||||
async function removeOne(row: any) {
|
||||
if (versions.length < 2) { notify('至少保留一个时间线版本'); return }
|
||||
if (!window.confirm(`删除时间线版本 v${row.version}「${row.name}」?\n只删除编排记录(片段/字幕/音轨),已导出成片与镜头产物不受影响。`)) return
|
||||
await run('删除版本', () => api.del(`/api/projects/${projectId}/timelines/${row.id}`), (r) => {
|
||||
if (viewVersion === row.id) showVersion(null)
|
||||
const back = r?.current_version ? `,已自动切换到 v${r.current_version}` : ''
|
||||
return `已删除 v${row.version}${back}`
|
||||
})
|
||||
}
|
||||
|
||||
function toggleBuildShot(id: number) {
|
||||
setBuild((f) => ({
|
||||
...f,
|
||||
shot_ids: f.shot_ids.includes(id) ? f.shot_ids.filter((x) => x !== id) : [...f.shot_ids, id]
|
||||
}))
|
||||
}
|
||||
function selectAllBuildable() {
|
||||
setBuild((f) => ({
|
||||
...f,
|
||||
shot_ids: f.shot_ids.length === buildable.length ? [] : buildable.map((s: any) => s.id)
|
||||
}))
|
||||
}
|
||||
|
||||
/* 时间线会随配音/生成任务自己变长,20 秒补一次;用户正在改编排设置时不抢手感 */
|
||||
useAutoRefresh(() => { void load() }, 20000, !!busy, !!busy || settingsDirty)
|
||||
|
||||
const patchBuild = (p: Partial<typeof BUILD_INIT>) => setBuild((f) => ({ ...f, ...p }))
|
||||
const patchCue = (p: Partial<typeof CUE_INIT>) => setCue((f) => ({ ...f, ...p }))
|
||||
const patchAudio = (p: Partial<typeof AUDIO_INIT>) => setAudio((f) => ({ ...f, ...p }))
|
||||
const patchSetting = (p: Partial<SettingValues>) => setSetting((f) => ({ ...f, ...p }))
|
||||
|
||||
return (
|
||||
<TabStack>
|
||||
<Between className="mb-3">
|
||||
{timeline ? (
|
||||
<Row>
|
||||
<b>{timeline.name}</b>
|
||||
<Tag tone="info">v{timeline.version}{timeline.is_current ? ' · 当前' : ' · 历史版本'}</Tag>
|
||||
<Chip as="span">{segments.length} 段</Chip>
|
||||
<Chip as="span">总时长 {fmtMs(timeline.total_duration_ms)}</Chip>
|
||||
<Chip as="span">{timeline.width}×{timeline.height} @{timeline.fps}</Chip>
|
||||
<Chip as="span">字幕 {subtitles.length}</Chip>
|
||||
<Chip as="span">音轨 {clips.length}</Chip>
|
||||
{report && <Tag tone={report.ready ? 'ok' : 'bad'}>{report.ready ? '可导出' : '存在阻塞'}</Tag>}
|
||||
</Row>
|
||||
) : <Row><span className={MUTED}>尚未构建时间线</span></Row>}
|
||||
<Row tight>
|
||||
<SectionTitle className="mt-0 mb-0">时间线版本 {versions.length}</SectionTitle>
|
||||
<Select size="sm" ariaLabel="选择时间线版本" className="w-[210px] shrink-0"
|
||||
value={viewVersion ?? ''}
|
||||
onChange={(next: any) => {
|
||||
const id = next === '' || next === null || next === undefined ? null : Number(next)
|
||||
showVersion(id)
|
||||
void load(false, id)
|
||||
}}
|
||||
options={versionOptions} />
|
||||
<Button variant="outline" size="sm" disabled={!!busy || !viewVersion} onClick={activateVersion}
|
||||
title={viewVersion ? '把下拉中选中的版本设为当前生效版本' : '先在左侧下拉中选择一个历史版本'}>
|
||||
★ 设为当前
|
||||
</Button>
|
||||
<Button variant="del" disabled={!!busy || !viewVersion || versions.length < 2} onClick={removeVersion}
|
||||
title={versions.length < 2 ? '至少保留一个时间线版本' : '删除选中的版本(仅删编排记录,不动成片)'}>
|
||||
✕ 删除版本
|
||||
</Button>
|
||||
{busy ? <span className={MUTED}><Spinner /> {busy}…</span> : null}
|
||||
</Row>
|
||||
</Between>
|
||||
<ErrorText className="mb-3">{error}</ErrorText>
|
||||
|
||||
{/* ===== 构建 / 报告 ===== */}
|
||||
<Grid cols={2} gap={12} oneAt="narrow">
|
||||
<Panel>
|
||||
<PanelHead eyebrow="PIPELINE · 时间线合成" title="构建时间线" />
|
||||
<Ctlbar>
|
||||
<Field label="时间线名称" width="grow">
|
||||
<input value={build.name} placeholder="留空使用「主时间线」"
|
||||
onChange={(e) => patchBuild({ name: e.target.value })} />
|
||||
</Field>
|
||||
<Check checked={build.only_approved} onChange={(v) => patchBuild({ only_approved: v })}
|
||||
title="不勾选任何镜头时按「仅合格」或全部有产物镜头自动编排。">
|
||||
仅收录审核合格的镜头
|
||||
</Check>
|
||||
</Ctlbar>
|
||||
<ChipBar>
|
||||
<Chip as="span">有产物镜头 {buildable.length}</Chip>
|
||||
<Chip as="span">已审核合格 {stats?.shots_approved ?? 0}</Chip>
|
||||
<Button variant="outline" size="sm" onClick={selectAllBuildable}>
|
||||
{build.shot_ids.length === buildable.length ? '清空指定' : '指定全部镜头'}
|
||||
</Button>
|
||||
</ChipBar>
|
||||
<ChipBar>
|
||||
{buildable.map((s: any) => (
|
||||
<Chip key={s.id} active={build.shot_ids.includes(s.id)} onClick={() => toggleBuildShot(s.id)}>
|
||||
#{s.order_index} {String(s.title || '').slice(0, 10)}
|
||||
</Chip>
|
||||
))}
|
||||
</ChipBar>
|
||||
<Actions>
|
||||
<Button variant="primary" disabled={!!busy || !buildable.length} onClick={buildTimeline}>≡ 构建 / 重建时间线</Button>
|
||||
<Button variant="secondary" disabled={!!busy || !missingVoice.length} onClick={makeVoiceover}>
|
||||
🔊 补齐缺失配音({missingVoice.length})
|
||||
</Button>
|
||||
</Actions>
|
||||
{!buildable.length && <LineHint className="mt-[10px]">先在调度中心生成镜头产物,才能构建时间线。</LineHint>}
|
||||
</Panel>
|
||||
|
||||
<Panel>
|
||||
<PanelHead eyebrow="DELIVERY PREFLIGHT" title="交付预检报告"
|
||||
right={report ? <Tag tone={report.ready ? 'ok' : 'bad'}>{report.ready ? 'READY' : 'BLOCKED'}</Tag> : undefined} />
|
||||
{!report && <Empty>构建时间线后生成报告。</Empty>}
|
||||
{report && (
|
||||
<>
|
||||
<ChipBar>
|
||||
<Chip as="span">片段 {report.segments}</Chip>
|
||||
<Chip as="span">字幕 {report.subtitles}</Chip>
|
||||
<Chip as="span">配音 {report.voice_clips}</Chip>
|
||||
<Chip as="span">BGM {report.bgm_clips}</Chip>
|
||||
<Chip as="span">总时长 {fmtMs(report.total_duration_ms)}</Chip>
|
||||
<Chip as="span">字幕 {subtitleModeLabel(report.subtitle_mode || (report.burn_subtitle ? 'burn' : 'sidecar'))}</Chip>
|
||||
</ChipBar>
|
||||
<Divider />
|
||||
{!report.issues?.length
|
||||
? <Value>✔ 没有阻塞项,可直接前往「导出与成本」出片。</Value>
|
||||
: (
|
||||
<div className="max-h-[190px] overflow-auto scrollbar-slim">
|
||||
{(report.issues || []).map((x: any, i: number) => (
|
||||
<IssueRow key={i} level={x.level}>
|
||||
<Tag tone={x.level === 'error' ? 'bad' : (x.level === 'warning' ? 'warn' : 'default')}>
|
||||
{statusLabel(x.level)}
|
||||
</Tag>
|
||||
<span>{x.message}</span>
|
||||
{x.segment_id ? <Mono className="text-faint">segment#{x.segment_id}</Mono> : null}
|
||||
{x.clip_id ? <Mono className="text-faint">clip#{x.clip_id}</Mono> : null}
|
||||
</IssueRow>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{!subtitleBurn && needsBurn ? (
|
||||
<LineHint className="mt-2">
|
||||
<span>⚠ 本机 ffmpeg 缺 libass(无 subtitles/ass 滤镜),烧录会自动降级为「内嵌软字幕轨」。安装完整版构建后把 FFMPEG_BIN 指向它即可,例如</span>
|
||||
<Mono>brew install ffmpeg-full</Mono>
|
||||
<span>或 ~/.local/ffmpeg/bin/ffmpeg。</span>
|
||||
</LineHint>
|
||||
) : !subtitleEmbed ? (
|
||||
<LineHint className="mt-2">⚠ 本机 ffmpeg 不支持内嵌字幕(mov_text),内嵌模式会降级为外挂 SRT。</LineHint>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</Panel>
|
||||
</Grid>
|
||||
|
||||
{/* ===== 片段编辑 ===== */}
|
||||
<Panel>
|
||||
<PanelHead eyebrow="SEGMENTS"
|
||||
title={<span title="拖不动时用左右箭头调整顺序;改动即时重算时间轴">片段与转场</span>} />
|
||||
{!segments.length && <Empty>还没有片段,先在上方构建时间线。</Empty>}
|
||||
{segments.map((seg: any, i: number) => (
|
||||
<SegmentRow key={seg.id} seg={seg} i={i} count={segments.length}
|
||||
item={segmentItems[i]} queue={segmentItems} shot={shotMap[seg.shot_id]}
|
||||
transitions={transitions} busy={!!busy} open={expanded.has(seg.id)}
|
||||
onToggle={() => toggleSeg(seg.id)} onMove={move} onOpen={() => openSegment(i)}
|
||||
onPatch={patchSegment} />
|
||||
))}
|
||||
</Panel>
|
||||
|
||||
<Layout>
|
||||
{/* ===== 字幕 ===== */}
|
||||
<Panel>
|
||||
<PanelHead eyebrow="SUBTITLES"
|
||||
title={<span title="点「编辑」后按字幕条目精确定位,改时间不会新增重复行;镜头只有一条字幕时人工文案会写回镜头,不会被自动组装覆盖。改动片段时长/顺序后,字幕时间会按配音时长重新对齐。">字幕</span>}
|
||||
right={subtitles.length ? (
|
||||
<Row>
|
||||
<ExtLink href={api.href(`/api/projects/${projectId}/timeline/subtitles`, { fmt: 'srt' })}>下载 SRT ↗</ExtLink>
|
||||
<ExtLink href={api.href(`/api/projects/${projectId}/timeline/subtitles`, { fmt: 'ass' })}>下载 ASS ↗</ExtLink>
|
||||
</Row>
|
||||
) : undefined} />
|
||||
{!subtitles.length && <Empty>时间线还没有字幕(镜头未填写台词/字幕文本)。</Empty>}
|
||||
{subtitles.map((c: any) => (
|
||||
<div key={c.id} className={cn(SUBLINE, 'grid-cols-[130px_minmax(0,1fr)_100px_auto] max-narrow:grid-cols-1')}>
|
||||
<Mono className={MUTED}>{fmtMs(c.start_ms)} – {fmtMs(c.end_ms)}</Mono>
|
||||
<span>{c.text}{c.speaker ? <span className={MUTED}> — {c.speaker}</span> : null}</span>
|
||||
<Mono className={MUTED}>{c.shot_id ? `shot#${c.shot_id}` : '全局'}</Mono>
|
||||
<Button variant="outline" size="sm" onClick={() => editSubtitle(c)}>编辑</Button>
|
||||
</div>
|
||||
))}
|
||||
<Divider />
|
||||
<FormRow>
|
||||
<Field label="所属镜头">
|
||||
<Select ariaLabel="字幕所属镜头" value={cue.shot_id} onChange={(v: any) => patchCue({ shot_id: v ?? '' })}
|
||||
options={[{ value: '', label: '(全局字幕)' }, ...shotOptions]} />
|
||||
</Field>
|
||||
<Field label="说话人">
|
||||
<input value={cue.speaker} placeholder="角色名,可留空" onChange={(e) => patchCue({ speaker: e.target.value })} />
|
||||
</Field>
|
||||
<Field label="起始 ms">
|
||||
<input type="number" min={0} step={50} value={cue.start_ms ?? ''}
|
||||
onChange={(e) => patchCue({ start_ms: e.target.value === '' ? null : Number(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="结束 ms">
|
||||
<input type="number" min={0} step={50} value={cue.end_ms ?? ''}
|
||||
onChange={(e) => patchCue({ end_ms: e.target.value === '' ? null : Number(e.target.value) })} />
|
||||
</Field>
|
||||
</FormRow>
|
||||
<FieldBlock label="字幕文本">
|
||||
<textarea rows={2} value={cue.text} placeholder={cue.cue_id ? '留空表示删除这条字幕' : '留空表示删除该镜头字幕'}
|
||||
onChange={(e) => patchCue({ text: e.target.value })} />
|
||||
</FieldBlock>
|
||||
<Actions>
|
||||
<Button variant="primary" size="sm" disabled={!!busy || !timeline} onClick={saveSubtitle}>保存字幕</Button>
|
||||
<Button variant="outline" size="sm"
|
||||
onClick={() => setCue({ ...CUE_INIT })}>
|
||||
{cue.cue_id ? `✕ 取消编辑 #${cue.cue_id}` : '清空表单(新增字幕)'}
|
||||
</Button>
|
||||
</Actions>
|
||||
</Panel>
|
||||
|
||||
{/* ===== 时间线设置 ===== */}
|
||||
<Panel>
|
||||
<PanelHead eyebrow="RENDER SETTINGS"
|
||||
title={<span title="「台词语音来源」改动会自动重排时间线:用原声的镜头按画面长度排布,字幕同步改为按片段窗口对齐;设置只作用于当前时间线,出片预设在「导出与成本」页选择。">混音与字幕设置</span>} />
|
||||
<FormRow>
|
||||
<Check checked={setting.duck_bgm} onChange={(v) => patchSetting({ duck_bgm: v })} className="self-center">
|
||||
配音时自动压低 BGM
|
||||
</Check>
|
||||
<Field label="字幕方式" title="内嵌=成片里一条可开关的字幕轨;烧录=字幕直接画进画面">
|
||||
<Select ariaLabel="字幕方式" value={setting.subtitle_mode}
|
||||
onChange={(v: any) => patchSetting({ subtitle_mode: v })} options={SUBTITLE_MODES} />
|
||||
</Field>
|
||||
<Check checked={setting.hold_last_frame} onChange={(v) => patchSetting({ hold_last_frame: v })} className="self-center">
|
||||
尾帧补足(避免时长不足)
|
||||
</Check>
|
||||
<Field label="台词语音来源"
|
||||
title="MiniMax H3 是原生音画同步模型:人声对着口型生成,零错位。默认「模型原声直出」,并且生成时平台会把角色声线的克隆样本当作参考音频(ref_audios)一起喂给模型,原声就是这个角色自己的嗓子,不再是模型随机挑的陌生人。TTS 是在画面之外另起一条音轨,长度与停顿和画面无关,正是「张嘴却静音 / 闭嘴还在说」的成因;只有产物确实没有音轨时才回退配音。">
|
||||
<Select ariaLabel="台词语音来源" value={setting.voice_source}
|
||||
onChange={(v: any) => patchSetting({ voice_source: v })}
|
||||
options={[
|
||||
{ value: 'native', label: '模型原声直出(口型同步 + 角色声线做参考 · 推荐,不生成 TTS)' },
|
||||
{ value: 'auto', label: '自动(台词优先原声,缺原声的镜头回退配音)' },
|
||||
{ value: 'dub', label: '始终用平台配音(音色可控,口型不保证)' }
|
||||
]} />
|
||||
</Field>
|
||||
<Field label="模型原声策略"
|
||||
title={'联合音视频模型(H3)没人说话时会自己加戏:把提示词念一遍、或凭空来一段旁白。\n· 全保留:模型给的声音都留下(有台词镜头的口型同步只能靠它)\n· 仅保留有台词镜头:无台词镜头的原声整段静音,只留平台音效/环境声/BGM\n· 全部静音:只信平台配音轨'}>
|
||||
<Select ariaLabel="模型原声策略" value={setting.native_audio_policy}
|
||||
onChange={(v: any) => patchSetting({ native_audio_policy: v })}
|
||||
options={[
|
||||
{ value: 'auto', label: '全保留(默认)' },
|
||||
{ value: 'dialogue_only', label: '仅保留有台词的镜头(无台词镜头原声静音)' },
|
||||
{ value: 'off', label: '全部静音(只用平台配音)' }
|
||||
]} />
|
||||
</Field>
|
||||
<Check checked={setting.keep_shot_audio} onChange={(v) => patchSetting({ keep_shot_audio: v })} className="self-center"
|
||||
title="台词走模型原声时必须勾选:镜头产物自带的就是那条人声/音效/环境声轨,关掉等于把它剪掉。切到「平台配音」时建议取消勾选,否则原声人声会和配音叠成双声">
|
||||
保留镜头自带音轨(模型原生音画同步)
|
||||
</Check>
|
||||
<Field label="原生音轨增益 dB">
|
||||
<input type="number" step={0.5} disabled={!setting.keep_shot_audio} value={setting.shot_audio_gain_db}
|
||||
onChange={(e) => patchSetting({ shot_audio_gain_db: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="配音增益 dB">
|
||||
<input type="number" step={0.5} value={setting.voice_gain_db}
|
||||
onChange={(e) => patchSetting({ voice_gain_db: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="BGM 增益 dB">
|
||||
<input type="number" step={0.5} value={setting.bgm_gain_db}
|
||||
onChange={(e) => patchSetting({ bgm_gain_db: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="目标响度 LUFS">
|
||||
<input type="number" step={0.5} value={setting.target_lufs}
|
||||
onChange={(e) => patchSetting({ target_lufs: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="片头留白 ms">
|
||||
<input type="number" step={10} value={setting.lead_padding_ms}
|
||||
onChange={(e) => patchSetting({ lead_padding_ms: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="片尾留白 ms">
|
||||
<input type="number" step={10} value={setting.tail_padding_ms}
|
||||
onChange={(e) => patchSetting({ tail_padding_ms: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="字幕字号(0=自动)">
|
||||
<input type="number" min={0} value={setting.sub_size}
|
||||
onChange={(e) => patchSetting({ sub_size: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="字幕下边距(0=自动)">
|
||||
<input type="number" min={0} value={setting.sub_margin}
|
||||
onChange={(e) => patchSetting({ sub_margin: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="字幕描边(0=自动)">
|
||||
<input type="number" min={0} value={setting.sub_outline}
|
||||
onChange={(e) => patchSetting({ sub_outline: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
</FormRow>
|
||||
<Actions>
|
||||
<Button variant="primary" size="sm" disabled={!!busy || !timeline} onClick={saveSettings}>保存并重排</Button>
|
||||
</Actions>
|
||||
</Panel>
|
||||
</Layout>
|
||||
|
||||
{/* ===== 音轨 ===== */}
|
||||
<Panel>
|
||||
<PanelHead eyebrow="AUDIO TRACKS" title="音轨(配音 / BGM / 音效)"
|
||||
right={<>
|
||||
<Value>共 {clips.length} 条</Value>
|
||||
{/* 旧站这颗按钮漏了 @click,点了没反应;配音表单就在同一页下方,直接接上 addAudio */}
|
||||
<Button variant="add" disabled={!!busy || !timeline} onClick={addAudio}
|
||||
title="导出时按 lead/tail padding 与配音时长对齐字幕;缺配音会用视频原声并给出提醒。">+ 追加音轨</Button>
|
||||
</>} />
|
||||
{!clips.length && <Empty>暂无音轨。配音由「补齐缺失配音」生成,BGM 可在下方上传。</Empty>}
|
||||
{clips.map((c: any) => (
|
||||
<div key={c.id} className={cn(SUBLINE, 'grid-cols-[120px_minmax(0,1fr)_210px_auto] max-narrow:grid-cols-1')}>
|
||||
<Mono className={MUTED}>{fmtMs(c.start_ms)} · {fmtMs(c.duration_ms)}</Mono>
|
||||
<span>
|
||||
{c.label || c.kind}
|
||||
<Tag tone={c.kind === 'voiceover' ? 'info' : 'default'} className="ml-1">{statusLabel(c.kind)}</Tag>
|
||||
{c.ducking ? <span className={MUTED}> · 触发压低</span> : null}
|
||||
{c.loop ? <span className={MUTED}> · 循环</span> : null}
|
||||
{c.text ? <div className={MUTED}>{c.text}</div> : null}
|
||||
</span>
|
||||
<AudioPlay src={c.source_url} label={c.label || c.kind} durationMs={c.duration_ms}
|
||||
hint={`${fmtMs(c.start_ms)} 起`} size="sm" />
|
||||
<Mono className={MUTED}>{c.gain_db} dB</Mono>
|
||||
</div>
|
||||
))}
|
||||
<Divider />
|
||||
<FormRow>
|
||||
<Field label="类型">
|
||||
<Select ariaLabel="音轨类型" value={audio.kind} onChange={(v: any) => patchAudio({ kind: v })} options={AUDIO_KINDS} />
|
||||
</Field>
|
||||
<Field label="标签">
|
||||
<input value={audio.label} placeholder="例如:主旋律 BGM" onChange={(e) => patchAudio({ label: e.target.value })} />
|
||||
</Field>
|
||||
<Field label="对齐镜头">
|
||||
<Select ariaLabel="音轨对齐镜头" value={audio.shot_id} onChange={(v: any) => patchAudio({ shot_id: v ?? '' })}
|
||||
options={[{ value: '', label: '(不绑定)' }, ...shotOptions]} />
|
||||
</Field>
|
||||
<Field label="起始 ms">
|
||||
<input type="number" min={0} step={50} value={audio.start_ms}
|
||||
onChange={(e) => patchAudio({ start_ms: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="时长 ms(0=自动)">
|
||||
<input type="number" min={0} step={50} value={audio.duration_ms}
|
||||
onChange={(e) => patchAudio({ duration_ms: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Field label="增益 dB">
|
||||
<input type="number" step={0.5} value={audio.gain_db}
|
||||
onChange={(e) => patchAudio({ gain_db: numOf(e.target.value) })} />
|
||||
</Field>
|
||||
<Check checked={audio.loop} onChange={(v) => patchAudio({ loop: v })} className="self-center">循环铺满</Check>
|
||||
<Check checked={audio.ducking} onChange={(v) => patchAudio({ ducking: v })} className="self-center">压低 BGM</Check>
|
||||
</FormRow>
|
||||
<Row tight>
|
||||
<FilePick label="🎵 选择音频文件" accept="audio/*"
|
||||
onFiles={(files) => patchAudio({ file: files[0] ?? null })} />
|
||||
{audio.file
|
||||
? <Chip as="span" active>{audio.file.name}</Chip>
|
||||
: <span className={MUTED}>或直接引用已有素材:</span>}
|
||||
{audioAssets.map((a: any) => (
|
||||
<Chip key={a.id} active={audio.source_path === a.path} onClick={() => useAsset(a.path)}>{a.name}</Chip>
|
||||
))}
|
||||
</Row>
|
||||
<FormRow className="mt-3">
|
||||
<Field label="素材路径(可留空,或直接点上方已有素材)">
|
||||
<input value={audio.source_path} placeholder="media 相对路径,如 5/bgm/timeline-bgm_xxx.mp3"
|
||||
onChange={(e) => patchAudio({ source_path: e.target.value })} />
|
||||
</Field>
|
||||
</FormRow>
|
||||
</Panel>
|
||||
|
||||
{/* ===== 版本 ===== */}
|
||||
{!!versions.length && (
|
||||
<Panel>
|
||||
<PanelHead eyebrow="VERSIONS" title="时间线版本"
|
||||
right={<span className={MUTED}>最近编辑 {fmtTime(versions[0]?.updated_at)}</span>} />
|
||||
<TableBox maxHeight={220}>
|
||||
<Table className="[&_tbody_tr[data-chosen]>td]:bg-accent-tint-2">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className={cellCenter}>版本</th><th>名称</th>
|
||||
<th className={cellRight}>片段</th><th className={cellRight}>时长</th>
|
||||
<th className={cellCenter}>状态</th><th>更新时间</th><th className={cellRight}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{versions.map((v: any) => (
|
||||
<tr key={v.id} data-chosen={v.is_current || undefined}>
|
||||
<td className={cn(cellCenter, MONO)}>v{v.version}</td>
|
||||
<td>{v.name}</td>
|
||||
<td className={cn(cellRight, MONO)}>{v.segments}</td>
|
||||
<td className={cn(cellRight, MONO)}>{fmtMs(v.total_duration_ms)}</td>
|
||||
<td className={cellCenter}>
|
||||
<Tag tone={v.is_current ? 'ok' : 'default'}>{v.is_current ? '当前生效' : '历史版本'}</Tag>
|
||||
</td>
|
||||
<td className={MUTED_MONO}>{fmtTime(v.updated_at)}</td>
|
||||
<td className={cellRight}>
|
||||
<Row tight className="justify-end">
|
||||
<Button variant="ghost" size="sm" onClick={() => { showVersion(v.id); void load(false, v.id) }}>查看</Button>
|
||||
<Button variant="ghost" size="sm" disabled={!!busy || v.is_current} onClick={() => activateOne(v)}>设为当前</Button>
|
||||
<Button variant="del" disabled={!!busy || versions.length < 2} onClick={() => removeOne(v)}>删除</Button>
|
||||
</Row>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</TableBox>
|
||||
</Panel>
|
||||
)}
|
||||
</TabStack>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 片段卡(.seg):序号 + 缩略图 + 一行元信息,展开后是 6 列密集参数栅格。
|
||||
*
|
||||
* 参数走「失焦提交」而不是逐字符 PATCH:片段一改后端就重算整条时间轴,
|
||||
* 边打字边保存会把没输完的中间值(空串、负号)写进库。
|
||||
* 输入框因此是非受控的,key 带上后端回来的值:
|
||||
* 后端把 5000ms 钳成 8000ms 时 key 变了、重挂一次,用户才看得见真实结果;
|
||||
* 值没变时不重挂,正在输入的半个数字不会被轮询冲掉。
|
||||
*/
|
||||
function SegmentRow({ seg, i, count, item, queue, shot, transitions, busy, open, onToggle, onMove, onOpen, onPatch }: {
|
||||
seg: any; i: number; count: number; item: MediaItem | null; queue: MediaItem[]
|
||||
shot: any; transitions: any[]; busy: boolean; open: boolean
|
||||
onToggle: () => void; onMove: (index: number, delta: number) => void; onOpen: () => void
|
||||
onPatch: (seg: any, body: any, label?: string) => void
|
||||
}) {
|
||||
const num = (field: string, label: string) => (e: FocusEvent<HTMLInputElement>) => {
|
||||
const v = Number(e.currentTarget.value)
|
||||
if (v === Number(seg[field])) return
|
||||
onPatch(seg, { [field]: v }, `调整${label}`)
|
||||
}
|
||||
const txt = (field: string, label: string) => (e: FocusEvent<HTMLInputElement>) => {
|
||||
const v = e.currentTarget.value
|
||||
if (v === (seg[field] ?? '')) return
|
||||
onPatch(seg, { [field]: v }, `修改${label}`)
|
||||
}
|
||||
const hasVoice = !!(shot?.dialogue || shot?.subtitle_text)
|
||||
const native = seg.voice_source === 'native'
|
||||
|
||||
return (
|
||||
<div className={cn('mb-[9px] grid items-start gap-[11px] rounded-[10px] border bg-card p-[11px]',
|
||||
open ? 'border-accent-line bg-raise' : 'border-emphasis',
|
||||
'grid-cols-[30px_112px_minmax(0,1fr)] max-narrow:grid-cols-[24px_minmax(0,1fr)]')}>
|
||||
<div className="pt-1 text-accent-deep text-[12px] font-bold">{seg.order_index}</div>
|
||||
<MediaThumb item={item} size="sm" width="104px" radius={6} queue={queue} index={i}
|
||||
title={`片段 ${seg.order_index} · ${seg.label}`} className="max-narrow:hidden" />
|
||||
<div className="min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-[5px_9px]">
|
||||
<h4 className="m-0 text-[12.5px] font-semibold">{seg.label}</h4>
|
||||
<Mono className={MUTED}>{fmtMs(seg.start_ms)} → {fmtMs(seg.start_ms + seg.duration_ms)}</Mono>
|
||||
<Chip as="span">源 {fmtMs(seg.source_in_ms)}–{fmtMs(seg.source_out_ms)}</Chip>
|
||||
{hasVoice && (
|
||||
<Tag tone={native ? 'info' : 'ok'}
|
||||
title={native ? '台词直接用模型自带音轨,与口型天然同步' : '台词用平台配音(TTS),片段按配音长度补足'}>
|
||||
{native ? '原声' : '配音'}
|
||||
</Tag>
|
||||
)}
|
||||
{shot && <Chip as="span">{statusLabel(shot.status)}</Chip>}
|
||||
{seg.muted && <Tag tone="warn">静音</Tag>}
|
||||
{!!seg.transition_out && seg.transition_out !== 'cut' && (
|
||||
<Tag tone="info">{opt('transition', seg.transition_out)} {seg.transition_duration_ms}ms</Tag>
|
||||
)}
|
||||
<Button variant="ghost" size="sm" className="ml-auto" aria-expanded={open} onClick={onToggle}>
|
||||
{open ? '收起参数 ▴' : '裁剪 / 转场 ▾'}
|
||||
</Button>
|
||||
</div>
|
||||
{open && (
|
||||
<>
|
||||
<FormRow cols={6} stack tight className="mt-[9px] [&_input]:px-[7px] [&_input]:text-tiny">
|
||||
<Field label="片段名称">
|
||||
<input key={`label-${seg.label}`} defaultValue={seg.label} onBlur={txt('label', '片段名称')} />
|
||||
</Field>
|
||||
<Field label="时长 ms">
|
||||
<input key={`duration-${seg.duration_ms}`} type="number" min={80} step={20}
|
||||
defaultValue={seg.duration_ms} onBlur={num('duration_ms', '时长')} />
|
||||
</Field>
|
||||
<Field label="源入点 ms">
|
||||
<input key={`in-${seg.source_in_ms}`} type="number" min={0} step={20}
|
||||
defaultValue={seg.source_in_ms} onBlur={num('source_in_ms', '源入点')} />
|
||||
</Field>
|
||||
<Field label="转场">
|
||||
<Select size="md" className="px-[7px] text-tiny" ariaLabel="片段出场转场"
|
||||
value={seg.transition_out ?? ''} options={transitions}
|
||||
onChange={(v: any) => onPatch(seg, { transition_out: v }, '修改转场')} />
|
||||
</Field>
|
||||
<Field label="转场时长 ms">
|
||||
<input key={`tdur-${seg.transition_duration_ms}`} type="number" min={0} step={50}
|
||||
defaultValue={seg.transition_duration_ms} onBlur={num('transition_duration_ms', '转场时长')} />
|
||||
</Field>
|
||||
<Field label="音量">
|
||||
<input key={`vol-${seg.volume}`} type="number" min={0} max={3} step={0.05}
|
||||
defaultValue={seg.volume} onBlur={num('volume', '音量')} />
|
||||
</Field>
|
||||
</FormRow>
|
||||
<Actions>
|
||||
<Button variant="outline" size="sm" disabled={busy || i === 0} onClick={() => onMove(i, -1)}>↑ 上移</Button>
|
||||
<Button variant="outline" size="sm" disabled={busy || i === count - 1} onClick={() => onMove(i, 1)}>↓ 下移</Button>
|
||||
<Button variant="outline" size="sm" onClick={() => onPatch(seg, { muted: !seg.muted }, '切换静音')}>
|
||||
{seg.muted ? '取消静音' : '静音该片段'}
|
||||
</Button>
|
||||
<Button variant="link" onClick={onOpen}>预览该片段 ↗</Button>
|
||||
</Actions>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue