| | import { v4 as uuidv4, validate as uuidValidate } from "uuid" |
| | import { HfInference } from "@huggingface/inference" |
| |
|
| | |
| |
|
| | import { VideoAPIRequest, Video } from "../types.mts" |
| | import { getValidNumber } from "./getValidNumber.mts" |
| | import { getValidResolution } from "./getValidResolution.mts" |
| | import { parseShotRequest } from "./parseShotRequest.mts" |
| | import { generateSeed } from "./generateSeed.mts" |
| | import { sequenceFormatVersion } from "../config.mts" |
| |
|
| | |
| | |
| |
|
| | export const parseVideoRequest = async (ownerId: string, request: VideoAPIRequest): Promise<Video> => { |
| | |
| | |
| | const id = uuidv4() |
| |
|
| | if (typeof request.prompt === "string" && request.prompt.length > 0) { |
| | console.log("we have a valid prompt:", request.prompt) |
| | |
| | request.sequence = { |
| | videoPrompt: request.prompt, |
| | } |
| | request.shots = [{ |
| | shotPrompt: request.prompt, |
| | environmentPrompt: "", |
| | photographyPrompt: "", |
| | actionPrompt: "", |
| | }] |
| | } |
| |
|
| | |
| | const video: Video = { |
| | |
| | id, |
| |
|
| | ownerId, |
| |
|
| | |
| | videoPrompt: `${request.sequence.videoPrompt || ''}`, |
| |
|
| | |
| | backgroundAudioPrompt: `${request.sequence.backgroundAudioPrompt || ''}`, |
| |
|
| | |
| | foregroundAudioPrompt: `${request.sequence.foregroundAudioPrompt || ''}`, |
| |
|
| | |
| | actorPrompt: `${request.sequence.actorPrompt || ''}`, |
| |
|
| | |
| | actorVoicePrompt: `${request.sequence.actorVoicePrompt || ''}`, |
| |
|
| | |
| | actorDialoguePrompt: `${request.sequence.actorDialoguePrompt || ''}`, |
| |
|
| | seed: getValidNumber(request.sequence.seed, 0, 2147483647, generateSeed()), |
| |
|
| | noise: request.sequence.noise === true, |
| | noiseAmount: request.sequence.noise === true ? 2 : 0, |
| |
|
| | steps: getValidNumber(request.sequence.steps, 10, 50, 45), |
| |
|
| | fps: getValidNumber(request.sequence.fps, 8, 60, 30), |
| |
|
| | resolution: getValidResolution(request.sequence.resolution), |
| |
|
| | outroTransition: 'staticfade', |
| | outroDurationMs: 3000, |
| |
|
| | |
| | version: sequenceFormatVersion, |
| | fileName: `${ownerId}_${id}.mp4`, |
| | status: "pending", |
| | hasAssembledVideo: false, |
| | hasGeneratedSpecs: false, |
| | nbCompletedShots: 0, |
| | progressPercent: 0, |
| | createdAt: new Date().toISOString(), |
| | completedAt: null, |
| | completed: false, |
| | error: '', |
| |
|
| |
|
| | |
| |
|
| | shots: [], |
| | } |
| |
|
| | |
| | const maybeShots = Array.isArray(request.shots) ? request.shots : [] |
| |
|
| | |
| | for (const maybeShot of maybeShots) { |
| | |
| | try { |
| | const shot = await parseShotRequest(video, maybeShot) |
| | video.shots.push(shot) |
| | } catch (err) { |
| | console.log(`error parsing shot: `, maybeShot) |
| | } |
| |
|
| | } |
| |
|
| | return video |
| | } |