Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,9 +24,9 @@ for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, EJEMPLO_VIDEO]:
|
|
24 |
|
25 |
# Configuraci贸n de chunks
|
26 |
CHUNK_SIZE = 60 # 1 minuto por chunk
|
27 |
-
SEGMENT_DURATION = 18 # Duraci贸n de cada segmento
|
28 |
-
|
29 |
-
|
30 |
|
31 |
def eliminar_archivo_tiempo(ruta, delay=1800):
|
32 |
def eliminar():
|
@@ -67,16 +67,21 @@ def crear_musica_fondo(duracion_total):
|
|
67 |
bg_music.export(tmp_bg.name, format="mp3")
|
68 |
return AudioFileClip(tmp_bg.name).volumex(0.15), tmp_bg.name
|
69 |
|
70 |
-
def create_slide_transition(clip1, clip2, duration=
|
71 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
72 |
transition = CompositeVideoClip([
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
], size=(1280, 720))
|
78 |
|
79 |
-
return transition
|
80 |
|
81 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
82 |
temp_files = []
|
@@ -86,7 +91,7 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
86 |
video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
|
87 |
duracion_video = video_original.duration
|
88 |
|
89 |
-
# Generar TTS y m煤sica de fondo
|
90 |
tts_audio, tts_path = await generar_tts(texto_tts, voz_seleccionada, duracion_video)
|
91 |
bg_audio, bg_path = crear_musica_fondo(duracion_video)
|
92 |
temp_files.extend([tts_path, bg_path])
|
@@ -99,44 +104,31 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
|
99 |
audios.append(tts_audio.set_start(0).volumex(0.85))
|
100 |
audio_final = CompositeAudioClip(audios).set_duration(duracion_video)
|
101 |
|
102 |
-
# Dividir video en segmentos
|
103 |
segments = []
|
104 |
current_time = 0
|
105 |
while current_time < duracion_video:
|
106 |
end_time = current_time + SEGMENT_DURATION
|
107 |
if end_time > duracion_video:
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
if segments and full_segment.duration >= OVERLAP:
|
113 |
-
full_segment = full_segment.subclip(0, full_segment.duration - OVERLAP)
|
114 |
-
|
115 |
-
segments.append(full_segment)
|
116 |
-
current_time += (SEGMENT_DURATION - OVERLAP)
|
117 |
|
118 |
-
#
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
duration=TRANSITION_DURATION
|
133 |
-
)
|
134 |
-
clips.pop()
|
135 |
-
clips.append(transition)
|
136 |
-
clips.append(segments[i])
|
137 |
-
|
138 |
-
video_final = concatenate_videoclips(clips, method="compose")
|
139 |
-
video_final = video_final.set_audio(audio_final)
|
140 |
|
141 |
# Agregar intro y outro
|
142 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(720, 1280))
|
|
|
24 |
|
25 |
# Configuraci贸n de chunks
|
26 |
CHUNK_SIZE = 60 # 1 minuto por chunk
|
27 |
+
SEGMENT_DURATION = 18 # Duraci贸n base de cada segmento
|
28 |
+
TRANSITION_DURATION = 1.5 # Duraci贸n del efecto slide (ahora m谩s visible)
|
29 |
+
OVERLAP = TRANSITION_DURATION # El overlap ahora es igual a la duraci贸n de la transici贸n
|
30 |
|
31 |
def eliminar_archivo_tiempo(ruta, delay=1800):
|
32 |
def eliminar():
|
|
|
67 |
bg_music.export(tmp_bg.name, format="mp3")
|
68 |
return AudioFileClip(tmp_bg.name).volumex(0.15), tmp_bg.name
|
69 |
|
70 |
+
def create_slide_transition(clip1, clip2, duration=TRANSITION_DURATION):
|
71 |
+
"""Transici贸n slide con movimiento m谩s pronunciado"""
|
72 |
+
# Tomar la 煤ltima parte del clip1 y la primera parte del clip2
|
73 |
+
part1 = clip1.subclip(clip1.duration - duration)
|
74 |
+
part2 = clip2.subclip(0, duration)
|
75 |
+
|
76 |
+
# Crear animaci贸n de deslizamiento
|
77 |
transition = CompositeVideoClip([
|
78 |
+
part1.fx(vfx.fadeout, duration),
|
79 |
+
part2.fx(vfx.fadein, duration).set_position(
|
80 |
+
lambda t: ('center', 720 - (720 * (t/duration))) # Movimiento desde abajo
|
81 |
+
)
|
82 |
+
], size=(1280, 720)).set_duration(duration)
|
83 |
|
84 |
+
return transition
|
85 |
|
86 |
async def procesar_video(video_input, texto_tts, voz_seleccionada):
|
87 |
temp_files = []
|
|
|
91 |
video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
|
92 |
duracion_video = video_original.duration
|
93 |
|
94 |
+
# Generar TTS y m煤sica de fondo
|
95 |
tts_audio, tts_path = await generar_tts(texto_tts, voz_seleccionada, duracion_video)
|
96 |
bg_audio, bg_path = crear_musica_fondo(duracion_video)
|
97 |
temp_files.extend([tts_path, bg_path])
|
|
|
104 |
audios.append(tts_audio.set_start(0).volumex(0.85))
|
105 |
audio_final = CompositeAudioClip(audios).set_duration(duracion_video)
|
106 |
|
107 |
+
# Dividir video en segmentos con superposici贸n controlada
|
108 |
segments = []
|
109 |
current_time = 0
|
110 |
while current_time < duracion_video:
|
111 |
end_time = current_time + SEGMENT_DURATION
|
112 |
if end_time > duracion_video:
|
113 |
+
end_time = duracion_video
|
114 |
+
segment = video_original.subclip(current_time, end_time)
|
115 |
+
segments.append(segment)
|
116 |
+
current_time += (SEGMENT_DURATION - OVERLAP) # Avance considerando el overlap
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
+
# Construir video con transiciones
|
119 |
+
clips = []
|
120 |
+
for i in range(len(segments)):
|
121 |
+
if i == 0:
|
122 |
+
clips.append(segments[i])
|
123 |
+
else:
|
124 |
+
# Crear transici贸n entre el final del clip anterior y el inicio del actual
|
125 |
+
transition = create_slide_transition(clips[-1], segments[i])
|
126 |
+
clips.pop()
|
127 |
+
clips.append(transition)
|
128 |
+
clips.append(segments[i].subclip(TRANSITION_DURATION)) # Eliminar parte ya usada en transici贸n
|
129 |
+
|
130 |
+
# Combinar todo
|
131 |
+
video_final = concatenate_videoclips(clips, method="compose").set_audio(audio_final)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
# Agregar intro y outro
|
134 |
intro = VideoFileClip(INTRO_VIDEO, target_resolution=(720, 1280))
|