File size: 1,940 Bytes
deae345
 
 
652f343
deae345
 
652f343
 
deae345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
652f343
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { saveCompletedTask } from "../database/saveCompletedTask.mts";
import { savePendingTask } from "../database/savePendingTask.mts";
import { updatePendingTask } from "../database/updatePendingTask.mts";
import { VideoTask } from "../types.mts";
import { downloadVideo } from "./downloadVideo.mts";
import { generateVideo } from "./generateVideo.mts";

export const processTask = async (task: VideoTask) => {
  console.log(`processing video task ${task.id}`)

  // something isn't right, the task is already completed
  if (task.completed) {
    console.log(`video task ${task.id} is already completed`)
    await saveCompletedTask(task)
    return
  }

  let nbCompletedShots = 0
  for (const shot of task.shots) {
    // skip completed shots
    if (shot.completed) {
      nbCompletedShots++
      continue
    }

    console.log(`need to complete shot ${shot.id}`)

    const shotFileName = `${shot.id}.mp4`

    if (!shot.hasGeneratedVideo) {
      console.log("generating primordial pixel soup (raw video)..")
      let generatedVideoUrl = ""

      // currenty we cannot generate too many frames at once,
      // otherwise the upscaler will have trouble

      // so for now, we fix it to 24 frames
      // const nbFramesForBaseModel = Math.min(3, Math.max(1, Math.round(duration))) * 8
      const nbFramesForBaseModel = 24

      try {
        generatedVideoUrl = await generateVideo(shot.shotPrompt, {
          seed: shot.seed,
          nbFrames: nbFramesForBaseModel,
          nbSteps: shot.steps,
        })

        console.log("downloading video..")

        await downloadVideo(generatedVideoUrl, shotFileName)

      } catch (err) {
        // something is wrong, let's put the whole thing back into the queue
        task.error = `failed to generate shot ${shot.id} (will try again later)`
        await updatePendingTask(task)
        break
      }

      
    }

    if (!shot.hasUpscaledVideo) {

    }

  }

}