Update app.py
Browse files
app.py
CHANGED
@@ -249,9 +249,9 @@ def process_entry(entry, i, video_width, video_height, add_voiceover, target_lan
|
|
249 |
logger.info("Methods in AudioFileClip:")
|
250 |
for method in dir(audio_clip):
|
251 |
logger.info(method)
|
252 |
-
audio_segment = audio_clip.
|
253 |
|
254 |
-
return txt_clip, audio_segment
|
255 |
|
256 |
def add_transcript_voiceover(video_path, translated_json, output_path, add_voiceover=False, target_language="en"):
|
257 |
"""
|
@@ -267,18 +267,21 @@ def add_transcript_voiceover(video_path, translated_json, output_path, add_voice
|
|
267 |
futures = [executor.submit(process_entry, entry, i, video.w, video.h, add_voiceover, target_language)
|
268 |
for i, entry in enumerate(translated_json)]
|
269 |
|
|
|
|
|
270 |
for future in concurrent.futures.as_completed(futures):
|
271 |
try:
|
272 |
-
txt_clip, audio_segment = future.result()
|
273 |
-
|
274 |
-
if add_voiceover and audio_segment:
|
275 |
-
audio_segments.append(audio_segment)
|
276 |
except Exception as e:
|
277 |
logger.error(f"Error processing entry: {e}")
|
278 |
-
|
279 |
-
# Sort
|
280 |
-
|
281 |
|
|
|
|
|
|
|
282 |
final_video = CompositeVideoClip([video] + text_clips)
|
283 |
|
284 |
logger.info("Methods in CompositeVideoClip:")
|
@@ -286,7 +289,7 @@ def add_transcript_voiceover(video_path, translated_json, output_path, add_voice
|
|
286 |
logger.info(method)
|
287 |
|
288 |
if add_voiceover and audio_segments:
|
289 |
-
audio_segments
|
290 |
final_audio = CompositeAudioClip(audio_segments) # Critical fix
|
291 |
final_audio = final_audio.with_duration(video.duration)
|
292 |
|
|
|
249 |
logger.info("Methods in AudioFileClip:")
|
250 |
for method in dir(audio_clip):
|
251 |
logger.info(method)
|
252 |
+
audio_segment = audio_clip.with_duration(entry["end"] - entry["start"]) # No subclip here
|
253 |
|
254 |
+
return i, txt_clip, audio_segment
|
255 |
|
256 |
def add_transcript_voiceover(video_path, translated_json, output_path, add_voiceover=False, target_language="en"):
|
257 |
"""
|
|
|
267 |
futures = [executor.submit(process_entry, entry, i, video.w, video.h, add_voiceover, target_language)
|
268 |
for i, entry in enumerate(translated_json)]
|
269 |
|
270 |
+
# Collect results with original index i
|
271 |
+
results = []
|
272 |
for future in concurrent.futures.as_completed(futures):
|
273 |
try:
|
274 |
+
i, txt_clip, audio_segment = future.result()
|
275 |
+
results.append((i, txt_clip, audio_segment))
|
|
|
|
|
276 |
except Exception as e:
|
277 |
logger.error(f"Error processing entry: {e}")
|
278 |
+
|
279 |
+
# Sort by original index i
|
280 |
+
results.sort(key=lambda x: x[0])
|
281 |
|
282 |
+
# Extract sorted clips
|
283 |
+
text_clips = [clip for i, clip, segment in results]
|
284 |
+
|
285 |
final_video = CompositeVideoClip([video] + text_clips)
|
286 |
|
287 |
logger.info("Methods in CompositeVideoClip:")
|
|
|
289 |
logger.info(method)
|
290 |
|
291 |
if add_voiceover and audio_segments:
|
292 |
+
audio_segments = [segment for i, clip, segment in results if segment is not None]
|
293 |
final_audio = CompositeAudioClip(audio_segments) # Critical fix
|
294 |
final_audio = final_audio.with_duration(video.duration)
|
295 |
|