Add retry logic with timeout to extractLastFrame to handle temporary file access issues in shot scripts
This commit is contained in:
+15
-2
@@ -70,6 +70,11 @@ export async function extractLastFrame(inputPath: string, outputPath: string) {
|
||||
throw new Error('Source video is missing')
|
||||
}
|
||||
|
||||
const maxTotalTimeMs = 5000
|
||||
const start = Date.now()
|
||||
let delayMs = 100
|
||||
|
||||
while (Date.now() - start < maxTotalTimeMs) {
|
||||
const attempts: string[][] = []
|
||||
try {
|
||||
const duration = await probeDuration(inputPath)
|
||||
@@ -88,11 +93,19 @@ export async function extractLastFrame(inputPath: string, outputPath: string) {
|
||||
await runFfmpeg(args, 60000)
|
||||
if (existsSync(outputPath) && statSync(outputPath).size >= 64) return
|
||||
} catch {
|
||||
// Try the next seek strategy.
|
||||
// Try next strategy
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Could not extract the last frame. The video looks incomplete — interrupting Comfy mid-encode usually causes this. Earlier saved parts are still in the library.')
|
||||
const elapsed = Date.now() - start
|
||||
if (elapsed >= maxTotalTimeMs) break
|
||||
|
||||
const wait = Math.min(delayMs, maxTotalTimeMs - elapsed)
|
||||
await new Promise(resolve => setTimeout(resolve, wait))
|
||||
delayMs = Math.min(delayMs * 2, maxTotalTimeMs - (Date.now() - start))
|
||||
}
|
||||
|
||||
throw new Error('Could not extract the last frame within the timeout. The video may still be encoding or is incomplete.')
|
||||
}
|
||||
|
||||
export async function extractFirstFrame(inputPath: string, outputPath: string) {
|
||||
|
||||
Reference in New Issue
Block a user