Spaces:
Runtime error
Runtime error
zfff
Browse files- requirements.txt +2 -1
- video_generator.py +37 -4
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ librosa
|
|
| 3 |
numpy
|
| 4 |
requests
|
| 5 |
stability-sdk
|
| 6 |
-
|
|
|
|
|
|
| 3 |
numpy
|
| 4 |
requests
|
| 5 |
stability-sdk
|
| 6 |
+
Opencv-python-headless
|
| 7 |
+
replicate
|
video_generator.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def generate_lyric_frame(text, image_size):
|
| 4 |
# Create an image object
|
|
@@ -15,15 +17,46 @@ def generate_lyric_frame(text, image_size):
|
|
| 15 |
draw.text((text_x, text_y), text, font=font, fill='white')
|
| 16 |
return image
|
| 17 |
|
| 18 |
-
def generate_video(lyrics_with_timing, image_size=(800, 600),
|
| 19 |
-
# Placeholder for configuring the animation
|
| 20 |
-
# ...
|
| 21 |
-
|
| 22 |
frames = []
|
| 23 |
for start_time, end_time, lyric in lyrics_with_timing:
|
| 24 |
# Calculate the number of frames for this lyric segment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def extract_last_frame_from_video(video):
|
| 27 |
# Your code to extract the last frame from the video
|
| 28 |
last_frame_image = None # Replace with actual image object
|
| 29 |
return last_frame_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont
|
| 2 |
+
import cv2
|
| 3 |
+
|
| 4 |
|
| 5 |
def generate_lyric_frame(text, image_size):
|
| 6 |
# Create an image object
|
|
|
|
| 17 |
draw.text((text_x, text_y), text, font=font, fill='white')
|
| 18 |
return image
|
| 19 |
|
| 20 |
+
def generate_video(lyrics_with_timing, image_size=(800, 600), frame_rate=30):
|
|
|
|
|
|
|
|
|
|
| 21 |
frames = []
|
| 22 |
for start_time, end_time, lyric in lyrics_with_timing:
|
| 23 |
# Calculate the number of frames for this lyric segment
|
| 24 |
+
num_frames = int((end_time - start_time) * frame_rate)
|
| 25 |
+
|
| 26 |
+
# Create frames with the lyric text
|
| 27 |
+
for _ in range(num_frames):
|
| 28 |
+
frame = generate_lyric_frame(lyric, image_size)
|
| 29 |
+
frames.append(frame)
|
| 30 |
+
|
| 31 |
+
# Combine frames into a video (replace with your preferred method)
|
| 32 |
+
video = combine_frames_into_video(frames, frame_rate)
|
| 33 |
+
return video
|
| 34 |
|
| 35 |
def extract_last_frame_from_video(video):
|
| 36 |
# Your code to extract the last frame from the video
|
| 37 |
last_frame_image = None # Replace with actual image object
|
| 38 |
return last_frame_image
|
| 39 |
+
|
| 40 |
+
def combine_frames_into_video(frames, frame_rate):
|
| 41 |
+
# Get the size of the frames
|
| 42 |
+
height, width, _ = frames[0].shape
|
| 43 |
+
|
| 44 |
+
# Define the codec and create a video writer object
|
| 45 |
+
fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
| 46 |
+
out = cv2.VideoWriter('output.avi', fourcc, frame_rate, (width, height))
|
| 47 |
+
|
| 48 |
+
# Write each frame to the video file
|
| 49 |
+
for frame in frames:
|
| 50 |
+
# Convert PIL image to NumPy array if the frames are PIL images
|
| 51 |
+
frame_np = np.array(frame)
|
| 52 |
+
|
| 53 |
+
# Convert RGB to BGR as OpenCV uses BGR format
|
| 54 |
+
frame_bgr = cv2.cvtColor(frame_np, cv2.COLOR_RGB2BGR)
|
| 55 |
+
|
| 56 |
+
# Write the BGR frame to the video
|
| 57 |
+
out.write(frame_bgr)
|
| 58 |
+
|
| 59 |
+
# Release the video writer object
|
| 60 |
+
out.release()
|
| 61 |
+
|
| 62 |
+
return 'output.avi'
|