Tighten needsFit to exact canvas size, guard against empty renders

needsFit only compared aspect ratio, so a same-aspect-but-larger still
(e.g. a 4032x2268 phone photo against a 1344x768 canvas) would skip
fitting and hand MiniMaxH3AddGuide a still that does not match the
job's own latent size. Require an exact width+height match instead;
anything else (including unreadable dimensions) still fits.

Also guard the video save path: an empty Comfy download, an empty
stitched assembly, or a stitched result with no readable duration now
fails the job with a clear error instead of silently saving/attaching
a broken zero-length clip.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-11 23:11:02 -05:00
co-authored by Cursor
parent 65c69b779a
commit d8f42ecc68
4 changed files with 58 additions and 10 deletions
+5 -5
View File
@@ -12,12 +12,12 @@ export async function fitStill(data: Buffer, width: number, height: number) {
return readFileSync(output)
} finally { rmSync(dir,{recursive:true,force:true}) }
}
/** Only scale/pad when the still's aspect truly differs from the job canvas.
* A matching frame (typical extend handoff) must reach Comfy byte-identical. */
/** Only skip the scale+pad when the still already matches the job canvas pixel-for-pixel.
* A same-aspect-but-larger still (e.g. a 4032x2268 phone photo against a 1344x768 canvas)
* still needs fitting: MiniMaxH3AddGuide expects an image sized to the job's own latent,
* not merely the same aspect ratio. Unreadable dimensions always fit (safe default). */
export function needsFit(data: Buffer, width: number, height: number) {
const size = imageDimensions(data)
if (!size?.width || !size?.height) return true
if (size.width === width && size.height === height) return false
const target = width / height, actual = size.width / size.height
return Math.abs(target - actual) > 0.01
return !(size.width === width && size.height === height)
}