Spaces:
Runtime error
Runtime error
besarismaili
commited on
Commit
•
77eaefe
1
Parent(s):
830ea02
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import cv2
|
|
|
3 |
import gradio as gr
|
4 |
from stability_sdk.api import Context
|
5 |
from stability_sdk.animation import AnimationArgs, Animator
|
@@ -111,28 +112,24 @@ def anim(f_promt, s_promt, stability_key, cadence_interp, width ,height ,sampler
|
|
111 |
|
112 |
if not os.path.exists(output_dir):
|
113 |
os.makedirs(output_dir)
|
114 |
-
|
115 |
-
#
|
116 |
-
|
|
|
|
|
|
|
117 |
for idx, frame in enumerate(animator.render()):
|
118 |
-
|
119 |
-
frame.
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
# Define the codec using VideoWriter_fourcc() and create a VideoWriter object
|
124 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # or use 'XVID'
|
125 |
-
height, width, _ = cv2.imread(images[0]).shape # get the frame size from the first image
|
126 |
-
video_path = os.path.join(output_dir, 'output.mp4') # specify your output video file path here
|
127 |
-
out = cv2.VideoWriter(video_path, fourcc, fps, (width, height))
|
128 |
-
|
129 |
-
# Write each frame to the video file
|
130 |
-
for image_path in images:
|
131 |
-
frame = cv2.imread(image_path)
|
132 |
-
out.write(frame)
|
133 |
|
134 |
# Release the VideoWriter
|
135 |
-
|
|
|
|
|
|
|
136 |
|
137 |
with gr.Blocks() as demo:
|
138 |
gr.Markdown("Stability Animation 1")
|
|
|
1 |
import os
|
2 |
import cv2
|
3 |
+
import numpy as np
|
4 |
import gradio as gr
|
5 |
from stability_sdk.api import Context
|
6 |
from stability_sdk.animation import AnimationArgs, Animator
|
|
|
112 |
|
113 |
if not os.path.exists(output_dir):
|
114 |
os.makedirs(output_dir)
|
115 |
+
|
116 |
+
# Define the codec using VideoWriter_fourcc and create a VideoWriter object
|
117 |
+
# We specify output file name as output.avi, codec as MJPG, fps as 25.0, and frame size as (width, height)
|
118 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
119 |
+
video = cv2.VideoWriter('output.mp4', fourcc, 25.0, (width, height))
|
120 |
+
|
121 |
for idx, frame in enumerate(animator.render()):
|
122 |
+
# Convert the image from BGR to RGB format
|
123 |
+
frame = cv2.cvtColor(np.array(frame), cv2.COLOR_RGB2BGR)
|
124 |
+
# Write the RGB image to file
|
125 |
+
video.write(frame)
|
126 |
+
print(f"Added frame {idx} to video.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
# Release the VideoWriter
|
129 |
+
video.release()
|
130 |
+
print("Video created successfully!")
|
131 |
+
|
132 |
+
|
133 |
|
134 |
with gr.Blocks() as demo:
|
135 |
gr.Markdown("Stability Animation 1")
|