Files
video-create/.claude/skills/video-from-script/scripts/lib/phase-assemble.js
sion123 6097a809bf refactor(video-pipeline): 移除 segments 机制,改为整段音频合成
移除 TTS 阶段逐句切分及 segments 数组逻辑,统一为整段音频合成。
CapCut 字幕切分由组装阶段按字符比例分配,简化音频上传、
时间线构建和字幕生成流程,减少冗余处理分支。
2026-05-02 02:31:55 +08:00

53 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Phase: assemble — CapCut 成片组装
*
* 图片/视频 + TTS → 剪映草稿
*/
const { log, getManifestDir } = require('./pipeline-utils')
async function phaseAssemble(manifest, manifestPath, options) {
const dir = getManifestDir(manifestPath)
const accountConfig = options.accountConfig || {}
const capcutConfig = accountConfig.capcut || {}
const videoItems = manifest.items.filter(it => it.video && it.status === 'done')
const hasVideos = videoItems.length > 0
const mode = hasVideos ? 'videos' : 'images'
// 前置校验:图片模式下检查 file 字段
if (mode === 'images') {
const missingFile = manifest.items.filter(it => !it.file)
if (missingFile.length > 0) {
throw new Error(`${missingFile.length} 个 item 缺少 file 字段id: ${missingFile.map(it => it.id).join(', ')}),请先运行 images 阶段生成图片`)
}
}
const assembleArgs = {
input: dir,
manifest: manifestPath,
mode,
format: manifest.format || accountConfig.defaultFormat || '9:16',
subtitles: 'true',
voiceover: manifest.items.some(it => it.audio) ? 'true' : 'false',
animation: capcutConfig.animation || '渐显+放大',
}
if (capcutConfig.defaultBGM) assembleArgs.bgm = capcutConfig.defaultBGM
if (capcutConfig.effects) assembleArgs.effects = capcutConfig.effects.join(',')
if (capcutConfig.filter) assembleArgs.filter = capcutConfig.filter
log('assemble', `模式: ${mode}, 字幕: true, 配音: ${assembleArgs.voiceover}, 动画: ${assembleArgs.animation}`)
try {
const { assemble } = require('../capcut_assemble')
await assemble(assembleArgs)
log('assemble', '成片完成')
} catch (err) {
log('assemble', `成片失败: ${err.message}`)
throw err
}
}
module.exports = { phaseAssemble }