gnosticdev commited on
Commit
ba3f899
verified
1 Parent(s): dccb3aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -333,7 +333,16 @@ def create_video(script_text: str, generate_script: bool, music_path: str | None
333
 
334
  video_files = video_data.get("video_files", [])
335
  if video_files:
336
- best_file = max(video_files, key=lambda f: f.get("width", 0))
 
 
 
 
 
 
 
 
 
337
  video_url = best_file.get("link")
338
 
339
  if video_url:
@@ -351,12 +360,20 @@ def create_video(script_text: str, generate_script: bool, music_path: str | None
351
  for path in video_paths:
352
  clip = None
353
  try:
354
- # Cargar el video
355
  clip = VideoFileClip(path)
356
  if clip is None:
357
  logger.error(f"No se pudo cargar el video: {path}")
358
  continue
359
 
 
 
 
 
 
 
 
 
360
  # Tomar m谩ximo 8 segundos de cada clip
361
  try:
362
  duration = min(8, clip.duration)
@@ -372,7 +389,8 @@ def create_video(script_text: str, generate_script: bool, music_path: str | None
372
  if processed_clip is not None:
373
  video_clips.append(processed_clip)
374
  else:
375
- processed_clip.close()
 
376
  clip.close()
377
  except Exception as e:
378
  logger.error(f"Error al normalizar video {path}: {e}")
 
333
 
334
  video_files = video_data.get("video_files", [])
335
  if video_files:
336
+ # Encontrar el video con la mejor calidad que sea MP4
337
+ best_file = None
338
+ for file in video_files:
339
+ if file.get("file_type") == "video/mp4":
340
+ if best_file is None or file.get("width", 0) > best_file.get("width", 0):
341
+ best_file = file
342
+
343
+ if best_file is None:
344
+ continue
345
+
346
  video_url = best_file.get("link")
347
 
348
  if video_url:
 
360
  for path in video_paths:
361
  clip = None
362
  try:
363
+ # Cargar el video con verificaci贸n adicional
364
  clip = VideoFileClip(path)
365
  if clip is None:
366
  logger.error(f"No se pudo cargar el video: {path}")
367
  continue
368
 
369
+ # Verificar que el clip se carg贸 correctamente intentando acceder a un frame
370
+ try:
371
+ clip.get_frame(0) # Intenta obtener el primer frame
372
+ except Exception as e:
373
+ logger.error(f"Video corrupto o incompatible: {path}, error: {e}")
374
+ clip.close()
375
+ continue
376
+
377
  # Tomar m谩ximo 8 segundos de cada clip
378
  try:
379
  duration = min(8, clip.duration)
 
389
  if processed_clip is not None:
390
  video_clips.append(processed_clip)
391
  else:
392
+ if 'processed_clip' in locals():
393
+ processed_clip.close()
394
  clip.close()
395
  except Exception as e:
396
  logger.error(f"Error al normalizar video {path}: {e}")