File size: 2,577 Bytes
f64828c
a99b4ac
 
07ae658
a99b4ac
07ae658
a99b4ac
f64828c
 
07ae658
 
 
a99b4ac
07ae658
f64828c
 
07ae658
 
f64828c
 
 
07ae658
66f11df
 
 
 
 
07ae658
f64828c
07ae658
f64828c
 
 
 
 
 
f132701
f64828c
a99b4ac
 
0cf8825
 
f64828c
0cf8825
 
 
f64828c
0cf8825
a99b4ac
 
f64828c
a99b4ac
 
f64828c
66f11df
f64828c
a99b4ac
 
07ae658
 
 
66f11df
 
 
 
 
 
 
 
 
 
 
07ae658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { v4 as uuid } from 'uuid'
import { upscaleVideo } from './upscaleVideo.mts'
import { keepVideo } from './keepVideo.mts'

import { demoPrompts } from './prompts.mts'
import { getStats } from './getStats.mts'
import { enhanceVideo } from './enhanceVideo.mts'
import { callZeroscope } from './callZeroscope.mts'
import { downloadVideo } from './downloadVideo.mts'

const main = async () => {
  console.log('Generating ideas..')
  const ideas = demoPrompts

  console.log('Generating videos sequences..')
  const instanceId = process.env.WEBTV_WORKER_INSTANCE_ID || '0'

  for (const { input, captions } of ideas) {
    console.log(`\nVideo sequence to generate: ${input}`)

    const sequenceId = uuid()

    const silentVideos: string[] = []

    // this is hardcoded everywhere for now, since videos longer than 3 sec require the Nvidia A100
    const videoDurationInSecs = 3

    for (const caption of captions) {
      console.log(`- generating shot: ${caption}`)
      try {
        const generatedVideoUrl = await callZeroscope(caption)

        const videoName = `inst_${instanceId}_seq_${sequenceId}_shot_${Date.now()}.mp4`

        console.log(`- downloading ${videoName} from ${generatedVideoUrl}`)
        await downloadVideo(generatedVideoUrl, videoName)

        console.log(`- downloaded ${videoName}`)

        console.log('- upscaling video..')
      
        try {
          await upscaleVideo(videoName, caption)
        } catch (err) {
          // upscaling is finicky, if it fails we try again
          console.log('- trying again to upscale video..')
          await upscaleVideo(videoName, caption)
        }

        console.log('- enhancing video..')
        await enhanceVideo(videoName)

        console.log('- saving final video..')
        await keepVideo(videoName, process.env.WEBTV_VIDEO_STORAGE_PATH_NEXT)

        silentVideos.push(videoName)

        console.log('- done!')
      } catch (err) {
        console.log(`- error: ${err}`)
      }

      const totalRunTime = videoDurationInSecs * silentVideos.length

      if (totalRunTime <= 0) {
        continue
      }

      console.log(`TODO: generate ${totalRunTime} seconds of music`)
      // TODO: generate music from MusicGen, with the correct length
      // (or we could generate a slightly larger track and let ffmpeg cut it)

    }  

    console.log('Finished gerating all video sequences')

    console.log('Current stats:', await getStats())
  }

  console.log('Finished the full cycle')
  setTimeout(() => {
    main()
  }, 3000)
}

setTimeout(() => {
  main()
}, 3000)