feat(skills): 完善视频生产 pipeline 及新增健身跟练账号
- SKILL.md: 新增工作流阶段定义、质量卡点、分镜规则 - manifest-schema.md: 补充完整字段规范及类型定义 - phase-tts.js: 优化 TTS 合成长逻辑,添加进度追踪 - capcut-tracks.js: 扩展轨道构建能力,支持更多元素类型 - capcut-timeline.js: 改进时间线生成,支持淡入淡出 - capcut_assemble.js: 新增 assemble 阶段完整实现 - cmd-init.js: 完善 init 命令逻辑 - qwen-tts.js: 调整超时配置 - accounts/禁忌帝王学: 更新拆分/图像/台词提示词 - accounts/健身跟练: 新增账号含 account.json 及全套提示词模板 - 新增 workflow-issues-20260501.md 参考文档 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
*
|
||||
* 核心算法模块。纯函数 + ffmpeg,自包含可测试。
|
||||
*
|
||||
* 规则:
|
||||
* 铁律(固化,不可绕过):
|
||||
* 音频:生成后不可调速(TTS=1.15x,CapCut无speed字段)
|
||||
* 视频:始终配合音频时长(只允许加速/截断,不允许慢放/冻结)
|
||||
*
|
||||
* 时间线规则:
|
||||
* 图片模式: TTS 音频时长 = 画面时长,无音频 = 跳过
|
||||
* 视频模式: TTS 为主轴,视频通过策略适配
|
||||
* 视频比音频长 → 加速(≤2x) / 裁剪(>2x)
|
||||
* 视频比音频短 → 放缓(≥0.5x) / 画面停顿(<0.5x)
|
||||
* 所有策略失败 → 兜底截断
|
||||
* 视频比音频短 → 禁止!应在分镜阶段拆分 shot,不允许慢放/冻结补齐
|
||||
*/
|
||||
|
||||
const fs = require('fs')
|
||||
@@ -20,6 +23,20 @@ const { US } = require('./capcut-api')
|
||||
// 时间线构建
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 构建时间线条目
|
||||
*
|
||||
* @param {Array} items - manifest items
|
||||
* @returns {Array} timeline entries
|
||||
*
|
||||
* 策略选择(固化,按 ratio = videoDur / audioDur):
|
||||
* ≥ 1.1, ≤ 2 → speed_up (视频加速追上音频,最优)
|
||||
* > 2 → trim (视频截断至音频时长)
|
||||
* 0.9 ~ 1.1 → none (接近匹配,无需调整)
|
||||
* < 0.9 → 禁止!音频时长超过视频,分镜阶段未正确拆分 shot
|
||||
*
|
||||
* 铁律:不允许 slow_down / freeze,不允许音频调速
|
||||
*/
|
||||
function buildTimeline(items) {
|
||||
let offset = 0
|
||||
return items.map(item => {
|
||||
@@ -46,7 +63,7 @@ function buildTimeline(items) {
|
||||
return entry
|
||||
}
|
||||
|
||||
// 视频模式:策略选择
|
||||
// 视频模式:策略选择(铁律:不允许音频>视频)
|
||||
const ratio = videoDur / audioDur
|
||||
|
||||
if (ratio > 1.1) {
|
||||
@@ -59,23 +76,25 @@ function buildTimeline(items) {
|
||||
offset += dur
|
||||
return entry
|
||||
}
|
||||
} else if (ratio < 0.9) {
|
||||
if (ratio >= 0.5) {
|
||||
const entry = { start: offset, end: offset + dur, duration: dur, speed: ratio, strategy: 'slow_down' }
|
||||
offset += dur
|
||||
return entry
|
||||
} else {
|
||||
const entry = {
|
||||
start: offset, end: offset + dur, duration: dur, speed: 1,
|
||||
strategy: 'freeze', freezeExtra: dur - videoDur,
|
||||
}
|
||||
offset += dur
|
||||
return entry
|
||||
}
|
||||
} else {
|
||||
} else if (ratio >= 0.9) {
|
||||
// 0.9 ~ 1.1:无需调整
|
||||
const entry = { start: offset, end: offset + dur, duration: dur, speed: 1, strategy: 'none' }
|
||||
offset += dur
|
||||
return entry
|
||||
} else {
|
||||
// ratio < 0.9:音频时长超过视频!
|
||||
// 铁律禁止:不允许慢放/冻结/拼接补齐。此情况应在分镜阶段拆分 shot。
|
||||
// 强制截断并打印错误标记,由主 Agent 上报给用户/打回分镜重做。
|
||||
const entry = {
|
||||
start: offset, end: offset + dur, duration: dur, speed: 1,
|
||||
strategy: 'FORBIDDEN_audio_gt_video',
|
||||
ratio: parseFloat(ratio.toFixed(3)),
|
||||
videoDur: parseFloat((videoDur / US).toFixed(2)),
|
||||
audioDur: parseFloat((audioDur / US).toFixed(2)),
|
||||
error: '音频时长(' + (audioDur / US).toFixed(2) + 's) > 视频时长(' + (videoDur / US).toFixed(2) + 's),分镜阶段 shot 未正确拆分,请打回重新切割',
|
||||
}
|
||||
offset += dur
|
||||
return entry
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -87,16 +106,18 @@ function buildTimeline(items) {
|
||||
/**
|
||||
* ffmpeg 视频调整:根据策略适配音频时长
|
||||
*
|
||||
* 策略(按 ratio = videoDur / audioDur 选择):
|
||||
* speed_up (ratio > 1.1, ≤2x) → setpts 压缩时间(加速)
|
||||
* trim (ratio > 2x) → 截断到目标时长
|
||||
* slow_down (ratio < 0.9, ≥0.5x) → setpts 拉长时间(慢放)
|
||||
* freeze (ratio < 0.5x) → 视频原速 + 最后一帧冻结补时长
|
||||
* 允许策略(按 ratio = videoDur / audioDur 选择):
|
||||
* speed_up (ratio > 1.1, ≤2x) → setpts 压缩时间(加速),最优
|
||||
* trim (ratio > 2x) → 截断到目标时长,次选
|
||||
* none (0.9~1.1) → 无需调整
|
||||
*
|
||||
* 禁止策略(已删除):
|
||||
* slow_down (ratio < 0.9) → ❌ 音频不可调速!
|
||||
* freeze (ratio < 0.5) → ❌ 不允许冻结帧补齐!
|
||||
*
|
||||
* 所有策略失败后兜底:截断到目标时长
|
||||
*/
|
||||
async function adjustVideoSpeed(videoPath, targetDurationSec, strategy = 'none', speed = 1, freezeExtraUs = 0) {
|
||||
async function adjustVideoSpeed(videoPath, targetDurationSec, strategy = 'none', speed = 1) {
|
||||
if (!fs.existsSync(videoPath)) return videoPath
|
||||
if (strategy === 'none') return videoPath
|
||||
|
||||
@@ -150,72 +171,9 @@ async function adjustVideoSpeed(videoPath, targetDurationSec, strategy = 'none',
|
||||
console.log(` 加速: ${videoDur.toFixed(1)}s → ${targetDurationSec.toFixed(1)}s (${speedVal}x)`)
|
||||
resolve(outPath)
|
||||
})
|
||||
} else if (strategy === 'slow_down') {
|
||||
const factor = (1 / speed).toFixed(3)
|
||||
execFile('ffmpeg', [
|
||||
'-y', '-i', videoPath,
|
||||
'-filter_complex', `setpts=PTS*${factor}`,
|
||||
'-an',
|
||||
outPath
|
||||
], { timeout: 30000 }, (err) => {
|
||||
if (err) {
|
||||
console.log(` 放缓失败,兜底截断: ${err.message}`)
|
||||
fallbackTrim(resolve)
|
||||
return
|
||||
}
|
||||
console.log(` 放缓: ${videoDur.toFixed(1)}s → ${targetDurationSec.toFixed(1)}s (${speed.toFixed(2)}x speed)`)
|
||||
resolve(outPath)
|
||||
})
|
||||
} else if (strategy === 'freeze') {
|
||||
const freezeSec = freezeExtraUs / US
|
||||
execFile('ffmpeg', [
|
||||
'-y', '-i', videoPath,
|
||||
'-filter_complex', `tpad=stop=-1:stop_duration=${freezeSec.toFixed(3)}`,
|
||||
'-an',
|
||||
outPath
|
||||
], { timeout: 30000 }, (err) => {
|
||||
if (err) {
|
||||
console.log(` tpad freeze 失败,尝试 concat 方案: ${err.message}`)
|
||||
const lastFrame = videoPath.replace(/(\.\w+)$/, '_lastframe.png')
|
||||
const frozenVideo = videoPath.replace(/(\.\w+)$/, '_frozen.mp4')
|
||||
execFile('ffmpeg', [
|
||||
'-y', '-sseof', '-0.1', '-i', videoPath,
|
||||
'-frames:v', '1', lastFrame
|
||||
], { timeout: 10000 }, (err2) => {
|
||||
if (err2) { console.log(` concat 方案也失败,兜底截断`); fallbackTrim(resolve); return }
|
||||
execFile('ffmpeg', [
|
||||
'-y', '-loop', '1', '-i', lastFrame,
|
||||
'-t', String(freezeSec.toFixed(3)),
|
||||
'-pix_fmt', 'yuv420p',
|
||||
'-vf', 'scale=trunc(iw/2)*2:trunc(ih/2)*2',
|
||||
frozenVideo
|
||||
], { timeout: 15000 }, (err3) => {
|
||||
if (err3) {
|
||||
try { fs.unlinkSync(lastFrame) } catch (_) {}
|
||||
console.log(` 冻结帧视频生成失败,兜底截断`)
|
||||
fallbackTrim(resolve)
|
||||
return
|
||||
}
|
||||
const concatList = path.join(path.dirname(videoPath), '_freeze_concat.txt')
|
||||
fs.writeFileSync(concatList, `file '${videoPath}'\nfile '${frozenVideo}'\n`)
|
||||
execFile('ffmpeg', [
|
||||
'-y', '-f', 'concat', '-safe', '0', '-i', concatList,
|
||||
'-c', 'copy', outPath
|
||||
], { timeout: 30000 }, (err4) => {
|
||||
try { fs.unlinkSync(lastFrame); fs.unlinkSync(frozenVideo); fs.unlinkSync(concatList) } catch (_) {}
|
||||
if (err4) { console.log(` 拼接失败,兜底截断`); fallbackTrim(resolve); return }
|
||||
console.log(` 画面停顿: ${videoDur.toFixed(1)}s + 冻结 ${freezeSec.toFixed(1)}s = ${targetDurationSec.toFixed(1)}s`)
|
||||
resolve(outPath)
|
||||
})
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
console.log(` 画面停顿: ${videoDur.toFixed(1)}s + 冻结 ${freezeSec.toFixed(1)}s = ${targetDurationSec.toFixed(1)}s`)
|
||||
resolve(outPath)
|
||||
})
|
||||
} else {
|
||||
resolve(videoPath)
|
||||
// 未知策略,兜底截断
|
||||
fallbackTrim(resolve)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user