Files
aigen/server/api/library/clips/[id]/last-frame.get.ts
T
TowstyandCursor e81f12f89a Add clip extension from the last frame with FFmpeg stitching.
Let a finished player continue into a new MiniMax segment, then losslessly concat the parts and discard the intermediate files so the library keeps one extended MP4.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-25 23:06:58 -05:00

26 lines
975 B
TypeScript

import { existsSync, readFileSync } from 'node:fs'
export default defineEventHandler(async (event) => {
const { owner } = assertLibraryOwner(event)
const id = String(getRouterParam(event, 'id') || '')
const clip = getClip(owner, id)
assertFolderAccess(event, clip.folderId)
const videoPath = clipVideoPath(owner, clip.id)
if (!existsSync(videoPath)) {
throw createError({ statusCode: 404, statusMessage: 'Video file is missing' })
}
const framePath = clipLastFramePath(owner, clip.id)
if (!existsSync(framePath)) {
try {
await extractLastFrame(videoPath, framePath)
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
throw createError({ statusCode: 500, statusMessage: `Could not extract the last frame: ${message}` })
}
}
const buf = readFileSync(framePath)
setHeader(event, 'Content-Type', 'image/png')
setHeader(event, 'Cache-Control', 'private, no-store')
return buf
})