feat(video-from-script): 支持分段音频时长测量
为 `capcut_assemble.js` 中的 item 增加 segments 属性支持,当 item 包含多个音频分段时,计算各分段总时长并赋给 `audioDuration`,提升对分段式音轨素材的处理能力。
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user