Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
|
@@ -86,8 +86,15 @@ def extract_audio_segment(video_path: str, start_seconds: float, end_seconds: fl
|
|
| 86 |
"-ac", "1",
|
| 87 |
output_wav
|
| 88 |
]
|
| 89 |
-
result = subprocess.run(cmd,
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
|
| 93 |
def transcribe_segment(audio_path: str) -> List[Tuple[float, float, str]]:
|
|
@@ -258,7 +265,10 @@ def process_video_segment(
|
|
| 258 |
if audio_ok and whisper_model is not None:
|
| 259 |
captions = transcribe_segment(temp_wav)
|
| 260 |
else:
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
| 262 |
captions = []
|
| 263 |
|
| 264 |
frame_caption_map = build_frame_caption_map(captions, fps)
|
|
@@ -314,10 +324,8 @@ def process_video_segment(
|
|
| 314 |
frame = cv2.resize(frame, (target_width, target_height), interpolation=cv2.INTER_LANCZOS4)
|
| 315 |
frame = apply_color_grading_wedding_retro(frame)
|
| 316 |
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
if processed_frames not in frame_caption_map:
|
| 320 |
-
current_caption = ""
|
| 321 |
|
| 322 |
if current_caption:
|
| 323 |
frame = burn_captions_to_frame(frame, current_caption)
|
|
@@ -508,9 +516,10 @@ async def scan_and_process_videos():
|
|
| 508 |
print("Video processing already running, skipping...")
|
| 509 |
return
|
| 510 |
|
| 511 |
-
# Wait
|
| 512 |
-
|
| 513 |
-
|
|
|
|
| 514 |
|
| 515 |
processing_state["is_running"] = True
|
| 516 |
print("\n" + "="*80)
|
|
|
|
| 86 |
"-ac", "1",
|
| 87 |
output_wav
|
| 88 |
]
|
| 89 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 90 |
+
if result.returncode != 0:
|
| 91 |
+
print(f" ✗ FFmpeg audio extraction failed: {result.stderr}")
|
| 92 |
+
return False
|
| 93 |
+
if not os.path.exists(output_wav):
|
| 94 |
+
print(f" ✗ Output WAV file not created: {output_wav}")
|
| 95 |
+
return False
|
| 96 |
+
print(f" ✓ Audio extracted successfully")
|
| 97 |
+
return True
|
| 98 |
|
| 99 |
|
| 100 |
def transcribe_segment(audio_path: str) -> List[Tuple[float, float, str]]:
|
|
|
|
| 265 |
if audio_ok and whisper_model is not None:
|
| 266 |
captions = transcribe_segment(temp_wav)
|
| 267 |
else:
|
| 268 |
+
if not audio_ok:
|
| 269 |
+
print(" ✗ Skipping transcription: audio extraction failed")
|
| 270 |
+
elif whisper_model is None:
|
| 271 |
+
print(" ✗ Skipping transcription: Whisper model not ready")
|
| 272 |
captions = []
|
| 273 |
|
| 274 |
frame_caption_map = build_frame_caption_map(captions, fps)
|
|
|
|
| 324 |
frame = cv2.resize(frame, (target_width, target_height), interpolation=cv2.INTER_LANCZOS4)
|
| 325 |
frame = apply_color_grading_wedding_retro(frame)
|
| 326 |
|
| 327 |
+
# Set caption for this frame (empty if none).
|
| 328 |
+
current_caption = frame_caption_map.get(processed_frames, "")
|
|
|
|
|
|
|
| 329 |
|
| 330 |
if current_caption:
|
| 331 |
frame = burn_captions_to_frame(frame, current_caption)
|
|
|
|
| 516 |
print("Video processing already running, skipping...")
|
| 517 |
return
|
| 518 |
|
| 519 |
+
# Wait for Space to fully initialize (reduced for testing)
|
| 520 |
+
startup_delay = int(os.getenv("STARTUP_DELAY", 5)) # Default 5 seconds for testing
|
| 521 |
+
print(f"Waiting {startup_delay} seconds before starting video processing...")
|
| 522 |
+
await asyncio.sleep(startup_delay)
|
| 523 |
|
| 524 |
processing_state["is_running"] = True
|
| 525 |
print("\n" + "="*80)
|