fix(video-pipeline): 自动修复上传前引用的候选图片路径并修复音频时长精度
在 `phase-upload` 中添加 `autoFixFile` 逻辑,当 `item.file` 指向不存在的文件时,自动从 `candidates` 中匹配实际存在的文件并更新 `item.file`,避免上传阶段因用户手动换图删除候选文件而导致失败。同时修复 `capcut-timeline` 音频/视频时长计算,使用 `Math.round` 避免微秒级浮点精度问题。
This commit is contained in:
@@ -128,7 +128,7 @@ node scripts/pipeline.js run --manifest <path> --phase images
|
|||||||
|
|
||||||
### Step 2-C: 人工确认(可跳过)
|
### Step 2-C: 人工确认(可跳过)
|
||||||
|
|
||||||
展示分镜图给用户 → 用户可确认全部 / 替换候选图 / 删除不合格项。
|
告知图片路径给用户自行查看 → 用户可确认全部 / 替换候选图 / 删除不合格项。
|
||||||
用户确认后 `pipeline.js confirm --manifest <path> --all`,跳过则批量设置 `confirmed=true`。
|
用户确认后 `pipeline.js confirm --manifest <path> --all`,跳过则批量设置 `confirmed=true`。
|
||||||
|
|
||||||
### Step 3-A: 视频提示词(B 模式专属,子 Agent 执行)
|
### Step 3-A: 视频提示词(B 模式专属,子 Agent 执行)
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ const { US } = require('./capcut-api')
|
|||||||
function buildTimeline(items) {
|
function buildTimeline(items) {
|
||||||
let offset = 0
|
let offset = 0
|
||||||
return items.map(item => {
|
return items.map(item => {
|
||||||
const audioDur = (item.audioDuration != null) ? item.audioDuration * US : 0
|
const audioDur = Math.round((item.audioDuration != null) ? item.audioDuration * US : 0)
|
||||||
const videoDur = (item.videoDuration != null) ? item.videoDuration * US : 0
|
const videoDur = Math.round((item.videoDuration != null) ? item.videoDuration * US : 0)
|
||||||
const hasVideo = !!(item.video || item.videoUrl || item.url)
|
const hasVideo = !!(item.video || item.videoUrl || item.url)
|
||||||
|
|
||||||
// 无 TTS 音频
|
// 无 TTS 音频
|
||||||
|
|||||||
@@ -5,12 +5,53 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
const { saveManifest, log, getManifestDir } = require('./pipeline-utils')
|
const { saveManifest, log, getManifestDir } = require('./pipeline-utils')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动修复 item.file:如果当前 file 不存在,从 candidates 中匹配实际存在的文件。
|
||||||
|
* 用户手动换图时可能删除了非选中候选,导致 file 指向不存在的文件。
|
||||||
|
*/
|
||||||
|
function autoFixFile(item, dir) {
|
||||||
|
const currentPath = path.resolve(dir, item.file)
|
||||||
|
if (fs.existsSync(currentPath)) return false
|
||||||
|
|
||||||
|
const cands = item.candidates || []
|
||||||
|
const existing = cands.filter(c => fs.existsSync(path.resolve(dir, c)))
|
||||||
|
|
||||||
|
if (existing.length === 0) {
|
||||||
|
log('upload', ` ⚠ ${item.file} 不存在,candidates 中也没有文件`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldFile = item.file
|
||||||
|
const candMatch = oldFile.match(/_cand(\d+)\./)
|
||||||
|
const targetCand = candMatch ? `_cand${candMatch[1]}.` : null
|
||||||
|
const matched = targetCand
|
||||||
|
? (existing.find(c => c.includes(targetCand)) || existing[0])
|
||||||
|
: existing[0]
|
||||||
|
|
||||||
|
item.file = matched
|
||||||
|
log('upload', ` 🔧 ${path.basename(oldFile)} → ${path.basename(matched)} (${existing.length}/${cands.length} 候选存在)`)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
async function phaseUpload(manifest, manifestPath) {
|
async function phaseUpload(manifest, manifestPath) {
|
||||||
const dir = getManifestDir(manifestPath)
|
const dir = getManifestDir(manifestPath)
|
||||||
const { uploadFile } = require('../oss-upload')
|
const { uploadFile } = require('../oss-upload')
|
||||||
|
|
||||||
|
// 自动修复:用户手动换图后 file 可能指向已删除的候选
|
||||||
|
let fixedCount = 0
|
||||||
|
for (const item of manifest.items) {
|
||||||
|
if (item.status === 'done' && item.file && !item.url) {
|
||||||
|
if (autoFixFile(item, dir)) fixedCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fixedCount > 0) {
|
||||||
|
saveManifest(manifestPath, manifest)
|
||||||
|
log('upload', `已自动修复 ${fixedCount} 个 file 路径`)
|
||||||
|
}
|
||||||
|
|
||||||
// 图片(含首尾帧 first frame)
|
// 图片(含首尾帧 first frame)
|
||||||
const imageItems = manifest.items.filter(it =>
|
const imageItems = manifest.items.filter(it =>
|
||||||
it.status === 'done' && it.file && !it.url
|
it.status === 'done' && it.file && !it.url
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"imageStylePrompt": "prompts/图片提示词.md",
|
"imageStylePrompt": "prompts/图片提示词.md",
|
||||||
"videoStylePrompt": "prompts/视频提示词.md",
|
"videoStylePrompt": "prompts/视频提示词.md",
|
||||||
"references": [
|
"references": [
|
||||||
{ "file": "0_3.png", "url": "https://muye-ai-chat.oss-cn-hangzhou.aliyuncs.com/tmp/0_3.png" }
|
{ "file": "mj-image.jpg", "url": "https://muye-ai-chat.oss-cn-hangzhou.aliyuncs.com/tmp/mj-image.jpg?OSSAccessKeyId=LTAI5tPV9Ag3csf41GZjaLTA&Expires=1809282229&Signature=knoxb7C0u133hwslYW4MhrO2KOs%3D" }
|
||||||
],
|
],
|
||||||
"capcut": {
|
"capcut": {
|
||||||
"effects": [],
|
"effects": [],
|
||||||
|
|||||||
BIN
accounts/瞬息实验室/references/mj-image.jpg
Normal file
BIN
accounts/瞬息实验室/references/mj-image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 396 KiB |
Reference in New Issue
Block a user