Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -261,6 +261,14 @@ def get_ffmpeg_style(caption_style: str, custom_font: str = None, custom_size: i
|
|
| 261 |
style_str = ",".join([f"{k}={v}" for k, v in style.items()])
|
| 262 |
return style_str
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
@app.get("/")
|
| 265 |
def read_root():
|
| 266 |
gemini_key, eleven_key, is_mock = get_api_keys()
|
|
@@ -390,7 +398,7 @@ def run_production_pipeline(job: TranslationJob, gemini_key: str, elevenlabs_key
|
|
| 390 |
"-c:a", "aac", "-ar", "16000", "-ac", "1",
|
| 391 |
input_video_path
|
| 392 |
])
|
| 393 |
-
|
| 394 |
|
| 395 |
# 2. Extract audio from video using FFmpeg
|
| 396 |
print(f"[{video_id}] Extracting audio using FFmpeg...")
|
|
@@ -399,7 +407,7 @@ def run_production_pipeline(job: TranslationJob, gemini_key: str, elevenlabs_key
|
|
| 399 |
"-vn", "-acodec", "libmp3lame", "-q:a", "2",
|
| 400 |
extracted_audio_path
|
| 401 |
]
|
| 402 |
-
|
| 403 |
|
| 404 |
# 3. Request Transcription & Translation from Gemini 2.5 Flash
|
| 405 |
print(f"[{video_id}] Calling Gemini 2.5 Flash for transcription/translation to '{job.target_lang}'...")
|
|
@@ -596,7 +604,7 @@ def run_production_pipeline(job: TranslationJob, gemini_key: str, elevenlabs_key
|
|
| 596 |
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-shortest",
|
| 597 |
output_video_path
|
| 598 |
]
|
| 599 |
-
|
| 600 |
else:
|
| 601 |
if job.has_lip_sync:
|
| 602 |
print(f"[{video_id}] Copying lip-synced video to final output path...")
|
|
@@ -608,7 +616,7 @@ def run_production_pipeline(job: TranslationJob, gemini_key: str, elevenlabs_key
|
|
| 608 |
"-map", "0:v", "-map", "1:a", "-c:v", "copy", "-c:a", "aac", "-shortest",
|
| 609 |
output_video_path
|
| 610 |
]
|
| 611 |
-
|
| 612 |
|
| 613 |
# Normalize Supabase base URL (remove trailing slash and rest/v1 path if present)
|
| 614 |
base_url = supabase_url.rstrip("/")
|
|
|
|
| 261 |
style_str = ",".join([f"{k}={v}" for k, v in style.items()])
|
| 262 |
return style_str
|
| 263 |
|
| 264 |
+
def run_ffmpeg_command(cmd, task_name="FFmpeg"):
|
| 265 |
+
print(f"Running {task_name} command: {' '.join(cmd)}")
|
| 266 |
+
res = subprocess.run(cmd, capture_output=True, text=True)
|
| 267 |
+
if res.returncode != 0:
|
| 268 |
+
error_logs = res.stderr.strip().splitlines()
|
| 269 |
+
last_logs = "\n".join(error_logs[-6:]) if error_logs else "No error logs outputted."
|
| 270 |
+
raise Exception(f"{task_name} failed with exit code {res.returncode}. FFmpeg error logs:\n{last_logs}")
|
| 271 |
+
|
| 272 |
@app.get("/")
|
| 273 |
def read_root():
|
| 274 |
gemini_key, eleven_key, is_mock = get_api_keys()
|
|
|
|
| 398 |
"-c:a", "aac", "-ar", "16000", "-ac", "1",
|
| 399 |
input_video_path
|
| 400 |
])
|
| 401 |
+
run_ffmpeg_command(cmd_standardize, "Video Standardization")
|
| 402 |
|
| 403 |
# 2. Extract audio from video using FFmpeg
|
| 404 |
print(f"[{video_id}] Extracting audio using FFmpeg...")
|
|
|
|
| 407 |
"-vn", "-acodec", "libmp3lame", "-q:a", "2",
|
| 408 |
extracted_audio_path
|
| 409 |
]
|
| 410 |
+
run_ffmpeg_command(cmd_extract, "Audio Extraction")
|
| 411 |
|
| 412 |
# 3. Request Transcription & Translation from Gemini 2.5 Flash
|
| 413 |
print(f"[{video_id}] Calling Gemini 2.5 Flash for transcription/translation to '{job.target_lang}'...")
|
|
|
|
| 604 |
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-shortest",
|
| 605 |
output_video_path
|
| 606 |
]
|
| 607 |
+
run_ffmpeg_command(cmd_merge, "Subtitle Burning & Video Merge")
|
| 608 |
else:
|
| 609 |
if job.has_lip_sync:
|
| 610 |
print(f"[{video_id}] Copying lip-synced video to final output path...")
|
|
|
|
| 616 |
"-map", "0:v", "-map", "1:a", "-c:v", "copy", "-c:a", "aac", "-shortest",
|
| 617 |
output_video_path
|
| 618 |
]
|
| 619 |
+
run_ffmpeg_command(cmd_merge, "Audio-Video Merge")
|
| 620 |
|
| 621 |
# Normalize Supabase base URL (remove trailing slash and rest/v1 path if present)
|
| 622 |
base_url = supabase_url.rstrip("/")
|