Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,7 @@ import tempfile
|
|
4 |
import numpy as np
|
5 |
import cv2
|
6 |
from PIL import Image
|
7 |
-
|
8 |
-
# from moviepy.editor import ImageClip, AudioFileClip, CompositeVideoClip
|
9 |
-
from moviepy import VideoFileClip, ImageClip, AudioFileClip, CompositeVideoClip
|
10 |
import random
|
11 |
import time
|
12 |
|
@@ -78,8 +76,8 @@ def add_sparkle_effect(frame, density=0.001):
|
|
78 |
def create_video(image_path, audio_path, effect_type, output_path, fps=24):
|
79 |
"""Create a video from an image and audio with the selected effect"""
|
80 |
# Load audio to get duration
|
81 |
-
|
82 |
-
duration =
|
83 |
|
84 |
# Load image
|
85 |
img = cv2.imread(image_path)
|
@@ -130,13 +128,21 @@ def create_video(image_path, audio_path, effect_type, output_path, fps=24):
|
|
130 |
# Release the video writer
|
131 |
out.release()
|
132 |
|
133 |
-
#
|
134 |
-
video
|
135 |
-
|
136 |
-
video.write_videofile(output_path, codec='libx264')
|
137 |
|
138 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
os.remove(temp_video_path)
|
|
|
|
|
|
|
140 |
|
141 |
progress_bar.progress(1.0)
|
142 |
return output_path
|
|
|
4 |
import numpy as np
|
5 |
import cv2
|
6 |
from PIL import Image
|
7 |
+
from moviepy import AudioFileClip, VideoFileClip, ImageClip
|
|
|
|
|
8 |
import random
|
9 |
import time
|
10 |
|
|
|
76 |
def create_video(image_path, audio_path, effect_type, output_path, fps=24):
|
77 |
"""Create a video from an image and audio with the selected effect"""
|
78 |
# Load audio to get duration
|
79 |
+
audio_clip = AudioFileClip(audio_path)
|
80 |
+
duration = audio_clip.duration
|
81 |
|
82 |
# Load image
|
83 |
img = cv2.imread(image_path)
|
|
|
128 |
# Release the video writer
|
129 |
out.release()
|
130 |
|
131 |
+
# Alternative approach using direct moviepy functionalities
|
132 |
+
# First create a mute video clip
|
133 |
+
video_clip = VideoFileClip(temp_video_path)
|
|
|
134 |
|
135 |
+
# Then set its audio to our audio clip
|
136 |
+
final_clip = video_clip.set_audio(audio_clip)
|
137 |
+
|
138 |
+
# Write the result to our output file
|
139 |
+
final_clip.write_videofile(output_path, codec='libx264')
|
140 |
+
|
141 |
+
# Clean up temporary file and close clips
|
142 |
os.remove(temp_video_path)
|
143 |
+
video_clip.close()
|
144 |
+
audio_clip.close()
|
145 |
+
final_clip.close()
|
146 |
|
147 |
progress_bar.progress(1.0)
|
148 |
return output_path
|