Spaces:
Running
Running
walter2161
commited on
Commit
•
1dae8a0
1
Parent(s):
c316797
Update app.py
Browse files
app.py
CHANGED
@@ -139,12 +139,12 @@ def add_narration_to_video(narrations, input_video, output_dir, output_file, tex
|
|
139 |
cap = cv2.VideoCapture(input_video)
|
140 |
fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
141 |
temp_video = os.path.join(output_dir, "with_transcript.avi")
|
142 |
-
out = cv2.VideoWriter(temp_video, fourcc,
|
143 |
full_narration = AudioSegment.empty()
|
144 |
for i, narration in enumerate(narrations):
|
145 |
audio = os.path.join(output_dir, "narrations", f"narration_{i+1}.wav")
|
146 |
duration = get_audio_duration(audio)
|
147 |
-
narration_frames = math.floor(duration /
|
148 |
full_narration += AudioSegment.from_file(audio)
|
149 |
char_count = len(narration.replace(" ", ""))
|
150 |
ms_per_char = duration / char_count
|
@@ -156,7 +156,7 @@ def add_narration_to_video(narrations, input_video, output_dir, output_file, tex
|
|
156 |
word_ms -= offset
|
157 |
if word_ms < 0:
|
158 |
word_ms = 0
|
159 |
-
for _ in range(math.floor(word_ms/
|
160 |
ret, frame = cap.read()
|
161 |
if not ret:
|
162 |
break
|
@@ -193,8 +193,8 @@ def add_narration_to_video(narrations, input_video, output_dir, output_file, tex
|
|
193 |
|
194 |
def create_video(narrations, output_dir, output_file, text_color, text_position): # Add text_color and text_position parameters here
|
195 |
width, height = 1080, 1920
|
196 |
-
frame_rate =
|
197 |
-
fade_time =
|
198 |
fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
199 |
temp_video = os.path.join(output_dir, "temp_video.avi")
|
200 |
out = cv2.VideoWriter(temp_video, fourcc, frame_rate, (width, height))
|
@@ -214,7 +214,7 @@ def create_video(narrations, output_dir, output_file, text_color, text_position)
|
|
214 |
duration -= fade_time
|
215 |
if i == image_count-1:
|
216 |
duration -= fade_time
|
217 |
-
for _ in range(math.floor(duration/
|
218 |
vertical_video_frame = np.zeros((height, width, 3), dtype=np.uint8)
|
219 |
vertical_video_frame[:image1.shape[0], :] = image1
|
220 |
out.write(vertical_video_frame)
|
@@ -251,7 +251,7 @@ def generate_video(topic, voice_choice):
|
|
251 |
},
|
252 |
{
|
253 |
"role": "user",
|
254 |
-
"content": f"""make a short video on: \n\n{topic} Generate
|
255 |
[Description of a background image]
|
256 |
Narrator: "One sentence of narration"
|
257 |
### The short should be 6 sentences maximum."""
|
|
|
139 |
cap = cv2.VideoCapture(input_video)
|
140 |
fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
141 |
temp_video = os.path.join(output_dir, "with_transcript.avi")
|
142 |
+
out = cv2.VideoWriter(temp_video, fourcc, 60, (int(cap.get(3)), int(cap.get(4))))
|
143 |
full_narration = AudioSegment.empty()
|
144 |
for i, narration in enumerate(narrations):
|
145 |
audio = os.path.join(output_dir, "narrations", f"narration_{i+1}.wav")
|
146 |
duration = get_audio_duration(audio)
|
147 |
+
narration_frames = math.floor(duration / 2000 * 60)
|
148 |
full_narration += AudioSegment.from_file(audio)
|
149 |
char_count = len(narration.replace(" ", ""))
|
150 |
ms_per_char = duration / char_count
|
|
|
156 |
word_ms -= offset
|
157 |
if word_ms < 0:
|
158 |
word_ms = 0
|
159 |
+
for _ in range(math.floor(word_ms/2000*60)):
|
160 |
ret, frame = cap.read()
|
161 |
if not ret:
|
162 |
break
|
|
|
193 |
|
194 |
def create_video(narrations, output_dir, output_file, text_color, text_position): # Add text_color and text_position parameters here
|
195 |
width, height = 1080, 1920
|
196 |
+
frame_rate = 60
|
197 |
+
fade_time = 2000
|
198 |
fourcc = cv2.VideoWriter_fourcc(*'XVID')
|
199 |
temp_video = os.path.join(output_dir, "temp_video.avi")
|
200 |
out = cv2.VideoWriter(temp_video, fourcc, frame_rate, (width, height))
|
|
|
214 |
duration -= fade_time
|
215 |
if i == image_count-1:
|
216 |
duration -= fade_time
|
217 |
+
for _ in range(math.floor(duration/2000*60)):
|
218 |
vertical_video_frame = np.zeros((height, width, 3), dtype=np.uint8)
|
219 |
vertical_video_frame[:image1.shape[0], :] = image1
|
220 |
out.write(vertical_video_frame)
|
|
|
251 |
},
|
252 |
{
|
253 |
"role": "user",
|
254 |
+
"content": f"""make a short video on: \n\n{topic} Generate 60 seconds to 1 minute of video. You will need to generate a very short description of images for each of the sentences. They will be used for background images. Note that the script will be fed into a text-to-speech engine, so dont use special characters. Respond with a pair of an image description in square brackets and a script below it. Both of them should be on their own lines, as follows: ###
|
255 |
[Description of a background image]
|
256 |
Narrator: "One sentence of narration"
|
257 |
### The short should be 6 sentences maximum."""
|