Update app.py
Browse files
app.py
CHANGED
|
@@ -245,17 +245,31 @@ def generate_voiceover(translated_json, language, output_audio_path):
|
|
| 245 |
tts = gTTS(text=full_text, lang=language)
|
| 246 |
tts.save(output_audio_path)
|
| 247 |
|
| 248 |
-
def replace_audio_in_video(video_path, new_audio_path, final_video_path):
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
# Save the final output
|
| 258 |
-
video.write_videofile(final_video_path, codec="libx264", audio_codec="aac")
|
| 259 |
|
| 260 |
def upload_and_manage(file, language, mode="transcription"):
|
| 261 |
if file is None:
|
|
|
|
| 245 |
tts = gTTS(text=full_text, lang=language)
|
| 246 |
tts.save(output_audio_path)
|
| 247 |
|
| 248 |
+
def replace_audio_in_video(video_path: str, new_audio_path: str, final_video_path: str):
|
| 249 |
+
try:
|
| 250 |
+
# Load the video file
|
| 251 |
+
logger.info(f"Loading video from: {video_path}")
|
| 252 |
+
video = VideoFileClip(video_path)
|
| 253 |
+
|
| 254 |
+
# Load the new audio file
|
| 255 |
+
logger.info(f"Loading audio from: {new_audio_path}")
|
| 256 |
+
new_audio = AudioFileClip(new_audio_path)
|
| 257 |
+
|
| 258 |
+
# Log available methods for debugging
|
| 259 |
+
logger.info(f"Methods available in VideoFileClip: {dir(video)}")
|
| 260 |
+
|
| 261 |
+
# Set the new audio to the video
|
| 262 |
+
logger.info("Replacing video audio...")
|
| 263 |
+
video = video.with_audio(new_audio)
|
| 264 |
+
|
| 265 |
+
# Save the final video
|
| 266 |
+
logger.info(f"Saving the final video to: {final_video_path}")
|
| 267 |
+
video.write_videofile(final_video_path, codec="libx264", audio_codec="aac")
|
| 268 |
+
|
| 269 |
+
logger.info("Video processing completed successfully.")
|
| 270 |
|
| 271 |
+
except Exception as e:
|
| 272 |
+
logger.error(f"Error replacing audio in video: {e}")
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
def upload_and_manage(file, language, mode="transcription"):
|
| 275 |
if file is None:
|