968 lines
56 KiB
TypeScript
968 lines
56 KiB
TypeScript
/**
|
||
* 长视频合成引擎 · 时间线(图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 { confirmAction } from '../../stores/confirm'
|
||
import { openPreview } from '../../stores/preview'
|
||
import { PageHead, ActionGroup, Actions, Button, Check, Chip, ChipBar, Ctlbar, Divider, Empty, ErrorText, ExtLink, Field, FieldBlock, FilePick, FormGrid, FormRow, Grid, Count, IconText, Input, IssueRow, Layout, LineHint, MONO, MUTED, MUTED_MONO, MaybeNumberInput, Mono, NumberInput, OptionGrid, PageStack, Panel, PanelHead, Row, Spinner, Status, Table, Tag, TagGroup, TextArea, Toolbar, Value, Clamp, useNarrowTable } from '../../components/ui'
|
||
import { IconAdd, IconCheck, IconChevronDown, IconChevronUp, IconClose, IconDelete, IconEye, IconSound, IconStar, IconTracks, IconWarn } from '../../components/icons'
|
||
import { IconArrowDown, IconArrowUp, IconEdit, IconMic, IconPass } from '../../components/icons/extra'
|
||
|
||
/**
|
||
* 这三条下拉(字幕方式 / 台词语音来源 / 模型原声策略)的选项名是一整句解释,
|
||
* 而「选中值」盒子在时间线右栏只有 135~303px(992 档实测 135)——整句永远放不下。
|
||
* 它们带 nex-prose-value:截图复核(scripts/ui/visualcheck.py 第 7 道)对这一族放行
|
||
* 省略号,代价由 antd 兜住:ellipsis + title 全文 + 面板按内容加宽折行(.nex-select-popup)。
|
||
* 判据:只有「选项名本身就是散文」才准挂这个标记;筛选类下拉(全部状态 / 按更新时间)
|
||
* 的值是筛选条件本身,看不见等于没筛,必须整颗放得下,不许挂。
|
||
*/
|
||
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 || '—'
|
||
|
||
/**
|
||
* 交付预检报告里的字幕模式短名。下拉里那串完整说明是给人做选择用的,
|
||
* 而标签(Tag)是 nowrap 的一行胶囊:整句塞进去实测 280px,比 264px 的
|
||
* TagGroup 还宽 16px,900px 断点下撑破面板。完整说法留在 title 里。
|
||
*/
|
||
const SUBTITLE_MODE_SHORT: Record<string, string> = {
|
||
embed: '内嵌软字幕轨', burn: '烧录硬字幕', both: '烧录 + 内嵌', sidecar: '仅外挂 SRT', off: '不输出'
|
||
}
|
||
const subtitleModeShort = (m: string) => SUBTITLE_MODE_SHORT[m] || 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-split py-2 text-xs [&>*]:min-w-0'
|
||
|
||
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
|
||
const [vers, sh, as] = await Promise.all([
|
||
api.get(`/api/projects/${projectId}/timelines`).catch(() => ({ timelines: [] })),
|
||
api.get(`/api/projects/${projectId}/shots`).catch(() => ({ shots: [] })),
|
||
api.get(`/api/projects/${projectId}/assets`).catch(() => ({ assets: [] }))
|
||
])
|
||
/*
|
||
时间线详情为什么不再和上面三枪并发:
|
||
症状:项目一次时间线都没建过时,GET /timeline 必然 404(后端 deps.get_timeline
|
||
找不到当前时间线就抛 404「尚未建立时间线」)。前端用 .catch() 把它当空状态吞了,
|
||
页面看起来是对的,但 devtools 的 console 里永远躺着一条
|
||
「Failed to load resource: the server responded with a status of 404」,
|
||
视觉体检按 console 计数就会每次都误报成故障。
|
||
做法:先拿版本清单,清单为空 = 这个资源根本不存在,那就别问;
|
||
切到某个历史版本时 want 有值,照旧按 id 请求。
|
||
为什么不干脆在体检里豁免这句 console:那条消息不带 URL,
|
||
接口 404 和素材文件 404 长得一模一样,豁免等于把真故障一起放过。
|
||
注意:详情失败依旧不能拖垮镜头/素材列表(否则「构建时间线」没有可选项,页面自锁),
|
||
所以这里仍然是 .then/.catch 收成 {ok,data,error},而不是让它抛出去。
|
||
*/
|
||
const exists = want !== null && want !== undefined ? true : (vers.timelines || []).length > 0
|
||
let tl: { ok: boolean; data: any; error: unknown } = { ok: false, data: null, error: null }
|
||
if (exists) {
|
||
tl = await 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 }))
|
||
}
|
||
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}`
|
||
const ok = await confirmAction({
|
||
title: `删除时间线版本 ${label}?`,
|
||
desc: '只删除编排记录(片段 / 字幕 / 音轨),已导出的成片与镜头产物不受影响。',
|
||
tone: 'danger', confirmText: '删除', confirmIcon: <IconDelete />
|
||
})
|
||
if (!ok) 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 }
|
||
const ok = await confirmAction({
|
||
title: `删除时间线版本 v${row.version}「${row.name}」?`,
|
||
desc: '只删除编排记录(片段 / 字幕 / 音轨),已导出的成片与镜头产物不受影响。',
|
||
tone: 'danger', confirmText: '删除', confirmIcon: <IconDelete />
|
||
})
|
||
if (!ok) 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 }))
|
||
|
||
/* 表格窄档(<992):窄屏另给一套列,宽档那份一字不动(1440 像素级不变) */
|
||
const narrow = useNarrowTable()
|
||
|
||
return (
|
||
<PageStack>
|
||
{/* 时间线总览 + 版本切换:以前是 Between 裸排在页面底色上
|
||
(名字 <b>、TagGroup、SectionTitle 当标签用、两颗按钮,四种高度挤一排)。
|
||
现在它是「只有卡头的卡」:名字进卡头标题、计数进 sub、版本操作进 extra。 */}
|
||
{/* 页头(第 1 条):时间线版本是这一页的全局对象——下拉选中哪一版,
|
||
「设为当前 / 删除」就作用于哪一版,三件必须同排,所以整组提进 PageHead。 */}
|
||
<PageHead
|
||
title="时间线合成"
|
||
sub="把有产物的镜头按镜序编排版本,逐段核对画面、配音与字幕,再交给导出。"
|
||
actions={<>
|
||
<ActionGroup>
|
||
<Select 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 disabled={!!busy || !viewVersion} onClick={activateVersion}
|
||
title={viewVersion ? '把下拉中选中的版本设为当前生效版本' : '先在左侧下拉中选择一个历史版本'}
|
||
icon={<IconStar />}>
|
||
设为当前
|
||
</Button>
|
||
<Button type="text" danger disabled={!!busy || !viewVersion || versions.length < 2} onClick={removeVersion}
|
||
title={versions.length < 2 ? '至少保留一个时间线版本' : '删除选中的版本(仅删编排记录,不动成片)'}
|
||
icon={<IconDelete />}>
|
||
删除版本
|
||
</Button>
|
||
</ActionGroup>
|
||
{busy ? <Value><Spinner /> {busy}…</Value> : null}
|
||
</>}
|
||
/>
|
||
|
||
{/* 当前这一版时间线是什么:名称进卡头标题,计数进 sub(第 8 条:不写项目信息)。 */}
|
||
<Toolbar
|
||
info={timeline ? timeline.name : '尚未构建时间线'}
|
||
sub={timeline
|
||
? <TagGroup className="mb-0">
|
||
<Tag tone="info">v{timeline.version}{timeline.is_current ? ' · 当前' : ' · 历史版本'}</Tag>
|
||
<Tag>{segments.length} 段</Tag>
|
||
<Tag>总时长 {fmtMs(timeline.total_duration_ms)}</Tag>
|
||
<Tag>{timeline.width}×{timeline.height} @{timeline.fps}</Tag>
|
||
<Tag>字幕 {subtitles.length}</Tag>
|
||
<Tag>音轨 {clips.length}</Tag>
|
||
{report && <Tag tone={report.ready ? 'ok' : 'bad'}>{report.ready ? '可导出' : '有阻塞'}</Tag>}
|
||
<Tag>共 {versions.length} 个版本</Tag>
|
||
</TagGroup>
|
||
: <Value>先在「构建时间线」生成第一个版本</Value>} />
|
||
<ErrorText className="mb-3">{error}</ErrorText>
|
||
|
||
{/* ===== 构建 / 报告 ===== */}
|
||
<Grid cols={2} gap={12} oneAt="lg">
|
||
<Panel>
|
||
<PanelHead title="构建时间线" />
|
||
<Ctlbar>
|
||
<Field inline 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>
|
||
{/* 计数是这颗按钮的口径说明,两者必须同一行;两颗主按钮也并进来,
|
||
原来「计数一行 / 按钮一行」把半张卡留白。 */}
|
||
<Ctlbar>
|
||
{/* 这两个数只是「构建按钮的口径说明」,不能点,就不该穿 chip 的胶囊皮;
|
||
和右侧按钮同排时用一句 Value 把它们连读,非零才上色。 */}
|
||
<Value>有产物镜头 <Count n={buildable.length} unit="个" /> · 已审核合格 <Count n={stats?.shots_approved ?? 0} tone="ok" unit="个" /></Value>
|
||
{/* 三颗按钮是同一个动作组:整组一起换行,别出现「两颗在这行、第三颗掉下行」 */}
|
||
<ActionGroup>
|
||
<Button icon={<IconCheck />} onClick={selectAllBuildable}>
|
||
{build.shot_ids.length === buildable.length ? '清空指定' : '指定全部镜头'}
|
||
</Button>
|
||
<Button type="primary" disabled={!!busy || !buildable.length} onClick={buildTimeline} icon={<IconTracks />}>构建 / 重建时间线</Button>
|
||
<Button disabled={!!busy || !missingVoice.length} onClick={makeVoiceover} icon={<IconSound />}>
|
||
补齐缺失配音({missingVoice.length})
|
||
</Button>
|
||
</ActionGroup>
|
||
</Ctlbar>
|
||
<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>
|
||
{!buildable.length && <LineHint className="mt-3">先在调度中心生成镜头产物,才能构建时间线。</LineHint>}
|
||
</Panel>
|
||
|
||
<Panel>
|
||
<PanelHead title="交付预检报告"
|
||
right={report ? <Tag tone={report.ready ? 'ok' : 'bad'}>{report.ready ? '可导出' : '有阻塞'}</Tag> : undefined} />
|
||
{!report && <Empty>构建时间线后生成报告。</Empty>}
|
||
{report && (
|
||
<>
|
||
<TagGroup>
|
||
<Tag>片段 {report.segments}</Tag>
|
||
<Tag>字幕 {report.subtitles}</Tag>
|
||
<Tag>配音 {report.voice_clips}</Tag>
|
||
<Tag>BGM {report.bgm_clips}</Tag>
|
||
<Tag>总时长 {fmtMs(report.total_duration_ms)}</Tag>
|
||
<Tag title={subtitleModeLabel(report.subtitle_mode || (report.burn_subtitle ? 'burn' : 'sidecar'))}>
|
||
字幕 {subtitleModeShort(report.subtitle_mode || (report.burn_subtitle ? 'burn' : 'sidecar'))}
|
||
</Tag>
|
||
</TagGroup>
|
||
<Divider />
|
||
{!report.issues?.length
|
||
? <Value><IconText icon={<IconPass />}>没有阻塞项,可直接前往「导出与成本」出片。</IconText></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-text-quaternary">segment#{x.segment_id}</Mono> : null}
|
||
{x.clip_id ? <Mono className="text-text-quaternary">clip#{x.clip_id}</Mono> : null}
|
||
</IssueRow>
|
||
))}
|
||
</div>
|
||
)}
|
||
{!subtitleBurn && needsBurn ? (
|
||
/* 与成片页那条同一口径:版面只说「会怎样」,
|
||
装什么、FFMPEG_BIN 指到哪里是部署侧的事,收进 title 给管理员看。 */
|
||
<LineHint className="mt-2">
|
||
<IconText align="start" icon={<IconWarn />}>
|
||
<span title={'安装带 libass 的完整版 ffmpeg 后,把 FFMPEG_BIN 指向它即可,例如 brew install ffmpeg-full 或 ~/.local/ffmpeg/bin/ffmpeg。当前使用:'
|
||
+ (health?.ffmpeg_capabilities?.ffmpeg_path || '未探测')}>
|
||
本机 ffmpeg 缺字幕滤镜,烧录会自动降级为「内嵌软字幕轨」。
|
||
</span>
|
||
</IconText>
|
||
</LineHint>
|
||
) : !subtitleEmbed ? (
|
||
<LineHint className="mt-2"><IconText align="start" icon={<IconWarn />}>本机 ffmpeg 不支持内嵌字幕(mov_text),内嵌模式会降级为外挂 SRT。</IconText></LineHint>
|
||
) : null}
|
||
</>
|
||
)}
|
||
</Panel>
|
||
</Grid>
|
||
|
||
{/* ===== 片段编辑 ===== */}
|
||
<Panel>
|
||
<PanelHead
|
||
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
|
||
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-sm: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 icon={<IconEdit />} size="sm" onClick={() => editSubtitle(c)}>编辑</Button>
|
||
</div>
|
||
))}
|
||
<Divider />
|
||
{/* 四个字段一行放完:默认三列会把「结束 ms」单独甩到第二行,
|
||
起始 / 结束必须并排才看得出是一条区间。 */}
|
||
{/* 两列而不是四列:这块面板在 1280 只有 624 宽,四列每格 148——
|
||
「所属镜头」的下拉值(镜号 + 镜头名)读不到一半,起始 / 结束也各自缩成一小截。
|
||
两列 296 一格,起始 / 结束仍然并排(注释里那条要求没变)。
|
||
控件撑满列宽由 FormRow 自带的表单作用域负责(app.css glue ①)。 */}
|
||
<FormRow cols={2}>
|
||
<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">
|
||
<MaybeNumberInput min={0} step={50} value={cue.start_ms} onChange={(v) => patchCue({ start_ms: v })} />
|
||
</Field>
|
||
<Field label="结束 ms">
|
||
<MaybeNumberInput min={0} step={50} value={cue.end_ms} onChange={(v) => patchCue({ end_ms: v })} />
|
||
</Field>
|
||
</FormRow>
|
||
<FieldBlock label="字幕文本">
|
||
<TextArea rows={2} value={cue.text} placeholder={cue.cue_id ? '留空表示删除这条字幕' : '留空表示删除该镜头字幕'} onChange={(e) => patchCue({ text: e.target.value })} />
|
||
</FieldBlock>
|
||
<Actions>
|
||
<Button icon={<IconCheck />} type="primary" size="sm" disabled={!!busy || !timeline} onClick={saveSubtitle}>保存字幕</Button>
|
||
<Button size="sm" icon={<IconClose />}
|
||
onClick={() => setCue({ ...CUE_INIT })}>
|
||
{cue.cue_id ? `取消编辑 #${cue.cue_id}` : '清空表单(新增字幕)'}
|
||
</Button>
|
||
</Actions>
|
||
</Panel>
|
||
|
||
{/* ===== 时间线设置 ===== */}
|
||
<Panel>
|
||
<PanelHead
|
||
title={<span title="「台词语音来源」改动会自动重排时间线:用原声的镜头按画面长度排布,字幕同步改为按片段窗口对齐;设置只作用于当前时间线,出片预设在「导出与成本」页选择。">混音与字幕设置</span>} />
|
||
{/* 这块面板是两栏正文的**侧栏**:1440 实测卡宽 428、1280 只有 368,
|
||
cols=3 时一格只剩 131 / 111——远低于规范 §9.3「最窄一格 ≥200」,
|
||
每个标签都折成两三行(配音时自动压低 BGM / 原生音轨增益 dB),
|
||
下拉的选中值全被裁成「内嵌软字…」「全保留(…」。降成两格(214 / 184)
|
||
之后标签回到一行,同排那颗裸复选框也才可能对得齐(glue ⑥ 让的是**一行**标签的高度)。 */}
|
||
<FormRow cols={2}>
|
||
<Check checked={setting.duck_bgm} onChange={(v) => patchSetting({ duck_bgm: v })}>
|
||
配音时自动压低 BGM
|
||
</Check>
|
||
<Field label="字幕方式" title="内嵌=成片里一条可开关的字幕轨;烧录=字幕直接画进画面">
|
||
<Select ariaLabel="字幕方式" value={setting.subtitle_mode}
|
||
onChange={(v: any) => patchSetting({ subtitle_mode: v })} options={SUBTITLE_MODES}
|
||
className="nex-prose-value" />
|
||
</Field>
|
||
<Check checked={setting.hold_last_frame} onChange={(v) => patchSetting({ hold_last_frame: v })}>
|
||
尾帧补足(避免时长不足)
|
||
</Check>
|
||
<Field label="台词语音来源"
|
||
title="MiniMax H3 是原生音画同步模型:人声对着口型生成,零错位。默认「模型原声直出」,并且生成时平台会把角色声线的克隆样本当作参考音频(ref_audios)一起喂给模型,原声就是这个角色自己的嗓子,不再是模型随机挑的陌生人。TTS 是在画面之外另起一条音轨,长度与停顿和画面无关,正是「张嘴却静音 / 闭嘴还在说」的成因;只有产物确实没有音轨时才回退配音。">
|
||
<Select ariaLabel="台词语音来源" value={setting.voice_source}
|
||
onChange={(v: any) => patchSetting({ voice_source: v })}
|
||
className="nex-prose-value"
|
||
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 })}
|
||
className="nex-prose-value"
|
||
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 })} title="台词走模型原声时必须勾选:镜头产物自带的就是那条人声/音效/环境声轨,关掉等于把它剪掉。切到「平台配音」时建议取消勾选,否则原声人声会和配音叠成双声">
|
||
保留镜头自带音轨(模型原生音画同步)
|
||
</Check>
|
||
<Field label="原生音轨增益 dB">
|
||
<NumberInput step={0.5} disabled={!setting.keep_shot_audio} value={setting.shot_audio_gain_db} onChange={ (v) => patchSetting({ shot_audio_gain_db: v })} />
|
||
</Field>
|
||
<Field label="配音增益 dB">
|
||
<NumberInput step={0.5} value={setting.voice_gain_db} onChange={ (v) => patchSetting({ voice_gain_db: v })} />
|
||
</Field>
|
||
<Field label="BGM 增益 dB">
|
||
<NumberInput step={0.5} value={setting.bgm_gain_db} onChange={ (v) => patchSetting({ bgm_gain_db: v })} />
|
||
</Field>
|
||
<Field label="目标响度 LUFS">
|
||
<NumberInput step={0.5} value={setting.target_lufs} onChange={ (v) => patchSetting({ target_lufs: v })} />
|
||
</Field>
|
||
<Field label="片头留白 ms">
|
||
<NumberInput step={10} value={setting.lead_padding_ms} onChange={ (v) => patchSetting({ lead_padding_ms: v })} />
|
||
</Field>
|
||
<Field label="片尾留白 ms">
|
||
<NumberInput step={10} value={setting.tail_padding_ms} onChange={ (v) => patchSetting({ tail_padding_ms: v })} />
|
||
</Field>
|
||
<Field label="字幕字号(0=自动)">
|
||
<NumberInput min={0} value={setting.sub_size} onChange={ (v) => patchSetting({ sub_size: v })} />
|
||
</Field>
|
||
<Field label="字幕下边距(0=自动)">
|
||
<NumberInput min={0} value={setting.sub_margin} onChange={ (v) => patchSetting({ sub_margin: v })} />
|
||
</Field>
|
||
<Field label="字幕描边(0=自动)">
|
||
<NumberInput min={0} value={setting.sub_outline} onChange={ (v) => patchSetting({ sub_outline: v })} />
|
||
</Field>
|
||
</FormRow>
|
||
<Actions>
|
||
<Button icon={<IconCheck />} type="primary" size="sm" disabled={!!busy || !timeline} onClick={saveSettings}>保存并重排</Button>
|
||
</Actions>
|
||
</Panel>
|
||
</Layout>
|
||
|
||
{/* ===== 音轨 ===== */}
|
||
<Panel>
|
||
<FormGrid>
|
||
<PanelHead title="音轨(配音 / BGM / 音效)"
|
||
right={<>
|
||
<Value>共 {clips.length} 条</Value>
|
||
{/* 旧站这颗按钮漏了 @click,点了没反应;配音表单就在同一页下方,直接接上 addAudio */}
|
||
<Button icon={<IconAdd />} type="dashed" 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-sm: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">
|
||
<NumberInput min={0} step={50} value={audio.start_ms} onChange={ (v) => patchAudio({ start_ms: v })} />
|
||
</Field>
|
||
<Field label="时长 ms(0=自动)">
|
||
<NumberInput min={0} step={50} value={audio.duration_ms} onChange={ (v) => patchAudio({ duration_ms: v })} />
|
||
</Field>
|
||
<Field label="增益 dB">
|
||
<NumberInput step={0.5} value={audio.gain_db} onChange={ (v) => patchAudio({ gain_db: v })} />
|
||
</Field>
|
||
<Check checked={audio.loop} onChange={(v) => patchAudio({ loop: v })}>循环铺满</Check>
|
||
<Check checked={audio.ducking} onChange={(v) => patchAudio({ ducking: v })}>压低 BGM</Check>
|
||
</FormRow>
|
||
{/* 「上传新文件」与「引用已有素材」是两条选择路径,各占一行;
|
||
已有素材是**从固定集合里挑一个**,走 OptionGrid 等宽格子(实测 13 个胶囊
|
||
自然排列时宽 84–158、折 2~3 行且每行起点随文案漂移)。 */}
|
||
<Row tight>
|
||
<FilePick icon={<IconMic />} label="选择音频文件" accept="audio/*"
|
||
onFiles={(files) => patchAudio({ file: files[0] ?? null })} />
|
||
{audio.file && (
|
||
<Tag tone="accent" title="已选本地文件,点「开始替换」生效">{audio.file.name}</Tag>
|
||
)}
|
||
</Row>
|
||
{!!audioAssets.length && (
|
||
<OptionGrid cols={4} label="或直接引用已有素材" hint="点一下填进下方路径"
|
||
className="mt-2">
|
||
{audioAssets.map((a: any) => (
|
||
<Chip key={a.id} active={audio.source_path === a.path}
|
||
onClick={() => useAsset(a.path)}>{a.name}</Chip>
|
||
))}
|
||
</OptionGrid>
|
||
)}
|
||
<FormRow className="mt-3">
|
||
<Field label="素材路径" title="可留空,直接从上方已上传的素材里点选一个。">
|
||
<Input value={audio.source_path} placeholder="media 相对路径,如 5/bgm/timeline-bgm_xxx.mp3" onChange={(e) => patchAudio({ source_path: e.target.value })} />
|
||
</Field>
|
||
</FormRow>
|
||
</FormGrid>
|
||
</Panel>
|
||
|
||
{/* ===== 版本 ===== */}
|
||
{!!versions.length && (
|
||
<Panel>
|
||
<PanelHead title="时间线版本"
|
||
right={<span className={MUTED}>最近编辑 {fmtTime(versions[0]?.updated_at)}</span>} />
|
||
<Table
|
||
maxHeight={220}
|
||
minWidth={narrow ? false : 820}
|
||
dataSource={versions}
|
||
chosen={(v: any) => !!v.is_current}
|
||
columns={narrow ? [
|
||
|
||
/* ── 窄档(<992 · NEX 阶段 8.5 六表收口之⑤「时间线版本」)──────────────────
|
||
数据特点:一屏就几版,读的是「哪一版在生效、要不要切回去」,行少而字段碎。
|
||
宽档 minWidth 820 在 430 溢出 464、768 溢出 358、576 溢出 318;
|
||
版本号 / 片段 / 时长 / 更新时间这四个数字列,没有一个重要到独占一列。
|
||
方案:版本号提到名称行首(v3 · 主时间线),片段数·时长·更新时间收成第二行
|
||
(全文挂 title,鼠标/触摸都能读回),只留「状态」「操作」两列定宽;
|
||
minWidth 同时关掉——窄屏那条 820 的横向滚动条换不来任何可读性。
|
||
操作列保持 128px 的三颗图标按钮(R15 那颗公式在 356 的容器里放得下)。 */
|
||
{ title: '版本 / 名称', key: 'name', render: (_: any, v: any) => (
|
||
<>
|
||
<Clamp lines={1} title={`v${v.version} · ${v.name}`}>
|
||
<span className={MONO}>v{v.version}</span> {v.name}
|
||
</Clamp>
|
||
<Clamp lines={1} className={MUTED_MONO}
|
||
title={`${v.segments} 段 · ${fmtMs(v.total_duration_ms)} · 更新于 ${fmtTime(v.updated_at)}`}>
|
||
{v.segments} 段 · {fmtMs(v.total_duration_ms)} · {fmtTime(v.updated_at)}
|
||
</Clamp>
|
||
</>
|
||
) },
|
||
{ title: '状态', key: 'state', width: 84, align: 'center', render: (_: any, v: any) =>
|
||
<Tag tone={v.is_current ? 'accent' : 'default'}>{v.is_current ? '当前生效' : '历史版本'}</Tag> },
|
||
{ title: '操作', key: 'actions', width: 128, align: 'right', render: (_: any, v: any) => (
|
||
<Row tight className="justify-end">
|
||
<Button type="text" shape="circle" icon={<IconEye />} title="查看这一版的时间线"
|
||
aria-label={`查看 v${v.version}`}
|
||
onClick={() => { showVersion(v.id); void load(false, v.id) }} />
|
||
<Button type="text" shape="circle" icon={<IconCheck />} title="设为当前生效版本"
|
||
aria-label={`将 v${v.version} 设为当前版本`}
|
||
disabled={!!busy || v.is_current} onClick={() => activateOne(v)} />
|
||
<Button type="text" shape="circle" danger icon={<IconDelete />} title="删除这一版"
|
||
aria-label={`删除 v${v.version}`}
|
||
disabled={!!busy || versions.length < 2} onClick={() => removeOne(v)} />
|
||
</Row>
|
||
) }
|
||
] : [
|
||
{ title: '版本', key: 'version', width: 72, align: 'center', className: MONO,
|
||
render: (_: any, v: any) => `v${v.version}` },
|
||
{ title: '名称', dataIndex: 'name', key: 'name' },
|
||
{ title: '片段', key: 'segments', width: 76, align: 'right', className: MONO, render: (_: any, v: any) => v.segments },
|
||
{ title: '时长', key: 'duration', width: 92, align: 'right', className: MONO,
|
||
render: (_: any, v: any) => fmtMs(v.total_duration_ms) },
|
||
{ title: '状态', key: 'state', width: 104, align: 'center', render: (_: any, v: any) =>
|
||
<Tag tone={v.is_current ? 'accent' : 'default'}>{v.is_current ? '当前生效' : '历史版本'}</Tag> },
|
||
{ title: '更新时间', key: 'updated', width: 140, className: `${MUTED_MONO} whitespace-nowrap`,
|
||
render: (_: any, v: any) => fmtTime(v.updated_at) },
|
||
/* 三颗动作收成图标按钮(R15):「查看 / 设为当前 / 删除」三枚带字按钮要 262px,
|
||
220 的列放不下就折成两排,整行被顶到 79px。图标 + title + aria-label 之后按
|
||
「3 颗 circle 按钮 3×32 + 2×6 间距 = 108,再加 antd small 单元格左右 16 内边距」
|
||
留 128px,一行放完,行高回到 48。名称列不设宽度,吃掉剩下的宽度。 */
|
||
{ title: '操作', key: 'actions', width: 128, align: 'right', render: (_: any, v: any) => (
|
||
<Row tight className="justify-end">
|
||
<Button type="text" shape="circle" icon={<IconEye />} title="查看这一版的时间线"
|
||
aria-label={`查看 v${v.version}`}
|
||
onClick={() => { showVersion(v.id); void load(false, v.id) }} />
|
||
<Button type="text" shape="circle" icon={<IconCheck />} title="设为当前生效版本"
|
||
aria-label={`将 v${v.version} 设为当前版本`}
|
||
disabled={!!busy || v.is_current} onClick={() => activateOne(v)} />
|
||
<Button type="text" shape="circle" danger icon={<IconDelete />} title="删除这一版"
|
||
aria-label={`删除 v${v.version}`}
|
||
disabled={!!busy || versions.length < 2} onClick={() => removeOne(v)} />
|
||
</Row>
|
||
) }
|
||
]}
|
||
/>
|
||
</Panel>
|
||
)}
|
||
</PageStack>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 片段卡(.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-2 grid items-start gap-3 rounded-lg border bg-bg-container p-3',
|
||
open ? 'border-primary-border bg-fill-secondary' : 'border-fill',
|
||
'grid-cols-[30px_112px_minmax(0,1fr)] max-sm:grid-cols-[24px_minmax(0,1fr)]')}>
|
||
<div className="pt-1 text-primary-active text-sm font-bold">{seg.order_index}</div>
|
||
<MediaThumb item={item} size="sm" width="104px" queue={queue} index={i}
|
||
title={`片段 ${seg.order_index} · ${seg.label}`} className="max-sm:hidden" />
|
||
<div className="min-w-0">
|
||
<div className="flex flex-wrap items-center gap-y-1 gap-x-2">
|
||
<h4 className="m-0 text-sm font-semibold">{seg.label}</h4>
|
||
<Mono className={MUTED}>{fmtMs(seg.start_ms)} → {fmtMs(seg.start_ms + seg.duration_ms)}</Mono>
|
||
<Tag>源 {fmtMs(seg.source_in_ms)}–{fmtMs(seg.source_out_ms)}</Tag>
|
||
{hasVoice && (
|
||
<Tag tone={native ? 'info' : 'default'}
|
||
title={native ? '台词直接用模型自带音轨,与口型天然同步' : '台词用平台配音(TTS),片段按配音长度补足'}>
|
||
{native ? '原声' : '配音'}
|
||
</Tag>
|
||
)}
|
||
{shot && <Status value={shot.status} />}
|
||
{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 type="text" size="sm" className="ml-auto" aria-expanded={open} onClick={onToggle}
|
||
icon={open ? <IconChevronUp /> : <IconChevronDown />}>
|
||
{open ? '收起参数' : '裁剪 / 转场'}
|
||
</Button>
|
||
</div>
|
||
{open && (
|
||
<>
|
||
<FormRow cols={6} tight className="mt-2 [&_input]:px-2 [&_input]:text-xs">
|
||
<Field label="片段名称">
|
||
<Input key={`label-${seg.label}`} defaultValue={seg.label} onBlur={txt('label', '片段名称')} />
|
||
</Field>
|
||
<Field label="时长 ms">
|
||
<NumberInput key={`duration-${seg.duration_ms}`} min={80} step={20} defaultValue={seg.duration_ms} onBlur={num('duration_ms', '时长')} />
|
||
</Field>
|
||
<Field label="源入点 ms">
|
||
<NumberInput key={`in-${seg.source_in_ms}`} min={0} step={20} defaultValue={seg.source_in_ms} onBlur={num('source_in_ms', '源入点')} />
|
||
</Field>
|
||
<Field label="转场">
|
||
<Select size="md" className="px-2 text-xs" ariaLabel="片段出场转场"
|
||
value={seg.transition_out ?? ''} options={transitions}
|
||
onChange={(v: any) => onPatch(seg, { transition_out: v }, '修改转场')} />
|
||
</Field>
|
||
<Field label="转场时长 ms">
|
||
<NumberInput key={`tdur-${seg.transition_duration_ms}`} min={0} step={50} defaultValue={seg.transition_duration_ms} onBlur={num('transition_duration_ms', '转场时长')} />
|
||
</Field>
|
||
<Field label="音量">
|
||
<NumberInput key={`vol-${seg.volume}`} min={0} max={3} step={0.05} defaultValue={seg.volume} onBlur={num('volume', '音量')} />
|
||
</Field>
|
||
</FormRow>
|
||
<Actions>
|
||
<Button size="sm" disabled={busy || i === 0} onClick={() => onMove(i, -1)} icon={<IconArrowUp />}>上移</Button>
|
||
<Button size="sm" disabled={busy || i === count - 1} onClick={() => onMove(i, 1)} icon={<IconArrowDown />}>下移</Button>
|
||
<Button icon={<IconSound />} size="sm" onClick={() => onPatch(seg, { muted: !seg.muted }, '切换静音')}>
|
||
{seg.muted ? '取消静音' : '静音该片段'}
|
||
</Button>
|
||
<Button type="link" onClick={onOpen} icon={<IconEye />}>预览该片段</Button>
|
||
</Actions>
|
||
</>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|