aladhefafalquran Claude Sonnet 4.5 commited on
Commit
ceef9a7
·
1 Parent(s): a575621

Fix timeout for long surahs - dynamic timeout calculation

Browse files

Issue: 120s timeout too short for long surahs (8+ minutes)
Solution: Calculate timeout dynamically based on video duration

Formula: timeout = max(120, duration * 2 + 60)
- Short videos (1 min): 120s timeout
- Medium videos (5 min): 660s timeout
- Long videos (10 min): 1260s timeout

This ensures FFmpeg has enough time to process subtitles
for any surah length without unnecessary waiting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. src/video_generator.py +6 -2
src/video_generator.py CHANGED
@@ -238,8 +238,12 @@ class VideoGenerator:
238
  print(f"Command: {' '.join(cmd[:10])}...") # Print first part to avoid too much logging
239
 
240
  try:
 
 
 
 
241
  # Try with ASS/SRT subtitles
242
- result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
243
  except subprocess.TimeoutExpired:
244
  print("FFmpeg timeout, falling back to video without subtitles...")
245
  result = subprocess.CompletedProcess(cmd, 1, "", "Timeout")
@@ -261,7 +265,7 @@ class VideoGenerator:
261
  "-movflags", "+faststart",
262
  output_path
263
  ]
264
- result = subprocess.run(cmd_simple, capture_output=True, text=True, timeout=120)
265
  if result.returncode != 0:
266
  raise Exception(f"Failed to create video: {result.stderr[:500]}")
267
  print("Warning: Created video without burned-in subtitles")
 
238
  print(f"Command: {' '.join(cmd[:10])}...") # Print first part to avoid too much logging
239
 
240
  try:
241
+ # Calculate timeout based on video duration (2x duration + 60s buffer, min 120s)
242
+ timeout = max(120, int(duration * 2 + 60))
243
+ print(f"Video duration: {duration:.1f}s, timeout: {timeout}s")
244
+
245
  # Try with ASS/SRT subtitles
246
+ result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
247
  except subprocess.TimeoutExpired:
248
  print("FFmpeg timeout, falling back to video without subtitles...")
249
  result = subprocess.CompletedProcess(cmd, 1, "", "Timeout")
 
265
  "-movflags", "+faststart",
266
  output_path
267
  ]
268
+ result = subprocess.run(cmd_simple, capture_output=True, text=True, timeout=timeout)
269
  if result.returncode != 0:
270
  raise Exception(f"Failed to create video: {result.stderr[:500]}")
271
  print("Warning: Created video without burned-in subtitles")