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>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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
|
||||
})
|
||||
Reference in New Issue
Block a user