From 7b743dc701d5328bac6a82fa7e518a894e756ca5 Mon Sep 17 00:00:00 2001 From: sion123 <450702724@qq.com> Date: Tue, 12 May 2026 01:08:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(video-from-script):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=86=E6=AE=B5=E9=9F=B3=E9=A2=91=E6=97=B6=E9=95=BF=E6=B5=8B?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 `capcut_assemble.js` 中的 item 增加 segments 属性支持,当 item 包含多个音频分段时,计算各分段总时长并赋给 `audioDuration`,提升对分段式音轨素材的处理能力。 --- .../video-from-script/scripts/capcut_assemble.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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)