Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,6 @@ for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, GLITCH_SOUND, EJEMPLO_VIDEO]:
|
|
| 24 |
raise FileNotFoundError(f"Falta: {file}")
|
| 25 |
|
| 26 |
def eliminar_archivo_tiempo(ruta, delay=1800):
|
| 27 |
-
"""Elimina el archivo después de 'delay' segundos (30 minutos por defecto)"""
|
| 28 |
def eliminar():
|
| 29 |
try:
|
| 30 |
if os.path.exists(ruta):
|
|
@@ -36,7 +35,7 @@ def eliminar_archivo_tiempo(ruta, delay=1800):
|
|
| 36 |
import gc
|
| 37 |
gc.collect()
|
| 38 |
from threading import Timer
|
| 39 |
-
Timer(delay, eliminar).start()
|
| 40 |
|
| 41 |
async def procesar_audio(texto, voz, duracion_video, audio_original):
|
| 42 |
temp_files = []
|
|
@@ -92,28 +91,6 @@ async def procesar_audio(texto, voz, duracion_video, audio_original):
|
|
| 92 |
except Exception as e:
|
| 93 |
logging.warning(f"Error limpiando {file}: {e}")
|
| 94 |
|
| 95 |
-
def aplicar_glitch(video_clip):
|
| 96 |
-
"""Versión corregida del efecto glitch"""
|
| 97 |
-
def glitch_effect(frame):
|
| 98 |
-
import numpy as np
|
| 99 |
-
frame = frame.copy()
|
| 100 |
-
height, width, _ = frame.shape
|
| 101 |
-
offset = np.random.randint(-5, 5)
|
| 102 |
-
|
| 103 |
-
if offset == 0 or height <= 0:
|
| 104 |
-
return frame
|
| 105 |
-
|
| 106 |
-
offset = max(-height + 1, min(offset, height))
|
| 107 |
-
|
| 108 |
-
if offset > 0:
|
| 109 |
-
frame[offset:, :] = np.roll(frame[:-offset, :], -offset, axis=0)
|
| 110 |
-
else:
|
| 111 |
-
frame[:offset, :] = np.roll(frame[-offset:, :], -offset, axis=0)
|
| 112 |
-
|
| 113 |
-
return frame
|
| 114 |
-
|
| 115 |
-
return video_clip.fl_image(glitch_effect)
|
| 116 |
-
|
| 117 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
| 118 |
try:
|
| 119 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(1080, 1920))
|
|
@@ -134,34 +111,42 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
| 134 |
audio_original
|
| 135 |
)
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
segments = []
|
| 141 |
-
glitch_clips = []
|
| 142 |
-
glitch_sound = AudioFileClip(GLITCH_SOUND).volumex(0.5)
|
| 143 |
-
|
| 144 |
start_time = 0
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
video_con_audio = video_final.set_audio(audio_final)
|
| 164 |
|
|
|
|
| 165 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(1080, 1920))
|
| 166 |
outro = VideoFileClip(OUTRO_VIDEO, target_resolution=(1080, 1920))
|
| 167 |
video_final = concatenate_videoclips([intro, video_con_audio, outro], method="compose")
|
|
@@ -171,7 +156,7 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
| 171 |
tmp.name,
|
| 172 |
codec="libx264",
|
| 173 |
audio_codec="aac",
|
| 174 |
-
fps=
|
| 175 |
threads=4,
|
| 176 |
bitrate="5M",
|
| 177 |
ffmpeg_params=[
|
|
@@ -182,7 +167,7 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
| 182 |
],
|
| 183 |
verbose=False
|
| 184 |
)
|
| 185 |
-
eliminar_archivo_tiempo(tmp.name, 1800)
|
| 186 |
return tmp.name
|
| 187 |
|
| 188 |
except Exception as e:
|
|
|
|
| 24 |
raise FileNotFoundError(f"Falta: {file}")
|
| 25 |
|
| 26 |
def eliminar_archivo_tiempo(ruta, delay=1800):
|
|
|
|
| 27 |
def eliminar():
|
| 28 |
try:
|
| 29 |
if os.path.exists(ruta):
|
|
|
|
| 35 |
import gc
|
| 36 |
gc.collect()
|
| 37 |
from threading import Timer
|
| 38 |
+
Timer(delay, eliminar).start()
|
| 39 |
|
| 40 |
async def procesar_audio(texto, voz, duracion_video, audio_original):
|
| 41 |
temp_files = []
|
|
|
|
| 91 |
except Exception as e:
|
| 92 |
logging.warning(f"Error limpiando {file}: {e}")
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
| 95 |
try:
|
| 96 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(1080, 1920))
|
|
|
|
| 111 |
audio_original
|
| 112 |
)
|
| 113 |
|
| 114 |
+
# Configuración de cortes dinámicos
|
| 115 |
+
segment_duration = 18 # Duración real visible
|
| 116 |
+
overlap = 2 # Segundos eliminados en cada corte
|
| 117 |
+
total_segments = int((duracion_video - overlap) // (segment_duration)) + 1
|
| 118 |
+
|
| 119 |
segments = []
|
|
|
|
|
|
|
|
|
|
| 120 |
start_time = 0
|
| 121 |
+
|
| 122 |
+
for _ in range(total_segments):
|
| 123 |
+
end_time = start_time + segment_duration + overlap
|
| 124 |
+
end_time = min(end_time, duracion_video)
|
| 125 |
+
|
| 126 |
+
# Extraer segmento completo
|
| 127 |
+
full_segment = video_original.subclip(start_time, end_time)
|
| 128 |
+
|
| 129 |
+
# Cortar los primeros 0.5 segundos para transición
|
| 130 |
+
if start_time > 0:
|
| 131 |
+
transition = full_segment.subclip(0, 0.5).speedx(1.5) # Efecto rápido
|
| 132 |
+
main_segment = full_segment.subclip(0.5)
|
| 133 |
+
else:
|
| 134 |
+
transition = None
|
| 135 |
+
main_segment = full_segment
|
| 136 |
+
|
| 137 |
+
# Combinar transición y segmento principal
|
| 138 |
+
if transition:
|
| 139 |
+
combined = concatenate_videoclips([transition, main_segment], method="compose")
|
| 140 |
+
else:
|
| 141 |
+
combined = main_segment
|
| 142 |
+
|
| 143 |
+
segments.append(combined)
|
| 144 |
+
start_time += segment_duration # Avanzar sin los 2 segundos de overlap
|
| 145 |
+
|
| 146 |
+
video_final = concatenate_videoclips(segments, method="compose")
|
| 147 |
video_con_audio = video_final.set_audio(audio_final)
|
| 148 |
|
| 149 |
+
# Recargar intro/outro
|
| 150 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(1080, 1920))
|
| 151 |
outro = VideoFileClip(OUTRO_VIDEO, target_resolution=(1080, 1920))
|
| 152 |
video_final = concatenate_videoclips([intro, video_con_audio, outro], method="compose")
|
|
|
|
| 156 |
tmp.name,
|
| 157 |
codec="libx264",
|
| 158 |
audio_codec="aac",
|
| 159 |
+
fps=video_original.fps,
|
| 160 |
threads=4,
|
| 161 |
bitrate="5M",
|
| 162 |
ffmpeg_params=[
|
|
|
|
| 167 |
],
|
| 168 |
verbose=False
|
| 169 |
)
|
| 170 |
+
eliminar_archivo_tiempo(tmp.name, 1800)
|
| 171 |
return tmp.name
|
| 172 |
|
| 173 |
except Exception as e:
|