diff --git a/.claude/skills/video-from-script/scripts/capcut_assemble.js b/.claude/skills/video-from-script/scripts/capcut_assemble.js index c7e254e..998b18b 100644 --- a/.claude/skills/video-from-script/scripts/capcut_assemble.js +++ b/.claude/skills/video-from-script/scripts/capcut_assemble.js @@ -177,7 +177,21 @@ async function assemble(args) { // 测量实际时长 let audioMeasured = 0, videoMeasured = 0 for (const item of items) { - if (item.audio && !item.audio.startsWith('http')) { + if (item.segments && item.segments.length > 0) { + let totalDur = 0 + for (const seg of item.segments) { + if (seg.audio && !seg.error) { + const segPath = path.isAbsolute(seg.audio) ? seg.audio : path.resolve(inputDir, seg.audio) + if (fs.existsSync(segPath)) { + const d = await getAudioDurationSec(segPath) + if (d != null) totalDur += d + } else if (seg.duration) { + totalDur += seg.duration + } + } + } + if (totalDur > 0) { item.audioDuration = totalDur; audioMeasured++ } + } else if (item.audio && !item.audio.startsWith('http')) { const audioPath = path.isAbsolute(item.audio) ? item.audio : path.resolve(inputDir, item.audio)