Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,9 +31,6 @@ def eliminar_archivo_tiempo(ruta, delay=1800):
|
|
31 |
logging.info(f"Archivo eliminado: {ruta}")
|
32 |
except Exception as e:
|
33 |
logging.error(f"Error al eliminar {ruta}: {e}")
|
34 |
-
finally:
|
35 |
-
import gc
|
36 |
-
gc.collect()
|
37 |
from threading import Timer
|
38 |
Timer(delay, eliminar).start()
|
39 |
|
@@ -91,13 +88,27 @@ async def procesar_audio(texto, voz, duracion_video, audio_original):
|
|
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))
|
97 |
outro = VideoFileClip(OUTRO_VIDEO, target_resolution=(1080, 1920))
|
98 |
video_original = VideoFileClip(video_input, target_resolution=(1080, 1920))
|
99 |
audio_original = video_original.audio
|
100 |
|
|
|
101 |
intro.reader.close()
|
102 |
outro.reader.close()
|
103 |
video_original.reader.close()
|
@@ -112,45 +123,53 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
112 |
)
|
113 |
|
114 |
# Configuraci贸n de cortes din谩micos
|
115 |
-
segment_duration = 18 # Duraci贸n
|
116 |
overlap = 2 # Segundos eliminados en cada corte
|
117 |
-
total_segments = int((duracion_video
|
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 |
-
#
|
130 |
-
if
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
else:
|
141 |
-
combined = main_segment
|
142 |
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
#
|
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")
|
153 |
|
|
|
154 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
155 |
video_final.write_videofile(
|
156 |
tmp.name,
|
|
|
31 |
logging.info(f"Archivo eliminado: {ruta}")
|
32 |
except Exception as e:
|
33 |
logging.error(f"Error al eliminar {ruta}: {e}")
|
|
|
|
|
|
|
34 |
from threading import Timer
|
35 |
Timer(delay, eliminar).start()
|
36 |
|
|
|
88 |
except Exception as e:
|
89 |
logging.warning(f"Error limpiando {file}: {e}")
|
90 |
|
91 |
+
def aplicar_glitch(video_clip):
|
92 |
+
def glitch_effect(frame):
|
93 |
+
import numpy as np
|
94 |
+
frame = frame.copy() # Correcci贸n clave para evitar errores
|
95 |
+
height, width, _ = frame.shape
|
96 |
+
offset = np.random.randint(5, 15)
|
97 |
+
if height > 0:
|
98 |
+
frame[offset:, :] = np.roll(frame[:-offset, :], -offset, axis=0)
|
99 |
+
return frame
|
100 |
+
|
101 |
+
return video_clip.fl_image(glitch_effect)
|
102 |
+
|
103 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
104 |
try:
|
105 |
+
# Carga optimizada
|
106 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(1080, 1920))
|
107 |
outro = VideoFileClip(OUTRO_VIDEO, target_resolution=(1080, 1920))
|
108 |
video_original = VideoFileClip(video_input, target_resolution=(1080, 1920))
|
109 |
audio_original = video_original.audio
|
110 |
|
111 |
+
# Liberar recursos
|
112 |
intro.reader.close()
|
113 |
outro.reader.close()
|
114 |
video_original.reader.close()
|
|
|
123 |
)
|
124 |
|
125 |
# Configuraci贸n de cortes din谩micos
|
126 |
+
segment_duration = 18 # Duraci贸n visible del segmento
|
127 |
overlap = 2 # Segundos eliminados en cada corte
|
128 |
+
total_segments = int((duracion_video) // (segment_duration)) + 1
|
129 |
|
130 |
segments = []
|
131 |
+
glitch_clips = []
|
132 |
+
glitch_sound = AudioFileClip(GLITCH_SOUND).volumex(0.5)
|
133 |
+
|
134 |
start_time = 0
|
135 |
+
for i in range(total_segments):
|
|
|
136 |
end_time = start_time + segment_duration + overlap
|
137 |
end_time = min(end_time, duracion_video)
|
138 |
|
139 |
# Extraer segmento completo
|
140 |
full_segment = video_original.subclip(start_time, end_time)
|
141 |
|
142 |
+
# Aplicar transici贸n/glitch
|
143 |
+
if i > 0:
|
144 |
+
# Tomar 0.5 segundos para glitch
|
145 |
+
glitch_part = full_segment.subclip(0, 0.5)
|
146 |
+
glitch_part = aplicar_glitch(glitch_part)
|
147 |
+
|
148 |
+
# Combinar con el resto del segmento
|
149 |
+
processed_segment = concatenate_videoclips([
|
150 |
+
glitch_part,
|
151 |
+
full_segment.subclip(0.5)
|
152 |
+
], method="compose")
|
|
|
|
|
153 |
|
154 |
+
# Agregar sonido de glitch
|
155 |
+
glitch_sound_clip = glitch_sound.set_start(start_time)
|
156 |
+
glitch_clips.append(glitch_sound_clip)
|
157 |
+
else:
|
158 |
+
processed_segment = full_segment
|
159 |
+
|
160 |
+
segments.append(processed_segment)
|
161 |
start_time += segment_duration # Avanzar sin los 2 segundos de overlap
|
162 |
|
163 |
+
# Combinar todos los segmentos
|
164 |
video_final = concatenate_videoclips(segments, method="compose")
|
165 |
video_con_audio = video_final.set_audio(audio_final)
|
166 |
|
167 |
+
# Agregar intro y outro
|
168 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(1080, 1920))
|
169 |
outro = VideoFileClip(OUTRO_VIDEO, target_resolution=(1080, 1920))
|
170 |
video_final = concatenate_videoclips([intro, video_con_audio, outro], method="compose")
|
171 |
|
172 |
+
# Renderizado final
|
173 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
174 |
video_final.write_videofile(
|
175 |
tmp.name,
|