Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
|
|
|
| 6 |
|
| 7 |
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
|
| 8 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
|
@@ -13,21 +14,15 @@ def export_to_video(video_frames):
|
|
| 13 |
video_frames = np.array(video_frames)
|
| 14 |
video_frames = (video_frames * 255).astype(np.uint8)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for .mp4 files
|
| 21 |
fps = 24 # Frames per second
|
| 22 |
-
|
| 23 |
|
| 24 |
-
# Write
|
| 25 |
-
|
| 26 |
-
frame = video_frames[i]
|
| 27 |
-
video_writer.write(frame)
|
| 28 |
-
|
| 29 |
-
# Release the video writer object
|
| 30 |
-
video_writer.release()
|
| 31 |
|
| 32 |
print("Video has been created successfully.")
|
| 33 |
return 'output_video.mp4'
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import torch
|
| 5 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 6 |
+
from moviepy.editor import ImageSequenceClip
|
| 7 |
|
| 8 |
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
|
| 9 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
|
|
|
| 14 |
video_frames = np.array(video_frames)
|
| 15 |
video_frames = (video_frames * 255).astype(np.uint8)
|
| 16 |
|
| 17 |
+
# Convert frames from (N, H, W, C) to list of (H, W, C)
|
| 18 |
+
frames_list = [frame for frame in video_frames]
|
| 19 |
|
| 20 |
+
# Create a video clip from the frames
|
|
|
|
| 21 |
fps = 24 # Frames per second
|
| 22 |
+
clip = ImageSequenceClip(frames_list, fps=fps)
|
| 23 |
|
| 24 |
+
# Write the video file
|
| 25 |
+
clip.write_videofile("output_video.mp4", codec="libx264")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
print("Video has been created successfully.")
|
| 28 |
return 'output_video.mp4'
|