jbilcke-hf HF staff commited on
Commit
b2bd451
·
1 Parent(s): c08a992

let's hear it

Browse files
src/scheduler/processTask.mts CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import { saveCompletedTask } from "./saveCompletedTask.mts"
2
  import { savePendingTask } from "./savePendingTask.mts"
3
  import { updatePendingTask } from "./updatePendingTask.mts"
@@ -12,6 +14,9 @@ import { postInterpolation } from "../production/postInterpolation.mts"
12
  import { moveVideoFromPendingToCompleted } from "../utils/moveVideoFromPendingToCompleted.mts"
13
  import { assembleShots } from "../production/assembleShots.mts"
14
  import { copyVideoFromPendingToCompleted } from "../utils/copyVideoFromPendingToCompleted.mts"
 
 
 
15
 
16
  export const processTask = async (task: VideoTask) => {
17
  console.log(`processing video task ${task.id}`)
@@ -192,6 +197,34 @@ export const processTask = async (task: VideoTask) => {
192
  }
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  if (!shot.hasPostProcessedVideo) {
197
  console.log("post-processing video..")
@@ -204,7 +237,7 @@ export const processTask = async (task: VideoTask) => {
204
  console.log('performing final scaling (1280x720 @ 24 FPS)')
205
 
206
  try {
207
- await postInterpolation(shot.fileName, shot.durationMs, shot.fps)
208
 
209
  shot.hasPostProcessedVideo = true
210
  shot.nbCompletedSteps++
 
1
+ import { v4 as uuidv4 } from "uuid"
2
+
3
  import { saveCompletedTask } from "./saveCompletedTask.mts"
4
  import { savePendingTask } from "./savePendingTask.mts"
5
  import { updatePendingTask } from "./updatePendingTask.mts"
 
14
  import { moveVideoFromPendingToCompleted } from "../utils/moveVideoFromPendingToCompleted.mts"
15
  import { assembleShots } from "../production/assembleShots.mts"
16
  import { copyVideoFromPendingToCompleted } from "../utils/copyVideoFromPendingToCompleted.mts"
17
+ import { generateAudio } from "../production/generateAudio.mts"
18
+ import { mergeAudio } from "../production/mergeAudio.mts"
19
+ import { addAudioToVideo } from "../production/addAudioToVideo.mts"
20
 
21
  export const processTask = async (task: VideoTask) => {
22
  console.log(`processing video task ${task.id}`)
 
197
  }
198
  }
199
 
200
+
201
+ let foregroundAudioFileName = `${task.ownerId}_${task.id}_${shot.id}_${uuidv4()}.m4a`
202
+
203
+ if (!shot.hasGeneratedForegroundAudio && shot.foregroundAudioPrompt) {
204
+ console.log("generating foreground audio..")
205
+
206
+ try {
207
+ await generateAudio(shot.foregroundAudioPrompt, foregroundAudioFileName)
208
+
209
+ shot.hasGeneratedForegroundAudio = true
210
+ shot.nbCompletedSteps++
211
+ nbCompletedSteps++
212
+ shot.progressPercent = Math.round((shot.nbCompletedSteps / shot.nbTotalSteps) * 100)
213
+ task.progressPercent = Math.round((nbCompletedSteps / nbTotalSteps) * 100)
214
+
215
+ await addAudioToVideo(shot.fileName, foregroundAudioFileName)
216
+
217
+ await updatePendingTask(task)
218
+
219
+ } catch (err) {
220
+ console.error(`failed to generate foreground audio for ${shot.id} (${err})`)
221
+ // something is wrong, let's put the whole thing back into the queue
222
+ task.error = `failed to generate foreground audio ${shot.id} (will try again later)`
223
+ await updatePendingTask(task)
224
+ break
225
+ }
226
+ }
227
+
228
 
229
  if (!shot.hasPostProcessedVideo) {
230
  console.log("post-processing video..")
 
237
  console.log('performing final scaling (1280x720 @ 24 FPS)')
238
 
239
  try {
240
+ await postInterpolation(shot.fileName, shot.durationMs, shot.fps, shot.noiseAmount)
241
 
242
  shot.hasPostProcessedVideo = true
243
  shot.nbCompletedSteps++
src/utils/parseShotRequest.mts CHANGED
@@ -21,7 +21,7 @@ export const parseShotRequest = async (sequence: VideoSequence, maybeShotMeta: P
21
  backgroundAudioPrompt: `${maybeShotMeta.backgroundAudioPrompt || ""}`,
22
 
23
  // describe the foreground audio (cars revving, footsteps, objects breaking, explosion etc)
24
- foregroundAudioPrompt: `${maybeShotMeta.foregroundAudioPrompt || ""}`,
25
 
26
  // describe the main actor visible in the shot (optional)
27
  actorPrompt: `${maybeShotMeta.actorPrompt || ""}`,
@@ -70,15 +70,14 @@ export const parseShotRequest = async (sequence: VideoSequence, maybeShotMeta: P
70
  hasPostProcessedVideo: false,
71
  nbCompletedSteps: 0,
72
 
73
- // 0. in queue
74
- // 1. generate with Zeroscope
75
- // 2. upscale with Zeroscope XL
76
- // 3. interpolate with FILE
77
- // 4. generate audio background
78
- // 5. generate audio foreground
79
- // 6. add audio to video
80
- // 7. post-processing
81
- nbTotalSteps: 7,
82
  progressPercent: 0,
83
  completedAt: '',
84
  completed: false,
 
21
  backgroundAudioPrompt: `${maybeShotMeta.backgroundAudioPrompt || ""}`,
22
 
23
  // describe the foreground audio (cars revving, footsteps, objects breaking, explosion etc)
24
+ foregroundAudioPrompt: `${maybeShotMeta.foregroundAudioPrompt || maybeShotMeta.shotPrompt || ""}`,
25
 
26
  // describe the main actor visible in the shot (optional)
27
  actorPrompt: `${maybeShotMeta.actorPrompt || ""}`,
 
70
  hasPostProcessedVideo: false,
71
  nbCompletedSteps: 0,
72
 
73
+ // - generate with Zeroscope
74
+ // - upscale with Zeroscope XL
75
+ // - interpolate with FILE
76
+ // - generate audio background
77
+ // - generate audio foreground
78
+ // - add audio to video
79
+ // - post-processing
80
+ nbTotalSteps: 5,
 
81
  progressPercent: 0,
82
  completedAt: '',
83
  completed: false,