Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -859,33 +859,15 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
859 |
except Exception as e:
|
860 |
logger.warning(f"Error ajustando duraci贸n del audio final: {str(e)}")
|
861 |
|
862 |
-
|
863 |
-
|
864 |
-
video_final = video_base.set_audio(final_audio)
|
865 |
-
|
866 |
-
if video_final is None or video_final.duration is None or video_final.duration <= 0:
|
867 |
-
logger.critical("Clip de video final (con audio) es inv谩lido antes de escribir (None o duraci贸n cero).")
|
868 |
-
raise ValueError("Clip de video final es inv谩lido antes de escribir.")
|
869 |
-
|
870 |
-
output_filename = "final_video.mp4"
|
871 |
output_path = os.path.join(temp_dir_intermediate, output_filename)
|
872 |
-
|
873 |
-
|
874 |
-
# SOLUCI脫N CON INDENTACI脫N ORIGINAL:
|
875 |
-
try:
|
876 |
-
# M茅todo directo que evita ANTIALIAS
|
877 |
-
if hasattr(video_final, 'fx') and callable(getattr(video_final.fx, 'resize', None)):
|
878 |
-
video_final = video_final.fx.resize(width=1920, height=1080)
|
879 |
-
else:
|
880 |
-
from moviepy.video.fx.all import resize
|
881 |
-
video_final = resize(video_final, width=1920, height=1080)
|
882 |
-
except Exception as e:
|
883 |
-
logger.warning(f"No se pudo redimensionar: {str(e)}. Usando tama帽o original con escalado FFmpeg")
|
884 |
-
|
885 |
video_final.write_videofile(
|
886 |
output_path,
|
887 |
fps=24,
|
888 |
-
threads=
|
889 |
codec="libx264",
|
890 |
audio_codec="aac",
|
891 |
preset="medium",
|
@@ -896,6 +878,24 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
896 |
logger='bar'
|
897 |
)
|
898 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
899 |
total_time = (datetime.now() - start_time).total_seconds()
|
900 |
logger.info(f"PROCESO DE VIDEO FINALIZADO | Output: {output_path} | Tiempo total: {total_time:.2f}s")
|
901 |
|
|
|
859 |
except Exception as e:
|
860 |
logger.warning(f"Error ajustando duraci贸n del audio final: {str(e)}")
|
861 |
|
862 |
+
# 7. Crear video final (INDENTACI脫N ORIGINAL)
|
863 |
+
output_filename = f"video_{int(time.time())}.mp4" # Nombre 煤nico con timestamp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
864 |
output_path = os.path.join(temp_dir_intermediate, output_filename)
|
865 |
+
|
866 |
+
# Escribir el video (como ya lo ten铆as)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
867 |
video_final.write_videofile(
|
868 |
output_path,
|
869 |
fps=24,
|
870 |
+
threads=2,
|
871 |
codec="libx264",
|
872 |
audio_codec="aac",
|
873 |
preset="medium",
|
|
|
878 |
logger='bar'
|
879 |
)
|
880 |
|
881 |
+
# --- BLOQUE NUEVO A A脩ADIR (respeta esta indentaci贸n) ---
|
882 |
+
try:
|
883 |
+
# Mover a ubicaci贸n permanente en /tmp
|
884 |
+
permanent_path = f"/tmp/{output_filename}"
|
885 |
+
shutil.copy(output_path, permanent_path) # Usamos copy() en lugar de move()
|
886 |
+
|
887 |
+
# Cierra los clips para liberar memoria
|
888 |
+
video_final.close()
|
889 |
+
if 'video_base' in locals():
|
890 |
+
video_base.close()
|
891 |
+
|
892 |
+
logger.info(f"Video guardado permanentemente en: {permanent_path}")
|
893 |
+
return permanent_path
|
894 |
+
|
895 |
+
except Exception as move_error:
|
896 |
+
logger.error(f"Error moviendo archivo: {str(move_error)}. Usando path original.")
|
897 |
+
return output_path
|
898 |
+
|
899 |
total_time = (datetime.now() - start_time).total_seconds()
|
900 |
logger.info(f"PROCESO DE VIDEO FINALIZADO | Output: {output_path} | Tiempo total: {total_time:.2f}s")
|
901 |
|