Update app.py
Browse files
app.py
CHANGED
@@ -14,10 +14,11 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(
|
|
14 |
INTRO_VIDEO = "introvideo.mp4"
|
15 |
OUTRO_VIDEO = "outrovideo.mp4"
|
16 |
MUSIC_BG = "musicafondo.mp3"
|
|
|
17 |
EJEMPLO_VIDEO = "ejemplo.mp4"
|
18 |
|
19 |
# Validar existencia de archivos
|
20 |
-
for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, EJEMPLO_VIDEO]:
|
21 |
if not os.path.exists(file):
|
22 |
logging.error(f"Falta archivo necesario: {file}")
|
23 |
raise FileNotFoundError(f"Falta: {file}")
|
@@ -99,6 +100,17 @@ async def procesar_audio(texto, voz, duracion_video, audio_original):
|
|
99 |
except Exception as e:
|
100 |
logging.warning(f"Error limpiando {file}: {e}")
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
103 |
try:
|
104 |
# Cargar componentes
|
@@ -131,8 +143,43 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
131 |
# Redimensionar video principal
|
132 |
video_resized = video_original.resize((target_width, target_height))
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
# Combinar video con audio
|
135 |
-
video_con_audio =
|
136 |
|
137 |
# Concatenar intro + video + outro SIN alteraciones
|
138 |
video_final = concatenate_videoclips(
|
|
|
14 |
INTRO_VIDEO = "introvideo.mp4"
|
15 |
OUTRO_VIDEO = "outrovideo.mp4"
|
16 |
MUSIC_BG = "musicafondo.mp3"
|
17 |
+
GLITCH_SOUND = "glitch.mp3" # Efecto de sonido para glitches
|
18 |
EJEMPLO_VIDEO = "ejemplo.mp4"
|
19 |
|
20 |
# Validar existencia de archivos
|
21 |
+
for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, GLITCH_SOUND, EJEMPLO_VIDEO]:
|
22 |
if not os.path.exists(file):
|
23 |
logging.error(f"Falta archivo necesario: {file}")
|
24 |
raise FileNotFoundError(f"Falta: {file}")
|
|
|
100 |
except Exception as e:
|
101 |
logging.warning(f"Error limpiando {file}: {e}")
|
102 |
|
103 |
+
def aplicar_glitch(video_clip):
|
104 |
+
"""Aplica un efecto de glitch al video."""
|
105 |
+
def glitch_effect(frame):
|
106 |
+
import numpy as np
|
107 |
+
# Desplazar aleatoriamente filas de píxeles
|
108 |
+
offset = np.random.randint(-10, 10)
|
109 |
+
frame[offset:, :] = frame[:-offset, :]
|
110 |
+
return frame
|
111 |
+
|
112 |
+
return video_clip.fl_image(glitch_effect)
|
113 |
+
|
114 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
115 |
try:
|
116 |
# Cargar componentes
|
|
|
143 |
# Redimensionar video principal
|
144 |
video_resized = video_original.resize((target_width, target_height))
|
145 |
|
146 |
+
# Dividir el video en segmentos de 20 segundos y eliminar 2 segundos en cada corte
|
147 |
+
segment_duration = 20
|
148 |
+
overlap = 2 # Segundos a eliminar en cada corte
|
149 |
+
num_segments = int(duracion_video // (segment_duration - overlap)) + 1
|
150 |
+
segments = []
|
151 |
+
glitch_clips = []
|
152 |
+
glitch_sound = AudioFileClip(GLITCH_SOUND)
|
153 |
+
|
154 |
+
start_time = 0
|
155 |
+
for i in range(num_segments):
|
156 |
+
end_time = min(start_time + segment_duration, duracion_video)
|
157 |
+
if start_time >= duracion_video:
|
158 |
+
break
|
159 |
+
|
160 |
+
# Extraer el segmento
|
161 |
+
segment = video_resized.subclip(start_time, end_time)
|
162 |
+
|
163 |
+
# Aplicar glitch al inicio del segmento (excepto el primero)
|
164 |
+
if i > 0:
|
165 |
+
glitch_segment = aplicar_glitch(segment.subclip(0, 0.5)) # Glitch de 0.5 segundos
|
166 |
+
glitch_sound_clip = glitch_sound.set_start(start_time).volumex(0.5)
|
167 |
+
glitch_clips.append(glitch_sound_clip)
|
168 |
+
segment = concatenate_videoclips([glitch_segment, segment.subclip(0.5)], method="compose")
|
169 |
+
|
170 |
+
segments.append(segment)
|
171 |
+
|
172 |
+
# Avanzar al siguiente segmento, eliminando 2 segundos
|
173 |
+
start_time += segment_duration - overlap
|
174 |
+
|
175 |
+
# Combinar los segmentos procesados
|
176 |
+
video_final = concatenate_videoclips(segments)
|
177 |
+
|
178 |
+
# Combinar audio con efectos de glitch
|
179 |
+
audio_final = CompositeAudioClip([audio_final] + glitch_clips).set_duration(video_final.duration)
|
180 |
+
|
181 |
# Combinar video con audio
|
182 |
+
video_con_audio = video_final.set_audio(audio_final)
|
183 |
|
184 |
# Concatenar intro + video + outro SIN alteraciones
|
185 |
video_final = concatenate_videoclips(
|